puzhibing
2023-06-01 c4a098e3f88bc5071e36b92b9e5dcceb51129957
management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TAgentController.java
@@ -1,10 +1,13 @@
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;
import com.stylefeng.guns.core.util.DateUtil;
import com.stylefeng.guns.modular.system.controller.resp.TAgentResp;
import com.stylefeng.guns.modular.system.controller.util.ExcelUtil;
@@ -21,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 +67,8 @@
    @Autowired
    private ITDriverWorkService tDriverWorkService;
    @Autowired
    private IUserService userService;
    @Autowired
    private RedisUtil redisUtil;
@@ -69,7 +76,8 @@
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
    public String index(Model model) {
        model.addAttribute("userType", Objects.requireNonNull(ShiroKit.getUser()).getRoleType());
        return PREFIX + "tAgent.html";
    }
@@ -156,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("/");
@@ -163,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(" ",""));
@@ -177,9 +190,30 @@
        tAgent.setProvinceName(province.getName());
        tAgent.setProvinceCode(province.getCode());
        TRegion city = tRegionService.selectById(split[1]);
        if(Objects.isNull(city)){
            city = tRegionService.selectOne(new EntityWrapper<TRegion>()
                    .eq("name",split[1])
                    .last("LIMIT 1"));
        }
        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;
    }