From 5506edbe54883b31db3cc8e4a1d9d0795a18a3c9 Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期五, 27 十二月 2024 14:37:54 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/2.0.1' into 2.0.1

---
 server/service/src/main/java/com/doumee/service/business/impl/CompanyUserApplyServiceImpl.java |  284 +++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 226 insertions(+), 58 deletions(-)

diff --git a/server/service/src/main/java/com/doumee/service/business/impl/CompanyUserApplyServiceImpl.java b/server/service/src/main/java/com/doumee/service/business/impl/CompanyUserApplyServiceImpl.java
index fcfbb13..b8df447 100644
--- a/server/service/src/main/java/com/doumee/service/business/impl/CompanyUserApplyServiceImpl.java
+++ b/server/service/src/main/java/com/doumee/service/business/impl/CompanyUserApplyServiceImpl.java
@@ -1,20 +1,35 @@
 package com.doumee.service.business.impl;
 
+import com.doumee.biz.system.SystemDictDataBiz;
+import com.doumee.core.constants.ResponseStatus;
+import com.doumee.core.exception.BusinessException;
+import com.doumee.core.model.LoginUserInfo;
 import com.doumee.core.model.PageData;
 import com.doumee.core.model.PageWrap;
+import com.doumee.core.utils.Constants;
 import com.doumee.core.utils.Utils;
-import com.doumee.dao.business.CompanyUserApplyMapper;
-import com.doumee.dao.business.model.CompanyUserApply;
+import com.doumee.dao.business.*;
+import com.doumee.dao.business.join.CompanyUserApplyJoinMapper;
+import com.doumee.dao.business.model.*;
+import com.doumee.dao.system.SystemUserMapper;
+import com.doumee.dao.system.model.SystemDictData;
+import com.doumee.dao.system.model.SystemUser;
 import com.doumee.service.business.CompanyUserApplyService;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.github.yulichang.base.MPJBaseMapper;
+import com.github.yulichang.query.MPJQueryWrapper;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
+import org.apache.commons.lang.StringUtils;
+import org.apache.shiro.SecurityUtils;
+import org.checkerframework.checker.units.qual.A;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
-import java.util.List;
+import java.util.*;
 
 /**
  * 闆嗗洟鐢宠璁板綍琛⊿ervice瀹炵幇
@@ -26,16 +41,119 @@
 
     @Autowired
     private CompanyUserApplyMapper companyUserApplyMapper;
+    @Autowired
+    private SystemUserMapper systemUserMapper;
+    @Autowired
+    private CompanyMapper companyMapper;
+    @Autowired
+    private MultifileMapper multifileMapper;
+    @Autowired
+    private CompanyUserApplyJoinMapper companyUserApplyJoinMapper;
+    @Autowired
+    private SystemDictDataBiz systemDictDataBiz;
+    @Autowired
+    private CompanyPermissionMapper companyPermissionMapper;
+    @Autowired
+    private NoticesMapper noticesMapper;
+
 
     @Override
     public Integer create(CompanyUserApply companyUserApply) {
+        LoginUserInfo loginUserInfo =(LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+        if(Objects.isNull(companyUserApply)
+            || Objects.isNull(companyUserApply.getUserId())
+            || CollectionUtils.isEmpty(companyUserApply.getMultifileList())
+            || StringUtils.isBlank(companyUserApply.getCompanyIds())
+            || StringUtils.isBlank(companyUserApply.getCompanyNames())){
+            throw new BusinessException(ResponseStatus.BAD_REQUEST);
+        }
+        if(!Constants.equalsInteger(loginUserInfo.getType(),Constants.ONE)){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鐧诲綍鐢ㄦ埛涓嶅厑璁稿綋鍓嶆搷浣�");
+        }
+        //鏌ヨ褰撳墠鐢ㄦ埛鏄惁瀛樺湪鐢宠涓�
+        if(companyUserApplyMapper.selectCount(new QueryWrapper<CompanyUserApply>().lambda()
+                .eq(CompanyUserApply::getUserId,companyUserApply.getUserId())
+                .eq(CompanyUserApply::getIsdeleted, Constants.ZERO)
+                .eq(CompanyUserApply::getStatus,Constants.ZERO))>Constants.ZERO){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"褰撳墠璐︽埛瀛樺湪寰呭鎵规暟鎹紝鏃犳硶杩涜鐢宠");
+        };
+        SystemUser applyUser = systemUserMapper.selectById(companyUserApply.getUserId());
+        if(Objects.isNull(applyUser)){
+            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌鐢宠鐢ㄦ埛淇℃伅");
+        }
+        Company applyCompany = companyMapper.selectById(applyUser.getCompanyId());
+        if(Objects.isNull(applyCompany)){
+            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌鐢宠鐢ㄦ埛浼佷笟淇℃伅");
+        }
+
+        List<String> companyIds = Arrays.asList(companyUserApply.getCompanyIds().split(","));
+        for (String companyId:companyIds) {
+            if(Constants.equalsInteger(loginUserInfo.getCompanyId(),Integer.valueOf(companyId))){
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鏃犳硶鐢宠褰掑睘鍏徃鏉冮檺");
+            }
+            if(companyPermissionMapper.selectCount(new QueryWrapper<CompanyPermission>().lambda()
+                    .eq(CompanyPermission::getCompanyId,companyId)
+                    .eq(CompanyPermission::getIsdeleted,Constants.ZERO)
+                    .eq(CompanyPermission::getUserId,companyUserApply.getUserId()))>Constants.ZERO
+            ){
+                Company company = companyMapper.selectById(companyId);
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"浼佷笟銆�"+company.getName()+"銆戝凡鐢宠,璇峰嬁閲嶅鐢宠!");
+            };
+        }
+        List<Company> companyList = companyMapper.selectList(new QueryWrapper<Company>().lambda()
+                .eq(Company::getIsdeleted, Constants.ZERO)
+                .eq(Company::getType,Constants.ZERO)
+                .in(Company::getId, companyIds)
+        );
+        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(companyList) || !Constants.equalsInteger(companyList.size(),companyIds.size())){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"浼佷笟淇℃伅寮傚父锛岃妫�鏌ラ�夋嫨浼佷笟淇℃伅");
+        }
+        companyUserApply.setStatus(Constants.ZERO);
+        companyUserApply.setIsdeleted(Constants.ZERO);
+        companyUserApply.setCreateDate(new Date());
+        companyUserApply.setCreator(loginUserInfo.getId());
         companyUserApplyMapper.insert(companyUserApply);
+
+        List<Multifile> multifileList = companyUserApply.getMultifileList();
+        for (Multifile multifile:multifileList) {
+            multifile.setIsdeleted(Constants.ZERO);
+            multifile.setCreator(loginUserInfo.getId());
+            multifile.setCreateDate(new Date());
+            multifile.setObjId(companyUserApply.getId());
+            multifile.setObjType(Constants.MultiFile.COMPANY_USER_APPLY.getKey());
+            multifileMapper.insert(multifile);
+        }
+
+        //瀛樺偍寰呭姙淇℃伅
+        Constants.NoticeObjectType noticeObjectType = Constants.NoticeObjectType.COMPANY_USER_APPLY;
+        //骞冲彴寰呭姙
+        Notices notices = new Notices(noticeObjectType,
+                Constants.ZERO
+                ,companyUserApply.getId(),
+                applyCompany.getName() + " - " + applyUser.getRealname() +"鎻愪氦闆嗗洟璐﹀彿鐢宠" ,
+                null
+                ,Constants.NoticeType.ZERO);
+        noticesMapper.insert(notices);
+
         return companyUserApply.getId();
     }
 
     @Override
     public void deleteById(Integer id) {
-        companyUserApplyMapper.deleteById(id);
+        LoginUserInfo loginUserInfo =(LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+        CompanyUserApply companyUserApply = companyUserApplyMapper.selectById(id);
+        if(Objects.isNull(companyUserApply)){
+            throw new BusinessException(ResponseStatus.DATA_EMPTY);
+        }
+        if(!Constants.equalsInteger(companyUserApply.getStatus(),Constants.ZERO)){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"褰撳墠涓氬姟鐘舵�佸凡娴佽浆锛屼笉鍏佽璇ユ搷浣�");
+        }
+        companyUserApplyMapper.update(null,new UpdateWrapper<CompanyUserApply>().lambda()
+                .set(CompanyUserApply::getIsdeleted,Constants.ONE)
+                .set(CompanyUserApply::getEditDate,new Date())
+                .set(CompanyUserApply::getEditor,loginUserInfo.getId())
+                .eq(CompanyUserApply::getId,id)
+        );
     }
 
     @Override
@@ -69,7 +187,35 @@
 
     @Override
     public CompanyUserApply findById(Integer id) {
-        return companyUserApplyMapper.selectById(id);
+        CompanyUserApply companyUserApply = companyUserApplyJoinMapper.selectJoinOne(CompanyUserApply.class,new MPJLambdaWrapper<CompanyUserApply>()
+                 .selectAll(CompanyUserApply.class)
+                 .select(" t3.name as companyName ")
+                 .select(" t1.REALNAME as realName ")
+                 .select(" t2.USERNAME as userName ")
+                 .leftJoin(" system_user t1 on t1.id = t.creator  ")
+                 .leftJoin(" system_user t2 on t2.id = t.user_id  ")
+                 .leftJoin(" company t3 on t3.id = t2.company_id  ")
+                .eq(CompanyUserApply::getId,id));
+        if(Objects.isNull(companyUserApply)){
+            throw new BusinessException(ResponseStatus.DATA_EMPTY);
+        }
+        List<Multifile> multifileList = multifileMapper.selectList(new QueryWrapper<Multifile>().lambda()
+                .eq(Multifile::getObjId,id)
+                .eq(Multifile::getObjType,Constants.MultiFile.COMPANY_USER_APPLY.getKey())
+                .eq(Multifile::getIsdeleted,Constants.ZERO)
+                .orderByDesc(Multifile::getId)
+        );
+        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(multifileList)){
+            String url = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()+
+                    systemDictDataBiz.queryByCode(Constants.OSS,Constants.COMPANY_USER_APPLY).getCode();
+            for (Multifile multifile:multifileList) {
+                if(StringUtils.isNotBlank(multifile.getFileurl())){
+                    multifile.setFileurlFull(url + multifile.getFileurl());
+                }
+            }
+            companyUserApply.setMultifileList(multifileList);
+        }
+        return companyUserApply;
     }
 
     @Override
@@ -87,64 +233,33 @@
     @Override
     public PageData<CompanyUserApply> findPage(PageWrap<CompanyUserApply> pageWrap) {
         IPage<CompanyUserApply> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
-        QueryWrapper<CompanyUserApply> queryWrapper = new QueryWrapper<>();
+        MPJLambdaWrapper<CompanyUserApply> queryWrapper = new MPJLambdaWrapper<CompanyUserApply>();
         Utils.MP.blankToNull(pageWrap.getModel());
-        if (pageWrap.getModel().getId() != null) {
-            queryWrapper.lambda().eq(CompanyUserApply::getId, pageWrap.getModel().getId());
+        queryWrapper.selectAll(CompanyUserApply.class);
+        queryWrapper.select(" t3.name as companyName ");
+        queryWrapper.select(" t1.REALNAME as realName ");
+        queryWrapper.select(" t2.USERNAME as userName ");
+        queryWrapper.leftJoin(" system_user t1 on t1.id = t.creator  ");
+        queryWrapper.leftJoin(" system_user t2 on t2.id = t.user_id  ");
+        queryWrapper.leftJoin(" company t3 on t3.id = t2.company_id  ");
+        queryWrapper.eq(CompanyUserApply::getIsdeleted,Constants.ZERO);
+
+
+        if (pageWrap.getModel().getCompanyId() != null) {
+            queryWrapper.apply(" t3.id = "+pageWrap.getModel().getCompanyId()+" ");
         }
-        if (pageWrap.getModel().getCreator() != null) {
-            queryWrapper.lambda().eq(CompanyUserApply::getCreator, pageWrap.getModel().getCreator());
-        }
-        if (pageWrap.getModel().getCreateDate() != null) {
-            queryWrapper.lambda().ge(CompanyUserApply::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate()));
-            queryWrapper.lambda().le(CompanyUserApply::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate()));
-        }
-        if (pageWrap.getModel().getEditor() != null) {
-            queryWrapper.lambda().eq(CompanyUserApply::getEditor, pageWrap.getModel().getEditor());
-        }
-        if (pageWrap.getModel().getEditDate() != null) {
-            queryWrapper.lambda().ge(CompanyUserApply::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate()));
-            queryWrapper.lambda().le(CompanyUserApply::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate()));
-        }
-        if (pageWrap.getModel().getIsdeleted() != null) {
-            queryWrapper.lambda().eq(CompanyUserApply::getIsdeleted, pageWrap.getModel().getIsdeleted());
-        }
-        if (pageWrap.getModel().getRemark() != null) {
-            queryWrapper.lambda().eq(CompanyUserApply::getRemark, pageWrap.getModel().getRemark());
-        }
-        if (pageWrap.getModel().getCompanyIds() != null) {
-            queryWrapper.lambda().eq(CompanyUserApply::getCompanyIds, pageWrap.getModel().getCompanyIds());
-        }
-        if (pageWrap.getModel().getUserId() != null) {
-            queryWrapper.lambda().eq(CompanyUserApply::getUserId, pageWrap.getModel().getUserId());
-        }
-        if (pageWrap.getModel().getContent() != null) {
-            queryWrapper.lambda().eq(CompanyUserApply::getContent, pageWrap.getModel().getContent());
-        }
+
         if (pageWrap.getModel().getStatus() != null) {
-            queryWrapper.lambda().eq(CompanyUserApply::getStatus, pageWrap.getModel().getStatus());
+            queryWrapper.eq(CompanyUserApply::getStatus, pageWrap.getModel().getStatus());
         }
-        if (pageWrap.getModel().getCompanyNames() != null) {
-            queryWrapper.lambda().eq(CompanyUserApply::getCompanyNames, pageWrap.getModel().getCompanyNames());
+
+        if (pageWrap.getModel().getUserId() != null) {
+            queryWrapper.eq(CompanyUserApply::getUserId, pageWrap.getModel().getUserId());
         }
-        if (pageWrap.getModel().getCheckorId() != null) {
-            queryWrapper.lambda().eq(CompanyUserApply::getCheckorId, pageWrap.getModel().getCheckorId());
-        }
-        if (pageWrap.getModel().getCheckDate() != null) {
-            queryWrapper.lambda().ge(CompanyUserApply::getCheckDate, Utils.Date.getStart(pageWrap.getModel().getCheckDate()));
-            queryWrapper.lambda().le(CompanyUserApply::getCheckDate, Utils.Date.getEnd(pageWrap.getModel().getCheckDate()));
-        }
-        if (pageWrap.getModel().getCheckInfo() != null) {
-            queryWrapper.lambda().eq(CompanyUserApply::getCheckInfo, pageWrap.getModel().getCheckInfo());
-        }
-        for(PageWrap.SortData sortData: pageWrap.getSorts()) {
-            if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
-                queryWrapper.orderByDesc(sortData.getProperty());
-            } else {
-                queryWrapper.orderByAsc(sortData.getProperty());
-            }
-        }
-        return PageData.from(companyUserApplyMapper.selectPage(page, queryWrapper));
+
+        queryWrapper.orderByDesc(CompanyUserApply::getCreateDate);
+        IPage<CompanyUserApply> iPage = companyUserApplyJoinMapper.selectJoinPage(page,CompanyUserApply.class,queryWrapper);
+        return PageData.from(iPage);
     }
 
     @Override
@@ -152,4 +267,57 @@
         QueryWrapper<CompanyUserApply> wrapper = new QueryWrapper<>(companyUserApply);
         return companyUserApplyMapper.selectCount(wrapper);
     }
+
+    @Override
+    public void audit(CompanyUserApply companyUserApply){
+        LoginUserInfo loginUserInfo =(LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+        if(Objects.isNull(companyUserApply)
+                ||Objects.isNull(companyUserApply.getId())
+                || Objects.isNull(companyUserApply.getStatus())
+                || !(Constants.equalsInteger(companyUserApply.getStatus(),Constants.ONE) || Constants.equalsInteger(companyUserApply.getStatus(),Constants.TWO))
+                || (StringUtils.isBlank(companyUserApply.getCheckInfo()) && Constants.equalsInteger(companyUserApply.getStatus(),Constants.TWO))
+        ){
+            throw new BusinessException(ResponseStatus.BAD_REQUEST);
+        }
+        CompanyUserApply userApply = companyUserApplyJoinMapper.selectById(companyUserApply.getId());
+        if(Objects.isNull(userApply)){
+            throw new BusinessException(ResponseStatus.DATA_EMPTY);
+        }
+        if(!Constants.equalsInteger(userApply.getStatus(),Constants.ZERO)){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"涓氬姟鐘舵�佸凡娴佽浆");
+        }
+        CompanyUserApply update = new CompanyUserApply();
+        update.setId(companyUserApply.getId());
+        update.setEditDate(new Date());
+        update.setEditor(loginUserInfo.getId());
+        update.setStatus(companyUserApply.getStatus());
+        update.setCheckInfo(companyUserApply.getCheckInfo());
+        update.setCheckDate(new Date());
+        update.setCheckorId(loginUserInfo.getId());
+        companyUserApplyJoinMapper.updateById(update);
+        if(Constants.equalsInteger(companyUserApply.getStatus(),Constants.ONE) && StringUtils.isNotBlank(userApply.getCompanyIds())){
+            List<String> ids = Arrays.asList(userApply.getCompanyIds().split(","));
+            List<CompanyPermission> companyPermissionList = new ArrayList<>();
+            for (String id:ids) {
+                CompanyPermission companyPermission = new CompanyPermission();
+                companyPermission.setCreator(loginUserInfo.getId());
+                companyPermission.setCreateDate(new Date());
+                companyPermission.setIsdeleted(Constants.ZERO);
+                companyPermission.setUserId(userApply.getUserId());
+                companyPermission.setCompanyId(Integer.valueOf(id));
+                companyPermission.setType(Constants.ONE);
+                companyPermissionList.add(companyPermission);
+            }
+            companyPermissionMapper.insertBatchSomeColumn(companyPermissionList);
+        }
+
+
+        //瀛樺偍寰呭姙淇℃伅
+        Constants.NoticeObjectType noticeObjectType = Constants.NoticeObjectType.COMPANY_USER_APPLY;
+        //鍒犻櫎鍏朵粬寰呭姙
+        noticesMapper.delete(new QueryWrapper<Notices>().lambda().eq(Notices::getObjType,noticeObjectType.getKey())
+                .ne(Notices::getType,Constants.NoticeType.SIX.getStatus())
+                .eq(Notices::getObjId,update.getId()));
+
+    }
 }

--
Gitblit v1.9.3