From d4202e0a054617cc1d18e5e5f92581cf9b07e1db Mon Sep 17 00:00:00 2001
From: ZQN <364596817@qq.com>
Date: 星期六, 22 六月 2024 10:35:06 +0800
Subject: [PATCH] 执法结果上报

---
 project-system/src/main/java/com/project/system/service/impl/SysCompanyServiceImpl.java |  151 ++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 126 insertions(+), 25 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 b92f1d6..b4df7a6 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
@@ -3,8 +3,10 @@
 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.core.domain.model.ImportError;
 import com.project.common.exception.base.BaseException;
 import com.project.common.utils.SecurityUtils;
+import com.project.system.domain.vo.SysCompanyResultVo;
 import com.project.system.service.ISysUserService;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -22,6 +24,7 @@
 import com.project.system.mapper.SysCompanyMapper;
 import com.project.system.service.ISysCompanyService;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
@@ -57,9 +60,11 @@
     public Boolean insertByBo(SysCompanyBo bo)
     {
         SysCompany add = Convert.convert(SysCompany.class, bo);
-        validEntityBeforeSave(add, 0);
+        add.setCompanyStatus(1);
+        validEntityBeforeSave(add);
+        add.setCompanyStatus(0);
         boolean save = this.save(add);
-        addCompanyUser(add);
+        addCompanyUser(add, 0);
         return save;
     }
 
@@ -74,10 +79,23 @@
             if (!delUser) {
                 throw new BaseException("鍘熶紒涓氱敤鎴锋竻闄ゅけ璐ワ紝璇疯仈绯荤鐞嗗憳锛�");
             }
-            this.addCompanyUser(update);
+            this.addCompanyUser(update, update.getCompanyStatus()==0 ? 1 : 0);
         }
-        validEntityBeforeSave(update, 0);
+        validEntityBeforeSave(update);
         return this.updateById(update);
+    }
+
+    @Override//鐘舵�佸紑鍏�
+    @Transactional
+    public Boolean updStatus(SysCompanyBo bo)
+    {
+        if (bo.getCompanyId()==null || bo.getCompanyStatus()==null) {
+            throw new BaseException("鍙傛暟鏈夎锛岀姸鎬佷慨鏀瑰け璐ワ紒");
+        }
+        SysCompany company = this.getById(bo.getCompanyId());
+        company.setCompanyStatus(bo.getCompanyStatus());
+        updCompanyUserStatus(company.getCompanyPhone(), bo.getCompanyStatus());
+        return this.updateById(company);
     }
 
     @Override//鍒犻櫎
@@ -93,18 +111,50 @@
         return this.removeByIds(ids);
     }
 
-    @Override//瀵煎叆
-    @Transactional
-    public Boolean importList(List<SysCompanyVo> list)
+
+    @Override
+    public SysCompanyResultVo doImport(List<SysCompanyVo> list)
     {
         if (list==null || list.size()<1){
-            throw new BaseException("鏈幏鍙栧埌瀵煎叆淇℃伅");
+            throw new BaseException("鏈幏鍙栧埌瀵煎叆淇℃伅锛�");
         }
-        List<SysCompany> companies = Convert.toList(SysCompany.class, list);
-        companies.forEach(e-> validEntityBeforeSave(e,1));
-        boolean b = this.saveOrUpdateBatch(companies);
+        SysCompanyResultVo resultVo = new SysCompanyResultVo();
+        resultVo.setVoList(list);
+        return this.checkImport(resultVo);
 
-        companies.forEach(this::addCompanyUser);
+    }
+
+    @Override
+    public SysCompanyResultVo checkImport(SysCompanyResultVo resultVo)
+    {
+        if (resultVo==null || StringUtils.isEmpty(resultVo.getVoList())){
+            throw new BaseException("鏈幏鍙栧埌瀵煎叆淇℃伅锛�");
+        }
+        for (SysCompanyVo vo : resultVo.getVoList()) {
+            List<ImportError> errors = new ArrayList<>();
+            validEntityBeforeImport(vo, errors);
+            vo.setErrorList(errors);
+        }
+        return  resultVo;
+    }
+
+    @Override
+    @Transactional
+    public Boolean saveImport(SysCompanyResultVo resultVo)
+    {
+        if (resultVo==null || StringUtils.isEmpty(resultVo.getVoList())){
+            throw new BaseException("鏈幏鍙栧埌瀵煎叆淇℃伅锛�");
+        }
+        resultVo.getVoList().forEach(e-> {
+            if (StringUtils.isNotEmpty(e.getErrorList())) {
+                throw new BaseException("杩樻湁鏈鐞嗛敊璇俊鎭紒");
+            }
+        });
+        List<SysCompany> companies = Convert.toList(SysCompany.class, resultVo.getVoList());
+        boolean b = this.saveOrUpdateBatch(companies);
+        for (SysCompany company : companies) {
+            addCompanyUser(company,1);
+        }
         return b;
     }
 
@@ -114,15 +164,12 @@
     /**
      * 淇濆瓨鍓嶆牎楠�
      * @param entity    鍙傛暟
-     * @param isImport  鏄惁瀵煎叆锛�0鍚︼紝1鏄�
      */
-    private void validEntityBeforeSave(SysCompany entity, int isImport)
+    private void validEntityBeforeSave(SysCompany entity)
     {
-        entity.setIsImport(isImport);
-        if (isImport!=1){
-            if (StringUtils.isEmpty(entity.getCompanyImg())){
-                throw new BaseException(String.format("%1$s锛岃涓婁紶钀ヤ笟鎵х収", entity.getCompanyName()));
-            }
+        entity.setIsImport(0);
+        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()));
@@ -132,6 +179,9 @@
         }
         if (StringUtils.isEmpty(entity.getCompanyPhone())){
             throw new BaseException(String.format("%1$s锛岃濉啓浼佷笟鑱旂郴浜虹數璇濓紒", entity.getCompanyName()));
+        }
+        if (StringUtils.isEmpty(entity.getCompanyAddress())){
+            throw new BaseException(String.format("%1$s锛岃濉啓浼佷笟鍦板潃锛�", entity.getCompanyName()));
         }
         if (StringUtils.isEmpty(entity.getCompanyName())){
             throw new BaseException("璇峰~鍐欎紒涓氬悕锛�");
@@ -149,6 +199,11 @@
             if (phoneCount>0){
                 throw new BaseException(String.format("%1$s锛屼紒涓氳仈绯荤數璇濆凡瀛樺湪锛�", entity.getCompanyName()));
             }
+            SysUser user = new SysUser();
+            user.setPhonenumber(entity.getCompanyPhone());
+            if (UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) {
+                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){
@@ -163,20 +218,61 @@
                 throw new BaseException(String.format("%1$s锛屼紒涓氳仈绯荤數璇濆凡瀛樺湪锛�", entity.getCompanyName()));
             }
         }
-        if (isImport==1){
-            entity.setCheckStatus(2);
-        }
     }
 
+
+    private void validEntityBeforeImport(SysCompanyVo entity, List<ImportError> errorList)
+    {
+        entity.setIsImport(1);
+        if (StringUtils.isEmpty(entity.getCompanyName())){
+            errorList.add(new ImportError(0, "璇峰~鍐欎紒涓氬悕锛�"));
+        }
+        if (StringUtils.isEmpty(entity.getCompanyCode())){
+            errorList.add(new ImportError(1, "璇峰~鍐欎紒涓氱ぞ浼氱紪鐮侊紒"));
+        }
+        if (StringUtils.isEmpty(entity.getCompanyUser())){
+            errorList.add(new ImportError(2, "璇峰~鍐欎紒涓氳仈绯讳汉锛�"));
+        }
+        if (StringUtils.isEmpty(entity.getCompanyPhone())){
+            errorList.add(new ImportError(3, "璇峰~鍐欎紒涓氳仈绯讳汉鐢佃瘽锛�"));
+        }
+        if (StringUtils.isEmpty(entity.getCompanyAddress())){
+            errorList.add(new ImportError(4, "璇峰~鍐欎紒涓氬湴鍧�锛�"));
+        }
+        int codeCount = this.count(lq().eq(SysCompany::getCompanyCode, entity.getCompanyCode()));
+        if (codeCount>0){
+            errorList.add(new ImportError(1, "浼佷笟绀句細缂栫爜宸插瓨鍦紒"));
+        }
+        int nameCount = this.count(lq().eq(SysCompany::getCompanyName, entity.getCompanyName()));
+        if (nameCount>0){
+            errorList.add(new ImportError(0, "浼佷笟鍚嶅凡瀛樺湪锛�"));
+        }
+        int phoneCount = this.count(lq().eq(SysCompany::getCompanyPhone, entity.getCompanyPhone()));
+        SysUser user = new SysUser();
+        user.setPhonenumber(entity.getCompanyPhone());
+        if (UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) {
+            errorList.add(new ImportError(3, "浼佷笟鑱旂郴鐢佃瘽绯荤粺涓凡瀛樺湪锛岃鏇存崲鐢佃瘽锛�"));
+        }
+        if (phoneCount>0){
+            errorList.add(new ImportError(3, "浼佷笟鑱旂郴鐢佃瘽宸插瓨鍦紒"));
+        }
+        entity.setCheckStatus(2);
+    }
 
     /**
      * 娣诲姞浼佷笟鐢ㄦ埛
      * @param entity    浼佷笟淇℃伅
      */
     @Async
-    protected void addCompanyUser(SysCompany entity)
+    protected void addCompanyUser(SysCompany entity, Integer isImport)
     {
+
         SysUser user = new SysUser();
+        if (isImport==1){
+            user.setStatus("0");
+        } else {
+            user.setStatus("1");
+        }
         SysCompany one = this.getOne(lq().eq(SysCompany::getCompanyCode, entity.getCompanyCode()));
         String phone = entity.getCompanyPhone();
         user.setPhonenumber(phone);
@@ -185,6 +281,7 @@
         user.setPassword(phone);
         user.setDeptId(one.getCompanyId());
         user.setUserType("02");
+        user.setRecommendUser(user.getPassword());
         if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user)))
         {
             return;
@@ -199,12 +296,16 @@
         {
             return;
         }
-        user.setCreateBy(SecurityUtils.getUsername());
         user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
-        user.setRecommendUser(user.getPassword());
         userService.insertUser(user);
     }
 
+    @Async
+    protected void updCompanyUserStatus(String phone, Integer status)
+    {
+        userService.update(userService.lu().set(SysUser::getStatus,status).eq(SysUser::getPhonenumber, phone));
+    }
+
     /**
      * 鍒犻櫎浼佷笟鐢ㄦ埛
      * @param companyId    浼佷笟id

--
Gitblit v1.9.1