package com.linkwechat.service.impl; import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.linkwechat.common.core.domain.AjaxResult; import com.linkwechat.common.exception.wecom.WeComException; import com.linkwechat.common.utils.bean.BeanUtils; import com.linkwechat.domain.sop.WeSopBase; import com.linkwechat.domain.sop.WeSopBaseTime; import com.linkwechat.domain.sop.vo.WeSopAddQueryVo; import com.linkwechat.domain.sop.vo.WeSopListsVo; import com.linkwechat.domain.sop.vo.WeSopQueryListVo; import com.linkwechat.mapper.WeSopBaseMapper; import com.linkwechat.service.IWeSopBaseService; import com.linkwechat.service.IWeSopBaseTimeService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.time.LocalDateTime; import java.util.Date; import java.util.List; /** * @author quchen * @date 2025/9/2 10:26 */ @Service public class IWeSopBaseServiceImpl extends ServiceImpl implements IWeSopBaseService { @Resource private IWeSopBaseService weSopBaseService; @Resource private IWeSopBaseTimeService weSopBaseTimeService; @Override @Transactional public WeSopBase addSop(WeSopAddQueryVo weSopAddQueryVo) { WeSopBase weSopBase = new WeSopBase(); BeanUtil.copyProperties(weSopAddQueryVo,weSopBase); this.save(weSopBase); if (weSopAddQueryVo.getTimeType() == 2) { for (String time : weSopAddQueryVo.getAbsoluteTime()) { WeSopBaseTime weSopBaseTime = new WeSopBaseTime(); weSopBaseTime.setSopId(weSopBase.getId()); weSopBaseTime.setAbsoluteTime(time); weSopBaseTimeService.save(weSopBaseTime); } } return weSopBase; } @Override @Transactional public WeSopBase updateSop(WeSopAddQueryVo weSopAddQueryVo) { WeSopBase weSopBase = weSopBaseService.getById(weSopAddQueryVo.getId()); if (weSopBase == null) { throw new WeComException("SOP不存在"); } BeanUtils.copyProperties(weSopAddQueryVo,weSopBase); this.updateById(weSopBase); if (weSopAddQueryVo.getTimeType() == 2) { weSopBaseTimeService.remove(new LambdaQueryWrapper().eq(WeSopBaseTime::getSopId,weSopBase.getId())); for (String time : weSopAddQueryVo.getAbsoluteTime()) { WeSopBaseTime weSopBaseTime = new WeSopBaseTime(); weSopBaseTime.setSopId(weSopBase.getId()); weSopBaseTime.setAbsoluteTime(time); weSopBaseTimeService.save(weSopBaseTime); } } return weSopBase; } @Override public AjaxResult deleteSop(String id) { WeSopBase weSopBase = weSopBaseService.getById(id); if (weSopBase == null) { throw new WeComException("SOP不存在"); } weSopBase.setDelFlag(1); this.removeById(weSopBase); weSopBaseTimeService.remove(new LambdaQueryWrapper().eq(WeSopBaseTime::getSopId,id)); return AjaxResult.success("删除成功"); } @Override public AjaxResult disableStatus(String id) { WeSopBase weSopBase = weSopBaseService.getById(id); if (weSopBase == null) { throw new WeComException("SOP不存在"); } weSopBase.setSopStatus(weSopBase.getSopStatus() == 1 ? 2 : 1); this.updateById(weSopBase); return AjaxResult.success(weSopBase.getSopStatus() == 1 ? "启用成功" : "禁用成功"); } @Override public AjaxResult getSop(String id) { WeSopBase weSopBase = weSopBaseService.getById(id); if (weSopBase == null) { throw new WeComException("SOP不存在"); } List weSopBaseTimes = weSopBaseTimeService.list(new LambdaQueryWrapper().eq(WeSopBaseTime::getSopId,id)); weSopBase.setAbsoluteTimeList(weSopBaseTimes); return AjaxResult.success(weSopBase); } @Override public WeSopBase copySop(String id) { WeSopBase weSopBase = weSopBaseService.getById(id); if (weSopBase == null) { throw new WeComException("SOP不存在"); } WeSopBase weSopBaseCopy = new WeSopBase(); BeanUtils.copyProperties(weSopBase,weSopBaseCopy); weSopBaseCopy.setId(null); weSopBaseCopy.setSopStatus(2); weSopBaseService.save(weSopBaseCopy); List weSopBaseTimes = weSopBaseTimeService.list(new LambdaQueryWrapper().eq(WeSopBaseTime::getSopId,id)); for (WeSopBaseTime weSopBaseTime : weSopBaseTimes) { weSopBaseTime.setId(null); weSopBaseTime.setSopId(weSopBaseCopy.getId()); weSopBaseTime.setAbsoluteTime(weSopBaseTime.getAbsoluteTime()); weSopBaseTimeService.save(weSopBaseTime); } return weSopBaseCopy; } @Override public List listSop(WeSopQueryListVo weSopQueryListVo) { return baseMapper.selectSopList(weSopQueryListVo); } }