|
@@ -1,16 +1,37 @@
|
|
|
package com.storlead.trade.service.impl;
|
|
package com.storlead.trade.service.impl;
|
|
|
|
|
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
+import com.storlead.framework.common.constant.CommonConstant;
|
|
|
import com.storlead.framework.common.constant.DSConstants;
|
|
import com.storlead.framework.common.constant.DSConstants;
|
|
|
|
|
+import com.storlead.framework.common.result.Result;
|
|
|
|
|
+import com.storlead.trade.dto.SopDetailCreateDTO;
|
|
|
|
|
+import com.storlead.trade.dto.SopDetailDTO;
|
|
|
|
|
+import com.storlead.trade.dto.SopDetailResponseDTO;
|
|
|
|
|
+import com.storlead.trade.dto.SopDetailUpdateDTO;
|
|
|
import com.storlead.trade.entity.SopDetailEntity;
|
|
import com.storlead.trade.entity.SopDetailEntity;
|
|
|
import com.storlead.trade.mapper.SopDetailMapper;
|
|
import com.storlead.trade.mapper.SopDetailMapper;
|
|
|
import com.storlead.trade.service.SopDetailService;
|
|
import com.storlead.trade.service.SopDetailService;
|
|
|
import com.storlead.trade.service.impl.support.TradeDataSourceServiceImpl;
|
|
import com.storlead.trade.service.impl.support.TradeDataSourceServiceImpl;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.Collections;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* SOP明细 Service实现类
|
|
* SOP明细 Service实现类
|
|
|
|
|
+ * 直接对 sop_detail 表做增删改查(逻辑删除,软删 is_delete=1)
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author Generated
|
|
|
*/
|
|
*/
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@Service
|
|
@Service
|
|
@@ -18,4 +39,132 @@ import org.springframework.stereotype.Service;
|
|
|
public class SopDetailServiceImpl
|
|
public class SopDetailServiceImpl
|
|
|
extends TradeDataSourceServiceImpl<SopDetailMapper, SopDetailEntity>
|
|
extends TradeDataSourceServiceImpl<SopDetailMapper, SopDetailEntity>
|
|
|
implements SopDetailService {
|
|
implements SopDetailService {
|
|
|
-}
|
|
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Result<Object> getList(SopDetailDTO dto) {
|
|
|
|
|
+ if (dto == null) {
|
|
|
|
|
+ dto = new SopDetailDTO();
|
|
|
|
|
+ }
|
|
|
|
|
+ Page<SopDetailEntity> page = new Page<>(dto.getPageIndex(), dto.getPageSize());
|
|
|
|
|
+ LambdaQueryWrapper<SopDetailEntity> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ // 软删过滤
|
|
|
|
|
+ wrapper.eq(SopDetailEntity::getIsDelete, CommonConstant.DEL_FLAG_0);
|
|
|
|
|
+ // 默认按 step 升序、再按 id 升序(步骤号稳定)
|
|
|
|
|
+ wrapper.orderByAsc(SopDetailEntity::getStep);
|
|
|
|
|
+ wrapper.orderByAsc(SopDetailEntity::getId);
|
|
|
|
|
+
|
|
|
|
|
+ if (!ObjectUtils.isEmpty(dto.getId())) {
|
|
|
|
|
+ wrapper.eq(SopDetailEntity::getId, dto.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!ObjectUtils.isEmpty(dto.getSopId())) {
|
|
|
|
|
+ wrapper.eq(SopDetailEntity::getSopId, dto.getSopId());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!ObjectUtils.isEmpty(dto.getStep())) {
|
|
|
|
|
+ wrapper.eq(SopDetailEntity::getStep, dto.getStep());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (dto.getName() != null && !dto.getName().trim().isEmpty()) {
|
|
|
|
|
+ wrapper.like(SopDetailEntity::getName, dto.getName().trim());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (dto.getEmailContent() != null && !dto.getEmailContent().trim().isEmpty()) {
|
|
|
|
|
+ wrapper.like(SopDetailEntity::getEmailContent, dto.getEmailContent().trim());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (dto.getDays() != null && !dto.getDays().trim().isEmpty()) {
|
|
|
|
|
+ wrapper.eq(SopDetailEntity::getDays, dto.getDays().trim());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (dto.getType() != null && !dto.getType().trim().isEmpty()) {
|
|
|
|
|
+ wrapper.eq(SopDetailEntity::getType, dto.getType().trim());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ IPage<SopDetailEntity> iPage = this.page(page, wrapper);
|
|
|
|
|
+ // 转响应 DTO
|
|
|
|
|
+ IPage<SopDetailResponseDTO> respPage = iPage.convert(this::toResponse);
|
|
|
|
|
+ return Result.result(respPage);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public Result<Object> add(SopDetailCreateDTO dto) {
|
|
|
|
|
+ if (dto == null) {
|
|
|
|
|
+ return Result.error("请求体不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ SopDetailEntity entity = new SopDetailEntity();
|
|
|
|
|
+ // sopId 入参
|
|
|
|
|
+ entity.setSopId(dto.getSopId());
|
|
|
|
|
+ entity.setStep(dto.getStep());
|
|
|
|
|
+ entity.setName(dto.getName());
|
|
|
|
|
+ entity.setEmailContent(dto.getEmailContent());
|
|
|
|
|
+ entity.setDays(dto.getDays());
|
|
|
|
|
+ entity.setType(dto.getType());
|
|
|
|
|
+ boolean ok = this.save(entity);
|
|
|
|
|
+ if (!ok) {
|
|
|
|
|
+ return Result.error("新增 SOP 明细失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ return Result.result(entity.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public Result<Object> edit(SopDetailUpdateDTO dto) {
|
|
|
|
|
+ if (dto == null || ObjectUtils.isEmpty(dto.getId())) {
|
|
|
|
|
+ return Result.error("id 不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ SopDetailEntity exist = this.getById(dto.getId());
|
|
|
|
|
+ if (exist == null || CommonConstant.DEL_FLAG_1.equals(exist.getIsDelete())) {
|
|
|
|
|
+ return Result.error("明细不存在或已删除");
|
|
|
|
|
+ }
|
|
|
|
|
+ // 只更新非空字段,避免误清空
|
|
|
|
|
+ if (!ObjectUtils.isEmpty(dto.getStep())) {
|
|
|
|
|
+ exist.setStep(dto.getStep());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (dto.getName() != null) {
|
|
|
|
|
+ exist.setName(dto.getName());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (dto.getEmailContent() != null) {
|
|
|
|
|
+ exist.setEmailContent(dto.getEmailContent());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (dto.getDays() != null) {
|
|
|
|
|
+ exist.setDays(dto.getDays());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (dto.getType() != null) {
|
|
|
|
|
+ exist.setType(dto.getType());
|
|
|
|
|
+ }
|
|
|
|
|
+ // sopId 一般不修改(明细属于 SOP 主表),如需变更走 sopId 入参
|
|
|
|
|
+ if (dto.getSopId() != null) {
|
|
|
|
|
+ exist.setSopId(dto.getSopId());
|
|
|
|
|
+ }
|
|
|
|
|
+ boolean ok = this.updateById(exist);
|
|
|
|
|
+ if (!ok) {
|
|
|
|
|
+ return Result.error("更新 SOP 明细失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ return Result.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public Result<Object> delete(List<Long> ids) {
|
|
|
|
|
+ if (CollectionUtils.isEmpty(ids)) {
|
|
|
|
|
+ return Result.error("id 列表不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ // 软删:is_delete = 1
|
|
|
|
|
+ LambdaUpdateWrapper<SopDetailEntity> wrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
+ wrapper.in(SopDetailEntity::getId, ids);
|
|
|
|
|
+ wrapper.set(SopDetailEntity::getIsDelete, CommonConstant.DEL_FLAG_1);
|
|
|
|
|
+ boolean ok = this.update(wrapper);
|
|
|
|
|
+ if (!ok) {
|
|
|
|
|
+ return Result.error("删除 SOP 明细失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ return Result.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Entity → ResponseDTO
|
|
|
|
|
+ */
|
|
|
|
|
+ private SopDetailResponseDTO toResponse(SopDetailEntity e) {
|
|
|
|
|
+ if (e == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ SopDetailResponseDTO r = new SopDetailResponseDTO();
|
|
|
|
|
+ BeanUtils.copyProperties(e, r);
|
|
|
|
|
+ return r;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|