|
@@ -0,0 +1,272 @@
|
|
|
+package com.ozs.plan.service.impl;
|
|
|
+
|
|
|
+import com.ozs.common.core.domain.AjaxResult;
|
|
|
+import com.ozs.common.core.domain.entity.SysDictData;
|
|
|
+import com.ozs.common.enums.ProjectStatus;
|
|
|
+import com.ozs.common.enums.ProjectTypes;
|
|
|
+import com.ozs.common.exception.ServiceException;
|
|
|
+import com.ozs.common.utils.StringUtils;
|
|
|
+import com.ozs.common.utils.bean.BeanUtils;
|
|
|
+import com.ozs.common.utils.bean.BeanValidators;
|
|
|
+import com.ozs.plan.doman.PlanYears;
|
|
|
+import com.ozs.plan.doman.vo.requestVo.PlanYearsStandardVo;
|
|
|
+import com.ozs.plan.doman.vo.responseVo.PlanYearsResponseVo;
|
|
|
+import com.ozs.plan.mapper.PlanYearsMapper;
|
|
|
+import com.ozs.plan.service.PlanYearsService;
|
|
|
+import com.ozs.system.service.ISysDictTypeService;
|
|
|
+import com.ozs.system.service.impl.SysUserServiceImpl;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.validation.Validator;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author buzhanyi
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class PlanYearsServiceImpl implements PlanYearsService {
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class);
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ PlanYearsMapper planYearsMapper;
|
|
|
+ @Autowired
|
|
|
+ protected Validator validator;
|
|
|
+ @Autowired
|
|
|
+ private ISysDictTypeService dictTypeService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<PlanYears> selectPlanOfYearsList(PlanYearsStandardVo vo) {
|
|
|
+ PlanYears ofYears = new PlanYears();
|
|
|
+ List<PlanYears> planYears = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ BeanUtils.copyProperties(vo, ofYears);
|
|
|
+ planYears = planYearsMapper.selectPlanOfYearsList(ofYears);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return planYears;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AjaxResult insertPlanOfYears(PlanYearsStandardVo yearsStandardVo) {
|
|
|
+ if (planYearsMapper.countProjectName(yearsStandardVo.getProjectName()).size() > 0) {
|
|
|
+ return AjaxResult.error("该项目名称已经存在");
|
|
|
+ }
|
|
|
+ PlanYears ofYears = new PlanYears();
|
|
|
+ try {
|
|
|
+ BeanUtils.copyProperties(yearsStandardVo, ofYears);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ //判断是否为超额计划
|
|
|
+ BigDecimal evaluation = yearsStandardVo.getEvaluation();
|
|
|
+ BigDecimal threshold = new BigDecimal(0);
|
|
|
+ //获取各个项目类型设定的概算金额阈值
|
|
|
+ List<SysDictData> data = dictTypeService.selectDictDataByType("sys_over_limit_threshold");
|
|
|
+ HashMap<String, String> thresholdMap = new LinkedHashMap<>();
|
|
|
+ //各个类型的概算金额阈值
|
|
|
+ for (SysDictData dictData : data) {
|
|
|
+ // 类型----阈值
|
|
|
+ thresholdMap.put(dictData.getDictLabel(), dictData.getDictValue());
|
|
|
+ }
|
|
|
+ //项目类型
|
|
|
+ for (ProjectTypes value : ProjectTypes.values()) {
|
|
|
+ if (yearsStandardVo.getProjectType().equals(value.getCode())) {
|
|
|
+ threshold = BigDecimal.valueOf(Long.parseLong(thresholdMap.get(value.getInfo())));
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (evaluation.compareTo(threshold) == 1) {
|
|
|
+ //是超额项目
|
|
|
+ ofYears.setIsExcess("1");
|
|
|
+ } else {
|
|
|
+ ofYears.setIsExcess("0");
|
|
|
+ }
|
|
|
+ ofYears.setProjectStatus(ProjectStatus.PLANWAITCOMMIT.getCode());
|
|
|
+ ofYears.setCreateTime(new Date());
|
|
|
+ planYearsMapper.insertPlanOfYears(ofYears);
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AjaxResult deletePlanOfYearsByIds(Long[] planIds) {
|
|
|
+ planYearsMapper.deletePlanOfYearsByIds(planIds);
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AjaxResult deletePlanOfYearsById(Long planId) {
|
|
|
+ planYearsMapper.deletePlanOfYearsById(planId);
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AjaxResult view(PlanYearsStandardVo yearsStandardVo) {
|
|
|
+ PlanYearsResponseVo planYearsResponseVo = new PlanYearsResponseVo();
|
|
|
+ PlanYears byId = planYearsMapper.getById(yearsStandardVo.getPlanYearId());
|
|
|
+ if (byId == null) {
|
|
|
+ return AjaxResult.error("数据查询失败");
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(byId, planYearsResponseVo);
|
|
|
+ return AjaxResult.success(planYearsResponseVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AjaxResult update(PlanYearsStandardVo yearsStandardVo) {
|
|
|
+ if (planYearsMapper.countProjectNameOther(yearsStandardVo.getProjectName(), String.valueOf(yearsStandardVo.getPlanYearId())) > 0) {
|
|
|
+ return AjaxResult.error("该项目名称已经存在");
|
|
|
+ }
|
|
|
+ PlanYears ofYears = new PlanYears();
|
|
|
+ try {
|
|
|
+ BeanUtils.copyProperties(yearsStandardVo, ofYears);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ BigDecimal evaluation = ofYears.getEvaluation();
|
|
|
+ BigDecimal threshold = new BigDecimal(0);
|
|
|
+ //获取各个项目类型设定的概算金额阈值
|
|
|
+ List<SysDictData> data = dictTypeService.selectDictDataByType("sys_over_limit_threshold");
|
|
|
+ HashMap<String, String> thresholdMap = new LinkedHashMap<>();
|
|
|
+ //各个类型的概算金额阈值
|
|
|
+ for (SysDictData dictData : data) {
|
|
|
+ // 类型----阈值
|
|
|
+ thresholdMap.put(dictData.getDictLabel(), dictData.getDictValue());
|
|
|
+ }
|
|
|
+ //项目类型
|
|
|
+ for (ProjectTypes value : ProjectTypes.values()) {
|
|
|
+ if (ofYears.getProjectType().equals(value.getCode())) {
|
|
|
+ threshold = BigDecimal.valueOf(Long.parseLong(thresholdMap.get(value.getInfo())));
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (evaluation.compareTo(threshold) == 1) {
|
|
|
+ //是超额项目
|
|
|
+ ofYears.setIsExcess("1");
|
|
|
+ } else {
|
|
|
+ ofYears.setIsExcess("0");
|
|
|
+ }
|
|
|
+
|
|
|
+ planYearsMapper.updateById(ofYears);
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String importPlanOfYears(List<PlanYears> planYears, boolean isUpdateSupport, String operName) {
|
|
|
+ if (StringUtils.isNull(planYears) || planYears.size() == 0) {
|
|
|
+ throw new ServiceException("导入年度计划数据不能为空!");
|
|
|
+ }
|
|
|
+ HashMap<String, HashMap<String, String>> planEnums = dictTypeService.getAboutEnums();
|
|
|
+ HashMap<String, String> projectTypesMap = planEnums.get("ProjectTypes");
|
|
|
+ HashMap<String, String> projectStatusMap = planEnums.get("ProjectStatus");
|
|
|
+ HashMap<String, String> planPurchaseModesMap = planEnums.get("PlanPurchaseModes");
|
|
|
+ HashMap<String, String> projectAttributes = planEnums.get("ProjectAttributes");
|
|
|
+ HashMap<String, String> purchaseServices = planEnums.get("purchaseServices");
|
|
|
+ int successNum = 0;
|
|
|
+ int failureNum = 0;
|
|
|
+ StringBuilder successMsg = new StringBuilder();
|
|
|
+ StringBuilder failureMsg = new StringBuilder();
|
|
|
+ for (PlanYears ofYear : planYears) {
|
|
|
+ try {
|
|
|
+ //验证项目名称是否重复导入
|
|
|
+ List<PlanYears> plan = planYearsMapper.countProjectName(ofYear.getProjectName());
|
|
|
+ if (plan.size() == 0) {
|
|
|
+ //将录入信息中的值更改为要保存的数据
|
|
|
+
|
|
|
+ planYearsMapper.insertPlanOfYears(ofYear);
|
|
|
+ successNum++;
|
|
|
+ successMsg.append("<br/>" + successNum + "、项目 " + ofYear.getProjectName() + " 导入成功");
|
|
|
+ } else if (isUpdateSupport) {
|
|
|
+ PlanYears years = plan.get(0);
|
|
|
+ BeanValidators.validateWithException(validator, ofYear);
|
|
|
+ years.setCreateBy(operName);
|
|
|
+ years.setCreateTime(new Date());
|
|
|
+ years.setProjectStatus(ProjectStatus.PLANWAITCOMMIT.getCode());
|
|
|
+ planYearsMapper.updateById(years);
|
|
|
+ successNum++;
|
|
|
+ successMsg.append("<br/>" + successNum + "、项目 " + ofYear.getProjectName() + " 更新成功");
|
|
|
+ } else {
|
|
|
+ failureNum++;
|
|
|
+ successMsg.append("<br/>" + successNum + "、项目 " + ofYear.getProjectName() + " 已存在");
|
|
|
+ }
|
|
|
+ } catch (Exception exc) {
|
|
|
+ failureNum++;
|
|
|
+ String msg = "<br/>" + successNum + "、项目 " + ofYear.getProjectName() + " 导入失败";
|
|
|
+ failureMsg.append(msg + exc.getMessage());
|
|
|
+ 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
|
|
|
+ public AjaxResult commit(PlanYearsStandardVo yearsStandardVo) {
|
|
|
+ //PlanOfYears byId = planOfYearsMapper.getById(yearsStandardVo.getPlanYearId());
|
|
|
+ //BigDecimal evaluation = byId.getEvaluation();
|
|
|
+ //BigDecimal threshold = new BigDecimal(0);
|
|
|
+ ////获取各个项目类型设定的概算金额阈值
|
|
|
+ //List<SysDictData> data = dictTypeService.selectDictDataByType("sys_over_limit_threshold");
|
|
|
+ //HashMap<String, String> thresholdMap = new LinkedHashMap<>();
|
|
|
+ ////各个类型的概算金额阈值
|
|
|
+ //for (SysDictData dictData : data) {
|
|
|
+ // // 类型----阈值
|
|
|
+ // thresholdMap.put(dictData.getDictLabel(), dictData.getDictValue());
|
|
|
+ //}
|
|
|
+ ////项目类型
|
|
|
+ //for (ProjectTypes value : ProjectTypes.values()) {
|
|
|
+ // if (byId.getProjectType().equals(value.getCode())) {
|
|
|
+ // threshold = BigDecimal.valueOf(Long.parseLong(thresholdMap.get(value.getInfo())));
|
|
|
+ // }
|
|
|
+ // break;
|
|
|
+ //}
|
|
|
+ //
|
|
|
+ //if (evaluation.compareTo(threshold) == 1) {
|
|
|
+ // //是超额项目
|
|
|
+ //}
|
|
|
+
|
|
|
+ int commit = planYearsMapper.commit(yearsStandardVo.getPlanYearId());
|
|
|
+ if (commit != 1) {
|
|
|
+ return AjaxResult.error("项目状态数据异常");
|
|
|
+ }
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AjaxResult reviewTo(PlanYearsStandardVo vo) {
|
|
|
+ PlanYears ofYears = new PlanYears();
|
|
|
+ ofYears.setPlanYearId(vo.getPlanYearId());
|
|
|
+ ofYears.setProjectStatus(ProjectStatus.PLANTOEXAMINE.getCode());
|
|
|
+ int review = planYearsMapper.review(ofYears);
|
|
|
+ if (review != 1) {
|
|
|
+ return AjaxResult.error("项目状态数据异常");
|
|
|
+ }
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AjaxResult reviewReturn(PlanYearsStandardVo vo) {
|
|
|
+ PlanYears ofYears = new PlanYears();
|
|
|
+ BeanUtils.copyProperties(vo, ofYears);
|
|
|
+ ofYears.setProjectStatus(ProjectStatus.PLANTOBACK.getCode());
|
|
|
+ int review = planYearsMapper.review(ofYears);
|
|
|
+ if (review != 1) {
|
|
|
+ return AjaxResult.error("项目状态数据异常");
|
|
|
+ }
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|