From 64b432916af9c9218ab3f3eca614e26c542142ae Mon Sep 17 00:00:00 2001 From: jiangping <jp@doumee.com> Date: 星期二, 07 十一月 2023 15:47:13 +0800 Subject: [PATCH] bug --- server/src/main/java/doumeemes/service/business/impl/SalaryParamServiceImpl.java | 210 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 194 insertions(+), 16 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 566d872..368d0ae 100644 --- a/server/src/main/java/doumeemes/service/business/impl/SalaryParamServiceImpl.java +++ b/server/src/main/java/doumeemes/service/business/impl/SalaryParamServiceImpl.java @@ -1,25 +1,38 @@ package doumeemes.service.business.impl; +import doumeemes.core.constants.ResponseStatus; +import doumeemes.core.exception.BusinessException; import doumeemes.core.model.LoginUserInfo; import doumeemes.core.model.PageData; import doumeemes.core.model.PageWrap; import doumeemes.core.utils.Constants; import doumeemes.core.utils.Utils; -import doumeemes.dao.business.SalaryParamMapper; -import doumeemes.dao.business.model.SalaryParam; +import doumeemes.core.utils.excel.EasyExcelUtil; +import doumeemes.dao.business.*; +import doumeemes.dao.business.model.*; +import doumeemes.dao.business.vo.SalaryParamVO; +import doumeemes.dao.ext.MaterialExtMapper; 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; +import org.springframework.web.multipart.MultipartFile; -import java.util.Date; -import java.util.List; +import java.math.BigDecimal; +import java.util.*; /** * 璁剧疆绫�-缁╂晥宸ヨ祫閰嶇疆琛⊿ervice瀹炵幇 @@ -32,22 +45,43 @@ @Autowired private SalaryParamMapper salaryParamMapper; + @Autowired + private DepartmentMapper departmentMapper; + @Lazy + @Autowired + private DepartmentExtService departmentExtService; + + @Autowired + private MaterialMapper materialMapper; + @Autowired + private MaterialDistributeMapper materialDistributeMapper; + + @Autowired + private ProceduresMapper proceduresMapper; + @Override public Integer create(SalaryParam salaryParam) { - LoginUserInfo principal = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); + LoginUserInfo principal = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); + DepartmentExtListVO department =departmentExtService.getModelById(principal.getCompany().getId(),salaryParam.getDepartId()); + Integer comDepartId = departmentExtService.getComDepartId(department); SalaryParam insert = new SalaryParam(); + insert.setRootDepartId(principal.getRootDepartment().getId()); + insert.setDepartId(salaryParam.getDepartId()); +// insert.setDepartId(comDepartId); + insert.setProcedureId(salaryParam.getProcedureId()); + insert.setMaterialId(salaryParam.getMaterialId()); insert.setDeleted((byte) Constants.ZERO); + insert.setType(salaryParam.getType()); + if(findOne(insert) != null){ + throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"鍚屼竴涓墿鏂欏湪鐩稿悓宸ュ簭涓嶈兘閲嶅閰嶇疆鍝︼紒"); + } insert.setCreateUser(principal.getId()); insert.setCreateTime(new Date()); insert.setUpdateUser(principal.getId()); insert.setUpdateTime(new Date()); insert.setRemark(salaryParam.getRemark()); - insert.setRootDepartId(salaryParam.getRootDepartId()); - insert.setDepartId(salaryParam.getDepartId()); - insert.setProcedureId(salaryParam.getProcedureId()); - insert.setMaterialId(salaryParam.getMaterialId()); - insert.setSalary(salaryParam.getSalary()); + insert.setSalary(salaryParam.getSalary().multiply(new BigDecimal("100"))); insert.setNum(salaryParam.getNum()); insert.setTimes(salaryParam.getTimes()); insert.setUnqualified(salaryParam.getUnqualified()); @@ -89,10 +123,10 @@ .set(SalaryParam::getUpdateTime,new Date()) .set(SalaryParam::getUpdateUser,principal.getId()) .set(SalaryParam::getType,salaryParam.getType()) - .set(SalaryParam::getDepartId,salaryParam.getDepartId()) - .set(SalaryParam::getMaterialId,salaryParam.getMaterialId()) - .set(SalaryParam::getProcedureId,salaryParam.getProcedureId()) - .set(SalaryParam::getSalary,salaryParam.getSalary()) +// .set(SalaryParam::getDepartId,salaryParam.getDepartId()) +// .set(SalaryParam::getMaterialId,salaryParam.getMaterialId()) +// .set(SalaryParam::getProcedureId,salaryParam.getProcedureId()) + .set(SalaryParam::getSalary,salaryParam.getSalary().multiply(new BigDecimal(100))) .set(SalaryParam::getNum,salaryParam.getNum()) .set(SalaryParam::getTimes,salaryParam.getTimes()) .set(SalaryParam::getUnqualified,salaryParam.getUnqualified()); @@ -117,6 +151,7 @@ @Override public SalaryParam findOne(SalaryParam salaryParam) { QueryWrapper<SalaryParam> wrapper = new QueryWrapper<>(salaryParam); + wrapper.last("limit 1"); return salaryParamMapper.selectOne(wrapper); } @@ -127,10 +162,17 @@ } @Override - public PageData<SalaryParam> findPage(PageWrap<SalaryParamDTO> pageWrap) { + 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(); - return PageData.from(salaryParamMapper.selectPage(page, model)); + model.setRootDepartId(principal.getRootDepartment().getId()); +// model.setDepartId(principal.getCurComDepartment().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)))); + } + return PageData.from(salaryParamVOIPage); } @Override @@ -138,4 +180,140 @@ QueryWrapper<SalaryParam> wrapper = new QueryWrapper<>(salaryParam); return salaryParamMapper.selectCount(wrapper); } + + @Transactional(rollbackFor = {Exception.class,BusinessException.class}) + @Override + public void importPlans(MultipartFile file) { + + LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); + if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){ + throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "瀵逛笉璧凤紝鎮ㄦ棤鏉冮檺杩涜璇ユ搷浣滐紒"); + } + //瑙f瀽excel + List<SalaryParamImportDTO> plansList = EasyExcelUtil.importExcel(file, 1, 1, SalaryParamImportDTO.class); + if(plansList == null || plansList.size()==0){ + throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "瀵煎叆鏁版嵁鍐呭鏈夎锛�"); + } + + plansList.forEach(s->{ + if (Objects.isNull(s.getType()) + || Objects.isNull(s.getDepartName()) + || Objects.isNull(s.getMaterialCode()) + || Objects.isNull(s.getProcedureName()) + || Objects.isNull(s.getNum())){ + throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "瀵煎叆鏁版嵁鍐呭鏈夎锛�"); + } + }); + + + 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) +// .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(); + department.setId(dparam.getId()); + department.setType(dparam.getType()); + department.setParentId(dparam.getParentId()); + department.setRootId(dparam.getRootId()); + department.setCompanyId(dparam.getCompanyId()); + Integer comDepartId = departmentExtService.getComDepartId(department); + QueryWrapper<Material> materialWrapper = new QueryWrapper<>(); + materialWrapper.lambda() + .eq(Material::getCode,salaryParamImportDTO.getMaterialCode()) + .eq(Material::getRootDepartId,dparam.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())){ + 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()) + .last("limit 1"); + Procedures procedures = proceduresMapper.selectOne(proceduresWrapper); + if (Objects.isNull(procedures)){ + throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "瀵煎叆鏁版嵁鍐呭銆愬伐搴忓悕绉般�戞湁璇紒"); + } + SalaryParam salaryParam = new SalaryParam(); + salaryParam.setRootDepartId(department.getRootId()); + salaryParam.setDepartId(dparam.getId()); + salaryParam.setProcedureId(procedures.getId()); + salaryParam.setMaterialId(materialDistribute.getId()); + salaryParam.setSalary(salaryParamImportDTO.getSalary()); + salaryParam.setNum(new BigDecimal(salaryParamImportDTO.getNum())); + salaryParam.setTimes(getIntegerTimes(salaryParamImportDTO.getTimesName())); + Integer unqualified = Optional.ofNullable(salaryParamImportDTO.getUnqualified()).map(s -> { + if ("鍚�".equals(s)) { + return 0; + } else { + return 1; + } + }).orElse(0); + salaryParam.setUnqualified(unqualified); + + Integer type = Optional.ofNullable(salaryParamImportDTO.getType()).map(s -> { + if ("璁′欢".equals(s)) { + return 0; + } else { + return 1; + } + }).orElse(0); + salaryParam.setType(type); + create(salaryParam); + } + + } + + private Integer getIntegerTimes(String a) { + int h =0,m=0,s=0; + try{ + int hIndex =a.lastIndexOf("灏忔椂"); + int mIndex=a.lastIndexOf("鍒嗛挓"); + int sIndex =a.lastIndexOf("绉�"); + if( hIndex>0){ + h = Integer.parseInt(a.substring(0,hIndex)); + } + if(mIndex > hIndex){ + m = Integer.parseInt(a.substring(hIndex >=0?hIndex+2:0,mIndex)); + } + if(sIndex > mIndex){ + s = Integer.parseInt(a.substring(mIndex >= 0 ? mIndex+2 : 0, sIndex)); + } + return h*3600+m*60+s; + }catch (Exception e){ + throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝鏃堕暱銆�"+a+"銆戞牸寮忎笉姝g‘锛�" ); + } + + } } -- Gitblit v1.9.3