Browse Source

生成目标责任书

wangchangsheng 2 years ago
parent
commit
af94a4091d

+ 4 - 6
ims-service/ims-eval/src/main/java/com/ims/eval/controller/DeptResponsibilityController.java

@@ -93,21 +93,19 @@ public class DeptResponsibilityController {
 	/**
 	 * 生成目标责任书
 	 *
-	 * @param orgEvalRuleIds 组织拷屏ids
-	 * @param date           日期(预留指定生成某个月的目标责任书)
+	 * @param responsibilityIds 目标责任书ids
 	 * @return
 	 */
 	//@ImsPreAuth("eval:deptResponsibility:edit")
 	@PostMapping(value = "/generate")
 	@ApiOperation(value = "生成部门责任书", notes = "生成部门责任书")
-	public R generateResponsibility(@RequestParam(value = "orgEvalRuleIds", required = true) String orgEvalRuleIds,
-									@RequestParam(value = "date", required = false) String date) {
+	public R generateResponsibility(@RequestParam(value = "responsibilityIds", required = true) String responsibilityIds) {
 
 		try {
-			List<String> orgEvalRuleIdList = Arrays.asList(orgEvalRuleIds.split(","));
+			List<String> orgEvalRuleIdList = Arrays.asList(responsibilityIds.split(","));
 			boolean b = false;
 			for (String id : orgEvalRuleIdList) {
-				b = deptResponsibilityService.generateResponsibility(id, date);
+				b = deptResponsibilityService.generateResponsibility(id);
 				if (!b) {
 					return R.error().data("保存失败!");
 				}

+ 5 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/entity/DeptResponsibility.java

@@ -25,6 +25,11 @@ public class DeptResponsibility extends Model {
      */
     private String id;
 
+	/**
+	 * 业务编码
+	 */
+	private String responsibilityCode;
+
     /**
      * 部门ID
      */

+ 1 - 1
ims-service/ims-eval/src/main/java/com/ims/eval/service/IDeptResponsibilityService.java

@@ -21,5 +21,5 @@ public interface IDeptResponsibilityService extends IService<DeptResponsibility>
 	List<DeptResponsibility> list( String organizationId, String checkCycle,  String year, String month);
 
 
-	boolean generateResponsibility(String orgEvalRuleId,String date);
+	boolean generateResponsibility(String orgEvalRuleId);
 }

+ 91 - 91
ims-service/ims-eval/src/main/java/com/ims/eval/service/impl/DeptResponsibilityServiceImpl.java

@@ -127,64 +127,68 @@ public class DeptResponsibilityServiceImpl extends ServiceImpl<DeptResponsibilit
 
 	@Transactional
 	@Override
-	public boolean generateResponsibility(String orgEvalRuleId, String date) {
+	public boolean generateResponsibility(String id) {
 
 		//单位目标责任书
-		DeptResponsibility responsibility = new DeptResponsibility();
+//		DeptResponsibility responsibility = new DeptResponsibility();
 		//责任书指标详情记录集合
 		//List<ResponsibilityIndicatorInfo> indicatorInfolist = new ArrayList<>();
 
-		Date newDate;
-		//获取当前时间
-		if (StringUtils.isEmpty(date)) {
-			newDate = DateUtils.getCurrentDate();
-		} else {
-			newDate = DateUtils.toDate(date);
-		}
+//		Date newDate;
+//		//获取当前时间
+//		if (StringUtils.isEmpty(date)) {
+//			newDate = DateUtils.getCurrentDate();
+//		} else {
+//			newDate = DateUtils.toDate(date);
+//		}
 
-		String year = String.valueOf(DateUtils.getYear(newDate));//获取年份
-		String season = String.valueOf(DateUtils.getSeason(newDate));//获取季度
-		String month = String.valueOf(DateUtils.getMonth(newDate));//获取月份
+//		String year = String.valueOf(DateUtils.getYear(newDate));//获取年份
+//		String season = String.valueOf(DateUtils.getSeason(newDate));//获取季度
+//		String month = String.valueOf(DateUtils.getMonth(newDate));//获取月份
 
+		DeptResponsibility oriResponsibility =  baseMapper.selectById(id);
+		if (null == oriResponsibility) {
+			throw new CustomException("此目标责任书不存在");
+		}
 		//获取指定部门的规则
-		OrganizationEvaluationRule evaluationRule = organizationEvaluationRuleService.getById(orgEvalRuleId);
+		OrganizationEvaluationRule evaluationRule = organizationEvaluationRuleService.getById(oriResponsibility.getOrganizationEvaluationRuleId());
 		if (null == evaluationRule) {
 			throw new CustomException("不存在此单位权重配置");
 		}
+//
+//		//判断该是否存在目标责任书
+//		List<DeptResponsibility> oriList = new ArrayList<>();
+//		if ("NDKP".equals(evaluationRule.getEvaluationCycle())) {
+//			oriList = list(evaluationRule.getOrganizationId(), evaluationRule.getEvaluationCycle(), year, "");
+//		}
+//		if ("JDKP".equals(evaluationRule.getEvaluationCycle())) {
+//			month = String.valueOf(Integer.valueOf(month) * Integer.valueOf(season));//季度考评将
+//			oriList = list(evaluationRule.getOrganizationId(), evaluationRule.getEvaluationCycle(), year, month);
+//		}
+//		if ("YDKP".equals(evaluationRule.getEvaluationCycle())) {
+//			oriList = list(evaluationRule.getOrganizationId(), evaluationRule.getEvaluationCycle(), year, month);
+//		}
+//		if (oriList.size() > 0) {
+//			throw new CustomException("已存在该单位目标责任书");
+//		}
 
-		//判断该是否存在目标责任书
-		List<DeptResponsibility> oriList = new ArrayList<>();
-		if ("NDKP".equals(evaluationRule.getEvaluationCycle())) {
-			oriList = list(evaluationRule.getOrganizationId(), evaluationRule.getEvaluationCycle(), year, "");
-		}
-		if ("JDKP".equals(evaluationRule.getEvaluationCycle())) {
-			month = String.valueOf(Integer.valueOf(month) * Integer.valueOf(season));//季度考评将
-			oriList = list(evaluationRule.getOrganizationId(), evaluationRule.getEvaluationCycle(), year, month);
-		}
-		if ("YDKP".equals(evaluationRule.getEvaluationCycle())) {
-			oriList = list(evaluationRule.getOrganizationId(), evaluationRule.getEvaluationCycle(), year, month);
-		}
-		if (oriList.size() > 0) {
-			throw new CustomException("已存在该单位目标责任书");
-		}
-
-		//保存目标责任书
-		responsibility.setOrganizationId(evaluationRule.getOrganizationId());//考评组织ID
-		responsibility.setOrganizationName(evaluationRule.getOrganizationName());//考评组织名称
-		responsibility.setCheckCycle(evaluationRule.getEvaluationCycle());//考评周期
-		responsibility.setYear(year);//年份
-		responsibility.setMonth(month);//月份
-		responsibility.setOrganizationEvaluationRuleId(evaluationRule.getId());//考评规则id
-		//responsibility.setBeginDate(null);
-		//responsibility.setEndDate(null);
-		responsibility.setStage("流程未启动");
-		responsibility.setCreateTime(new Date());
-		//responsibility.setCreateBy("");
-
-		boolean b = super.saveOrUpdate(responsibility);
-		if (!b) {
-			throw new CustomException("保存目标责任书失败");
-		}
+//		//保存目标责任书
+//		responsibility.setOrganizationId(evaluationRule.getOrganizationId());//考评组织ID
+//		responsibility.setOrganizationName(evaluationRule.getOrganizationName());//考评组织名称
+//		responsibility.setCheckCycle(evaluationRule.getEvaluationCycle());//考评周期
+//		responsibility.setYear(year);//年份
+//		responsibility.setMonth(month);//月份
+//		responsibility.setOrganizationEvaluationRuleId(evaluationRule.getId());//考评规则id
+//		//responsibility.setBeginDate(null);
+//		//responsibility.setEndDate(null);
+//		responsibility.setStage("流程未启动");
+//		responsibility.setCreateTime(new Date());
+//		//responsibility.setCreateBy("");
+//
+//		boolean b = super.saveOrUpdate(responsibility);
+//		if (!b) {
+//			throw new CustomException("保存目标责任书失败");
+//		}
 
 		//获取对应的考评规(至少存在一条)
 		List<String> evaluateRuleIds = Arrays.asList(evaluationRule.getEvaluateRuleId().split(","));
@@ -210,7 +214,7 @@ public class DeptResponsibilityServiceImpl extends ServiceImpl<DeptResponsibilit
 
 		resDTOS.stream().forEach(r -> {
 			ResponsibilityIndicatorInfo info = new ResponsibilityIndicatorInfo();
-			info.setDeptResponsibilityId(responsibility.getId());
+			info.setDeptResponsibilityId(oriResponsibility.getId());
 			info.setIndicatorId(r.getId());
 			info.setIndicatorDictionaryId(r.getIndicatorDictionaryID());
 			info.setOptionCode(r.getOptionCode());
@@ -228,62 +232,58 @@ public class DeptResponsibilityServiceImpl extends ServiceImpl<DeptResponsibilit
 	@Override
 	public boolean saveOrUpdate(DeptResponsibility entity) {
 
+		//获取指定部门的规则
+		OrganizationEvaluationRule evaluationRule = organizationEvaluationRuleService.getById(entity.getOrganizationEvaluationRuleId());
+		if (null == evaluationRule) {
+			throw new CustomException("不存在此单位权重配置");
+		}
 
-//		DeptResponsibility responsibility = new DeptResponsibility();
-//
-//		//获取指定部门的规则
-//		OrganizationEvaluationRule evaluationRule = organizationEvaluationRuleService.getById(orgEvalRuleId);
-//		if (null == evaluationRule) {
-//			throw new CustomException("不存在此单位权重配置");
-//		}
-//		Date newDate;
-//		//获取当前时间
-//		if (StringUtils.isEmpty(date)) {
-//			newDate = DateUtils.getCurrentDate();
-//		} else {
-//			newDate = DateUtils.toDate(date);
-//		}
-//
-//		String year = String.valueOf(DateUtils.getYear(newDate));//获取年份
-//		String season = String.valueOf(DateUtils.getSeason(newDate));//获取季度
-//		String month = String.valueOf(DateUtils.getMonth(newDate));//获取月份
-//		//保存目标责任书
-//		responsibility.setOrganizationId(evaluationRule.getOrganizationId());//考评组织ID
-//		responsibility.setOrganizationName(evaluationRule.getOrganizationName());//考评组织名称
-//		responsibility.setCheckCycle(evaluationRule.getEvaluationCycle());//考评周期
-//		responsibility.setYear(year);//年份
-//		responsibility.setMonth(month);//月份
-//		responsibility.setOrganizationEvaluationRuleId(evaluationRule.getId());//考评规则id
-//		//responsibility.setBeginDate(null);
-//		//responsibility.setEndDate(null);
-//		responsibility.setStage("流程未启动");
-//		responsibility.setCreateTime(new Date());
-//		//responsibility.setCreateBy("");
-//
-//		boolean b = super.saveOrUpdate(responsibility);
-//		if (!b) {
-//			throw new CustomException("保存目标责任书失败");
-//		}
+		StringBuilder responsibilityCode = new StringBuilder();
+		responsibilityCode.append(evaluationRule.getOrganizationType()).append("_");
+		responsibilityCode.append(evaluationRule.getEvaluationCycle()).append("_");
 
+		//判断该是否存在目标责任书
+		List<DeptResponsibility> oriList = new ArrayList<>();
+		if ("NDKP".equals(evaluationRule.getEvaluationCycle())) {
+			oriList = list(evaluationRule.getOrganizationId(), evaluationRule.getEvaluationCycle(), entity.getYear(), "");
+			responsibilityCode.append(entity.getYear()).append("_");
+		}
+		if ("JDKP".equals(evaluationRule.getEvaluationCycle())) {
+			Date newDate = DateUtils.toDate(entity.getYear() + "-" + entity.getMonth() + "-01");
+			String season = String.valueOf(DateUtils.getSeason(newDate));//获取季度
+			String month = String.valueOf(Integer.valueOf(entity.getMonth()) * Integer.valueOf(season));//季度考评将
+			oriList = list(evaluationRule.getOrganizationId(), evaluationRule.getEvaluationCycle(), entity.getYear(), month);
+			responsibilityCode.append(entity.getYear()).append("_").append(month).append("_");
+		}
+		if ("YDKP".equals(evaluationRule.getEvaluationCycle())) {
+			oriList = list(evaluationRule.getOrganizationId(), evaluationRule.getEvaluationCycle(), entity.getYear(), entity.getMonth());
+			responsibilityCode.append(entity.getYear()).append("_").append(entity.getMonth()).append("_");
+		}
+		responsibilityCode.append(evaluationRule.getOrganizationId()).append("_");
 
 
-		QueryWrapper<DeptResponsibility> qw = new QueryWrapper();
 		if (null != entity && (null == entity.getId() || "".equals(entity.getId().trim()))) {
-			qw.lambda().eq(DeptResponsibility::getOrganizationId, entity.getOrganizationId());
-			qw.lambda().eq(DeptResponsibility::getCheckCycle, entity.getCheckCycle());
-			qw.lambda().eq(DeptResponsibility::getYear, entity.getYear());
-			List<DeptResponsibility> list = baseMapper.selectList(qw);
-			if (null != list && list.size() > 0) {
+			if (null != oriList && oriList.size() > 0) {
 				throw new CustomException("此单位在该阶段已存在目标责任书");
 			}
-
+			//保存目标责任书
+			entity.setResponsibilityCode(responsibilityCode.toString());
+			entity.setOrganizationId(evaluationRule.getOrganizationId());//考评组织ID
+			entity.setOrganizationName(evaluationRule.getOrganizationName());//考评组织名称
+			entity.setCheckCycle(evaluationRule.getEvaluationCycle());//考评周期
+			entity.setStage("流程未启动");
 			entity.setCreateTime(new Date());
 		} else {
+			DeptResponsibility update = baseMapper.selectById(entity.getId());
+			if (null != oriList && oriList.size() > 1 && !update.getId().equals(oriList.get(0).getId())) {
+				throw new CustomException("编辑记录未找到");
+			}
+			entity.setOrganizationId(evaluationRule.getOrganizationId());//考评组织ID
+			entity.setOrganizationName(evaluationRule.getOrganizationName());//考评组织名称
+			entity.setCheckCycle(evaluationRule.getEvaluationCycle());//考评周期
 			entity.setUpdateTime(new Date());
 		}
-
 		boolean b = super.saveOrUpdate(entity);
-
 		return b;
 	}