123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- package com.persagy.calendar.handle;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Set;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Component;
- import org.springframework.transaction.annotation.Transactional;
- import com.persagy.calendar.pojo.dto.WorkCalendar;
- import com.persagy.calendar.pojo.dto.WorkCalendarRule;
- import com.persagy.calendar.pojo.vo.CustomCalendarVO;
- import com.persagy.calendar.pojo.vo.WorkCalendarRuleCreateVO;
- import com.persagy.calendar.pojo.vo.WorkCalendarRuleUpdateVO;
- import com.persagy.calendar.service.IWorkCalendarRuleService;
- import com.persagy.calendar.service.IWorkCalendarService;
- import com.persagy.common.enums.ResponseCode;
- import com.persagy.common.exception.BusinessException;
- import cn.hutool.core.collection.CollectionUtil;
- import cn.hutool.core.util.BooleanUtil;
- /**
- * @version 定义规则信息
- * @description
- * @company persagy
- * @author zhangqiankun
- * @since 2020年10月3日: 下午1:03:19
- */
- @Component
- public class WorkCalendarRuleHandler {
-
- @Autowired
- private IWorkCalendarService workCalendarService;
-
- @Autowired
- private IWorkCalendarRuleService workCalendarRuleService;
-
- /**
- * 批量创建规则信息
- */
- @Transactional
- public void batchCreateCalednarRule(CustomCalendarVO<WorkCalendarRuleCreateVO> createVO) {
- boolean result = false;
- WorkCalendarRule workCalendarRule = null;
- List<WorkCalendarRuleCreateVO> batchInfo = createVO.getBatchInfo();
- Set<String> calendarIds = new HashSet<String>();
- for (WorkCalendarRuleCreateVO rule : batchInfo) {
- // 优先判断工作历信息是否存在
- if (!calendarIds.contains(rule.getCalendarId())) {
- WorkCalendar workCalendar = this.workCalendarService.getById(rule.getCalendarId(), createVO.getProjectId());
- if (workCalendar == null) {
- throw new BusinessException("工作历主信息不存在");
- }
- }
- workCalendarRule = new WorkCalendarRule();
- BeanUtils.copyProperties(rule, workCalendarRule);
- workCalendarRule.setId(null);
- workCalendarRule.setGroupCode(createVO.getGroupCode());
- workCalendarRule.setProjectId(createVO.getProjectId());
- workCalendarRule.setUpdateUser(createVO.getUserId());
- // 为兼容IBMS,紧急修改内容: shop 类型的工作历规则,一个项目的dictType+dictCode+value已存在的话,直接更新
- if ("shop".equals(rule.getDictType()) && CollectionUtil.isNotEmpty(workCalendarRule.getValue())) {
- String ruleId = this.workCalendarRuleService.getCalendarRule(workCalendarRule);
- if (ruleId != null ) {
- // 直接更新
- workCalendarRule.setId(ruleId);
- result = workCalendarRuleService.updateWorkCalendarRule(workCalendarRule);
- if (!result) {
- throw new BusinessException("工作历规则信息保存失败");
- }
- calendarIds.add(rule.getCalendarId());
- continue;
- }
- }
- // 是否需要删除旧规则
- if (BooleanUtil.isTrue(createVO.getIsDelete()) && !calendarIds.contains(rule.getCalendarId())) {
- workCalendarRuleService.removeWorkCalendarRule(null, rule.getCalendarId(), rule.getDictType());
- //throw new BusinessException("工作历ID为:" + rule.getCalendarId() + "的工作历,删除规则信息失败");
- }
- result = this.workCalendarRuleService.createWorkCalendarRule(workCalendarRule);
- if (!result) {
- throw new BusinessException("工作历规则信息创建失败");
- }
- calendarIds.add(rule.getCalendarId());
- }
- calendarIds.clear();
- }
-
- /**
- * 批量更新规则信息
- */
- @Transactional
- public void batchUpdateCalednarRule(CustomCalendarVO<WorkCalendarRuleUpdateVO> updateVO) {
- boolean result = false;
- WorkCalendarRule workCalendarRule = null;
- List<WorkCalendarRuleUpdateVO> batchInfo = updateVO.getBatchInfo();
- Set<String> calendarIds = new HashSet<String>();
- for (WorkCalendarRuleUpdateVO rule : batchInfo) {
- // 优先判断工作历信息是否存在
- if (!calendarIds.contains(rule.getCalendarId())) {
- WorkCalendar workCalendar = this.workCalendarService.getById(rule.getCalendarId(), updateVO.getProjectId());
- if (workCalendar == null) {
- throw new BusinessException("工作历主信息不存在");
- }
- }
- // 再判断原规则数据是否存在
- WorkCalendarRule calendar = workCalendarRuleService.getById(rule.getId(), updateVO.getProjectId());
- if (calendar == null) {
- throw new BusinessException(ResponseCode.C0320.getDesc());
- }
- // 是否需要删除旧规则
- if (BooleanUtil.isTrue(updateVO.getIsDelete()) && !calendarIds.contains(rule.getCalendarId())) {
- workCalendarRuleService.removeWorkCalendarRule(null, rule.getCalendarId(), rule.getDictCode());
- //throw new BusinessException("工作历ID为:" + rule.getCalendarId() + "的工作历,删除规则信息失败");
- }
- workCalendarRule = new WorkCalendarRule();
- BeanUtils.copyProperties(rule, workCalendarRule);
- workCalendarRule.setGroupCode(updateVO.getGroupCode());
- workCalendarRule.setProjectId(updateVO.getProjectId());
- workCalendarRule.setUpdateUser(updateVO.getUserId());
- result = workCalendarRuleService.updateWorkCalendarRule(workCalendarRule);
- if (!result) {
- throw new BusinessException("工作历规则信息更新失败");
- }
- calendarIds.add(rule.getCalendarId());
- }
- calendarIds.clear();
- }
-
- }
|