| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.basic.PageInfo; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.system.dto.TCrmBranchDTO; |
| | | import com.ruoyi.system.mapper.TCrmBranchAreaMapper; |
| | | import com.ruoyi.system.mapper.SysUserMapper; |
| | | import com.ruoyi.system.mapper.TCrmBranchMapper; |
| | | import com.ruoyi.system.model.TCrmBranch; |
| | | import com.ruoyi.system.model.TCrmBranchArea; |
| | | import com.ruoyi.system.model.TCrmDevice; |
| | | import com.ruoyi.system.model.TCrmBranchSalary; |
| | | import com.ruoyi.system.query.TCrmBranchQuery; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import com.ruoyi.system.service.TCrmBranchAreaService; |
| | | import com.ruoyi.system.service.TCrmBranchSalaryService; |
| | | import com.ruoyi.system.service.TCrmBranchService; |
| | | import com.ruoyi.system.vo.TCrmBranchVO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | public class TCrmBranchServiceImpl extends ServiceImpl<TCrmBranchMapper, TCrmBranch> implements TCrmBranchService { |
| | | |
| | | @Autowired |
| | | private TCrmBranchAreaMapper crmBranchAreaMapper; |
| | | private TCrmBranchAreaService crmBranchAreaService; |
| | | @Autowired |
| | | private TCrmBranchSalaryService crmBranchSalaryService; |
| | | @Autowired |
| | | private ISysUserService sysUserService; |
| | | |
| | | @Override |
| | | public PageInfo<TCrmBranchVO> pageList(TCrmBranchQuery query) { |
| | | List<TCrmBranchArea> crmBranchAreas = new ArrayList<>(); |
| | | if(StringUtils.isNotEmpty(query.getCityCode())){ |
| | | crmBranchAreas = crmBranchAreaMapper.selectList(Wrappers.lambdaQuery(TCrmBranchArea.class) |
| | | crmBranchAreas = crmBranchAreaService.list(Wrappers.lambdaQuery(TCrmBranchArea.class) |
| | | .eq(TCrmBranchArea::getCityCode, query.getCityCode())); |
| | | } |
| | | |
| | | if(!StringUtils.isNotEmpty(query.getCityCode()) && StringUtils.isNotEmpty(query.getProvinceCode())){ |
| | | crmBranchAreas = crmBranchAreaMapper.selectList(Wrappers.lambdaQuery(TCrmBranchArea.class) |
| | | crmBranchAreas = crmBranchAreaService.list(Wrappers.lambdaQuery(TCrmBranchArea.class) |
| | | .eq(TCrmBranchArea::getProvinceCode, query.getProvinceCode())); |
| | | } |
| | | if(!CollectionUtils.isEmpty(crmBranchAreas)){ |
| | |
| | | return pageInfo; |
| | | } |
| | | List<String> branchIds = list.stream().map(TCrmBranchVO::getId).collect(Collectors.toList()); |
| | | List<TCrmBranchArea> crmBranchAreaList = crmBranchAreaMapper.selectList(Wrappers.lambdaQuery(TCrmBranchArea.class) |
| | | List<TCrmBranchArea> crmBranchAreaList = crmBranchAreaService.list(Wrappers.lambdaQuery(TCrmBranchArea.class) |
| | | .in(TCrmBranchArea::getBranchId, branchIds)); |
| | | for (TCrmBranchVO tCrmBranchVO : list) { |
| | | List<TCrmBranchArea> tCrmBranchAreas = crmBranchAreaList.stream().filter(t -> t.getBranchId().equals(tCrmBranchVO.getId())).collect(Collectors.toList()); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public R<Boolean> add(TCrmBranchDTO dto) { |
| | | public R<Boolean> addBranch(TCrmBranchDTO dto) { |
| | | if (isExit(dto)) { |
| | | return R.fail("crm分公司管理名称已存在"); |
| | | } |
| | | return null; |
| | | // 判断账号是否已存在 |
| | | SysUser sysUser = sysUserService.selectUserByUserName(dto.getPhone()); |
| | | if(Objects.nonNull(sysUser)){ |
| | | return R.fail(dto.getPhone()+"-账号已存在"); |
| | | } |
| | | this.save(dto); |
| | | // 添加区域 |
| | | List<TCrmBranchArea> branchAreas = dto.getBranchAreas(); |
| | | branchAreas.forEach(t -> t.setBranchId(dto.getId())); |
| | | crmBranchAreaService.saveBatch(branchAreas); |
| | | // 添加职位薪资 |
| | | List<TCrmBranchSalary> branchSalaries = dto.getBranchSalaries(); |
| | | branchSalaries.forEach(t -> t.setBranchId(dto.getId())); |
| | | crmBranchSalaryService.saveBatch(branchSalaries); |
| | | // 添加账号 |
| | | SysUser user = new SysUser(); |
| | | user.setUserName(dto.getPhone()); |
| | | user.setPhonenumber(dto.getPhone()); |
| | | user.setNickName(dto.getUserName()); |
| | | user.setPassword(SecurityUtils.encryptPassword(dto.getPassword())); |
| | | user.setStatus("0"); |
| | | user.setDelFlag("0"); |
| | | user.setRoleType(2); |
| | | user.setRoleId(2L); |
| | | sysUserService.insertUser(user); |
| | | dto.setUserId(user.getUserId()); |
| | | this.updateById(dto); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | return this.count(Wrappers.lambdaQuery(TCrmBranch.class).eq(TCrmBranch::getBranchName, dto.getBranchName())) > 0; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public R<Boolean> updateBranch(TCrmBranchDTO dto) { |
| | | if (isExit(dto)) { |
| | | return R.fail("crm分公司管理名称已存在"); |
| | | } |
| | | // 判断账号是否已存在 |
| | | SysUser sysUser1 = sysUserService.selectUserByUserName(dto.getPhone()); |
| | | if(Objects.nonNull(sysUser1) && !sysUser1.getUserId().equals(dto.getUserId())){ |
| | | return R.fail(dto.getPhone()+"-账号已存在"); |
| | | } |
| | | SysUser user = sysUserService.selectUserById(dto.getUserId()); |
| | | this.updateById(dto); |
| | | // 删除区域 |
| | | crmBranchAreaService.remove(Wrappers.lambdaQuery(TCrmBranchArea.class).eq(TCrmBranchArea::getBranchId, dto.getId())); |
| | | // 添加区域 |
| | | List<TCrmBranchArea> branchAreas = dto.getBranchAreas(); |
| | | branchAreas.forEach(t -> t.setBranchId(dto.getId())); |
| | | crmBranchAreaService.saveBatch(branchAreas); |
| | | // 删除职位薪资 |
| | | crmBranchSalaryService.remove(Wrappers.lambdaQuery(TCrmBranchSalary.class).eq(TCrmBranchSalary::getBranchId, dto.getId())); |
| | | // 添加职位薪资 |
| | | List<TCrmBranchSalary> branchSalaries = dto.getBranchSalaries(); |
| | | branchSalaries.forEach(t -> t.setBranchId(dto.getId())); |
| | | crmBranchSalaryService.saveBatch(branchSalaries); |
| | | if(Objects.nonNull(user)){ |
| | | // 修改账号 |
| | | user.setPhonenumber(dto.getPhone()); |
| | | user.setUserName(dto.getPhone()); |
| | | user.setNickName(dto.getUserName()); |
| | | user.setPassword(SecurityUtils.encryptPassword(dto.getPassword())); |
| | | sysUserService.updateUser(user); |
| | | } |
| | | // if(Objects.nonNull(user) && user.getUserName().equals(dto.getPhone()) && StringUtils.isNotEmpty(dto.getPassword())) { |
| | | // // 修改密码 |
| | | // user.setPassword(SecurityUtils.encryptPassword(dto.getPassword())); |
| | | // sysUserService.updateUser(user); |
| | | // } |
| | | return R.ok(); |
| | | } |
| | | } |