|
@@ -2,15 +2,22 @@ package com.ozs.plan.service.impl;
|
|
|
|
|
|
import com.ozs.common.core.domain.AjaxResult;
|
|
|
import com.ozs.common.enums.ProjectStatus;
|
|
|
+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.PlanOfYears;
|
|
|
import com.ozs.plan.doman.vo.requestVo.PlanOfYearsStandardVo;
|
|
|
import com.ozs.plan.doman.vo.responseVo.PlanOfYearsResponseVo;
|
|
|
import com.ozs.plan.mapper.PlanOfYearsMapper;
|
|
|
import com.ozs.plan.service.PlanOfYearsService;
|
|
|
+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.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
@@ -20,9 +27,12 @@ import java.util.List;
|
|
|
*/
|
|
|
@Service
|
|
|
public class PlanOfYearsServiceImpl implements PlanOfYearsService {
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class);
|
|
|
|
|
|
@Autowired
|
|
|
PlanOfYearsMapper planOfYearsMapper;
|
|
|
+ @Autowired
|
|
|
+ protected Validator validator;
|
|
|
|
|
|
@Override
|
|
|
public List<PlanOfYears> selectPlanOfYearsList(PlanOfYearsStandardVo vo) {
|
|
@@ -39,7 +49,7 @@ public class PlanOfYearsServiceImpl implements PlanOfYearsService {
|
|
|
|
|
|
@Override
|
|
|
public AjaxResult insertPlanOfYears(PlanOfYearsStandardVo yearsStandardVo) {
|
|
|
- if (planOfYearsMapper.countProjectName(yearsStandardVo.getProjectName()) > 0) {
|
|
|
+ if (planOfYearsMapper.countProjectName(yearsStandardVo.getProjectName()).size() > 0) {
|
|
|
return AjaxResult.error("该项目名称已经存在");
|
|
|
}
|
|
|
PlanOfYears ofYears = new PlanOfYears();
|
|
@@ -70,11 +80,13 @@ public class PlanOfYearsServiceImpl implements PlanOfYearsService {
|
|
|
|
|
|
@Override
|
|
|
public AjaxResult view(PlanOfYearsStandardVo yearsStandardVo) {
|
|
|
+ PlanOfYearsResponseVo planOfYearsResponseVo = new PlanOfYearsResponseVo();
|
|
|
PlanOfYears byId = planOfYearsMapper.getById(yearsStandardVo.getPlanYearId());
|
|
|
if (byId == null) {
|
|
|
return AjaxResult.error("数据查询失败");
|
|
|
}
|
|
|
- return AjaxResult.success(byId);
|
|
|
+ BeanUtils.copyProperties(byId, planOfYearsResponseVo);
|
|
|
+ return AjaxResult.success(planOfYearsResponseVo);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -92,4 +104,84 @@ public class PlanOfYearsServiceImpl implements PlanOfYearsService {
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String importPlanOfYears(List<PlanOfYears> planOfYears, boolean isUpdateSupport, String operName) {
|
|
|
+ if (StringUtils.isNull(planOfYears) || planOfYears.size() == 0) {
|
|
|
+ throw new ServiceException("导入年度计划数据不能为空!");
|
|
|
+ }
|
|
|
+ int successNum = 0;
|
|
|
+ int failureNum = 0;
|
|
|
+ StringBuilder successMsg = new StringBuilder();
|
|
|
+ StringBuilder failureMsg = new StringBuilder();
|
|
|
+ for (PlanOfYears ofYear : planOfYears) {
|
|
|
+ try {
|
|
|
+ //验证项目名称是否重复导入
|
|
|
+ List<PlanOfYears> plan = planOfYearsMapper.countProjectName(ofYear.getProjectName());
|
|
|
+ if (plan.size() == 0) {
|
|
|
+ planOfYearsMapper.insertPlanOfYears(ofYear);
|
|
|
+ successNum++;
|
|
|
+ successMsg.append("<br/>" + successNum + "、项目 " + ofYear.getProjectName() + " 导入成功");
|
|
|
+ } else if (isUpdateSupport) {
|
|
|
+ PlanOfYears years = plan.get(0);
|
|
|
+ BeanValidators.validateWithException(validator, ofYear);
|
|
|
+ years.setCreateBy(operName);
|
|
|
+ years.setCreateTime(new Date());
|
|
|
+ years.setProjectStatus(ProjectStatus.PLANWAITCOMMIT.getCode());
|
|
|
+ planOfYearsMapper.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(PlanOfYearsStandardVo yearsStandardVo) {
|
|
|
+
|
|
|
+ int commit = planOfYearsMapper.commit(yearsStandardVo.getPlanYearId());
|
|
|
+ if (commit != 1) {
|
|
|
+ return AjaxResult.error("项目状态数据异常");
|
|
|
+ }
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AjaxResult reviewTo(PlanOfYearsStandardVo vo) {
|
|
|
+ PlanOfYears ofYears = new PlanOfYears();
|
|
|
+ ofYears.setPlanYearId(vo.getPlanYearId());
|
|
|
+ ofYears.setProjectStatus(ProjectStatus.PLANTOEXAMINE.getCode());
|
|
|
+ int review = planOfYearsMapper.review(ofYears);
|
|
|
+ if (review != 1) {
|
|
|
+ return AjaxResult.error("项目状态数据异常");
|
|
|
+ }
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AjaxResult reviewReturn(PlanOfYearsStandardVo vo) {
|
|
|
+ PlanOfYears ofYears = new PlanOfYears();
|
|
|
+ BeanUtils.copyProperties(vo, ofYears);
|
|
|
+ ofYears.setProjectStatus(ProjectStatus.PLANTOBACK.getCode());
|
|
|
+ int review = planOfYearsMapper.review(ofYears);
|
|
|
+ if (review != 1) {
|
|
|
+ return AjaxResult.error("项目状态数据异常");
|
|
|
+ }
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
}
|