package com.ozs.plan.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ozs.common.core.domain.AjaxResult; import com.ozs.common.core.domain.entity.SysDept; import com.ozs.common.core.domain.entity.SysDictData; import com.ozs.common.core.domain.entity.SysUser; import com.ozs.common.core.domain.model.LoginUser; import com.ozs.common.enums.DataIsDelete; import com.ozs.common.enums.PmProjectStatus; import com.ozs.common.enums.ProjectStatus; import com.ozs.common.enums.QuarterEnum; import com.ozs.common.enums.SysFileRefEnum; import com.ozs.common.exception.ServiceException; import com.ozs.common.utils.DateUtils; import com.ozs.common.utils.SecurityUtils; import com.ozs.common.utils.StringUtils; import com.ozs.common.utils.bean.BeanUtils; import com.ozs.plan.doman.PlanQuarter; import com.ozs.plan.doman.PlanYears; import com.ozs.plan.doman.vo.requestVo.PlanQuarterStandardVo; import com.ozs.plan.doman.vo.responseVo.PlanQuarterResponseVo; import com.ozs.plan.mapper.PlanQuarterMapper; import com.ozs.plan.mapper.PlanYearsMapper; import com.ozs.plan.service.PlanQuarterService; import com.ozs.pm.doman.PmAuditDeptRef; import com.ozs.pm.doman.PmDemand; import com.ozs.pm.mapper.PmAuditDeptRefMapper; import com.ozs.pm.mapper.PmDemandMapper; import com.ozs.pm.service.IPmDemandService; import com.ozs.pm.service.PmAuditDeptRefService; import com.ozs.system.domain.SysDeptOrgan; import com.ozs.system.domain.SysFileInfo; import com.ozs.system.domain.SysFileRef; import com.ozs.system.domain.vo.responseVo.SysDeptResponseVo; import com.ozs.system.mapper.SysDeptMapper; import com.ozs.system.mapper.SysDeptOrganMapper; import com.ozs.system.mapper.SysFileRefMapper; import com.ozs.system.service.ISysDeptService; import com.ozs.system.service.ISysDictDataService; import com.ozs.system.service.ISysDictTypeService; import com.ozs.system.service.ISysUserService; import com.ozs.system.service.SysFileService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.token.TokenService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; import javax.validation.Validator; import java.math.BigDecimal; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * @author buzhanyi */ @Service @Slf4j public class PlanQuarterServiceImpl extends ServiceImpl implements PlanQuarterService { @Autowired PlanQuarterMapper planQuarterMapper; @Autowired PlanYearsMapper planYearsMapper; @Autowired protected Validator validator; @Autowired private ISysDictTypeService dictTypeService; @Autowired private ISysDeptService deptService; @Autowired SysFileRefMapper sysFileRefMapper; @Autowired private SysDeptMapper deptMapper; @Autowired private SysFileService fileService; @Autowired private PmDemandMapper pmDemandMapper; @Autowired private IPmDemandService demandService; @Autowired private ISysUserService userService; @Autowired private PmAuditDeptRefService pmAuditDeptRefService; @Autowired private PmAuditDeptRefMapper pmAuditDeptRefMapper; @Autowired private SysDeptOrganMapper sysDeptOrganMapper; @Override public List selectPlanQuarterListEXP(PlanQuarterStandardVo vo, LoginUser loginUser) { List list = new ArrayList<>(); List planQuarterList = new ArrayList<>(); try { int num = 1; int size = 200; while (size == 200) { LambdaQueryWrapper lw = new LambdaQueryWrapper<>(); if (!loginUser.getUserId().equals(Long.valueOf("1"))) { lw.eq(PlanQuarter::getCreated, loginUser.getUserId()); //lw.eq(PlanQuarter::getPurchaseDeptId, loginUser.getDeptId()); } lw.eq(PlanQuarter::getPlanType, "0"); if (!ObjectUtils.isEmpty(vo.getProjectName())) { lw.like(PlanQuarter::getProjectName, vo.getProjectName()); } if (!ObjectUtils.isEmpty(vo.getPurchaseServices())) { lw.eq(PlanQuarter::getPurchaseServices, vo.getPurchaseServices()); } if (!ObjectUtils.isEmpty(vo.getProjectStatus())) { lw.eq(PlanQuarter::getProjectStatus, vo.getProjectStatus()); } if (!ObjectUtils.isEmpty(vo.getParams())) { if (!ObjectUtils.isEmpty(vo.getParams().get("beginTime"))) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM"); Date ofMonth = dateFormat.parse(vo.getParams().get("beginTime").toString() + "-01"); lw.ge(PlanQuarter::getPlanDemandSubTime, ofMonth); } if (!ObjectUtils.isEmpty(vo.getParams().get("endTime"))) { SimpleDateFormat dateFormaH = new SimpleDateFormat("yyyy-MM"); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat dateFormatT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS"); Date ofMonth = DateUtils.getLastDayOfMonth(dateFormaH.parse(vo.getParams().get("endTime").toString())); Date parse = dateFormatT.parse(dateFormat.format(ofMonth) + " 23:59:59:999"); lw.le(PlanQuarter::getPlanDemandSubTime, parse); } } lw.eq(PlanQuarter::getDelFlay, DataIsDelete.DataNOTDelete.getCode()); Page page = planQuarterMapper.selectPage(new Page<>(num, size, false), lw); list.addAll(page.getRecords()); size = page.getRecords().size(); num++; } planQuarterList = changeTo(list); } catch (Exception e) { e.printStackTrace(); } return planQuarterList; } @Override public List selectPlanQuarterExamineListEXP(PlanQuarterStandardVo vo, LoginUser loginUser) { List list = new ArrayList<>(); List planQuarterList = new ArrayList<>(); try { int num = 1; int size = 200; while (size == 200) { LambdaQueryWrapper lw = new LambdaQueryWrapper(); if (!loginUser.getUserId().equals(Long.valueOf("1"))) { lw.eq(PlanQuarter::getPurchaseDeptId, loginUser.getDeptId()); } lw.eq(PlanQuarter::getPlanType, "0"); if (!ObjectUtils.isEmpty(vo.getProjectName())) { lw.like(PlanQuarter::getProjectName, vo.getProjectName()); } if (!ObjectUtils.isEmpty(vo.getPurchaseServices())) { lw.eq(PlanQuarter::getPurchaseServices, vo.getPurchaseServices()); } if (!ObjectUtils.isEmpty(vo.getProjectStatus())) { lw.eq(PlanQuarter::getProjectStatus, vo.getProjectStatus()); } else { lw.in(PlanQuarter::getProjectStatus, "1,3,4"); } if (!ObjectUtils.isEmpty(vo.getParams())) { if (!ObjectUtils.isEmpty(vo.getParams().get("beginTime"))) { lw.ge(PlanQuarter::getPlanDemandSubTime, vo.getParams().get("beginTime")); } if (!ObjectUtils.isEmpty(vo.getParams().get("endTime"))) { SimpleDateFormat dateFormatT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS"); Date parse = dateFormatT.parse(vo.getParams().get("endTime").toString() + " 23:59:59:999"); lw.le(PlanQuarter::getPlanDemandSubTime, parse); } } lw.eq(PlanQuarter::getDelFlay, DataIsDelete.DataNOTDelete.getCode()); Page page = planQuarterMapper.selectPage(new Page(num, size, false), lw); list.addAll(page.getRecords()); size = page.getRecords().size(); num++; } planQuarterList = changeTo(list); } catch (Exception e) { e.printStackTrace(); } return planQuarterList; } @Transactional @Override public AjaxResult insertPlanQuarter(PlanQuarterStandardVo quarterStandardVo) { if (planQuarterMapper.countProjectName(quarterStandardVo.getProjectName()) > 0) { return AjaxResult.error("该项目名称已经存在"); } //默认未超额 PlanQuarter quarters = new PlanQuarter(); try { BeanUtils.copyProperties(quarterStandardVo, quarters); } catch (Exception e) { e.printStackTrace(); } quarters.setProjectStatus(ProjectStatus.PLANWAITCOMMIT.getCode()); quarters.setCreateTime(new Date()); planQuarterMapper.insertPlanQuarter(quarters); log.info("id:{}", quarters.getPlanPracticalId()); List sysFileRefs = quarterStandardVo.getSysFileRefs(); if (!ObjectUtils.isEmpty(sysFileRefs)) { for (SysFileRef ref : sysFileRefs) { ref.setRedId(quarters.getPlanPracticalId()); ref.setType(SysFileRefEnum.PLAN_TEMPORARY.getType()); ref.setCreated(quarters.getCreated()); ref.setCreateTime(new Date()); ref.setUpdated(quarters.getCreated()); ref.setUpdateTime(new Date()); sysFileRefMapper.insert(ref); } } return AjaxResult.success(); } @Override public AjaxResult deletePlanQuarterByIds(Long[] planIds) { planQuarterMapper.deletePlanQuarterByIds(planIds); return AjaxResult.success(); } @Override public AjaxResult deletePlanQuarterById(Long planId) { planQuarterMapper.deletePlanQuarterById(planId); return AjaxResult.success(); } @Override public AjaxResult view(PlanQuarterStandardVo quarterStandardVo) { PlanQuarterResponseVo responseVo = new PlanQuarterResponseVo(); PlanQuarter byId = planQuarterMapper.getById(quarterStandardVo.getPlanPracticalId()); if (byId == null) { return AjaxResult.error("数据查询失败"); } SysDeptResponseVo sysDeptResponseVo = (SysDeptResponseVo) deptService.selectDeptById(Long.valueOf(byId.getPurchaseDeptId())).get("sysDept"); byId.setPurchaseDeptName(sysDeptResponseVo.getDeptName()); LambdaQueryWrapper lw = new LambdaQueryWrapper<>(); lw.eq(SysFileRef::getRedId, quarterStandardVo.getPlanPracticalId()); lw.in(SysFileRef::getType, Arrays.asList(SysFileRefEnum.PLAN_TEMPORARY.getType(), SysFileRefEnum.PLAN_TEMPORARY_EXAMINE.getType())); List fileRefs = sysFileRefMapper.selectList(lw); List fileInfos = new ArrayList<>(); BeanUtils.copyProperties(byId, responseVo); if (!ObjectUtils.isEmpty(fileRefs)) { for (SysFileRef ref : fileRefs) { SysFileInfo fileInfo = fileService.getById(ref.getFileId()); fileInfos.add(fileInfo); } responseVo.setFileInfos(fileInfos); } String organDivision = byId.getOrganDivision(); if (!ObjectUtils.isEmpty(organDivision)) { int length = organDivision.split(",").length; SysDeptOrgan organ = new SysDeptOrgan(); if (length > 1) { StringBuilder builder = new StringBuilder(); String[] split = organDivision.split(","); for (String s : split) { organ = sysDeptOrganMapper.selectById(s); if (!ObjectUtils.isEmpty(organ)) { if (!organDivision.endsWith(s)) { builder.append(organ.getOrganName() + ","); } else { builder.append(organ.getOrganName()); } } } responseVo.setOrganDivisionStr(builder.toString()); } else if (length == 1) { organ = sysDeptOrganMapper.selectById(organDivision); if (!ObjectUtils.isEmpty(organ)) { responseVo.setOrganDivisionStr(organ.getOrganName()); } } } return AjaxResult.success(responseVo); } @Transactional @Override public AjaxResult update(PlanQuarterStandardVo quarterStandardVo) { Date now = new Date(); if (planQuarterMapper.countProjectNameOther(quarterStandardVo.getProjectName(), String.valueOf(quarterStandardVo.getPlanPracticalId())) > 0) { return AjaxResult.error("该项目名称已经存在"); } PlanQuarter quarters = new PlanQuarter(); try { BeanUtils.copyProperties(quarterStandardVo, quarters); } catch (Exception e) { e.printStackTrace(); } quarters.setUpdateTime(now); PlanQuarter byId = planQuarterMapper.selectById(quarters.getPlanPracticalId()); //临时计划修改后要更新年度计划 if (byId.getPlanType().equals(Integer.parseInt("1"))) { if (!ObjectUtils.isEmpty(planYearsMapper.selectById(byId.getPlanYearId()))) { PlanYears years = new PlanYears(); BeanUtils.copyProperties(quarterStandardVo, years); years.setProjectAttr(null); years.setPlanYearId(null); planYearsMapper.updateById(years); } } planQuarterMapper.updateById(quarters); List sysFileRefs = quarterStandardVo.getSysFileRefs(); if (!ObjectUtils.isEmpty(sysFileRefs)) { // 删关联 LambdaQueryWrapper lw = new LambdaQueryWrapper<>(); lw.eq(SysFileRef::getRedId, quarters.getPlanPracticalId()); lw.eq(SysFileRef::getType, SysFileRefEnum.PLAN_TEMPORARY.getType()); sysFileRefMapper.delete(lw); for (SysFileRef ref : sysFileRefs) { ref.setRedId(quarters.getPlanPracticalId()); ref.setType(SysFileRefEnum.PLAN_TEMPORARY.getType()); ref.setCreated(quarterStandardVo.getUpdated()); ref.setCreateTime(now); ref.setUpdated(quarterStandardVo.getUpdated()); ref.setUpdateTime(now); sysFileRefMapper.insert(ref); } } return AjaxResult.success(); } @Override public String importPlanQuarter(List planQuarters, boolean isUpdateSupport, LoginUser loginUser) { if (StringUtils.isNull(planQuarters) || planQuarters.size() == 0) { throw new ServiceException("导入季度计划数据不能为空!"); } List list = new ArrayList<>(); for (PlanQuarterStandardVo standardVo : planQuarters) { PlanQuarter quarter = new PlanQuarter(); BeanUtils.copyProperties(standardVo, quarter); quarter.setPurchaseDeptName(standardVo.getPurchaseDeptId()); list.add(quarter); } HashMap> planEnums = dictTypeService.getAboutEnums(); HashMap projectTypesMap = planEnums.get("projectTypes"); HashMap projectAttributes = planEnums.get("projectAttributes"); int successNum = 0; int failureNum = 0; StringBuilder successMsg = new StringBuilder(); StringBuilder failureMsg = new StringBuilder(); //deptService for (PlanQuarter planQuarter : list) { try { //验证项目名称是否重复导入 //将录入信息中的值更改为要保存的数据 if (planQuarterMapper.countProjectName(planQuarter.getProjectName()) == 0) { //采购单位 SysDept info = deptMapper.checkDeptNameOnlyOne(planQuarter.getPurchaseDeptName()); if (!ObjectUtils.isEmpty(info)) { planQuarter.setPurchaseDeptId(String.valueOf(info.getDeptId())); } else { ++failureNum; failureMsg.append("*" + failureNum + "*采购单位“" + planQuarter.getPurchaseDeptName() + "”不存在
"); } planQuarter.setProjectType(projectTypesMap.get(planQuarter.getProjectType())); planQuarter.setProjectStatus(ProjectStatus.PLANWAITCOMMIT.getCode()); //项目属性是多选字段 StringBuilder builder = new StringBuilder(); if (planQuarter.getProjectAttr().contains(",")) { String[] split = planQuarter.getProjectAttr().split(","); for (String s : split) { if (!planQuarter.getProjectAttr().endsWith(s)) { builder.append(projectAttributes.get(s) + ","); } else { builder.append(projectAttributes.get(s)); } } } else { builder.append(projectAttributes.get(planQuarter.getProjectAttr())); } planQuarter.setProjectAttr(builder.toString()); planQuarter.setCreated(String.valueOf(loginUser.getUserId())); planQuarter.setCreateTime(new Date()); planQuarterMapper.insertPlanQuarter(planQuarter); successNum++; successMsg.append("*" + successNum + "、项目 " + planQuarter.getProjectName() + " 导入成功!
"); } else { failureNum++; failureMsg.append(failureNum + "*项目 " + planQuarter.getProjectName() + " 已存在!
"); } } catch (Exception exc) { String msg = " *" + successNum + "*项目 " + planQuarter.getProjectName() + " 导入失败
"; failureMsg.append(msg); log.error(msg, exc); } } if (failureNum > 0) { failureMsg.insert(0, "导入失败!共 " + failureNum + " 条数据格式不正确:
"); throw new ServiceException(failureMsg.toString()); } else { successMsg.insert(0, "导入成功!共 " + successNum + " 条。
"); } return successMsg.toString(); } @Override @Transactional public AjaxResult commit(PlanQuarterStandardVo quarterStandardVo) { PlanQuarter byId = planQuarterMapper.getById(quarterStandardVo.getPlanPracticalId()); if (!isBetweenValue(byId)) { return AjaxResult.error("所创计划不在提报日期内!"); } //申请修改之后再次提交,先清除上一次提交后的审核记录 PmAuditDeptRef ref = new PmAuditDeptRef(); ref.setRefId(byId.getPlanPracticalId()); ref.setRefType("1"); ref.setProjectType(byId.getProjectType()); ref.setEvaluation(byId.getEvaluation()); refIsExist(ref, pmAuditDeptRefMapper); insertAuditDeptRef(userService, pmAuditDeptRefService, ref); int commit = planQuarterMapper.commit(quarterStandardVo.getPlanPracticalId()); if (commit != 1) { return AjaxResult.error("项目状态数据异常"); } return AjaxResult.success(); } //是否已存在--关联审核部门 static void refIsExist(PmAuditDeptRef ref, PmAuditDeptRefMapper pmAuditDeptRefMapper) { LambdaQueryWrapper lp = new LambdaQueryWrapper<>(); lp.eq(PmAuditDeptRef::getRefId, ref.getRefId()); lp.eq(PmAuditDeptRef::getRefType, ref.getRefType()); List refs = pmAuditDeptRefMapper.selectList(lp); if (!ObjectUtils.isEmpty(refs)) { pmAuditDeptRefMapper.delete(lp); } } static void insertAuditDeptRef(ISysUserService userService, PmAuditDeptRefService pmAuditDeptRefService, PmAuditDeptRef ref) { SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId()); Long deptId = sysUser.getDeptId(); if (!pmAuditDeptRefService.insertPmAuditDeptRefs(ref.getRefId(), ref.getRefType(), deptId, ref.getEvaluation(), sysUser.getUserId(), ref.getProjectType())) { throw new ServiceException("审核关联数据插入失败"); } } @Override @Transactional public AjaxResult reviewTo(PlanQuarterStandardVo vo) { SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId()); Long deptId = sysUser.getDeptId(); SysDept sysDept = deptMapper.selectDeptById(deptId); String[] ancestors = sysDept.getAncestors().split(","); String deptLevel = null; if (ancestors.length == 2) { //C级 deptLevel = "C"; } else if (ancestors.length == 3) { //B级 deptLevel = "B"; } else if (ancestors.length == 4) { //A级 deptLevel = "A"; } LambdaQueryWrapper lw = new LambdaQueryWrapper(); lw.eq(PmAuditDeptRef::getRefId, vo.getPlanPracticalId()); lw.eq(PmAuditDeptRef::getRefType, "1"); List list = pmAuditDeptRefService.list(lw); boolean flay = true; if (!ObjectUtils.isEmpty(list)) { for (PmAuditDeptRef pmAuditDeptRef : list) { // 判断 deptLevel 是否还有更高的 且是 待审核的数据 if (pmAuditDeptRef.getDeptLevel().compareTo(deptLevel) > 0 && pmAuditDeptRef.getStatus().equals(Integer.parseInt("0"))) { flay = false; } // 更新当前 deptLevel 级别的审核状态 if (pmAuditDeptRef.getDeptLevel().compareTo(deptLevel) == 0) { pmAuditDeptRef.setStatus(1); pmAuditDeptRefService.updateById(pmAuditDeptRef); } } } realReviewTo(vo, flay); return AjaxResult.success(); } public AjaxResult realReviewTo(PlanQuarterStandardVo vo, boolean flay) { Date now = new Date(); //季度计划审核通过后同步到年度计划和项目管理 PlanQuarter byId = planQuarterMapper.getById(vo.getPlanPracticalId()); //上传审核文件并赋予计划审核通过 upExamineFile(vo); if (flay) { //同步到项目管理 PmDemand demand = new PmDemand(); BeanUtils.copyProperties(byId, demand); demand.setEvaluation(byId.getEvaluation().doubleValue()); demand.setPlanId(byId.getPlanPracticalId()); demand.setPurchaseDeptId(Long.valueOf(byId.getPurchaseDeptId())); //同步到项目管理状态为需求待填制 demand.setProjectStatus(PmProjectStatus.DEMAND_WAIT_FILL.getCode()); demand.setCreateTime(now); demand.setCreateBy(byId.getCreated()); demand.setUpdateTime(now); demand.setUpdateBy(demand.getCreateBy()); pmDemandMapper.insert(demand); demandService.updateDemandWarnStatus(demand.getDemandId()); //计划附件也进行同步---查询季度计划附件后同步到项目需求附件和年度计划附件 LambdaQueryWrapper sysFileRefLp = new LambdaQueryWrapper<>(); sysFileRefLp.eq(SysFileRef::getRedId, vo.getPlanPracticalId()); sysFileRefLp.in(SysFileRef::getType, Arrays.asList(SysFileRefEnum.PLAN_TEMPORARY.getType(), SysFileRefEnum.PLAN_TEMPORARY_EXAMINE.getType())); List sysFileRefs = sysFileRefMapper.selectList(sysFileRefLp); if (!ObjectUtils.isEmpty(sysFileRefs)) { for (SysFileRef ref : sysFileRefs) { ref.setRedId(demand.getDemandId()); ref.setType(SysFileRefEnum.PM_DEMAND.getType()); ref.setId(null); ref.setCreated(vo.getUpdated()); ref.setCreateTime(now); ref.setUpdated(vo.getUpdated()); ref.setUpdateTime(now); sysFileRefMapper.insert(ref); } } //赋予项目状态已审核 vo.setProjectStatus(ProjectStatus.PLANTOEXAMINE.getCode()); return review(vo); } return AjaxResult.success("成功"); } @Override @Transactional public AjaxResult reviewReturn(PlanQuarterStandardVo vo) { vo.setProjectStatus(ProjectStatus.PLANTOBACK.getCode()); //上传审核文件并赋予计划审核退回 upExamineFile(vo); return review(vo); } /** * 上传审核文件 * * @param vo */ @Override @Transactional public void upExamineFile(PlanQuarterStandardVo vo) { Date now = new Date(); List sysFileRefuses = vo.getSysFileRefs(); if (!ObjectUtils.isEmpty(sysFileRefuses)) { for (SysFileRef ref : sysFileRefuses) { ref.setRedId(vo.getPlanPracticalId()); ref.setType(SysFileRefEnum.PLAN_TEMPORARY_EXAMINE.getType()); ref.setCreated(vo.getUpdated()); ref.setCreateTime(now); ref.setUpdated(vo.getUpdated()); ref.setUpdateTime(now); sysFileRefMapper.insert(ref); } } } private AjaxResult review(PlanQuarterStandardVo vo) { int review = planQuarterMapper.review(vo); if (review != 1) { return AjaxResult.error("项目状态数据异常"); } return AjaxResult.success(); } @Override public AjaxResult appUpdate(PlanQuarterStandardVo vo) { //申请后会成为未提交的状态,可以进行修改 PlanQuarter planQuarter = new PlanQuarter(); BeanUtils.copyProperties(vo, planQuarter); planQuarter.setAppUpdate("true"); planQuarterMapper.updateById(planQuarter); return AjaxResult.success("申请成功"); } @Override @Transactional public AjaxResult handleAppUpdate(PlanQuarterStandardVo vo) { //getProjectAttr传值1为同意。-1为拒绝 PlanQuarter planQuarter = new PlanQuarter(); planQuarter.setPlanPracticalId(vo.getPlanPracticalId()); //同意修改申请 if ("1".equals(vo.getProjectAttr())) { //同意申请之后进行修改,提交后可再次申请 planQuarter.setAppUpdate(""); planQuarter.setProjectStatus(ProjectStatus.PLANWAITCOMMIT.getCode()); planQuarterMapper.updateById(planQuarter); return AjaxResult.success("已同意该修改申请"); } //拒绝后可以再次申请 planQuarter.setAppUpdate(""); planQuarterMapper.updateById(planQuarter); return AjaxResult.success("已拒绝改申请"); } @Override public AjaxResult sendLetter(PlanQuarterStandardVo quarterStandardVo) { PlanQuarter quarter = new PlanQuarter(); BeanUtils.copyProperties(quarterStandardVo, quarter); quarter.setSendLetter("1"); quarter.setLetterTime(new Date()); int review = planQuarterMapper.updateById(quarter); if (review != 1) { return AjaxResult.error("项目状态数据异常"); } return AjaxResult.success(); } @Override public AjaxResult upLoadPlanFile(PlanQuarterStandardVo quarterStandardVo) { List sysFileRefs = quarterStandardVo.getSysFileRefs(); if (!ObjectUtils.isEmpty(sysFileRefs)) { for (SysFileRef ref : sysFileRefs) { ref.setRedId(quarterStandardVo.getPlanPracticalId()); ref.setType(SysFileRefEnum.PLAN_TEMPORARY.getType()); sysFileRefMapper.insert(ref); } } return AjaxResult.success(); } @Override public List queryPage(PlanQuarterStandardVo vo) { LoginUser loginUser = SecurityUtils.getLoginUser(); if (!loginUser.getUserId().equals(Long.valueOf("1")) && StringUtils.isEmpty(vo.getPurchaseDeptId())) { vo.setPurchaseDeptId(String.valueOf(loginUser.getDeptId())); } List query = planQuarterMapper.query(vo); List queryTwo = new LinkedList<>(); if (!ObjectUtils.isEmpty(query)) { for (PlanQuarter quarter : query) { LambdaQueryWrapper lw = new LambdaQueryWrapper(); lw.eq(PmAuditDeptRef::getRefId, quarter.getPlanPracticalId()); lw.eq(PmAuditDeptRef::getRefType, "1"); List list = pmAuditDeptRefService.list(lw); //是否显示审核按钮 boolean fl = true; //是否为本单位已审核过的数据 boolean fg = false; if (!ObjectUtils.isEmpty(list) && list.size() > 0) { List collect = list.stream() .filter(f -> f.getDeptId().equals(Long.valueOf(vo.getPurchaseDeptId()))) .collect(Collectors.toList()); if (ObjectUtils.isEmpty(collect)) { fl = false; } else { String deptLevel = collect.get(0).getDeptLevel(); fl = collect.get(0).getStatus().equals(Integer.parseInt("1")) ? false : true; //该计划的审核信息 for (PmAuditDeptRef pmAuditDeptRef : list) { //自己下级单位未进行审核时。不显示审核按钮 if (pmAuditDeptRef.getDeptLevel().compareTo(deptLevel) == -1 && pmAuditDeptRef.getStatus().equals(Integer.parseInt("0"))) { fl = false; } //本单位已审核 if (pmAuditDeptRef.getDeptLevel().compareTo(deptLevel) == 0 && pmAuditDeptRef.getStatus().equals(Integer.parseInt("1"))) { fg = true; } } } /* * String s1="A"; String s2="B"; System.out.println(s1.compareTo(s2)); * over: -1 * */ } if (vo.getCreated().equals("1")) { fl = false; } quarter.setFlag(fl); if (fl == true || quarter.getPurchaseDeptId().equals(vo.getPurchaseDeptId())) { queryTwo.add(quarter); } else if (fg == true) { queryTwo.add(quarter); } } } return queryTwo; } /** * 导入年度计划数据 * * @param planYearIds * @return */ @Override @Transactional public AjaxResult importPlanYearsData(List planYearIds) { Date now = new Date(); StringBuilder sb = new StringBuilder("项目【'"); for (Long yearId : planYearIds) { PlanQuarter byPlanYearId = planQuarterMapper.getByPlanYearId(yearId); if (!ObjectUtils.isEmpty(byPlanYearId)) { sb.append(byPlanYearId.getProjectName() + "'、'"); } else { PlanQuarter quarter = new PlanQuarter(); PlanYears years = planYearsMapper.getById(yearId); BeanUtils.copyProperties(years, quarter); quarter.setPlanYearId(yearId); quarter.setPlanType(0); quarter.setProjectStatus(ProjectStatus.PLANWAITCOMMIT.getCode()); planQuarterMapper.insert(quarter); //项目上传附件和审核文件进行同步 LambdaQueryWrapper lw = new LambdaQueryWrapper<>(); lw.eq(SysFileRef::getRedId, years.getPlanYearId()); lw.in(SysFileRef::getType, Arrays.asList(SysFileRefEnum.PLAN_YEAR.getType(), SysFileRefEnum.PLAN_YEAR_EXAMINE.getType())); List fileRefs = sysFileRefMapper.selectList(lw); for (SysFileRef fileRef : fileRefs) { fileRef.setId(null); fileRef.setRedId(quarter.getPlanPracticalId()); fileRef.setType(SysFileRefEnum.PLAN_TEMPORARY.getType()); fileRef.setCreateTime(now); fileRef.setCreated(SecurityUtils.getUserId() + ""); sysFileRefMapper.insert(fileRef); } } } sb.append("】已存在,请勿选择。"); if (sb.length() > 14) { return AjaxResult.error(sb.toString()); } return AjaxResult.success(); } @Override public AjaxResult appDelete(PlanQuarterStandardVo quarterStandardVo) { PlanQuarter planQuarter = new PlanQuarter(); BeanUtils.copyProperties(quarterStandardVo, planQuarter); planQuarter.setAppDelete("true"); planQuarterMapper.updateById(planQuarter); return AjaxResult.success("申请成功"); } @Override public AjaxResult handleApp(PlanQuarterStandardVo quarterStandardVo) { //getProjectAttr传值1为同意。-1为拒绝 if ("1".equals(quarterStandardVo.getProjectAttr())) { planQuarterMapper.deletePlanQuarterById(quarterStandardVo.getPlanPracticalId()); return AjaxResult.success("已成功进行撤销"); } PlanQuarter planQuarter = new PlanQuarter(); planQuarter.setPlanPracticalId(quarterStandardVo.getPlanPracticalId()); planQuarter.setAppDelete("false"); planQuarterMapper.updateById(planQuarter); return AjaxResult.success("已拒绝改申请"); } //字段赋值对应的名称 public List changeTo(List planQuarters) { //获取季度计划各个季度提报时间的阈值 List supTime = dictTypeService.selectDictDataByType("sys_quarterly_plan"); HashMap thresholdMap = new LinkedHashMap<>(); //各个季度提报时间的阈值 for (SysDictData dictData : supTime) { // 季度----阈值 thresholdMap.put(dictData.getDictLabel(), dictData.getDictValue()); } //提前或延后*天进行提醒 List alertTime = dictTypeService.selectDictDataByType("alert_time_setting"); HashMap alertTimeMap = new LinkedHashMap<>(); //根据时间类别设定的提醒时间 for (SysDictData dictData : alertTime) { // 字段名称----阈值 alertTimeMap.put(dictData.getDictLabel(), dictData.getDictValue()); } //获取字典数据 HashMap> planEnums = dictTypeService.getAboutEnums(); //项目属性 HashMap projectAttributes = planEnums.get("projectAttributes"); //项目审核状态 HashMap projectStatusMap = planEnums.get("projectStatus"); //项目类型 HashMap projectTypesMap = planEnums.get("projectTypes"); //预算科目 HashMap budgetAccountMap = planEnums.get("budgetAccount"); //采购服务站 HashMap purchaseServicesMap = planEnums.get("purchaseServices"); List list = new ArrayList(); for (PlanQuarter planQuarter : planQuarters) { PlanQuarterResponseVo responseVo = new PlanQuarterResponseVo(); SysDeptResponseVo sysDeptResponseVo = (SysDeptResponseVo) deptService.selectDeptById(Long.valueOf(planQuarter.getPurchaseDeptId())).get("sysDept"); planQuarter.setPurchaseDeptName(sysDeptResponseVo.getDeptName()); //预算科目 for (Map.Entry entry : budgetAccountMap.entrySet()) { if (!ObjectUtils.isEmpty(planQuarter.getBudgetAccount()) && planQuarter.getBudgetAccount().equals(entry.getValue())) { planQuarter.setBudgetAccountStr(entry.getKey()); break; } } //采购服务站 for (Map.Entry entry : purchaseServicesMap.entrySet()) { if (!ObjectUtils.isEmpty(planQuarter.getPurchaseServices()) && planQuarter.getPurchaseServices().equals(entry.getValue())) { planQuarter.setPurchaseServicesStr(entry.getKey()); break; } } //项目审核状态 for (Map.Entry entry : projectStatusMap.entrySet()) { if (!ObjectUtils.isEmpty(planQuarter.getProjectStatus()) && planQuarter.getProjectStatus().equals(entry.getValue())) { planQuarter.setProjectStatusStr(entry.getKey()); break; } } //项目类型 for (Map.Entry entry : projectTypesMap.entrySet()) { if (!ObjectUtils.isEmpty(planQuarter.getProjectType()) && planQuarter.getProjectType().equals(entry.getValue())) { planQuarter.setProjectTypeStr(entry.getKey()); break; } } //项目属性为value拼接 if (!ObjectUtils.isEmpty(planQuarter.getProjectAttr())) { if (planQuarter.getProjectAttr().length() > 1) { StringBuilder builder = new StringBuilder(); String[] split = planQuarter.getProjectAttr().split(","); for (String s : split) { for (Map.Entry entry : projectAttributes.entrySet()) { if (s.equals(entry.getValue())) { if (!planQuarter.getProjectAttr().endsWith(s)) { builder.append(entry.getKey() + ","); } else { builder.append(entry.getKey()); } break; } } } planQuarter.setProjectAttrName(builder.toString()); } else { for (Map.Entry entry : projectAttributes.entrySet()) { if (planQuarter.getProjectAttr().equals(entry.getValue())) { planQuarter.setProjectAttrName(entry.getKey()); break; } } } } //机关业务指导处(科)为id拼接 String organDivision = planQuarter.getOrganDivision(); if (!ObjectUtils.isEmpty(organDivision)) { int length = organDivision.split(",").length; SysDeptOrgan organ = new SysDeptOrgan(); if (length > 1) { StringBuilder builder = new StringBuilder(); String[] split = organDivision.split(","); for (String s : split) { organ = sysDeptOrganMapper.selectById(s); if (!ObjectUtils.isEmpty(organ)) { if (!organDivision.endsWith(s)) { builder.append(organ.getOrganName() + ","); } else { builder.append(organ.getOrganName()); } } } planQuarter.setOrganDivisionStr(builder.toString()); } else if (length == 1) { organ = sysDeptOrganMapper.selectById(organDivision); if (!ObjectUtils.isEmpty(organ)) { planQuarter.setOrganDivisionStr(organ.getOrganName()); } } } //是否可以申请撤销和申请修改 //需求待填制可以申请,需求建档就不能申请 PmDemand demand = demandService.selectByPlanId(planQuarter.getPlanPracticalId()); if (!ObjectUtils.isEmpty(demand) && !demand.getProjectStatus().equals(PmProjectStatus.DEMAND_WAIT_FILL.getCode())) { planQuarter.setAppDeleteDo("false"); planQuarter.setAppUpdateDo("false"); } else { //能否申请撤销 if (!ObjectUtils.isEmpty(planQuarter.getAppDelete()) && planQuarter.getAppDelete().equals("true")) { //申请过的不能再申请 planQuarter.setAppDeleteDo("false"); } else if (planQuarter.getProjectStatus().equals("0")) { planQuarter.setAppDeleteDo("false"); } else { //提交后可以申请撤销 planQuarter.setAppDeleteDo("true"); } //能否申请修改 if (!ObjectUtils.isEmpty(planQuarter.getAppUpdate()) && planQuarter.getAppUpdate().equals("true")) { //申请过的不能再申请 planQuarter.setAppUpdateDo("false"); } else if (planQuarter.getProjectStatus().equals("0")) { planQuarter.setAppUpdateDo("false"); } else { //提交后可以申请撤销 planQuarter.setAppUpdateDo("true"); } } BeanUtils.copyProperties(planQuarter, responseVo); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); responseVo.setPlanDemandSubTimeStr(sdf.format(responseVo.getPlanDemandSubTime())); responseVo.setPlanPurchaseFinishTimeStr(sdf.format(responseVo.getPlanPurchaseFinishTime())); responseVo.setPlanDeliverTimeStr(sdf.format(responseVo.getPlanDeliverTime())); //状态在采购需求对接和流废标退回之间的项目可以进行催告---已发函不可再次发函 responseVo.setSendLetterDo("false"); if (!ObjectUtils.isEmpty(demand)) { if (sendLetterDo(demand.getProjectStatus()) && planQuarter.getSendLetter().equals("0")) { responseVo.setSendLetterDo("true"); } } try { responseVo.setTipsMessage(planQuarterGetTips(thresholdMap, alertTimeMap)); } catch (ParseException e) { e.printStackTrace(); } list.add(responseVo); } return list; } //是否可以执行发函 @Override public boolean sendLetterDo(String projectStatus) { List ls = new ArrayList<>(); ls.add(PmProjectStatus.PURCHASE_DEMAND_DOCKING.getCode()); ls.add(PmProjectStatus.EXPERT_FEEDBACK.getCode()); ls.add(PmProjectStatus.PROCUREMENT_DOCUMENTS_REVIEW.getCode()); ls.add(PmProjectStatus.PROCUREMENT_ANNOUNCEMENT.getCode()); ls.add(PmProjectStatus.PRE_BID_QUERY.getCode()); ls.add(PmProjectStatus.WAIT_OPEN_BID.getCode()); ls.add(PmProjectStatus.BID_RESULT_ANNOUNCEMENT.getCode()); ls.add(PmProjectStatus.WASTE_BID_HANDLE.getCode()); ls.add(PmProjectStatus.POST_BID_QUERY.getCode()); ls.add(PmProjectStatus.WASTE_BID_RETURN.getCode()); return ls.contains(projectStatus); } @Override public List idNotDemand() { return planQuarterMapper.idNotDemand(); } /** * 根据季度计划在各个季度提报时间的阈值进行提示 * * @return */ public String planQuarterGetTips(HashMap thresholdMap, HashMap alertTimeMap) throws ParseException { //提示信息:定义距离结束时间*天内提示 int alertDay = Integer.parseInt(alertTimeMap.get("计划提报时间")); Integer remindTine = 1000 * 60 * 60 * 24 * alertDay; String subTips = ""; //季度提报时间的结束时间阈值 Date thresholdTime = null; SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = new Date(); for (QuarterEnum val : QuarterEnum.values()) { if (val.getInfo().contains(date.getMonth() + "")) { switch (val.getCode()) { case "1": thresholdTime = dateFormat.parse(thresholdMap.get("第一季度结束时间")); case "2": thresholdTime = dateFormat.parse(thresholdMap.get("第二季度结束时间")); case "3": thresholdTime = dateFormat.parse(thresholdMap.get("第三季度结束时间")); case "4": thresholdTime = dateFormat.parse(thresholdMap.get("第四季度结束时间")); default: } break; } } double surplus = thresholdTime.getTime() - date.getTime(); //少于设定时间便提醒 if (surplus < remindTine && surplus > 0) { //剩余天数(向上取整) int i = (int) Math.ceil(surplus / 1000 / 60 / 60 / 24); if (i > 0) { subTips = "距离计划提报时间不足" + i + "天"; } } return subTips; } //是否在提报时间内 public Boolean isBetweenValue(PlanQuarter planQuarter) { //获取年度计划提报时间的阈值 //获取季度计划各个季度提报时间的阈值 List supTime = dictTypeService.selectDictDataByType("sys_quarterly_plan"); HashMap thresholdMap = new LinkedHashMap<>(); //各个季度提报时间的阈值 for (SysDictData dictData : supTime) { // 季度----阈值 thresholdMap.put(dictData.getDictLabel(), dictData.getDictValue()); } SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date thresholdTimeStart = null; Date thresholdTimeEnd = null; Calendar instance = Calendar.getInstance(); instance.setTime(planQuarter.getPlanDemandSubTime()); try { for (QuarterEnum val : QuarterEnum.values()) { if (val.getInfo().contains((instance.get(Calendar.MONTH) + 1) + "")) { //System.err.println("MONTH" + (instance.get(Calendar.MONTH) + 1)); switch (val.getCode()) { case "1": thresholdTimeStart = dateFormat.parse(thresholdMap.get("第一季度开始时间")); thresholdTimeEnd = dateFormat.parse(thresholdMap.get("第一季度结束时间")); break; case "2": thresholdTimeStart = dateFormat.parse(thresholdMap.get("第二季度开始时间")); thresholdTimeEnd = dateFormat.parse(thresholdMap.get("第二季度结束时间")); break; case "3": thresholdTimeStart = dateFormat.parse(thresholdMap.get("第三季度开始时间")); thresholdTimeEnd = dateFormat.parse(thresholdMap.get("第三季度结束时间")); break; default: thresholdTimeStart = dateFormat.parse(thresholdMap.get("第四季度开始时间")); thresholdTimeEnd = dateFormat.parse(thresholdMap.get("第四季度结束时间")); } break; } } if (!ObjectUtils.isEmpty(thresholdTimeStart) && !ObjectUtils.isEmpty(thresholdTimeEnd)) { System.err.println("instance=" + new Date(instance.getTime().getTime())); System.err.println("thresholdTimeStart=" + thresholdTimeStart); System.err.println("thresholdTimeEnd=" + thresholdTimeEnd); System.err.println("instance.before(thresholdTimeStart)=" + instance.before(thresholdTimeStart)); System.err.println("instance.after(thresholdTimeEnd)=" + instance.after(thresholdTimeEnd)); Date date = new Date(instance.getTime().getTime()); if (date.before(thresholdTimeStart) || date.after(thresholdTimeEnd)) { return false; } } } catch (ParseException e) { e.printStackTrace(); } return true; } }