|
@@ -1,18 +1,38 @@
|
|
|
package com.ozs.plan.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.ozs.common.core.domain.entity.SysDept;
|
|
|
+import com.ozs.common.core.domain.entity.SysDictData;
|
|
|
+import com.ozs.common.core.domain.model.LoginUser;
|
|
|
+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.plan.doman.PlanYears;
|
|
|
import com.ozs.plan.doman.ProvisionalPlan;
|
|
|
import com.ozs.plan.mapper.PlanYearsMapper;
|
|
|
import com.ozs.plan.mapper.ProvisionalPlanMapper;
|
|
|
import com.ozs.plan.service.ProvisionalPlanService;
|
|
|
+import com.ozs.system.mapper.SysDeptMapper;
|
|
|
+import com.ozs.system.service.ISysDictTypeService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
@Service
|
|
|
public class ProvisionalPlanServiceImpl extends ServiceImpl<ProvisionalPlanMapper, ProvisionalPlan> implements ProvisionalPlanService {
|
|
|
|
|
|
@Autowired
|
|
|
private ProvisionalPlanMapper provisionalPlanMapper;
|
|
|
+ @Autowired
|
|
|
+ private ISysDictTypeService dictTypeService;
|
|
|
+ @Autowired
|
|
|
+ private SysDeptMapper deptMapper;
|
|
|
|
|
|
@Override
|
|
|
public int deleteProvisionalPlanById(Integer planYearId) {
|
|
@@ -23,4 +43,104 @@ public class ProvisionalPlanServiceImpl extends ServiceImpl<ProvisionalPlanMappe
|
|
|
public int updateProvisionalPlanById(ProvisionalPlan provisionalPlan) {
|
|
|
return provisionalPlanMapper.updateProvisionalPlanById(provisionalPlan);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String importProvisionalPlan(List<ProvisionalPlan> provisionalPlans, boolean updateSupport, LoginUser loginUser) {
|
|
|
+ // 字典项
|
|
|
+ HashMap<String, HashMap<String, String>> planEnums = dictTypeService.getAboutEnums();
|
|
|
+ HashMap<String, String> projectTypesMap = planEnums.get("projectTypes");
|
|
|
+ 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 (ProvisionalPlan ofProvisionalPlan : provisionalPlans) {
|
|
|
+ try {
|
|
|
+ //验证项目名称是否重复导入
|
|
|
+ List<ProvisionalPlan> plan = provisionalPlanMapper.selectProjectName(ofProvisionalPlan.getProjectName());
|
|
|
+ //将录入信息中的值更改为要保存的数据
|
|
|
+ if (plan.size() == 0) {
|
|
|
+ //采购单位
|
|
|
+ SysDept info = deptMapper.checkDeptNameOnlyOne(ofProvisionalPlan.getPurchaseDeptName());
|
|
|
+ if (StringUtils.isNotNull(info)) {
|
|
|
+ ofProvisionalPlan.setPurchaseDeptId(info.getDeptId());
|
|
|
+ }
|
|
|
+ ofProvisionalPlan.setProjectType(projectTypesMap.get(ofProvisionalPlan.getProjectType()));
|
|
|
+ ofProvisionalPlan.setProjectStatus(ProjectStatus.PLANWAITCOMMIT.getCode());
|
|
|
+ ofProvisionalPlan.setPurchaseMode(planPurchaseModesMap.get(ofProvisionalPlan.getPurchaseMode()));
|
|
|
+ //项目属性是多选字段
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
+ if (ofProvisionalPlan.getProjectAttr().contains(",")) {
|
|
|
+ String[] split = ofProvisionalPlan.getProjectAttr().split(",");
|
|
|
+ for (String s : split) {
|
|
|
+ builder.append(projectAttributes.get(s) + ",");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ builder.append(projectAttributes.get(ofProvisionalPlan.getProjectAttr()));
|
|
|
+ }
|
|
|
+ ofProvisionalPlan.setProjectAttr(builder.toString());
|
|
|
+ ofProvisionalPlan.setPurchaseServices(purchaseServices.get(ofProvisionalPlan.getPurchaseServices()));
|
|
|
+ ofProvisionalPlan.setIsExcess(isExcessOrNo(ofProvisionalPlan.getProjectType(), ofProvisionalPlan.getEvaluation()));
|
|
|
+ ofProvisionalPlan.setCreated(String.valueOf(loginUser.getUserId()));
|
|
|
+ ofProvisionalPlan.setCreateTime(new Date());
|
|
|
+ provisionalPlanMapper.insert(ofProvisionalPlan);
|
|
|
+ successNum++;
|
|
|
+ successMsg.append("*" + successNum + "、项目 " + ofProvisionalPlan.getProjectName() + " 导入成功!");
|
|
|
+ //} else if (isUpdateSupport) {
|
|
|
+ // PlanYears years = plan.get(0);
|
|
|
+ // BeanValidators.validateWithException(validator, ofYear);
|
|
|
+ // years.setCreateTime(new Date());
|
|
|
+ // years.setProjectStatus(ProjectStatus.PLANWAITCOMMIT.getCode());
|
|
|
+ // planYearsMapper.updateById(years);
|
|
|
+ // successNum++;
|
|
|
+ // successMsg.append("<br/>" + successNum + "、项目 " + ofYear.getProjectName() + " 更新成功");
|
|
|
+ } else {
|
|
|
+ failureNum++;
|
|
|
+ failureMsg.append("*" + successNum + "、项目 " + ofProvisionalPlan.getProjectName() + " 已存在");
|
|
|
+ }
|
|
|
+ } catch (Exception exc) {
|
|
|
+ failureNum++;
|
|
|
+ String msg = "*" + successNum + "、项目 " + ofProvisionalPlan.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();
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断是否为超额计划
|
|
|
+ public String isExcessOrNo(String projectType, BigDecimal evaluation) {
|
|
|
+ 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 (projectType.equals(value.getCode())) {
|
|
|
+ threshold = BigDecimal.valueOf(Long.parseLong(thresholdMap.get(value.getInfo())));
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (evaluation.compareTo(threshold) == 1) {
|
|
|
+ //是超额计划
|
|
|
+ return ("1");
|
|
|
+ } else {
|
|
|
+ return ("0");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|