123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- package com.ozs.pm.service.impl;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.ozs.common.core.domain.entity.SysDept;
- import com.ozs.common.core.domain.entity.SysProcurementStandard;
- import com.ozs.common.exception.ServiceException;
- import com.ozs.common.exception.base.BaseException;
- import com.ozs.plan.mapper.PlanYearsMapper;
- import com.ozs.pm.mapper.PmAuditDeptRefMapper;
- import com.ozs.pm.doman.PmAuditDeptRef;
- import com.ozs.pm.service.PmAuditDeptRefService;
- import com.ozs.system.mapper.SysDeptMapper;
- import com.ozs.system.mapper.SysProcurementStandardMapper;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.util.ObjectUtils;
- import javax.annotation.Resource;
- import java.math.BigDecimal;
- import java.util.Arrays;
- import java.util.Date;
- import java.util.List;
- /**
- * 审核关联表(PmAuditDeptRef)表æå¡å®ç°ç±»
- *
- * @author makejava
- * @since 2023-02-22 22:10:08
- */
- @Service
- public class PmAuditDeptRefServiceImpl extends ServiceImpl<PmAuditDeptRefMapper, PmAuditDeptRef> implements PmAuditDeptRefService {
- @Resource
- PlanYearsMapper planYearsMapper;
- @Resource
- private SysDeptMapper deptMapper;
- @Resource
- private SysProcurementStandardMapper sysProcurementStandardMapper;
- @Resource
- private PmAuditDeptRefService pmAuditDeptRefService;
- @Override
- @Transactional
- public Boolean insertPmAuditDeptRefs(Long refId, String refType, Long deptId, BigDecimal evaluation, Long userId, String projectType) {
- Date now = new Date();
- SysDept sysDept = deptMapper.selectDeptById(deptId);
- String[] ancestors = sysDept.getAncestors().split(",");
- //当前用户的部门,是否允许提交(不在规定等级范围不可提交)
- //查询当前用户的部门是否有上级,是否需要上级及祖级进行审核
- Long cdeptId = null;
- Long bdeptId = null;
- String deptLevel = null;
- if (ancestors.length < 5) {
- if (ancestors.length == 2) { //C级
- deptLevel = "C";
- } else if (ancestors.length == 3) { //B级
- deptLevel = "B";
- cdeptId = Long.valueOf(ancestors[2]);
- } else if (ancestors.length == 4) { //A级
- deptLevel = "A";
- cdeptId = Long.valueOf(ancestors[2]);
- bdeptId = Long.valueOf(ancestors[3]);
- }
- } else if (ancestors.length >= 5) {
- deptLevel = "A";
- bdeptId = Long.valueOf(ancestors[ancestors.length - 1]);
- cdeptId = Long.valueOf(ancestors[ancestors.length - 2]);
- }
- if (!Arrays.asList("A", "B", "C").contains(deptLevel)) {
- throw new BaseException("管理员无权限提交需求。");
- }
- //判断每个级别是否允许审核,并插入审核关联表
- PmAuditDeptRef refA = new PmAuditDeptRef(null, refId, refType, deptId,
- "A", 0, userId + "", now,
- userId + "", now);
- PmAuditDeptRef refB = new PmAuditDeptRef(null, refId, refType, bdeptId,
- "B", 0, userId + "",
- now, userId + "", now);
- PmAuditDeptRef refC = null;
- //审核关联表--PmAuditDeptRef
- switch (deptLevel) {
- case "A":
- // A的判断 最少插入1条。最多插入3条
- //获取各个项目类型设定的概算金额阈值
- LambdaQueryWrapper<SysProcurementStandard> queryWrapperA = new LambdaQueryWrapper<>();
- queryWrapperA.eq(SysProcurementStandard::getDeptId, deptId);
- queryWrapperA.eq(SysProcurementStandard::getCategory, projectType.equals("2") ? "1" : projectType.equals("1") ? "2" : projectType);
- List<SysProcurementStandard> sysProcurementStandardsListA = sysProcurementStandardMapper.selectList(queryWrapperA);
- if (ObjectUtils.isEmpty(sysProcurementStandardsListA)) {
- throw new ServiceException("部门id为" + deptId + "的部门采购标准未进行初始化!");
- }
- //A不限额就自己审核
- SysProcurementStandard sA = sysProcurementStandardsListA.get(0);
- if (!sA.getState().equals(Integer.valueOf(0))) {
- //refA采用初始化数据
- //A限额了判断是否超额,超额未超额都自己先审。超额了追加上级
- BigDecimal maximum = sA.getMaximum();
- if (maximum.compareTo(evaluation) != 1) {
- //refA采用初始化数据
- //A限额了,找B
- // (3月23逻辑更改):本单位超限额的记录由本单位先进行审核,随后交由上级审核。(超额未超额都自己先审)
- LambdaQueryWrapper<SysProcurementStandard> queryWrapperB = new LambdaQueryWrapper<>();
- queryWrapperB.eq(SysProcurementStandard::getDeptId, bdeptId);
- queryWrapperB.eq(SysProcurementStandard::getCategory, projectType.equals("2") ? "1" : projectType.equals("1") ? "2" : projectType);
- List<SysProcurementStandard> sysProcurementStandardsListB = sysProcurementStandardMapper.selectList(queryWrapperB);
- //B不限额,B审
- if (ObjectUtils.isEmpty(sysProcurementStandardsListB)) {
- throw new ServiceException("部门id为" + bdeptId + "的部门采购标准未进行初始化!");
- }
- SysProcurementStandard sB = sysProcurementStandardsListB.get(0);
- if (sB.getState().equals(Integer.valueOf(0))) {
- //refB采用初始化数据
- pmAuditDeptRefService.save(refB);
- } else {
- //B限额了判断是否超额,不超额就自己审。超额了追加C级
- BigDecimal maximumB = sB.getMaximum();
- //B超额
- if (maximumB.compareTo(evaluation) == -1) {
- //C不限额,
- refC = new PmAuditDeptRef(null, refId, refType, cdeptId, "C", 0, userId + "", now, userId + "", now);
- pmAuditDeptRefService.save(refC);
- }
- //refB采用初始化数据
- pmAuditDeptRefService.save(refB);
- }
- }
- }
- if (!ObjectUtils.isEmpty(refA)) {
- pmAuditDeptRefService.save(refA);
- }
- break;
- case "B":
- // B的判断 最少插入1条。最多插入2条
- LambdaQueryWrapper<SysProcurementStandard> queryWrapperB = new LambdaQueryWrapper<>();
- queryWrapperB.eq(SysProcurementStandard::getDeptId, deptId);
- queryWrapperB.eq(SysProcurementStandard::getCategory, projectType.equals("2") ? "1" : projectType.equals("1") ? "2" : projectType);
- List<SysProcurementStandard> sysProcurementStandardsListB = sysProcurementStandardMapper.selectList(queryWrapperB);
- //B不限额,B审
- if (ObjectUtils.isEmpty(sysProcurementStandardsListB)) {
- throw new ServiceException("部门id为" + deptId + "的部门采购标准未进行初始化!");
- }
- SysProcurementStandard sB = sysProcurementStandardsListB.get(0);
- refB = new PmAuditDeptRef(null, refId, refType, deptId, "B", 0, userId + "", now, userId + "", now);
- if (sB.getState() == 1) {
- //B限额了判断是否超额,不超额就自己审。超额了追加C级
- BigDecimal maximumB = sB.getMaximum();
- //B不超额B审
- if (maximumB.compareTo(evaluation) == 1) {
- refB = new PmAuditDeptRef(null, refId, refType, deptId, "B", 0, userId + "", now, userId + "", now);
- } else {
- //C不限额C审,(B先自己审核)
- refB = new PmAuditDeptRef(null, refId, refType, deptId, "B", 0, userId + "", now, userId + "", now);
- refC = new PmAuditDeptRef(null, refId, refType, cdeptId, "C", 0, userId + "", now, userId + "", now);
- pmAuditDeptRefService.save(refC);
- }
- }
- pmAuditDeptRefService.save(refB);
- break;
- default:
- //C不限额C审,
- // 插入1条
- refC = new PmAuditDeptRef(null, refId, refType, deptId, "C", 0, userId + "", now, userId + "", now);
- pmAuditDeptRefService.save(refC);
- }
- return true;
- }
- }
|