|
|
@@ -1,14 +1,20 @@
|
|
|
package com.ktg.iscs.service.impl;
|
|
|
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.ktg.common.core.text.Convert;
|
|
|
-import com.ktg.common.utils.DateUtils;
|
|
|
+import com.ktg.common.utils.bean.BeanUtils;
|
|
|
import com.ktg.iscs.domain.IsSop;
|
|
|
+import com.ktg.iscs.domain.IsSopPoints;
|
|
|
+import com.ktg.iscs.domain.dto.sop.AddSopDTO;
|
|
|
import com.ktg.iscs.mapper.IsSopMapper;
|
|
|
+import com.ktg.iscs.service.IIsSopPointsService;
|
|
|
import com.ktg.iscs.service.IIsSopService;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
@@ -19,10 +25,11 @@ import java.util.List;
|
|
|
* @date 2024-10-18
|
|
|
*/
|
|
|
@Service
|
|
|
-public class IsSopServiceImpl extends ServiceImpl<IsSopMapper, IsSop> implements IIsSopService
|
|
|
-{
|
|
|
+public class IsSopServiceImpl extends ServiceImpl<IsSopMapper, IsSop> implements IIsSopService {
|
|
|
@Autowired
|
|
|
private IsSopMapper isSopMapper;
|
|
|
+ @Autowired
|
|
|
+ private IIsSopPointsService iIsSopPointsService;
|
|
|
|
|
|
/**
|
|
|
* 查询SOP信息
|
|
|
@@ -31,8 +38,7 @@ public class IsSopServiceImpl extends ServiceImpl<IsSopMapper, IsSop> implements
|
|
|
* @return SOP信息
|
|
|
*/
|
|
|
@Override
|
|
|
- public IsSop selectIsSopBySopId(Long sopId)
|
|
|
- {
|
|
|
+ public IsSop selectIsSopBySopId(Long sopId) {
|
|
|
return isSopMapper.selectIsSopBySopId(sopId);
|
|
|
}
|
|
|
|
|
|
@@ -43,35 +49,86 @@ public class IsSopServiceImpl extends ServiceImpl<IsSopMapper, IsSop> implements
|
|
|
* @return SOP信息
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<IsSop> selectIsSopList(IsSop isSop)
|
|
|
- {
|
|
|
+ public List<IsSop> selectIsSopList(IsSop isSop) {
|
|
|
return isSopMapper.selectIsSopList(isSop);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 新增SOP信息
|
|
|
*
|
|
|
- * @param isSop SOP信息
|
|
|
+ * @param dto SOP信息
|
|
|
* @return 结果
|
|
|
*/
|
|
|
+ @Transactional
|
|
|
@Override
|
|
|
- public int insertIsSop(IsSop isSop)
|
|
|
- {
|
|
|
- isSop.setCreateTime(DateUtils.getNowDate());
|
|
|
- return isSopMapper.insertIsSop(isSop);
|
|
|
+ public Boolean insertIsSop(AddSopDTO dto) {
|
|
|
+ // 断言校验
|
|
|
+ Assert.notNull(dto.getWorkshopId(), "所属车间不可为空!");
|
|
|
+ Assert.isTrue(StringUtils.isNotBlank(dto.getSopName()), "SOP名称不可为空!");
|
|
|
+ Assert.isTrue(StringUtils.isNotBlank(dto.getSopCode()), "SOP编号名称不可为空!");
|
|
|
+ List<IsSop> list = list(Wrappers.<IsSop>lambdaQuery().eq(IsSop::getSopCode, dto.getSopCode()));
|
|
|
+ Assert.isTrue(list.isEmpty(), "该SOP编号已被使用!");
|
|
|
+ // 1.判断隔离点必选
|
|
|
+ Assert.isTrue(StringUtils.isNotBlank(dto.getPointIds()), "隔离点id不可为空!");
|
|
|
+ // 2.开始新增sop数据
|
|
|
+ IsSop isSop = BeanUtils.toBean(dto, IsSop.class);
|
|
|
+ save(isSop);
|
|
|
+ // 3.新增车间、区域、隔离点和sop的关联关系
|
|
|
+ // TODO 批量新增
|
|
|
+ Long[] pointIds = Convert.toLongArray(dto.getPointIds());
|
|
|
+ for (Long pointId : pointIds) {
|
|
|
+ IsSopPoints isSopPoints = new IsSopPoints();
|
|
|
+ isSopPoints.setSopId(isSop.getSopId());
|
|
|
+ isSopPoints.setWorkshopId(dto.getWorkshopId());
|
|
|
+ isSopPoints.setWorkareaId(dto.getWorkareaId());
|
|
|
+ isSopPoints.setPointId(pointId);
|
|
|
+ iIsSopPointsService.save(isSopPoints);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改SOP信息
|
|
|
*
|
|
|
- * @param isSop SOP信息
|
|
|
+ * @param dto SOP信息
|
|
|
* @return 结果
|
|
|
*/
|
|
|
+ @Transactional
|
|
|
@Override
|
|
|
- public int updateIsSop(IsSop isSop)
|
|
|
- {
|
|
|
- isSop.setUpdateTime(DateUtils.getNowDate());
|
|
|
- return isSopMapper.updateIsSop(isSop);
|
|
|
+ public Boolean updateIsSop(AddSopDTO dto) {
|
|
|
+ // 断言校验
|
|
|
+ Assert.notNull(dto.getSopId(), "sopId不可为空!");
|
|
|
+ Assert.notNull(dto.getWorkshopId(), "所属车间不可为空!");
|
|
|
+ Assert.isTrue(StringUtils.isNotBlank(dto.getSopName()), "SOP名称不可为空!");
|
|
|
+ Assert.isTrue(StringUtils.isNotBlank(dto.getSopCode()), "SOP编号名称不可为空!");
|
|
|
+ List<IsSop> list = list(Wrappers.<IsSop>lambdaQuery()
|
|
|
+ .eq(IsSop::getSopCode, dto.getSopCode())
|
|
|
+ .ne(IsSop::getSopId, dto.getSopId()));
|
|
|
+ Assert.isTrue(list.isEmpty(), "该SOP编号已被使用!");
|
|
|
+ // 1.判断隔离点必选
|
|
|
+ Assert.isTrue(StringUtils.isNotBlank(dto.getPointIds()), "隔离点id不可为空!");
|
|
|
+ // 2.开始检查隔离点有没有变更
|
|
|
+ Long[] pointIds = Convert.toLongArray(dto.getPointIds());
|
|
|
+ List<IsSopPoints> isSopPoints = iIsSopPointsService.list(Wrappers.<IsSopPoints>lambdaQuery()
|
|
|
+ .eq(IsSopPoints::getSopId, dto.getSopId())
|
|
|
+ .in(IsSopPoints::getPointId, pointIds));
|
|
|
+ // 2.1如果查出来变更了,开始执行删除,重新增加一轮
|
|
|
+ if (pointIds.length != isSopPoints.size()) {
|
|
|
+ iIsSopPointsService.remove(Wrappers.<IsSopPoints>lambdaQuery().eq(IsSopPoints::getSopId, dto.getSopId()));
|
|
|
+ // TODO 批量新增
|
|
|
+ for (Long pointId : pointIds) {
|
|
|
+ IsSopPoints newSopPoints = new IsSopPoints();
|
|
|
+ newSopPoints.setSopId(dto.getSopId());
|
|
|
+ newSopPoints.setWorkshopId(dto.getWorkshopId());
|
|
|
+ newSopPoints.setWorkareaId(dto.getWorkareaId());
|
|
|
+ newSopPoints.setPointId(pointId);
|
|
|
+ iIsSopPointsService.save(newSopPoints);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 3.开始执行更新操作
|
|
|
+ IsSop isSop = BeanUtils.toBean(dto, IsSop.class);
|
|
|
+ isSopMapper.updateById(isSop);
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -81,8 +138,7 @@ public class IsSopServiceImpl extends ServiceImpl<IsSopMapper, IsSop> implements
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deleteIsSopBySopIds(String sopIds)
|
|
|
- {
|
|
|
+ public int deleteIsSopBySopIds(String sopIds) {
|
|
|
Assert.notBlank(sopIds, "请选择需要删除的数据!");
|
|
|
Long[] longIds = Convert.toLongArray(sopIds);
|
|
|
return isSopMapper.deleteIsSopBySopIds(longIds);
|
|
|
@@ -95,8 +151,8 @@ public class IsSopServiceImpl extends ServiceImpl<IsSopMapper, IsSop> implements
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deleteIsSopBySopId(Long sopId)
|
|
|
- {
|
|
|
+ public int deleteIsSopBySopId(Long sopId) {
|
|
|
return isSopMapper.deleteIsSopBySopId(sopId);
|
|
|
}
|
|
|
+
|
|
|
}
|