guanglong 3 лет назад
Родитель
Сommit
91b483f8e1

+ 88 - 41
mp-admin/src/main/java/com/qs/mp/web/controller/api/channel/ChannelController.java

@@ -1,16 +1,24 @@
 package com.qs.mp.web.controller.api.channel;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.qs.mp.channel.domain.Channel;
+import com.qs.mp.channel.domain.ChannelAddr;
+import com.qs.mp.channel.domain.param.ChannelParam;
 import com.qs.mp.channel.domain.vo.ChannelVO;
 import com.qs.mp.channel.service.IChannelService;
 import com.qs.mp.common.core.domain.AjaxResult;
 import com.qs.mp.common.core.page.TableDataInfo;
 import com.qs.mp.common.enums.ErrorCodeEnum;
 import com.qs.mp.system.service.id.BizIdGenerator;
+import com.qs.mp.utils.SecurityUtils;
 import com.qs.mp.web.controller.common.BaseApiController;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import ma.glasnost.orika.MapperFacade;
+
+import java.util.Date;
 import java.util.List;
 
 import org.apache.commons.lang3.StringUtils;
@@ -18,6 +26,7 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.stereotype.Component;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -34,50 +43,88 @@ import org.springframework.web.bind.annotation.RestController;
 @Component
 public class ChannelController extends BaseApiController {
 
-  @Autowired
-  private IChannelService channelService;
+	@Autowired
+	private IChannelService channelService;
+
+	@Autowired
+	private BizIdGenerator bizIdGenerator;
+
+	@Autowired
+	private MapperFacade mapperFacade;
+
+	/**
+	 * 子渠道列表查询
+	 *
+	 * @return
+	 */
+	@PostMapping("subchannel/list")
+	public TableDataInfo list(@RequestBody Channel channel) {
+		startPage();
+		List<Channel> list = channelService.list(new LambdaQueryWrapper<Channel>());
+		return getDataTable(list);
+	}
+
+	/**
+	 * 获取我的下级渠道详情信息
+	 *
+	 * @param
+	 * @return
+	 */
+	@PostMapping(value = "subchannel/detail")
+	public AjaxResult getInfo(@RequestBody Channel channel) {
+		if (null == channel || null == channel.getChannelId()) {
+			return error(ErrorCodeEnum.ERROR_CODE_1001);
+		}
+
+		Long channelId = channel.getChannelId();
+		ChannelVO channelVO = new ChannelVO();
+		Channel queryChannel = channelService.getById(channelId);
+	    BeanUtils.copyProperties(queryChannel, channelVO);
+		return AjaxResult.success(channelVO);
+	}
 
-  @Autowired
-  private BizIdGenerator bizIdGenerator;
+	/**
+	 * 增子渠道信息
+	 * @param
+	 * @return
+	 */
+	@ApiOperation(value = "新增子渠道信息", notes = "渠道端新增子渠道")
+	@PostMapping("subchannel/create")
+	public AjaxResult addChannel(@Validated @RequestBody ChannelParam channelParam) {
+		if (channelParam.getChannelId() != null && channelParam.getChannelId() != 0) {
+			return AjaxResult.error("该渠道已存在");
+		}
+		Long channelId = SecurityUtils.getLoginUser().getChannelId();
 
-  /**
-   * 子渠道列表查询
-   *
-   * @return
-   */
-  @PostMapping("subchannel/list")
-  public TableDataInfo list(@RequestBody Channel channel) {
+		Channel channel = mapperFacade.map(channelParam, Channel.class);
+		channel.setParentId(channelId);
+		try {
+			channelService.saveChannel(channel);
+		} catch (Exception e) {
+			return AjaxResult.error("新增子渠道信息'" + channel.getName() + "'失败");
+		}
+		return AjaxResult.success("新增子渠道信息'" + channel.getName() + "'成功");
+	}
 
-    startPage();
-    List<Channel> list = channelService.list(new LambdaQueryWrapper<Channel>());
-    return getDataTable(list);
-  }
-  
-  
-  /**
-   * 获取我的下级渠道详情信息
-   *
-   * @param
-   * @return
-   */
-  @PostMapping(value = "subchannel/detail")
-  public AjaxResult getInfo(@RequestBody Channel channel) {
-    if (null == channel || null == channel.getChannelId()) {
-      return error(ErrorCodeEnum.ERROR_CODE_1001);
-    }
+	/**
+	 * 编辑子渠道信息
+	 * @param
+	 * @return
+	 */
+	@ApiOperation(value = "编辑子渠道信息", notes = "渠道端编辑子渠道")
+	@PostMapping("subchannel/update")
+	public AjaxResult editChannel(@Validated @RequestBody ChannelParam channelParam) {
 
-    Long channelId = channel.getChannelId();
-    ChannelVO channelVO = new ChannelVO();
-//    try {
-//      Customer queryCustomer = customerService.getById(custId);
-//      BeanUtils.copyProperties(queryCustomer, queryCustomerVO);
-//      int totalShopCnt = shopService.count(new QueryWrapper<Shop>().lambda()
-//          .eq(Shop::getCustId, hostHolder.getUser().getCustId()).in(Shop::getShopType, ShopTypeEnum.getShopTypes()));
-//      queryCustomerVO.setShopNum(totalShopCnt);
-//    } catch (DataOperationException e) {
-//      return AjaxResult.error(e.getCode(), e.getMessage(), null);
-//    }
-    return AjaxResult.success(channelVO);
-  }
+		if (null == channelParam || null == channelParam.getChannelId()) {
+			return error(ErrorCodeEnum.ERROR_CODE_1001);
+		}
+		Channel channel = mapperFacade.map(channelParam, Channel.class);
+		try {
+			channelService.updateChannel(channel);
+		} catch (Exception e) {
+			return AjaxResult.error("编辑子渠道信息'" + channel.getName() + "'失败");
+		}
+		return AjaxResult.success("编辑子渠道信息'" + channel.getName() + "'成功");
+	}
 
 }

+ 55 - 0
mp-service/src/main/java/com/qs/mp/channel/domain/param/ChannelParam.java

@@ -0,0 +1,55 @@
+package com.qs.mp.channel.domain.param;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.math.BigDecimal;
+
+import javax.validation.constraints.NotNull;
+
+import lombok.Data;
+
+@ApiModel(value= "地址参数")
+@Data
+public class ChannelParam {
+
+	@ApiModelProperty(value = "渠道ID",required=false)
+	private Long channelId;
+
+	@NotNull(message = "手机不能为空")
+	@ApiModelProperty(value = "手机",required=true)
+	private String mobile;
+	
+	@NotNull(message = "渠道名称不能为空")
+	@ApiModelProperty(value = "渠道名称",required=true)
+	private String name;
+
+	@NotNull(message = "省ID不能为空")
+	@ApiModelProperty(value = "省ID",required=true)
+	private Long provinceId;
+
+	@NotNull(message = "城市ID不能为空")
+	@ApiModelProperty(value = "城市ID",required=true)
+	private Long cityId;
+
+	@NotNull(message = "区ID不能为空")
+	@ApiModelProperty(value = "区ID",required=true)
+	private Long areaId;
+
+	@NotNull(message = "省不能为空")
+	@ApiModelProperty(value = "省",required=true)
+	private String province;
+
+	@NotNull(message = "城市不能为空")
+	@ApiModelProperty(value = "城市",required=true)
+	private String city;
+
+	@NotNull(message = "区不能为空")
+	@ApiModelProperty(value = "区",required=true)
+	private String area;
+
+	@NotNull(message = "分佣百分比不能为空")
+	@ApiModelProperty(value = "分佣百分比",required=true)
+    private BigDecimal commRate;
+
+}

+ 19 - 0
mp-service/src/main/java/com/qs/mp/channel/service/IChannelService.java

@@ -16,6 +16,25 @@ import com.baomidou.mybatisplus.extension.service.IService;
  * @since 2022-03-02
  */
 public interface IChannelService extends IService<Channel> {
+	
+    
+	/**
+	 * 新增子渠道信息
+	 * 
+	 * @param channel
+	 * @return
+	 */
+    public void saveChannel(Channel channel) throws Exception;
+    
+    
+    /**
+	 * 编辑子渠道信息
+	 * 
+	 * @param channel
+	 * @return
+	 */
+    public void updateChannel(Channel channel) throws Exception;
+    
 
 	/**
 	 * 获取我的下级渠道列表信息,支持翻页

+ 31 - 4
mp-service/src/main/java/com/qs/mp/channel/service/impl/ChannelServiceImpl.java

@@ -5,11 +5,16 @@ import com.qs.mp.channel.domain.Channel;
 import com.qs.mp.channel.domain.vo.ChannelVO;
 import com.qs.mp.channel.mapper.ChannelMapper;
 import com.qs.mp.channel.service.IChannelService;
+import com.qs.mp.system.service.ISysUserService;
+import com.qs.mp.system.service.id.BizIdGenerator;
+import com.qs.mp.utils.SecurityUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
 import java.util.List;
 
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 /**
  * <p>
@@ -22,21 +27,43 @@ import org.springframework.stereotype.Service;
 @Service
 public class ChannelServiceImpl extends ServiceImpl<ChannelMapper, Channel> implements IChannelService {
 
+	@Autowired
+	private IChannelService channelService;
+	
+    @Autowired
+    private ISysUserService userService;
+
+	@Autowired
+	private BizIdGenerator bizIdGenerator;
+
+	@Override
+	@Transactional
+	public void saveChannel(Channel channel) throws Exception {
+		// 1、校验名称是否重复、手机号是否存在(渠道表)
+		
+
+	}
+	
+
+	@Override
+	public void updateChannel(Channel channel) throws Exception {
+		// 1、校验修改子渠道是否为当前用户的子渠道
+		Long channelId = SecurityUtils.getLoginUser().getChannelId();
+
+	}
+
 	@Override
 	public List<ChannelVO> selectVoList(Channel channel) {
 
 		return null;
 	}
-	
-	
+
 	@Override
 	public ChannelVO getVoById(Long channelId) {
 		// TODO Auto-generated method stub
 		return null;
 	}
 
-
-
 	@Override
 	public Channel getChannelByUserId(Long userId) {
 		return getBaseMapper().selectOne(new LambdaQueryWrapper<Channel>().eq(Channel::getUserId, userId));