WfSubscriptionServiceImpl.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. package com.xjrsoft.module.ledger.service.impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  6. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  7. import com.github.yulichang.base.MPJBaseServiceImpl;
  8. import com.github.yulichang.wrapper.MPJLambdaWrapper;
  9. import com.xjrsoft.common.utils.VoToColumnUtil;
  10. import com.xjrsoft.module.ledger.dto.WfSubscriptionPageDto;
  11. import com.xjrsoft.module.ledger.entity.WfSubscription;
  12. import com.xjrsoft.module.ledger.entity.WfSubscriptionList;
  13. import com.xjrsoft.module.ledger.mapper.WfSubscriptionListMapper;
  14. import com.xjrsoft.module.ledger.mapper.WfSubscriptionMapper;
  15. import com.xjrsoft.module.ledger.service.IWfSubscriptionService;
  16. import com.xjrsoft.module.ledger.vo.WfSubscriptionExcelVo;
  17. import com.xjrsoft.module.ledger.vo.WfSubscriptionListInfoVo;
  18. import com.xjrsoft.module.ledger.vo.WfSubscriptionListVo;
  19. import com.xjrsoft.module.ledger.vo.WfSubscriptionPageVo;
  20. import com.xjrsoft.module.ledger.vo.WorkflowRecordVo;
  21. import com.xjrsoft.module.student.entity.BaseStudentAssessmentItem;
  22. import com.xjrsoft.module.student.vo.BaseStudentAssessmentItemPageVo;
  23. import com.xjrsoft.module.system.entity.File;
  24. import com.xjrsoft.module.system.service.IFileService;
  25. import com.xjrsoft.module.workflow.entity.WorkflowExtra;
  26. import com.xjrsoft.module.workflow.entity.WorkflowFormRelation;
  27. import com.xjrsoft.module.workflow.entity.WorkflowRecord;
  28. import com.xjrsoft.module.workflow.mapper.WorkflowExtraMapper;
  29. import com.xjrsoft.module.workflow.mapper.WorkflowFormRelationMapper;
  30. import com.xjrsoft.module.workflow.mapper.WorkflowRecordMapper;
  31. import lombok.AllArgsConstructor;
  32. import org.springframework.stereotype.Service;
  33. import org.springframework.transaction.annotation.Transactional;
  34. import java.text.SimpleDateFormat;
  35. import java.time.LocalDate;
  36. import java.time.ZoneId;
  37. import java.util.ArrayList;
  38. import java.util.Date;
  39. import java.util.HashMap;
  40. import java.util.List;
  41. import java.util.Map;
  42. import java.util.Objects;
  43. import java.util.stream.Collectors;
  44. /**
  45. * @title: 物品申购
  46. * @Author dzx
  47. * @Date: 2024-02-19
  48. * @Version 1.0
  49. */
  50. @Service
  51. @AllArgsConstructor
  52. public class WfSubscriptionServiceImpl extends MPJBaseServiceImpl<WfSubscriptionMapper, WfSubscription> implements IWfSubscriptionService {
  53. private final WfSubscriptionMapper wfSubscriptionMapper;
  54. private final WfSubscriptionListMapper wfSubscriptionListMapper;
  55. private IFileService fileService;
  56. private WorkflowRecordMapper workflowRecordMapper;
  57. private WorkflowExtraMapper workflowExtraMapper;
  58. private WorkflowFormRelationMapper workflowFormRelationMapper;
  59. @Override
  60. @Transactional(rollbackFor = Exception.class)
  61. public Boolean add(WfSubscription wfSubscription) {
  62. wfSubscriptionMapper.insert(wfSubscription);
  63. for (WfSubscriptionList wfSubscriptionList : wfSubscription.getWfSubscriptionListList()) {
  64. wfSubscriptionList.setParentId(wfSubscription.getId());
  65. wfSubscriptionListMapper.insert(wfSubscriptionList);
  66. }
  67. return true;
  68. }
  69. @Override
  70. @Transactional(rollbackFor = Exception.class)
  71. public Boolean update(WfSubscription wfSubscription) {
  72. wfSubscriptionMapper.updateById(wfSubscription);
  73. //********************************* WfSubscriptionList 增删改 开始 *******************************************/
  74. {
  75. // 查出所有子级的id
  76. List<WfSubscriptionList> wfSubscriptionListList = wfSubscriptionListMapper.selectList(Wrappers.lambdaQuery(WfSubscriptionList.class).eq(WfSubscriptionList::getParentId, wfSubscription.getId()).select(WfSubscriptionList::getId));
  77. List<Long> wfSubscriptionListIds = wfSubscriptionListList.stream().map(WfSubscriptionList::getId).collect(Collectors.toList());
  78. //原有子表单 没有被删除的主键
  79. List<Long> wfSubscriptionListOldIds = wfSubscription.getWfSubscriptionListList().stream().map(WfSubscriptionList::getId).filter(Objects::nonNull).collect(Collectors.toList());
  80. //找到需要删除的id
  81. List<Long> wfSubscriptionListRemoveIds = wfSubscriptionListIds.stream().filter(item -> !wfSubscriptionListOldIds.contains(item)).collect(Collectors.toList());
  82. for (WfSubscriptionList wfSubscriptionList : wfSubscription.getWfSubscriptionListList()) {
  83. //如果不等于空则修改
  84. if (wfSubscriptionList.getId() != null) {
  85. wfSubscriptionListMapper.updateById(wfSubscriptionList);
  86. }
  87. //如果等于空 则新增
  88. else {
  89. //已经不存在的id 删除
  90. wfSubscriptionList.setParentId(wfSubscription.getId());
  91. wfSubscriptionListMapper.insert(wfSubscriptionList);
  92. }
  93. }
  94. //已经不存在的id 删除
  95. if(wfSubscriptionListRemoveIds.size() > 0){
  96. wfSubscriptionListMapper.deleteBatchIds(wfSubscriptionListRemoveIds);
  97. }
  98. }
  99. //********************************* WfSubscriptionList 增删改 结束 *******************************************/
  100. return true;
  101. }
  102. @Override
  103. @Transactional(rollbackFor = Exception.class)
  104. public Boolean delete(List<Long> ids) {
  105. wfSubscriptionMapper.deleteBatchIds(ids);
  106. wfSubscriptionListMapper.delete(Wrappers.lambdaQuery(WfSubscriptionList.class).in(WfSubscriptionList::getParentId, ids));
  107. return true;
  108. }
  109. @Override
  110. public Page<WfSubscriptionPageVo> getPage(Page<WfSubscriptionPageVo> page, WfSubscriptionPageDto dto) {
  111. Page<WfSubscriptionPageVo> voPage = wfSubscriptionMapper.getPage(page, dto);
  112. List<WfSubscriptionList> wfSubscriptionList = wfSubscriptionListMapper.selectList(
  113. new QueryWrapper<WfSubscriptionList>().lambda().orderByAsc(WfSubscriptionList::getId)
  114. );
  115. Map<Long, String> flowMap = new HashMap<>();
  116. for (WfSubscriptionList subscriptionList : wfSubscriptionList) {
  117. if(flowMap.containsKey(subscriptionList.getParentId())){
  118. continue;
  119. }
  120. flowMap.put(subscriptionList.getParentId(), subscriptionList.getNameOfThePurchasedItem());
  121. }
  122. for (WfSubscriptionPageVo record : voPage.getRecords()) {
  123. List<File> list = fileService.list(Wrappers.lambdaQuery(File.class).eq(File::getFolderId, record.getFolderId()));
  124. record.setFileInfos(list);
  125. record.setFlowName(flowMap.get(Long.valueOf(record.getId())));
  126. }
  127. return voPage;
  128. }
  129. @Override
  130. public WfSubscriptionListInfoVo getSubscriptionList(Long id) {
  131. WfSubscriptionListInfoVo info = wfSubscriptionMapper.getInfoById(id);
  132. List<WfSubscriptionList> subscriptionListList = wfSubscriptionListMapper.selectList(
  133. new QueryWrapper<WfSubscriptionList>().lambda().eq(WfSubscriptionList::getParentId, id)
  134. );
  135. info.setSubscriptionList(BeanUtil.copyToList(subscriptionListList, WfSubscriptionListVo.class));
  136. List<WorkflowRecord> recordList = workflowRecordMapper.selectList(
  137. new MPJLambdaWrapper<WorkflowRecord>()
  138. .select(WorkflowRecord.class, x -> VoToColumnUtil.fieldsToColumns(WorkflowRecordVo.class).contains(x.getProperty()))
  139. .innerJoin(WorkflowFormRelation.class, WorkflowFormRelation::getProcessId, WorkflowRecord::getProcessId)
  140. .eq(WorkflowFormRelation::getFormKeyValue, id)
  141. );
  142. info.setWorkflowRecordList(BeanUtil.copyToList(recordList, WorkflowRecordVo.class));
  143. List<WorkflowFormRelation> relations = workflowFormRelationMapper.selectList(new QueryWrapper<WorkflowFormRelation>().lambda().eq(WorkflowFormRelation::getFormKeyValue, id));
  144. if(!relations.isEmpty()){
  145. info.setProcessId(relations.get(0).getProcessId());
  146. }
  147. //查询最后一个节点的taskId
  148. List<WorkflowExtra> taskList = workflowExtraMapper.selectList(
  149. new QueryWrapper<WorkflowExtra>().lambda()
  150. .eq(WorkflowExtra::getProcessId, info.getProcessId())
  151. .orderByDesc(WorkflowExtra::getStartTime)
  152. );
  153. if(!taskList.isEmpty()){
  154. info.setTaskId(taskList.get(0).getTaskId());
  155. }
  156. return info;
  157. }
  158. @Override
  159. public List<WfSubscriptionExcelVo> getList(WfSubscriptionPageDto dto) {
  160. List<WfSubscriptionList> wfSubscriptionList = wfSubscriptionListMapper.selectList(
  161. new QueryWrapper<WfSubscriptionList>().lambda().orderByAsc(WfSubscriptionList::getId)
  162. );
  163. Map<Long, String> flowMap = new HashMap<>();
  164. for (WfSubscriptionList subscriptionList : wfSubscriptionList) {
  165. if(flowMap.containsKey(subscriptionList.getParentId())){
  166. continue;
  167. }
  168. flowMap.put(subscriptionList.getParentId(), subscriptionList.getNameOfThePurchasedItem());
  169. }
  170. List<WfSubscriptionPageVo> list = wfSubscriptionMapper.getList(dto);
  171. List<WfSubscriptionExcelVo> result = new ArrayList<>();
  172. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  173. for (WfSubscriptionPageVo record : list) {
  174. WfSubscriptionExcelVo excelVo = BeanUtil.toBean(record, WfSubscriptionExcelVo.class);
  175. if(record.getShenQingRiQi4752() != null){
  176. excelVo.setApplyDate(sdf.format(record.getShenQingRiQi4752()));
  177. }
  178. excelVo.setFlowName(flowMap.get(Long.valueOf(record.getId())));
  179. result.add(excelVo);
  180. }
  181. return result;
  182. }
  183. @Override
  184. public Boolean dataHandle(Long formId) {
  185. WfSubscription wfSubscription = this.getById(formId);
  186. if(wfSubscription != null){
  187. Date shenQingRiQi = wfSubscription.getShenQingRiQi4752();
  188. LocalDate localDate = shenQingRiQi.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
  189. String year = String.valueOf(localDate.getYear());
  190. //获取当前内存中的最大编号
  191. LambdaQueryWrapper<WfSubscription> wfSubscriptionLambdaQueryWrapper = new LambdaQueryWrapper<>();
  192. wfSubscriptionLambdaQueryWrapper
  193. .select(WfSubscription.class, x -> VoToColumnUtil.fieldsToColumns(WfSubscription.class).contains(x.getProperty()))
  194. .likeRight(WfSubscription::getNumber, year)
  195. .orderByDesc(WfSubscription::getNumber)
  196. .last("limit 1");
  197. WfSubscription wfSubscriptionMax = this.getOne(wfSubscriptionLambdaQueryWrapper);
  198. if(wfSubscriptionMax != null){
  199. String number = wfSubscriptionMax.getNumber();
  200. WfSubscription wfSubscriptionNew = new WfSubscription();
  201. int num = Integer.parseInt(number);
  202. num = num + 1;
  203. wfSubscriptionNew.setNumber(String.valueOf(num));
  204. wfSubscriptionNew.setId(wfSubscription.getId());
  205. wfSubscriptionNew.setStatus(1);
  206. return this.updateById(wfSubscriptionNew);
  207. }else{
  208. WfSubscription wfSubscriptionNew = new WfSubscription();
  209. wfSubscriptionNew.setNumber(year + "001");
  210. wfSubscriptionNew.setId(wfSubscription.getId());
  211. wfSubscriptionNew.setStatus(1);
  212. return this.updateById(wfSubscriptionNew);
  213. }
  214. }
  215. return true;
  216. }
  217. }