xuhy
2023-05-17 566c44cc5712ab9c997424ee5a5438e0a81a016e
management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TAgentController.java
@@ -1,8 +1,10 @@
package com.stylefeng.guns.modular.system.controller.general;
import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.base.tips.SuccessTip;
import com.stylefeng.guns.core.common.constant.state.ManagerStatus;
import com.stylefeng.guns.core.exception.GunsException;
import com.stylefeng.guns.core.exception.ServiceExceptionEnum;
import com.stylefeng.guns.core.shiro.ShiroKit;
@@ -22,6 +24,8 @@
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -62,6 +66,8 @@
    private ITDriverService tDriverService;
    @Autowired
    private ITDriverWorkService tDriverWorkService;
    @Autowired
    private IUserService userService;
    @Autowired
    private RedisUtil redisUtil;
@@ -158,6 +164,7 @@
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRES_NEW)
    public Object add(TAgent tAgent) {
        String[] split1 = tAgent.getArea().split("/");
@@ -165,7 +172,11 @@
        int count = tAgentService.selectCount(new EntityWrapper<TAgent>().eq("provinceName", split1[0]).eq("cityName",split1[1]));
        if(count>0){
            return new SuccessTip(500,"该代理商已存在!");
        }
        int count1 = userService.selectCount(new EntityWrapper<User>().eq("account", tAgent.getAccount()));
        if (count1 > 0){
            return new SuccessTip(500,"该账号已存在!");
        }
        tAgent.setPrincipal(tAgent.getPrincipal().replace(" ",""));
@@ -182,6 +193,22 @@
        tAgent.setCityName(city.getName());
        tAgent.setCityCode(city.getCode());
        tAgentService.insert(tAgent);
        //添加User对象
        User user = new User();
        user.setAccount(tAgent.getAccount());
        user.setSalt(ShiroKit.getRandomSalt(5));
        user.setPassword(ShiroKit.md5(tAgent.getPassword(), user.getSalt()));
        user.setStatus(ManagerStatus.OK.getCode());
        user.setRoleid("2");
        user.setDeptid(25);
        user.setCreatetime(new Date());
        user.setRoleType(3);
        user.setObjectId(tAgent.getId());
        user.setName(tAgent.getPrincipal());
        user.setSex(1);
        userService.insert(user);
        return SUCCESS_TIP;
    }