修改质检人员管理功能
This commit is contained in:
parent
83098677eb
commit
e3b86df482
|
|
@ -207,6 +207,29 @@
|
|||
<artifactId>minio</artifactId>
|
||||
<version>8.5.17</version>
|
||||
</dependency>
|
||||
<!-- ==================== OnlyOffice JWT ==================== -->
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-api</artifactId>
|
||||
<version>0.12.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-impl</artifactId>
|
||||
<version>0.12.6</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-jackson</artifactId>
|
||||
<version>0.12.6</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>software.amazon.awssdk</groupId>
|
||||
<artifactId>s3</artifactId>
|
||||
<version>2.39.5</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import lombok.Data;
|
|||
public class QmsQualityInspectorCategoryVO {
|
||||
|
||||
/**
|
||||
* 关联记录ID(qms_quality_inspector.id)
|
||||
* 关联记录ID(qms_inspector_material_category_item.id)
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import lombok.Data;
|
|||
public class QmsQualityInspectorMaterialVO {
|
||||
|
||||
/**
|
||||
* 关联记录ID(qms_quality_inspector.id)
|
||||
* 关联记录ID(qms_inspector_material_item.id)
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,63 @@
|
|||
package com.nflg.wms.repository.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 质检员物料类别表
|
||||
* </p>
|
||||
*
|
||||
* @author 代码生成器生成
|
||||
* @since 2025
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
@TableName("qms_inspector_material_category_item")
|
||||
public class QmsInspectorMaterialCategoryItem implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 质检员ID (qms_quality_inspector.id)
|
||||
*/
|
||||
private Long inspectorId;
|
||||
|
||||
/**
|
||||
* 物料类别ID (qms_qc_material_category.id)
|
||||
*/
|
||||
private Long materialCategoryId;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 修改人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
package com.nflg.wms.repository.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 质检员物料明细表
|
||||
* </p>
|
||||
*
|
||||
* @author 代码生成器生成
|
||||
* @since 2025
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
@TableName("qms_inspector_material_item")
|
||||
public class QmsInspectorMaterialItem implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 质检员ID (qms_quality_inspector.id)
|
||||
*/
|
||||
private Long inspectorId;
|
||||
|
||||
/**
|
||||
* 物料ID (qms_qc_material.id)
|
||||
*/
|
||||
private Long materialId;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 修改人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
|
|
@ -36,11 +36,6 @@ public class QmsQualityInspector implements Serializable {
|
|||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 物料ID (qms_qc_material.id),可为空
|
||||
*/
|
||||
private Long materialId;
|
||||
|
||||
/**
|
||||
* 启用状态:true=启用,false=禁用
|
||||
*/
|
||||
|
|
@ -75,9 +70,4 @@ public class QmsQualityInspector implements Serializable {
|
|||
* 修改时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 物料类别编码
|
||||
*/
|
||||
private String materialCategoryCode;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
package com.nflg.wms.repository.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nflg.wms.repository.entity.QmsInspectorMaterialCategoryItem;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 质检员物料类别明细 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author 代码生成器生成
|
||||
* @since 2025
|
||||
*/
|
||||
public interface QmsInspectorMaterialCategoryItemMapper extends BaseMapper<QmsInspectorMaterialCategoryItem> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.nflg.wms.repository.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nflg.wms.repository.entity.QmsInspectorMaterialItem;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 质检员物料明细 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author 代码生成器生成
|
||||
* @since 2025
|
||||
*/
|
||||
public interface QmsInspectorMaterialItemMapper extends BaseMapper<QmsInspectorMaterialItem> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.nflg.wms.repository.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.nflg.wms.repository.entity.QmsInspectorMaterialCategoryItem;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 质检员物料类别明细 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author 代码生成器生成
|
||||
* @since 2025
|
||||
*/
|
||||
public interface IQmsInspectorMaterialCategoryItemService extends IService<QmsInspectorMaterialCategoryItem> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.nflg.wms.repository.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.nflg.wms.repository.entity.QmsInspectorMaterialItem;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 质检员物料明细 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author 代码生成器生成
|
||||
* @since 2025
|
||||
*/
|
||||
public interface IQmsInspectorMaterialItemService extends IService<QmsInspectorMaterialItem> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package com.nflg.wms.repository.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.nflg.wms.repository.entity.QmsInspectorMaterialCategoryItem;
|
||||
import com.nflg.wms.repository.mapper.QmsInspectorMaterialCategoryItemMapper;
|
||||
import com.nflg.wms.repository.service.IQmsInspectorMaterialCategoryItemService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 质检员物料类别明细 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author 代码生成器生成
|
||||
* @since 2025
|
||||
*/
|
||||
@Service
|
||||
public class QmsInspectorMaterialCategoryItemServiceImpl
|
||||
extends ServiceImpl<QmsInspectorMaterialCategoryItemMapper, QmsInspectorMaterialCategoryItem>
|
||||
implements IQmsInspectorMaterialCategoryItemService {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package com.nflg.wms.repository.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.nflg.wms.repository.entity.QmsInspectorMaterialItem;
|
||||
import com.nflg.wms.repository.mapper.QmsInspectorMaterialItemMapper;
|
||||
import com.nflg.wms.repository.service.IQmsInspectorMaterialItemService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 质检员物料明细 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author 代码生成器生成
|
||||
* @since 2025
|
||||
*/
|
||||
@Service
|
||||
public class QmsInspectorMaterialItemServiceImpl
|
||||
extends ServiceImpl<QmsInspectorMaterialItemMapper, QmsInspectorMaterialItem>
|
||||
implements IQmsInspectorMaterialItemService {
|
||||
|
||||
}
|
||||
|
|
@ -16,9 +16,15 @@ import com.nflg.wms.common.pojo.vo.QmsQualityInspectorDetailVO;
|
|||
import com.nflg.wms.common.pojo.vo.QmsQualityInspectorMaterialVO;
|
||||
import com.nflg.wms.common.pojo.vo.QmsQualityInspectorVO;
|
||||
import com.nflg.wms.common.util.UserUtil;
|
||||
import com.nflg.wms.repository.entity.QmsInspectorMaterialCategoryItem;
|
||||
import com.nflg.wms.repository.entity.QmsInspectorMaterialItem;
|
||||
import com.nflg.wms.repository.entity.QmsQcMaterialCategory;
|
||||
import com.nflg.wms.repository.entity.QmsQualityInspector;
|
||||
import com.nflg.wms.repository.entity.User;
|
||||
import com.nflg.wms.repository.mapper.QmsQualityInspectorMapper;
|
||||
import com.nflg.wms.repository.service.IQmsInspectorMaterialCategoryItemService;
|
||||
import com.nflg.wms.repository.service.IQmsInspectorMaterialItemService;
|
||||
import com.nflg.wms.repository.service.IQmsQcMaterialCategoryService;
|
||||
import com.nflg.wms.repository.service.IQmsQualityInspectorService;
|
||||
import com.nflg.wms.repository.service.IUserService;
|
||||
import jakarta.annotation.Resource;
|
||||
|
|
@ -29,8 +35,8 @@ import org.springframework.util.CollectionUtils;
|
|||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
|
@ -48,6 +54,31 @@ public class QmsQualityInspectorServiceImpl extends ServiceImpl<QmsQualityInspec
|
|||
@Resource
|
||||
private IUserService userService;
|
||||
|
||||
@Resource
|
||||
private IQmsInspectorMaterialItemService materialItemService;
|
||||
|
||||
@Resource
|
||||
private IQmsInspectorMaterialCategoryItemService materialCategoryItemService;
|
||||
|
||||
@Resource
|
||||
private IQmsQcMaterialCategoryService qcMaterialCategoryService;
|
||||
|
||||
// ========================= 工具方法 =========================
|
||||
|
||||
/**
|
||||
* 按物料类别编码列表批量查询 id 映射(code -> id)
|
||||
*/
|
||||
private Map<String, Long> getCategoryCodeToIdMap(List<String> codes) {
|
||||
if (CollectionUtils.isEmpty(codes)) {
|
||||
return Map.of();
|
||||
}
|
||||
List<QmsQcMaterialCategory> categories = qcMaterialCategoryService.lambdaQuery()
|
||||
.in(QmsQcMaterialCategory::getCategoryCode, codes)
|
||||
.list();
|
||||
return categories.stream()
|
||||
.collect(Collectors.toMap(QmsQcMaterialCategory::getCategoryCode, QmsQcMaterialCategory::getId));
|
||||
}
|
||||
|
||||
// ========================= 新增 =========================
|
||||
|
||||
@Transactional
|
||||
|
|
@ -55,99 +86,76 @@ public class QmsQualityInspectorServiceImpl extends ServiceImpl<QmsQualityInspec
|
|||
public void add(QmsQualityInspectorAddQO request) {
|
||||
String operator = UserUtil.getUserName();
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
List<QmsQualityInspector> records = new ArrayList<>();
|
||||
|
||||
boolean hasMaterial = !CollectionUtils.isEmpty(request.getMaterialIds());
|
||||
boolean hasCategory = !CollectionUtils.isEmpty(request.getMaterialCategoryCodes());
|
||||
|
||||
if (hasMaterial) {
|
||||
for (Long materialId : request.getMaterialIds()) {
|
||||
records.add(buildRecord(request.getUserId(), request.getInspectionType(),
|
||||
materialId, null, operator, now));
|
||||
// 校验物料ID是否已被其他质检员绑定
|
||||
if (!CollectionUtils.isEmpty(request.getMaterialIds())) {
|
||||
List<QmsInspectorMaterialItem> conflictMaterials = materialItemService.lambdaQuery()
|
||||
.in(QmsInspectorMaterialItem::getMaterialId, request.getMaterialIds())
|
||||
.list();
|
||||
if (!conflictMaterials.isEmpty()) {
|
||||
throw new NflgException(STATE.BusinessError, "物料ID已被其他质检员绑定,不允许重复新增");
|
||||
}
|
||||
}
|
||||
if (hasCategory) {
|
||||
for (String categoryCode : request.getMaterialCategoryCodes()) {
|
||||
records.add(buildRecord(request.getUserId(), request.getInspectionType(),
|
||||
null, categoryCode, operator, now));
|
||||
|
||||
// 校验物料类别是否已被其他质检员绑定
|
||||
if (!CollectionUtils.isEmpty(request.getMaterialCategoryCodes())) {
|
||||
Map<String, Long> codeToIdMap = getCategoryCodeToIdMap(request.getMaterialCategoryCodes());
|
||||
List<Long> categoryIds = new ArrayList<>(codeToIdMap.values());
|
||||
if (!categoryIds.isEmpty()) {
|
||||
List<QmsInspectorMaterialCategoryItem> conflictCategories = materialCategoryItemService.lambdaQuery()
|
||||
.in(QmsInspectorMaterialCategoryItem::getMaterialCategoryId, categoryIds)
|
||||
.list();
|
||||
if (!conflictCategories.isEmpty()) {
|
||||
throw new NflgException(STATE.BusinessError, "物料类别已被其他质检员绑定,不允许重复新增");
|
||||
}
|
||||
}
|
||||
}
|
||||
// 物料id和物料类别都不传时,插入一条无物料关联的记录
|
||||
if (!hasMaterial && !hasCategory) {
|
||||
records.add(buildRecord(request.getUserId(), request.getInspectionType(),
|
||||
null, null, operator, now));
|
||||
}
|
||||
|
||||
saveBatch(records);
|
||||
}
|
||||
|
||||
private QmsQualityInspector buildRecord(Long userId, Integer inspectionType,
|
||||
Long materialId, String categoryCode,
|
||||
String operator, LocalDateTime now) {
|
||||
return new QmsQualityInspector()
|
||||
.setUserId(userId)
|
||||
.setInspectionType(inspectionType)
|
||||
.setMaterialId(materialId)
|
||||
.setMaterialCategoryCode(categoryCode)
|
||||
// 插入主表
|
||||
QmsQualityInspector inspector = new QmsQualityInspector()
|
||||
.setUserId(request.getUserId())
|
||||
.setInspectionType(request.getInspectionType())
|
||||
.setEnable(true)
|
||||
.setCreateBy(operator)
|
||||
.setCreateTime(now)
|
||||
.setUpdateBy(operator)
|
||||
.setUpdateTime(now);
|
||||
}
|
||||
save(inspector);
|
||||
Long inspectorId = inspector.getId();
|
||||
|
||||
/**
|
||||
* 删除物料/物料类别关联行。
|
||||
* 若删除后该 userId 下记录数归零,则保留其中一条(清空 materialId 和 materialCategoryCode),
|
||||
* 不做物理删除,确保人员记录始终存在。
|
||||
*/
|
||||
private void removeMaterialOrClear(Long userId, List<QmsQualityInspector> toRemove,
|
||||
String operator, LocalDateTime now) {
|
||||
if (CollectionUtils.isEmpty(toRemove)) {
|
||||
return;
|
||||
// 批量插入物料明细
|
||||
if (!CollectionUtils.isEmpty(request.getMaterialIds())) {
|
||||
List<QmsInspectorMaterialItem> materialItems = request.getMaterialIds().stream()
|
||||
.map(materialId -> new QmsInspectorMaterialItem()
|
||||
.setInspectorId(inspectorId)
|
||||
.setMaterialId(materialId)
|
||||
.setCreateBy(operator)
|
||||
.setCreateTime(now)
|
||||
.setUpdateBy(operator)
|
||||
.setUpdateTime(now))
|
||||
.collect(Collectors.toList());
|
||||
materialItemService.saveBatch(materialItems);
|
||||
}
|
||||
|
||||
// 该用户当前全部记录
|
||||
List<QmsQualityInspector> all = lambdaQuery()
|
||||
.eq(QmsQualityInspector::getUserId, userId)
|
||||
.list();
|
||||
long total = all.size();
|
||||
|
||||
// 待删除的行 ID 集合
|
||||
Set<Long> removeIdSet = toRemove.stream()
|
||||
.map(QmsQualityInspector::getId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
// 删除后剩余条数
|
||||
long remaining = total - removeIdSet.size();
|
||||
|
||||
if (remaining <= 0) {
|
||||
// 删完后一条不剩:从所有记录中选一条保留(优先选不在 toRemove 中的,没有则从 toRemove 中选第一条)
|
||||
QmsQualityInspector keep = all.stream()
|
||||
.filter(r -> !removeIdSet.contains(r.getId()))
|
||||
.findFirst()
|
||||
.orElse(toRemove.get(0));
|
||||
|
||||
// 删除其余所有行(保留行除外)
|
||||
List<Long> deleteIds = all.stream()
|
||||
.map(QmsQualityInspector::getId)
|
||||
.filter(id -> !id.equals(keep.getId()))
|
||||
.collect(Collectors.toList());
|
||||
if (!deleteIds.isEmpty()) {
|
||||
removeByIds(deleteIds);
|
||||
// 批量插入物料类别明细(按编码查 ID)
|
||||
if (!CollectionUtils.isEmpty(request.getMaterialCategoryCodes())) {
|
||||
Map<String, Long> codeToIdMap = getCategoryCodeToIdMap(request.getMaterialCategoryCodes());
|
||||
List<QmsInspectorMaterialCategoryItem> categoryItems = new ArrayList<>();
|
||||
for (String code : request.getMaterialCategoryCodes()) {
|
||||
Long categoryId = codeToIdMap.get(code);
|
||||
if (Objects.nonNull(categoryId)) {
|
||||
categoryItems.add(new QmsInspectorMaterialCategoryItem()
|
||||
.setInspectorId(inspectorId)
|
||||
.setMaterialCategoryId(categoryId)
|
||||
.setCreateBy(operator)
|
||||
.setCreateTime(now)
|
||||
.setUpdateBy(operator)
|
||||
.setUpdateTime(now));
|
||||
}
|
||||
}
|
||||
if (!categoryItems.isEmpty()) {
|
||||
materialCategoryItemService.saveBatch(categoryItems);
|
||||
}
|
||||
|
||||
// 保留行的物料字段清空
|
||||
lambdaUpdate()
|
||||
.eq(QmsQualityInspector::getId, keep.getId())
|
||||
.set(QmsQualityInspector::getMaterialId, null)
|
||||
.set(QmsQualityInspector::getMaterialCategoryCode, null)
|
||||
.set(QmsQualityInspector::getUpdateBy, operator)
|
||||
.set(QmsQualityInspector::getUpdateTime, now)
|
||||
.update();
|
||||
} else {
|
||||
// 正常物理删除
|
||||
removeByIds(new ArrayList<>(removeIdSet));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -156,21 +164,27 @@ public class QmsQualityInspectorServiceImpl extends ServiceImpl<QmsQualityInspec
|
|||
@Transactional
|
||||
@Override
|
||||
public void delete(Long userId) {
|
||||
// 查询该用户是否存在记录
|
||||
List<QmsQualityInspector> records = lambdaQuery()
|
||||
// 查询主表记录
|
||||
QmsQualityInspector inspector = lambdaQuery()
|
||||
.eq(QmsQualityInspector::getUserId, userId)
|
||||
.list();
|
||||
if (records.isEmpty()) {
|
||||
.one();
|
||||
if (Objects.isNull(inspector)) {
|
||||
throw new NflgException(STATE.BusinessError, "该质检人员不存在");
|
||||
}
|
||||
// 启用状态下不允许删除
|
||||
boolean enabled = records.stream().anyMatch(r -> Boolean.TRUE.equals(r.getEnable()));
|
||||
if (enabled) {
|
||||
if (Boolean.TRUE.equals(inspector.getEnable())) {
|
||||
throw new NflgException(STATE.BusinessError, "该质检人员处于启用状态,不允许删除,请先禁用后再删除");
|
||||
}
|
||||
// 删除该用户所有记录
|
||||
List<Long> ids = records.stream().map(QmsQualityInspector::getId).collect(Collectors.toList());
|
||||
removeByIds(ids);
|
||||
Long inspectorId = inspector.getId();
|
||||
// 删除两张明细表
|
||||
materialItemService.lambdaUpdate()
|
||||
.eq(QmsInspectorMaterialItem::getInspectorId, inspectorId)
|
||||
.remove();
|
||||
materialCategoryItemService.lambdaUpdate()
|
||||
.eq(QmsInspectorMaterialCategoryItem::getInspectorId, inspectorId)
|
||||
.remove();
|
||||
// 删除主表
|
||||
removeById(inspectorId);
|
||||
}
|
||||
|
||||
// ========================= 修改物料/物料类别 =========================
|
||||
|
|
@ -182,49 +196,68 @@ public class QmsQualityInspectorServiceImpl extends ServiceImpl<QmsQualityInspec
|
|||
LocalDateTime now = LocalDateTime.now();
|
||||
Long userId = request.getUserId();
|
||||
|
||||
// 查询当前该质检人的任意一条记录,取 inspectionType(同一人 inspectionType 相同)
|
||||
QmsQualityInspector any = lambdaQuery()
|
||||
// 查主表,获取 inspectorId
|
||||
QmsQualityInspector inspector = lambdaQuery()
|
||||
.eq(QmsQualityInspector::getUserId, userId)
|
||||
.last("LIMIT 1")
|
||||
.one();
|
||||
if (Objects.isNull(any)) {
|
||||
if (Objects.isNull(inspector)) {
|
||||
throw new NflgException(STATE.BusinessError, "该质检人员不存在");
|
||||
}
|
||||
Integer inspectionType = any.getInspectionType();
|
||||
Long inspectorId = inspector.getId();
|
||||
|
||||
// 追加物料
|
||||
if (!CollectionUtils.isEmpty(request.getAddMaterialIds())) {
|
||||
List<QmsQualityInspector> toAdd = request.getAddMaterialIds().stream()
|
||||
.map(materialId -> buildRecord(userId, inspectionType, materialId, null, operator, now))
|
||||
List<QmsInspectorMaterialItem> toAdd = request.getAddMaterialIds().stream()
|
||||
.map(materialId -> new QmsInspectorMaterialItem()
|
||||
.setInspectorId(inspectorId)
|
||||
.setMaterialId(materialId)
|
||||
.setCreateBy(operator)
|
||||
.setCreateTime(now)
|
||||
.setUpdateBy(operator)
|
||||
.setUpdateTime(now))
|
||||
.collect(Collectors.toList());
|
||||
saveBatch(toAdd);
|
||||
materialItemService.saveBatch(toAdd);
|
||||
}
|
||||
|
||||
// 追加物料类别
|
||||
if (!CollectionUtils.isEmpty(request.getAddMaterialCategoryCodes())) {
|
||||
List<QmsQualityInspector> toAdd = request.getAddMaterialCategoryCodes().stream()
|
||||
.map(code -> buildRecord(userId, inspectionType, null, code, operator, now))
|
||||
.collect(Collectors.toList());
|
||||
saveBatch(toAdd);
|
||||
}
|
||||
|
||||
// 删除物料(按 userId + material_id)和 物料类别(按 userId + material_category_code)
|
||||
// 两者合并到一次操作,避免分步计算 total 不准确
|
||||
List<QmsQualityInspector> toRemove = new ArrayList<>();
|
||||
// 删除物料
|
||||
if (!CollectionUtils.isEmpty(request.getRemoveMaterialIds())) {
|
||||
toRemove.addAll(lambdaQuery()
|
||||
.eq(QmsQualityInspector::getUserId, userId)
|
||||
.in(QmsQualityInspector::getMaterialId, request.getRemoveMaterialIds())
|
||||
.list());
|
||||
materialItemService.lambdaUpdate()
|
||||
.eq(QmsInspectorMaterialItem::getInspectorId, inspectorId)
|
||||
.in(QmsInspectorMaterialItem::getMaterialId, request.getRemoveMaterialIds())
|
||||
.remove();
|
||||
}
|
||||
|
||||
// 追加物料类别(按编码查 ID)
|
||||
if (!CollectionUtils.isEmpty(request.getAddMaterialCategoryCodes())) {
|
||||
Map<String, Long> codeToIdMap = getCategoryCodeToIdMap(request.getAddMaterialCategoryCodes());
|
||||
List<QmsInspectorMaterialCategoryItem> toAdd = new ArrayList<>();
|
||||
for (String code : request.getAddMaterialCategoryCodes()) {
|
||||
Long categoryId = codeToIdMap.get(code);
|
||||
if (Objects.nonNull(categoryId)) {
|
||||
toAdd.add(new QmsInspectorMaterialCategoryItem()
|
||||
.setInspectorId(inspectorId)
|
||||
.setMaterialCategoryId(categoryId)
|
||||
.setCreateBy(operator)
|
||||
.setCreateTime(now)
|
||||
.setUpdateBy(operator)
|
||||
.setUpdateTime(now));
|
||||
}
|
||||
}
|
||||
if (!toAdd.isEmpty()) {
|
||||
materialCategoryItemService.saveBatch(toAdd);
|
||||
}
|
||||
}
|
||||
|
||||
// 删除物料类别(按编码查 ID)
|
||||
if (!CollectionUtils.isEmpty(request.getRemoveMaterialCategoryCodes())) {
|
||||
toRemove.addAll(lambdaQuery()
|
||||
.eq(QmsQualityInspector::getUserId, userId)
|
||||
.in(QmsQualityInspector::getMaterialCategoryCode, request.getRemoveMaterialCategoryCodes())
|
||||
.list());
|
||||
}
|
||||
if (!toRemove.isEmpty()) {
|
||||
removeMaterialOrClear(userId, toRemove, operator, now);
|
||||
Map<String, Long> codeToIdMap = getCategoryCodeToIdMap(request.getRemoveMaterialCategoryCodes());
|
||||
List<Long> removeIds = new ArrayList<>(codeToIdMap.values());
|
||||
if (!removeIds.isEmpty()) {
|
||||
materialCategoryItemService.lambdaUpdate()
|
||||
.eq(QmsInspectorMaterialCategoryItem::getInspectorId, inspectorId)
|
||||
.in(QmsInspectorMaterialCategoryItem::getMaterialCategoryId, removeIds)
|
||||
.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -237,12 +270,11 @@ public class QmsQualityInspectorServiceImpl extends ServiceImpl<QmsQualityInspec
|
|||
|
||||
@Override
|
||||
public QmsQualityInspectorDetailVO getDetailByUserId(Long userId) {
|
||||
// 查询该用户的任意一条记录(取 inspectionType/enable)
|
||||
QmsQualityInspector first = lambdaQuery()
|
||||
// 查主表
|
||||
QmsQualityInspector inspector = lambdaQuery()
|
||||
.eq(QmsQualityInspector::getUserId, userId)
|
||||
.last("LIMIT 1")
|
||||
.one();
|
||||
if (Objects.isNull(first)) {
|
||||
if (Objects.isNull(inspector)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -251,13 +283,12 @@ public class QmsQualityInspectorServiceImpl extends ServiceImpl<QmsQualityInspec
|
|||
|
||||
QmsQualityInspectorDetailVO detail = new QmsQualityInspectorDetailVO();
|
||||
detail.setUserId(userId);
|
||||
detail.setInspectionType(first.getInspectionType());
|
||||
detail.setEnable(first.getEnable());
|
||||
detail.setInspectionType(inspector.getInspectionType());
|
||||
detail.setEnable(inspector.getEnable());
|
||||
if (Objects.nonNull(user)) {
|
||||
detail.setUserCode(user.getUserCode());
|
||||
detail.setUserName(user.getUserName());
|
||||
}
|
||||
// 部门领导暂不填充,字段预留
|
||||
detail.setDeptLeaderName(null);
|
||||
|
||||
// 查物料列表
|
||||
|
|
@ -273,6 +304,77 @@ public class QmsQualityInspectorServiceImpl extends ServiceImpl<QmsQualityInspec
|
|||
@Transactional
|
||||
@Override
|
||||
public void updateStatus(Long userId, Boolean enable) {
|
||||
// 仅在改为启用时做校验
|
||||
if (Boolean.TRUE.equals(enable)) {
|
||||
QmsQualityInspector inspector = lambdaQuery()
|
||||
.eq(QmsQualityInspector::getUserId, userId)
|
||||
.one();
|
||||
if (Objects.isNull(inspector)) {
|
||||
throw new NflgException(STATE.BusinessError, "该质检人员不存在");
|
||||
}
|
||||
Long inspectorId = inspector.getId();
|
||||
|
||||
// 查当前人员绑定的物料ID列表
|
||||
List<QmsInspectorMaterialItem> myMaterials = materialItemService.lambdaQuery()
|
||||
.eq(QmsInspectorMaterialItem::getInspectorId, inspectorId)
|
||||
.list();
|
||||
|
||||
// 查当前人员绑定的物料类别ID列表
|
||||
List<QmsInspectorMaterialCategoryItem> myCategories = materialCategoryItemService.lambdaQuery()
|
||||
.eq(QmsInspectorMaterialCategoryItem::getInspectorId, inspectorId)
|
||||
.list();
|
||||
|
||||
// 校验物料是否已被其他启用的质检员接管
|
||||
if (!myMaterials.isEmpty()) {
|
||||
List<Long> myMaterialIds = myMaterials.stream()
|
||||
.map(QmsInspectorMaterialItem::getMaterialId)
|
||||
.collect(Collectors.toList());
|
||||
// 查其他人员中是否有相同物料绑定(排除自己)
|
||||
List<QmsInspectorMaterialItem> conflictItems = materialItemService.lambdaQuery()
|
||||
.in(QmsInspectorMaterialItem::getMaterialId, myMaterialIds)
|
||||
.ne(QmsInspectorMaterialItem::getInspectorId, inspectorId)
|
||||
.list();
|
||||
if (!conflictItems.isEmpty()) {
|
||||
// 进一步判断接管人员是否处于启用状态
|
||||
List<Long> conflictInspectorIds = conflictItems.stream()
|
||||
.map(QmsInspectorMaterialItem::getInspectorId)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
long enabledCount = lambdaQuery()
|
||||
.in(QmsQualityInspector::getId, conflictInspectorIds)
|
||||
.eq(QmsQualityInspector::getEnable, true)
|
||||
.count();
|
||||
if (enabledCount > 0) {
|
||||
throw new NflgException(STATE.BusinessError, "该质检员的部分物料已被其他启用的质检员接管,不允许启用");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 校验物料类别是否已被其他启用的质检员接管
|
||||
if (!myCategories.isEmpty()) {
|
||||
List<Long> myCategoryIds = myCategories.stream()
|
||||
.map(QmsInspectorMaterialCategoryItem::getMaterialCategoryId)
|
||||
.collect(Collectors.toList());
|
||||
List<QmsInspectorMaterialCategoryItem> conflictItems = materialCategoryItemService.lambdaQuery()
|
||||
.in(QmsInspectorMaterialCategoryItem::getMaterialCategoryId, myCategoryIds)
|
||||
.ne(QmsInspectorMaterialCategoryItem::getInspectorId, inspectorId)
|
||||
.list();
|
||||
if (!conflictItems.isEmpty()) {
|
||||
List<Long> conflictInspectorIds = conflictItems.stream()
|
||||
.map(QmsInspectorMaterialCategoryItem::getInspectorId)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
long enabledCount = lambdaQuery()
|
||||
.in(QmsQualityInspector::getId, conflictInspectorIds)
|
||||
.eq(QmsQualityInspector::getEnable, true)
|
||||
.count();
|
||||
if (enabledCount > 0) {
|
||||
throw new NflgException(STATE.BusinessError, "该质检员的部分物料类别已被其他启用的质检员接管,不允许启用");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lambdaUpdate()
|
||||
.eq(QmsQualityInspector::getUserId, userId)
|
||||
.set(QmsQualityInspector::getEnable, enable)
|
||||
|
|
@ -308,11 +410,13 @@ public class QmsQualityInspectorServiceImpl extends ServiceImpl<QmsQualityInspec
|
|||
}
|
||||
|
||||
@Override
|
||||
public PageData<QmsQualityInspectorMaterialVO> getMaterialsByUserId(String materialNo, String materialCategoryCode, String materialDesc, Integer pageNum, Integer pageSize) {
|
||||
public PageData<QmsQualityInspectorMaterialVO> getMaterialsByUserId(String materialNo, String materialCategoryCode,
|
||||
String materialDesc, Integer pageNum, Integer pageSize) {
|
||||
Long userId = UserUtil.getUserId();
|
||||
Page<QmsQualityInspectorMaterialVO> page = new Page<>(pageNum, pageSize);
|
||||
IPage<QmsQualityInspectorMaterialVO> result = baseMapper.getMaterialsByUserIdWithFilter(page, userId, materialNo, materialCategoryCode, materialDesc);
|
||||
|
||||
IPage<QmsQualityInspectorMaterialVO> result = baseMapper.getMaterialsByUserIdWithFilter(
|
||||
page, userId, materialNo, materialCategoryCode, materialDesc);
|
||||
|
||||
return new PageData<QmsQualityInspectorMaterialVO>()
|
||||
.setPage((int) result.getCurrent())
|
||||
.setPageSize((int) result.getSize())
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nflg.wms.repository.mapper.QmsInspectorMaterialCategoryItemMapper">
|
||||
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nflg.wms.repository.mapper.QmsInspectorMaterialItemMapper">
|
||||
|
||||
</mapper>
|
||||
|
|
@ -3,8 +3,7 @@
|
|||
<mapper namespace="com.nflg.wms.repository.mapper.QmsQualityInspectorMapper">
|
||||
|
||||
<!--
|
||||
分页查询:以质检人为主体,每个 user_id 只返回一条记录
|
||||
使用 DISTINCT ON (qi.user_id) 保证每人唯一
|
||||
分页查询:以质检人为主体,每个 user_id 只返回一条记录(主表一人一条)
|
||||
JOIN user_interior/department 获取部门信息
|
||||
JOIN user AS cu 获取转办人姓名
|
||||
支持动态过滤:员工工号(userCode)、人员名称模糊(userName)、物料编号(materialNo)
|
||||
|
|
@ -27,11 +26,7 @@
|
|||
qi.create_time,
|
||||
qi.update_by,
|
||||
qi.update_time
|
||||
FROM (
|
||||
SELECT DISTINCT ON (user_id) *
|
||||
FROM qms_quality_inspector
|
||||
ORDER BY user_id, id DESC
|
||||
) qi
|
||||
FROM qms_quality_inspector qi
|
||||
LEFT JOIN "user" u ON u.id = qi.user_id
|
||||
LEFT JOIN user_interior ui ON ui.user_id = qi.user_id
|
||||
LEFT JOIN department d ON d.id = ui.dept_id
|
||||
|
|
@ -45,9 +40,10 @@
|
|||
</if>
|
||||
<if test="request.materialNo != null and request.materialNo != ''">
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM qms_quality_inspector qi2
|
||||
LEFT JOIN qms_qc_material m ON m.id = qi2.material_id
|
||||
WHERE qi2.user_id = qi.user_id
|
||||
SELECT 1
|
||||
FROM qms_inspector_material_item imi
|
||||
LEFT JOIN qms_qc_material m ON m.id = imi.material_id
|
||||
WHERE imi.inspector_id = qi.id
|
||||
AND m.material_no ilike concat('%', #{request.materialNo}, '%')
|
||||
)
|
||||
</if>
|
||||
|
|
@ -58,8 +54,8 @@
|
|||
<!-- 按 userId 查询关联物料列表(JOIN qms_qc_material 获取物料详情) -->
|
||||
<select id="getMaterialsByUserId" resultType="com.nflg.wms.common.pojo.vo.QmsQualityInspectorMaterialVO">
|
||||
SELECT
|
||||
qi.id,
|
||||
qi.material_id,
|
||||
imi.id,
|
||||
imi.material_id,
|
||||
m.material_no,
|
||||
m.material_category_code,
|
||||
m.material_category_code_path_name AS material_category_name,
|
||||
|
|
@ -67,18 +63,19 @@
|
|||
m.material_specifications,
|
||||
m.material_texture,
|
||||
m.is_standard_maintained AS material_status
|
||||
FROM qms_quality_inspector qi
|
||||
LEFT JOIN qms_qc_material m ON m.id = qi.material_id
|
||||
WHERE qi.user_id = #{userId}
|
||||
AND qi.material_id IS NOT NULL
|
||||
ORDER BY qi.id ASC
|
||||
FROM qms_inspector_material_item imi
|
||||
LEFT JOIN qms_qc_material m ON m.id = imi.material_id
|
||||
WHERE imi.inspector_id = (
|
||||
SELECT id FROM qms_quality_inspector WHERE user_id = #{userId} LIMIT 1
|
||||
)
|
||||
ORDER BY imi.id ASC
|
||||
</select>
|
||||
|
||||
<!-- 按 userId 查询关联物料列表(支持供应商过滤) -->
|
||||
<select id="getMaterialsByUserIdWithSupplier" resultType="com.nflg.wms.common.pojo.vo.QmsQualityInspectorMaterialVO">
|
||||
SELECT
|
||||
qi.id,
|
||||
qi.material_id,
|
||||
imi.id,
|
||||
imi.material_id,
|
||||
m.material_no,
|
||||
m.material_category_code,
|
||||
m.material_category_code_path_name AS material_category_name,
|
||||
|
|
@ -86,29 +83,30 @@
|
|||
m.material_specifications,
|
||||
m.material_texture,
|
||||
m.is_standard_maintained AS material_status
|
||||
FROM qms_quality_inspector qi
|
||||
LEFT JOIN qms_qc_material m ON m.id = qi.material_id
|
||||
FROM qms_inspector_material_item imi
|
||||
LEFT JOIN qms_qc_material m ON m.id = imi.material_id
|
||||
LEFT JOIN qms_coa_review cr ON cr.material_id = m.id
|
||||
LEFT JOIN user_supplier us ON us.id = cr.supplier_id
|
||||
WHERE qi.user_id = #{userId}
|
||||
AND qi.material_id IS NOT NULL
|
||||
WHERE imi.inspector_id = (
|
||||
SELECT id FROM qms_quality_inspector WHERE user_id = #{userId} LIMIT 1
|
||||
)
|
||||
<if test="supplierCode != null and supplierCode != ''">
|
||||
AND us.supplier_code = #{supplierCode}
|
||||
</if>
|
||||
<if test="supplierName != null and supplierName != ''">
|
||||
AND us.supplier_name LIKE CONCAT('%', #{supplierName}, '%')
|
||||
</if>
|
||||
GROUP BY qi.id, qi.material_id, m.material_no, m.material_category_code,
|
||||
GROUP BY imi.id, imi.material_id, m.material_no, m.material_category_code,
|
||||
m.material_category_code_path_name, m.material_desc,
|
||||
m.material_specifications, m.material_texture, m.is_standard_maintained
|
||||
ORDER BY qi.id ASC
|
||||
ORDER BY imi.id ASC
|
||||
</select>
|
||||
|
||||
<!-- 按 userId 查询绑定物料列表(支持物料编号/类别/描述过滤) -->
|
||||
<select id="getMaterialsByUserIdWithFilter" resultType="com.nflg.wms.common.pojo.vo.QmsQualityInspectorMaterialVO">
|
||||
SELECT
|
||||
qi.id,
|
||||
qi.material_id,
|
||||
imi.id,
|
||||
imi.material_id,
|
||||
m.material_no,
|
||||
m.drawing_no,
|
||||
m.drawing_no_ver,
|
||||
|
|
@ -118,10 +116,11 @@
|
|||
m.material_specifications,
|
||||
m.material_texture,
|
||||
m.is_standard_maintained AS material_status
|
||||
FROM qms_quality_inspector qi
|
||||
LEFT JOIN qms_qc_material m ON m.id = qi.material_id
|
||||
WHERE qi.user_id = #{userId}
|
||||
AND qi.material_id IS NOT NULL
|
||||
FROM qms_inspector_material_item imi
|
||||
LEFT JOIN qms_qc_material m ON m.id = imi.material_id
|
||||
WHERE imi.inspector_id = (
|
||||
SELECT id FROM qms_quality_inspector WHERE user_id = #{userId} LIMIT 1
|
||||
)
|
||||
<if test="materialNo != null and materialNo != ''">
|
||||
AND m.material_no = #{materialNo}
|
||||
</if>
|
||||
|
|
@ -131,21 +130,21 @@
|
|||
<if test="materialDesc != null and materialDesc != ''">
|
||||
AND m.material_desc LIKE CONCAT('%', #{materialDesc}, '%')
|
||||
</if>
|
||||
ORDER BY qi.id ASC
|
||||
ORDER BY imi.id ASC
|
||||
</select>
|
||||
|
||||
<!-- 按 userId 查询关联物料类别列表(JOIN qms_qc_material 取类别名称) -->
|
||||
<!-- 按 userId 查询关联物料类别列表(JOIN qms_qc_material_category 取类别信息) -->
|
||||
<select id="getCategoriesByUserId" resultType="com.nflg.wms.common.pojo.vo.QmsQualityInspectorCategoryVO">
|
||||
SELECT DISTINCT ON (qi.material_category_code)
|
||||
qi.id,
|
||||
qi.material_category_code,
|
||||
m.material_category_code_path_name AS material_category_name
|
||||
FROM qms_quality_inspector qi
|
||||
LEFT JOIN qms_qc_material m ON m.material_category_code = qi.material_category_code
|
||||
WHERE qi.user_id = #{userId}
|
||||
AND qi.material_category_code IS NOT NULL
|
||||
AND qi.material_id IS NULL
|
||||
ORDER BY qi.material_category_code, qi.id ASC
|
||||
SELECT
|
||||
imci.id,
|
||||
mc.category_code AS material_category_code,
|
||||
mc.category_name AS material_category_name
|
||||
FROM qms_inspector_material_category_item imci
|
||||
LEFT JOIN qms_qc_material_category mc ON mc.id = imci.material_category_id
|
||||
WHERE imci.inspector_id = (
|
||||
SELECT id FROM qms_quality_inspector WHERE user_id = #{userId} LIMIT 1
|
||||
)
|
||||
ORDER BY imci.id ASC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue