IWeSopBaseServiceImpl.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package com.linkwechat.service.impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  5. import com.linkwechat.common.core.domain.AjaxResult;
  6. import com.linkwechat.common.exception.wecom.WeComException;
  7. import com.linkwechat.common.utils.bean.BeanUtils;
  8. import com.linkwechat.domain.sop.WeSopBase;
  9. import com.linkwechat.domain.sop.WeSopBaseTime;
  10. import com.linkwechat.domain.sop.vo.WeSopAddQueryVo;
  11. import com.linkwechat.domain.sop.vo.WeSopListsVo;
  12. import com.linkwechat.domain.sop.vo.WeSopQueryListVo;
  13. import com.linkwechat.mapper.WeSopBaseMapper;
  14. import com.linkwechat.service.IWeSopBaseService;
  15. import com.linkwechat.service.IWeSopBaseTimeService;
  16. import org.springframework.stereotype.Service;
  17. import org.springframework.transaction.annotation.Transactional;
  18. import javax.annotation.Resource;
  19. import java.time.LocalDateTime;
  20. import java.util.Date;
  21. import java.util.List;
  22. /**
  23. * @author quchen
  24. * @date 2025/9/2 10:26
  25. */
  26. @Service
  27. public class IWeSopBaseServiceImpl extends ServiceImpl<WeSopBaseMapper, WeSopBase> implements IWeSopBaseService {
  28. @Resource
  29. private IWeSopBaseService weSopBaseService;
  30. @Resource
  31. private IWeSopBaseTimeService weSopBaseTimeService;
  32. @Override
  33. @Transactional
  34. public WeSopBase addSop(WeSopAddQueryVo weSopAddQueryVo) {
  35. WeSopBase weSopBase = new WeSopBase();
  36. BeanUtil.copyProperties(weSopAddQueryVo,weSopBase);
  37. this.save(weSopBase);
  38. if (weSopAddQueryVo.getTimeType() == 2) {
  39. for (String time : weSopAddQueryVo.getAbsoluteTime()) {
  40. WeSopBaseTime weSopBaseTime = new WeSopBaseTime();
  41. weSopBaseTime.setSopId(weSopBase.getId());
  42. weSopBaseTime.setAbsoluteTime(time);
  43. weSopBaseTimeService.save(weSopBaseTime);
  44. }
  45. }
  46. return weSopBase;
  47. }
  48. @Override
  49. @Transactional
  50. public WeSopBase updateSop(WeSopAddQueryVo weSopAddQueryVo) {
  51. WeSopBase weSopBase = weSopBaseService.getById(weSopAddQueryVo.getId());
  52. if (weSopBase == null) {
  53. throw new WeComException("SOP不存在");
  54. }
  55. BeanUtils.copyProperties(weSopAddQueryVo,weSopBase);
  56. this.updateById(weSopBase);
  57. if (weSopAddQueryVo.getTimeType() == 2) {
  58. weSopBaseTimeService.remove(new LambdaQueryWrapper<WeSopBaseTime>().eq(WeSopBaseTime::getSopId,weSopBase.getId()));
  59. for (String time : weSopAddQueryVo.getAbsoluteTime()) {
  60. WeSopBaseTime weSopBaseTime = new WeSopBaseTime();
  61. weSopBaseTime.setSopId(weSopBase.getId());
  62. weSopBaseTime.setAbsoluteTime(time);
  63. weSopBaseTimeService.save(weSopBaseTime);
  64. }
  65. }
  66. return weSopBase;
  67. }
  68. @Override
  69. public AjaxResult deleteSop(String id) {
  70. WeSopBase weSopBase = weSopBaseService.getById(id);
  71. if (weSopBase == null) {
  72. throw new WeComException("SOP不存在");
  73. }
  74. weSopBase.setDelFlag(1);
  75. this.removeById(weSopBase);
  76. weSopBaseTimeService.remove(new LambdaQueryWrapper<WeSopBaseTime>().eq(WeSopBaseTime::getSopId,id));
  77. return AjaxResult.success("删除成功");
  78. }
  79. @Override
  80. public AjaxResult disableStatus(String id) {
  81. WeSopBase weSopBase = weSopBaseService.getById(id);
  82. if (weSopBase == null) {
  83. throw new WeComException("SOP不存在");
  84. }
  85. weSopBase.setSopStatus(weSopBase.getSopStatus() == 1 ? 2 : 1);
  86. this.updateById(weSopBase);
  87. return AjaxResult.success(weSopBase.getSopStatus() == 1 ? "启用成功" : "禁用成功");
  88. }
  89. @Override
  90. public AjaxResult getSop(String id) {
  91. WeSopBase weSopBase = weSopBaseService.getById(id);
  92. if (weSopBase == null) {
  93. throw new WeComException("SOP不存在");
  94. }
  95. List<WeSopBaseTime> weSopBaseTimes = weSopBaseTimeService.list(new LambdaQueryWrapper<WeSopBaseTime>().eq(WeSopBaseTime::getSopId,id));
  96. weSopBase.setAbsoluteTimeList(weSopBaseTimes);
  97. return AjaxResult.success(weSopBase);
  98. }
  99. @Override
  100. public WeSopBase copySop(String id) {
  101. WeSopBase weSopBase = weSopBaseService.getById(id);
  102. if (weSopBase == null) {
  103. throw new WeComException("SOP不存在");
  104. }
  105. WeSopBase weSopBaseCopy = new WeSopBase();
  106. BeanUtils.copyProperties(weSopBase,weSopBaseCopy);
  107. weSopBaseCopy.setId(null);
  108. weSopBaseCopy.setSopStatus(2);
  109. weSopBaseService.save(weSopBaseCopy);
  110. List<WeSopBaseTime> weSopBaseTimes = weSopBaseTimeService.list(new LambdaQueryWrapper<WeSopBaseTime>().eq(WeSopBaseTime::getSopId,id));
  111. for (WeSopBaseTime weSopBaseTime : weSopBaseTimes) {
  112. weSopBaseTime.setId(null);
  113. weSopBaseTime.setSopId(weSopBaseCopy.getId());
  114. weSopBaseTime.setAbsoluteTime(weSopBaseTime.getAbsoluteTime());
  115. weSopBaseTimeService.save(weSopBaseTime);
  116. }
  117. return weSopBaseCopy;
  118. }
  119. @Override
  120. public List<WeSopListsVo> listSop(WeSopQueryListVo weSopQueryListVo) {
  121. return baseMapper.selectSopList(weSopQueryListVo);
  122. }
  123. }