| | |
| | | package com.stylefeng.guns.modular.system.controller.general; |
| | | |
| | | import cn.hutool.crypto.SecureUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | 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.shiro.ShiroKit; |
| | | import com.stylefeng.guns.core.util.SinataUtil; |
| | | import com.stylefeng.guns.modular.system.controller.resp.TBranchOfficeResp; |
| | | import com.stylefeng.guns.modular.system.controller.resp.TDriverResp; |
| | | import com.stylefeng.guns.modular.system.enums.StatusEnum; |
| | |
| | | import io.swagger.annotations.ApiOperation; |
| | | 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; |
| | |
| | | private ITDriverService tDriverService; |
| | | @Autowired |
| | | private ITDriverWorkService tDriverWorkService; |
| | | @Autowired |
| | | private IUserService userService; |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | |
| | |
| | | */ |
| | | @RequestMapping(value = "/add") |
| | | @ResponseBody |
| | | @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRES_NEW) |
| | | public Object add(TBranchOffice tBranchOffice) { |
| | | int count = tBranchOfficeService.selectCount(new EntityWrapper<TBranchOffice>().eq("branchOfficeName", tBranchOffice.getBranchOfficeName())); |
| | | if(count>0){ |
| | | return new SuccessTip(500,"该分公司名称已存在!"); |
| | | } |
| | | int count1 = userService.selectCount(new EntityWrapper<User>().eq("account", tBranchOffice.getAccount())); |
| | | if (count1 > 0){ |
| | | return new SuccessTip(500,"该账号已存在!"); |
| | | } |
| | | |
| | | Object o = tBranchOfficeService.addOrUpdate(tBranchOffice); |
| | |
| | | tBranchOffice.setStatus(StatusEnum.NORMAL.getCode()); |
| | | |
| | | tBranchOfficeService.insert(tBranchOffice); |
| | | |
| | | //添加User对象 |
| | | User user = new User(); |
| | | user.setAccount(tBranchOffice.getAccount()); |
| | | user.setSalt(ShiroKit.getRandomSalt(5)); |
| | | user.setPassword(ShiroKit.md5(tBranchOffice.getPassword(), user.getSalt())); |
| | | user.setStatus(ManagerStatus.OK.getCode()); |
| | | user.setRoleid("3"); |
| | | user.setDeptid(25); |
| | | user.setCreatetime(new Date()); |
| | | user.setRoleType(2); |
| | | user.setObjectId(tBranchOffice.getId()); |
| | | user.setName(tBranchOffice.getPrincipal()); |
| | | user.setSex(1); |
| | | userService.insert(user); |
| | | |
| | | return SUCCESS_TIP; |
| | | } |
| | | |
| | |
| | | */ |
| | | @RequestMapping(value = "/update") |
| | | @ResponseBody |
| | | @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRES_NEW) |
| | | public Object update(TBranchOffice tBranchOffice) { |
| | | TBranchOffice branchOffice = tBranchOfficeService.selectById(tBranchOffice.getId()); |
| | | User user = userService.selectOne(new EntityWrapper<User>() |
| | | .eq("role_type", 2) |
| | | .eq("object_id", branchOffice.getId()) |
| | | .last("LIMIT 1")); |
| | | //判断账号是否已存在 |
| | | if (SinataUtil.isNotEmpty(tBranchOffice.getAccount()) && SinataUtil.isNotEmpty(tBranchOffice.getPassword())){ |
| | | if(Objects.isNull(user)){ |
| | | //添加User对象 |
| | | user.setAccount(tBranchOffice.getAccount()); |
| | | user.setSalt(ShiroKit.getRandomSalt(5)); |
| | | user.setPassword(ShiroKit.md5(tBranchOffice.getPassword(), user.getSalt())); |
| | | user.setStatus(ManagerStatus.OK.getCode()); |
| | | user.setRoleid("3"); |
| | | user.setDeptid(25); |
| | | user.setCreatetime(new Date()); |
| | | user.setRoleType(2); |
| | | user.setObjectId(tBranchOffice.getId()); |
| | | user.setName(tBranchOffice.getPrincipal()); |
| | | user.setSex(1); |
| | | userService.insert(user); |
| | | }else { |
| | | if (!tBranchOffice.getAccount().equals(user.getAccount())){ |
| | | //判断账号是否已存在 |
| | | int count = userService.selectCount(new EntityWrapper<User>().eq("account", tBranchOffice.getAccount())); |
| | | if (count > 0){ |
| | | return new SuccessTip(500,"该账号已存在!"); |
| | | } |
| | | } |
| | | user.setAccount(tBranchOffice.getAccount()); |
| | | user.setPassword(ShiroKit.md5(user.getPassword(), user.getSalt())); |
| | | userService.updateById(user); |
| | | } |
| | | } |
| | | |
| | | TBranchOffice office = tBranchOfficeService.selectOne(new EntityWrapper<TBranchOffice>().eq("branchOfficeName", tBranchOffice.getBranchOfficeName()) |
| | | .last("LIMIT 1")); |
| | | if(Objects.nonNull(office) && !tBranchOffice.getId().equals(office.getId())){ |