From 3a2b86071fca71b4c789762ccb2dfaf7423b0c07 Mon Sep 17 00:00:00 2001 From: ZQN <364596817@qq.com> Date: 星期一, 17 六月 2024 18:56:31 +0800 Subject: [PATCH] 执法流程添加,企业导入添加 --- project-system/src/main/java/com/project/system/service/impl/SysCompanyServiceImpl.java | 153 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 141 insertions(+), 12 deletions(-) diff --git a/project-system/src/main/java/com/project/system/service/impl/SysCompanyServiceImpl.java b/project-system/src/main/java/com/project/system/service/impl/SysCompanyServiceImpl.java index 421b46c..ed25210 100644 --- a/project-system/src/main/java/com/project/system/service/impl/SysCompanyServiceImpl.java +++ b/project-system/src/main/java/com/project/system/service/impl/SysCompanyServiceImpl.java @@ -1,13 +1,18 @@ package com.project.system.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.project.common.constant.UserConstants; +import com.project.common.core.domain.entity.SysUser; +import com.project.common.exception.base.BaseException; +import com.project.common.utils.SecurityUtils; +import com.project.system.service.ISysUserService; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import cn.hutool.core.convert.Convert; import com.project.common.utils.StringUtils; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import org.springframework.transaction.annotation.Transactional; import com.project.system.domain.vo.SysCompanyVo; @@ -29,7 +34,7 @@ @RequiredArgsConstructor(onConstructor_ = @Autowired) public class SysCompanyServiceImpl extends ServiceImpl<SysCompanyMapper, SysCompany> implements ISysCompanyService { - + private final ISysUserService userService; @Override//鍒楄〃鏌ヨ public List<SysCompanyVo> queryList(SysCompanyQueryBo bo) @@ -52,16 +57,26 @@ public Boolean insertByBo(SysCompanyBo bo) { SysCompany add = Convert.convert(SysCompany.class, bo); - validEntityBeforeSave(add); - return this.save(add); + validEntityBeforeSave(add, 0); + boolean save = this.save(add); + addCompanyUser(add); + return save; } @Override//淇敼 @Transactional public Boolean updateByBo(SysCompanyBo bo) { + SysCompany old = this.getById(bo.getCompanyId()); SysCompany update = Convert.convert(SysCompany.class, bo); - validEntityBeforeSave(update); + if (!old.getCompanyPhone().equals(update.getCompanyPhone())){ + boolean delUser = delCompanyUser(old.getCompanyId()); + if (!delUser) { + throw new BaseException("鍘熶紒涓氱敤鎴锋竻闄ゅけ璐ワ紝璇疯仈绯荤鐞嗗憳锛�"); + } + this.addCompanyUser(update); + } + validEntityBeforeSave(update, 0); return this.updateById(update); } @@ -69,22 +84,136 @@ @Transactional public Boolean deleteByIds(Collection<Long> ids) { - - //鍋氫竴浜涗笟鍔′笂鐨勬牎楠�,鍒ゆ柇鏄惁闇�瑕佹牎楠� - + for (Long id : ids) { + boolean b = delCompanyUser(id); + if (!b) { + throw new BaseException(String.format("鍘熶紒涓� %1$s 鐢ㄦ埛娓呴櫎澶辫触锛岃鑱旂郴绠$悊鍛橈紒", id)); + } + } return this.removeByIds(ids); + } + + @Override//瀵煎叆 + @Transactional + public Boolean importList(List<SysCompanyVo> list) + { + if (list==null || list.size()<1){ + throw new BaseException("鏈幏鍙栧埌瀵煎叆淇℃伅"); + } + List<SysCompany> companies = Convert.toList(SysCompany.class, list); + companies.forEach(e-> validEntityBeforeSave(e,1)); + boolean b = this.saveOrUpdateBatch(companies); + + companies.forEach(this::addCompanyUser); + return b; } //------------------------------------------------------------------------------------- - //淇濆瓨鍓嶆牎楠� - private void validEntityBeforeSave(SysCompany entity) + /** + * 淇濆瓨鍓嶆牎楠� + * @param entity 鍙傛暟 + * @param isImport 鏄惁瀵煎叆锛�0鍚︼紝1鏄� + */ + private void validEntityBeforeSave(SysCompany entity, int isImport) { - //鍋氫竴浜涙暟鎹牎楠�,濡傚敮涓�绾︽潫 + if (isImport!=1){ + if (StringUtils.isEmpty(entity.getCompanyImg())){ + throw new BaseException(String.format("%1$s锛岃涓婁紶钀ヤ笟鎵х収", entity.getCompanyName())); + } + } + if (StringUtils.isEmpty(entity.getCompanyCode())){ + throw new BaseException(String.format("%1$s锛岃濉啓浼佷笟绀句細缂栫爜锛�", entity.getCompanyName())); + } + if (StringUtils.isEmpty(entity.getCompanyUser())){ + throw new BaseException(String.format("%1$s锛岃濉啓浼佷笟鑱旂郴浜猴紒", entity.getCompanyName())); + } + if (StringUtils.isEmpty(entity.getCompanyPhone())){ + throw new BaseException(String.format("%1$s锛岃濉啓浼佷笟鑱旂郴浜虹數璇濓紒", entity.getCompanyName())); + } + if (StringUtils.isEmpty(entity.getCompanyName())){ + throw new BaseException("璇峰~鍐欎紒涓氬悕锛�"); + } + if (entity.getCompanyId()==null){ //鏂板 + int codeCount = this.count(lq().eq(SysCompany::getCompanyCode, entity.getCompanyCode())); + if (codeCount>0){ + throw new BaseException(String.format("%1$s锛屼紒涓氱ぞ浼氱紪鐮佸凡瀛樺湪锛�", entity.getCompanyName())); + } + int nameCount = this.count(lq().eq(SysCompany::getCompanyName, entity.getCompanyName())); + if (nameCount>0){ + throw new BaseException(String.format("%1$s锛屼紒涓氬悕宸插瓨鍦紒", entity.getCompanyName())); + } + int phoneCount = this.count(lq().eq(SysCompany::getCompanyPhone, entity.getCompanyPhone())); + if (phoneCount>0){ + throw new BaseException(String.format("%1$s锛屼紒涓氳仈绯荤數璇濆凡瀛樺湪锛�", entity.getCompanyName())); + } + } else { + int codeCount = this.count(lq().eq(SysCompany::getCompanyCode, entity.getCompanyCode()).ne(SysCompany::getCompanyId,entity.getCompanyId())); + if (codeCount>0){ + throw new BaseException(String.format("%1$s锛屼紒涓氱ぞ浼氱紪鐮佸凡瀛樺湪锛�", entity.getCompanyName())); + } + int nameCount = this.count(lq().eq(SysCompany::getCompanyName, entity.getCompanyName()).ne(SysCompany::getCompanyId,entity.getCompanyId())); + if (nameCount>0){ + throw new BaseException(String.format("%1$s锛屼紒涓氬悕宸插瓨鍦紒", entity.getCompanyName())); + } + int phoneCount = this.count(lq().eq(SysCompany::getCompanyPhone, entity.getCompanyPhone()).ne(SysCompany::getCompanyId,entity.getCompanyId())); + if (phoneCount>0){ + throw new BaseException(String.format("%1$s锛屼紒涓氳仈绯荤數璇濆凡瀛樺湪锛�", entity.getCompanyName())); + } + } } - //鑾峰彇鏌ヨ鍙傛暟 + + /** + * 娣诲姞浼佷笟鐢ㄦ埛 + * @param entity 浼佷笟淇℃伅 + */ + @Async + protected void addCompanyUser(SysCompany entity) + { + SysUser user = new SysUser(); + SysCompany one = this.getOne(lq().eq(SysCompany::getCompanyCode, entity.getCompanyCode())); + String phone = entity.getCompanyPhone(); + user.setPhonenumber(phone); + user.setUserName(entity.getCompanyUser()); + user.setPassword(phone); + user.setDeptId(one.getCompanyId()); + user.setUserType("02"); + if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user))) + { + return; + } + else if (StringUtils.isNotEmpty(user.getPhonenumber()) + && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) + { + return; + } + else if (StringUtils.isNotEmpty(user.getEmail()) + && UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user))) + { + return; + } + user.setCreateBy(SecurityUtils.getUsername()); + user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); + user.setRecommendUser(user.getPassword()); + userService.insertUser(user); + } + + /** + * 鍒犻櫎浼佷笟鐢ㄦ埛 + * @param companyId 浼佷笟id + */ + protected boolean delCompanyUser(Long companyId) + { + return userService.deleteUserByDeptId(companyId)>0; + } + + /** + * 鑾峰彇鏌ヨ鍙傛暟 + * @param bo 鍙傛暟 + * @return 鏌ヨ鍙傛暟 + */ private QueryWrapper<SysCompany> getQw(SysCompanyQueryBo bo) { QueryWrapper<SysCompany> qw = Wrappers.query(); -- Gitblit v1.9.1