Helius
2021-07-14 182248f071a545649f2ce60ee1aa21b653a97c84
add distrib/join
5 files added
3 files modified
151 ■■■■■ changed files
gc-core/src/main/java/com/xzx/gc/entity/AccountInfo.java 7 ●●●●● patch | view | raw | blame | history
gc-user/src/main/java/com/xzx/gc/user/controller/ApiDistribController.java 34 ●●●●● patch | view | raw | blame | history
gc-user/src/main/java/com/xzx/gc/user/dto/DistribJoinDto.java 17 ●●●●● patch | view | raw | blame | history
gc-user/src/main/java/com/xzx/gc/user/mapper/UserHeadRelateMapper.java 10 ●●●●● patch | view | raw | blame | history
gc-user/src/main/java/com/xzx/gc/user/mapper/UserShareInfoMapper.java 3 ●●●● patch | view | raw | blame | history
gc-user/src/main/java/com/xzx/gc/user/service/DistribService.java 64 ●●●●● patch | view | raw | blame | history
gc-user/src/main/resources/mapper/user/UserHeadRelateMapper.xml 8 ●●●●● patch | view | raw | blame | history
gc-user/src/main/resources/mapper/user/UserShareInfoMapper.xml 8 ●●●●● patch | view | raw | blame | history
gc-core/src/main/java/com/xzx/gc/entity/AccountInfo.java
@@ -42,6 +42,8 @@
    private Short adjustFlag;
    private String isProhibit;
    public static final String IS_PROHIBIT_Y = "1";
    public static final String IS_PROHIBIT_N = "0";
    private String createTime;
    private String updateTime;
@@ -70,5 +72,10 @@
//    @ApiModelProperty("用户所在区域ID")
//    private transient String townId;
    private Integer isHead;
    public static final Integer IS_HEAD_Y = 1;
    public static final Integer IS_HEAD_N = 2;
}
gc-user/src/main/java/com/xzx/gc/user/controller/ApiDistribController.java
New file
@@ -0,0 +1,34 @@
package com.xzx.gc.user.controller;
import com.xzx.gc.common.request.BaseController;
import com.xzx.gc.model.JsonResult;
import com.xzx.gc.user.dto.DistribJoinDto;
import com.xzx.gc.user.service.DistribService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
/**
 * @author wzy
 * @date 2021-07-14
 **/
@Api(tags = "小程序接口参数类")
@Slf4j
@RestController
public class ApiDistribController extends BaseController {
    @Autowired
    private DistribService distribService;
    @ApiOperation("加入团队")
    @PostMapping(value = "/distrib/join")
    public JsonResult<String> join(DistribJoinDto distribJoinDto, HttpServletRequest request) {
        distribService.join(distribJoinDto.getHeadId(), getUserId(request));
        return JsonResult.success();
    }
}
gc-user/src/main/java/com/xzx/gc/user/dto/DistribJoinDto.java
New file
@@ -0,0 +1,17 @@
package com.xzx.gc.user.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
 * @author wzy
 * @date 2021-07-14
 **/
@Data
@ApiModel(value = "DistribJoinDto", description = "加入团长参数接收类")
public class DistribJoinDto {
    @ApiModelProperty(value = "团长ID")
    private String headId;
}
gc-user/src/main/java/com/xzx/gc/user/mapper/UserHeadRelateMapper.java
New file
@@ -0,0 +1,10 @@
package com.xzx.gc.user.mapper;
import com.xzx.gc.entity.UserHeadRelate;
import com.xzx.gc.util.GcMapper;
import org.apache.ibatis.annotations.Param;
public interface UserHeadRelateMapper extends GcMapper<UserHeadRelate> {
    UserHeadRelate selectMemberByUserId(@Param("userId") String userId);
}
gc-user/src/main/java/com/xzx/gc/user/mapper/UserShareInfoMapper.java
@@ -2,12 +2,13 @@
import com.xzx.gc.entity.UserShareInfo;
import com.xzx.gc.util.GcMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
@Repository
public interface UserShareInfoMapper extends GcMapper<UserShareInfo> {
    UserShareInfo selectByRegistPhone(@Param("registPhone") String registPhone);
}
gc-user/src/main/java/com/xzx/gc/user/service/DistribService.java
@@ -1,16 +1,80 @@
package com.xzx.gc.user.service;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.xzx.gc.common.exception.RestException;
import com.xzx.gc.entity.AccountInfo;
import com.xzx.gc.entity.SysMessage;
import com.xzx.gc.entity.UserHeadRelate;
import com.xzx.gc.entity.UserShareInfo;
import com.xzx.gc.user.mapper.AccountMapper;
import com.xzx.gc.user.mapper.SysMessageMapper;
import com.xzx.gc.user.mapper.UserHeadRelateMapper;
import com.xzx.gc.user.mapper.UserShareInfoMapper;
import com.xzx.gc.user.vo.ViewSettingVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.Date;
@Service
@Transactional
public class DistribService {
    @Autowired
    private UserHeadRelateMapper userHeadRelateMapper;
    @Autowired
    private AccountMapper accountMapper;
    @Autowired
    private UserShareInfoMapper userShareInfoMapper;
    @Autowired
    private SysMessageMapper sysMessageMapper;
    public ViewSettingVo viewSetting(Long id) {
        ViewSettingVo viewSettingVo = new ViewSettingVo();
        return viewSettingVo;
    }
    public void join(String headId, String userId) {
        AccountInfo headInfo = accountMapper.selectOneByUserId(headId);
        if (AccountInfo.IS_HEAD_N.equals(headInfo.getIsHead())) {
            throw new RestException(-3, "不是团长");
        }
        if (AccountInfo.IS_PROHIBIT_Y.equals(headInfo.getIsProhibit())) {
            throw new RestException(-3, "该用户被冻结");
        }
        UserHeadRelate existHeadRelate = userHeadRelateMapper.selectMemberByUserId(userId);
        if (existHeadRelate != null) {
            throw new RestException(-3, "已加入其他团队");
        }
        AccountInfo accountInfo = accountMapper.selectOneByUserId(userId);
        UserShareInfo userShareInfo = userShareInfoMapper.selectByRegistPhone(accountInfo.getAccountName());
        if (userShareInfo != null) {
            throw new RestException(-3, "您已与推广员绑定, 无法加入");
        }
        UserHeadRelate userHeadRelate = new UserHeadRelate();
        userHeadRelate.setHeadUserId(headId);
        userHeadRelate.setUserId(userId);
        userHeadRelate.setScore(BigDecimal.ZERO);
        userHeadRelate.setAmount(BigDecimal.ZERO);
        userHeadRelateMapper.insert(userHeadRelate);
        SysMessage sysMessage = new SysMessage();
        sysMessage.setCreateTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
        sysMessage.setCreateUserId(userId);
        sysMessage.setMobilePhone(accountInfo.getAccountName());
        sysMessage.setMessageType("4");
        sysMessage.setMessage("手机号:" + accountInfo.getAccountName() + "的用户, 成功加入您的团队");
        sysMessage.setFlag("2");
        sysMessageMapper.insert(sysMessage);
    }
}
gc-user/src/main/resources/mapper/user/UserHeadRelateMapper.xml
New file
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xzx.gc.user.mapper.UserHeadRelateMapper">
    <select id="selectMemberByUserId" resultType="com.xzx.gc.entity.UserHeadRelate">
        select * from xzx_user_head_relate where user_id=#{userId}
    </select>
</mapper>
gc-user/src/main/resources/mapper/user/UserShareInfoMapper.xml
New file
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xzx.gc.user.mapper.UserShareInfoMapper">
    <select id="selectByRegistPhone" resultType="com.xzx.gc.entity.UserShareInfo">
        select * from xzx_user_share_info where register_mobile_phone=#{registPhone}
    </select>
</mapper>