From ba8b66cc8f5a3f1f7774063152f70b4a82e8327c Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期五, 18 八月 2023 21:43:01 +0800
Subject: [PATCH] 修复bug

---
 server/src/main/java/doumeemes/service/business/impl/SalaryParamServiceImpl.java |   63 +++++++++++++++++++++++--------
 1 files changed, 46 insertions(+), 17 deletions(-)

diff --git a/server/src/main/java/doumeemes/service/business/impl/SalaryParamServiceImpl.java b/server/src/main/java/doumeemes/service/business/impl/SalaryParamServiceImpl.java
index 2233fcf..767be19 100644
--- a/server/src/main/java/doumeemes/service/business/impl/SalaryParamServiceImpl.java
+++ b/server/src/main/java/doumeemes/service/business/impl/SalaryParamServiceImpl.java
@@ -8,22 +8,23 @@
 import doumeemes.core.utils.Constants;
 import doumeemes.core.utils.Utils;
 import doumeemes.core.utils.excel.EasyExcelUtil;
-import doumeemes.dao.business.DepartmentMapper;
-import doumeemes.dao.business.MaterialMapper;
-import doumeemes.dao.business.ProceduresMapper;
-import doumeemes.dao.business.SalaryParamMapper;
+import doumeemes.dao.business.*;
 import doumeemes.dao.business.model.*;
 import doumeemes.dao.business.vo.SalaryParamVO;
 import doumeemes.dao.ext.dto.SalaryParamDTO;
 import doumeemes.dao.ext.dto.SalaryParamImportDTO;
+import doumeemes.dao.ext.vo.DepartmentExtListVO;
 import doumeemes.service.business.DepartmentService;
 import doumeemes.service.business.SalaryParamService;
 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 doumeemes.service.ext.DepartmentExtService;
 import org.apache.shiro.SecurityUtils;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
@@ -45,9 +46,14 @@
 
     @Autowired
     private DepartmentMapper departmentMapper;
+    @Lazy
+    @Autowired
+    private DepartmentExtService departmentExtService;
 
     @Autowired
     private MaterialMapper materialMapper;
+    @Autowired
+    private MaterialDistributeMapper materialDistributeMapper;
 
     @Autowired
     private ProceduresMapper proceduresMapper;
@@ -59,7 +65,7 @@
         LoginUserInfo principal = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
 
         SalaryParam insert = new SalaryParam();
-        insert.setRootDepartId(salaryParam.getRootDepartId());
+        insert.setRootDepartId(principal.getRootDepartment().getId());
         insert.setDepartId(salaryParam.getDepartId());
         insert.setProcedureId(salaryParam.getProcedureId());
         insert.setMaterialId(salaryParam.getMaterialId());
@@ -117,7 +123,7 @@
 //                .set(SalaryParam::getDepartId,salaryParam.getDepartId())
 //                .set(SalaryParam::getMaterialId,salaryParam.getMaterialId())
 //                .set(SalaryParam::getProcedureId,salaryParam.getProcedureId())
-                .set(SalaryParam::getSalary,salaryParam.getSalary().divide(new BigDecimal(100)))
+                .set(SalaryParam::getSalary,salaryParam.getSalary().multiply(new BigDecimal(100)))
                 .set(SalaryParam::getNum,salaryParam.getNum())
                 .set(SalaryParam::getTimes,salaryParam.getTimes())
                 .set(SalaryParam::getUnqualified,salaryParam.getUnqualified());
@@ -155,7 +161,10 @@
     @Override
     public PageData<SalaryParamVO> findPage(PageWrap<SalaryParamDTO> pageWrap) {
         IPage<SalaryParam> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
+        LoginUserInfo principal = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
         SalaryParamDTO model = pageWrap.getModel();
+        model.setRootDepartId(principal.getRootDepartment().getId());
+//        model.setDepartId(principal.getComDepartment().getId());
         IPage<SalaryParamVO> salaryParamVOIPage = salaryParamMapper.selectPage(page, model);
         if (!CollectionUtils.isEmpty(salaryParamVOIPage.getRecords())){
             salaryParamVOIPage.getRecords().forEach(s->s.setSalary(s.getSalary().divide(new BigDecimal(100))));
@@ -196,35 +205,55 @@
 
         for (int i = 0; i < plansList.size(); i++) {
             SalaryParamImportDTO salaryParamImportDTO = plansList.get(i);
-
-            QueryWrapper<Department> wrapper = new QueryWrapper<>();
-            wrapper.lambda()
-                    .eq(Department::getName,salaryParamImportDTO.getDepartName())
-                    .eq(Department::getType,Constants.DEPART_TYPE.factory)
-                    .last("limit 1");
-            Department department = departmentMapper.selectOne(wrapper);
-            if (Objects.isNull(department)){
+//
+//            QueryWrapper<Department> wrapper = new QueryWrapper<>();
+//            wrapper.lambda()
+//                    .eq(Department::getName,salaryParamImportDTO.getDepartName())
+//                    .eq(Department::getType,Constants.DEPART_TYPE.factory)
+//                    .eq(Department::getDeleted,Constants.ZERO)
+//                    .last("limit 1");
+            Department dparam = new Department();
+            dparam.setName(salaryParamImportDTO.getDepartName());
+            dparam.setDeleted(Constants.ZERO);
+            dparam.setType(Constants.DEPART_TYPE.factory);
+            dparam = departmentExtService.findOne(dparam);
+            if (Objects.isNull(dparam)){
                 throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "瀵煎叆鏁版嵁鍐呭銆愬叕鍙稿悕绉般�戞湁璇紒");
             }
+            DepartmentExtListVO department = new DepartmentExtListVO();
+            BeanUtils.copyProperties(dparam, department);
+            Integer comDepartId = departmentExtService.getComDepartId(department);
 
             QueryWrapper<Material> materialWrapper = new QueryWrapper<>();
             materialWrapper.lambda()
                     .eq(Material::getCode,salaryParamImportDTO.getMaterialCode())
                     .eq(Material::getRootDepartId,department.getRootId())
+                    .eq(Material::getDeleted,Constants.ZERO)
                     .last("limit 1");
             Material material = materialMapper.selectOne(materialWrapper);
 
             if (Objects.isNull(material)){
                 throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "瀵煎叆鏁版嵁鍐呭銆愪骇鍝佺紪鐮併�戞湁璇紒");
             }
-            if (Objects.nonNull(material) && Objects.equals(material.getName(),salaryParamImportDTO.getMaterialName())){
+            if (Objects.nonNull(material) && !Objects.equals(material.getName(),salaryParamImportDTO.getMaterialName())){
                 throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "瀵煎叆鏁版嵁鍐呭銆愪骇鍝佸悕绉般�戞湁璇紒");
+            }
+            QueryWrapper<MaterialDistribute> materialDistributeQueryWrapper = new QueryWrapper<>();
+            materialDistributeQueryWrapper.lambda()
+                    .eq(MaterialDistribute::getMaterialId,material.getId())
+                    .eq(MaterialDistribute::getRootDepartId,department.getRootId())
+                    .eq(MaterialDistribute::getDepartId, comDepartId)
+                    .eq(MaterialDistribute::getDeleted,Constants.ZERO)
+                    .last("limit 1");
+            MaterialDistribute materialDistribute = materialDistributeMapper.selectOne(materialDistributeQueryWrapper);
+            if (Objects.isNull(materialDistribute)){
+                throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "瀵煎叆鏁版嵁鍐呭銆愪骇鍝佺紪鐮併�戞湁璇紒");
             }
             QueryWrapper<Procedures> proceduresWrapper = new QueryWrapper<>();
             proceduresWrapper.lambda()
                     .eq(Procedures::getName,salaryParamImportDTO.getProcedureName())
                     .eq(Procedures::getRootDepartId,department.getRootId())
-                    .eq(Procedures::getOrgId,department.getId())
+//                    .eq(Procedures::getOrgId,department.getId())
                     .last("limit 1");
             Procedures procedures = proceduresMapper.selectOne(proceduresWrapper);
             if (Objects.isNull(procedures)){
@@ -234,7 +263,7 @@
             salaryParam.setRootDepartId(department.getRootId());
             salaryParam.setDepartId(department.getId());
             salaryParam.setProcedureId(procedures.getId());
-            salaryParam.setMaterialId(material.getId());
+            salaryParam.setMaterialId(materialDistribute.getId());
             salaryParam.setSalary(salaryParamImportDTO.getSalary());
             salaryParam.setNum(new BigDecimal(salaryParamImportDTO.getNum()));
             salaryParam.setTimes(getIntegerTimes(salaryParamImportDTO.getTimesName()));

--
Gitblit v1.9.3