feat(supplier-user): 新增
This commit is contained in:
parent
9e858d41e4
commit
acc32284b3
|
|
@ -5,7 +5,8 @@ import com.nflg.wms.common.pojo.ApiResult;
|
|||
import com.nflg.wms.common.pojo.PageData;
|
||||
import com.nflg.wms.common.pojo.qo.EnableQO;
|
||||
import com.nflg.wms.common.pojo.qo.QmsSupplierSqeSearchQO;
|
||||
import com.nflg.wms.common.pojo.qo.SetSupplierQO;
|
||||
import com.nflg.wms.common.pojo.qo.QmsSetSupplierQO;
|
||||
import com.nflg.wms.common.pojo.qo.QmsSetUserQO;
|
||||
import com.nflg.wms.common.pojo.vo.QmsSupplierSqeMapVO;
|
||||
import com.nflg.wms.repository.service.IQmsSupplierSqeMapService;
|
||||
import com.nflg.wms.starter.BaseController;
|
||||
|
|
@ -16,7 +17,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 供应商-SQE 关联管理
|
||||
* 供应商-用户 关联管理
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/supplierSqe")
|
||||
|
|
@ -26,7 +27,7 @@ public class QmsSupplierSqeController extends BaseController {
|
|||
private IQmsSupplierSqeMapService supplierSqeMapService;
|
||||
|
||||
/**
|
||||
* 分页查询供应商-SQE关联列表(直接查关联表,支持动态过滤)
|
||||
* 分页查询供应商-用户关联列表(直接查关联表,支持动态过滤)
|
||||
*/
|
||||
@PostMapping("search")
|
||||
public ApiResult<PageData<QmsSupplierSqeMapVO>> search(@Valid @RequestBody QmsSupplierSqeSearchQO request) {
|
||||
|
|
@ -34,17 +35,27 @@ public class QmsSupplierSqeController extends BaseController {
|
|||
}
|
||||
|
||||
/**
|
||||
* 设置供应商(为选中用户绑定供应商,多对多,覆盖式更新,以用户为主体)
|
||||
* 设置供应商(为选中用户绑定供应商,多对多,以用户为主体)
|
||||
*/
|
||||
@Transactional
|
||||
@PostMapping("setSupplier")
|
||||
public ApiResult<Void> setSupplier(@Valid @RequestBody SetSupplierQO request) {
|
||||
public ApiResult<Void> setSupplier(@Valid @RequestBody QmsSetSupplierQO request) {
|
||||
supplierSqeMapService.setSupplier(request.getUserId(), request.getSupplierIds());
|
||||
return ApiResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用/禁用供应商-SQE关联关系
|
||||
* 设置用户(为选中供应商绑定用户,多对多,以供应商为主体)
|
||||
*/
|
||||
@Transactional
|
||||
@PostMapping("setUser")
|
||||
public ApiResult<Void> setUser(@Valid @RequestBody QmsSetUserQO request) {
|
||||
supplierSqeMapService.setUser(request.getSupplierId(), request.getUserIds());
|
||||
return ApiResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用/禁用供应商-用户关联关系
|
||||
*/
|
||||
@Transactional
|
||||
@PostMapping("enable")
|
||||
|
|
@ -54,7 +65,7 @@ public class QmsSupplierSqeController extends BaseController {
|
|||
}
|
||||
|
||||
/**
|
||||
* 删除供应商-SQE关联关系(启用状态下不允许删除)
|
||||
* 删除供应商-用户关联关系(启用状态下不允许删除)
|
||||
*
|
||||
* @param id 关联记录ID
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import java.util.List;
|
|||
* 为用户设置供应商参数(多对多)
|
||||
*/
|
||||
@Data
|
||||
public class SetSupplierQO {
|
||||
public class QmsSetSupplierQO {
|
||||
|
||||
/**
|
||||
* 用户ID(user.id)
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package com.nflg.wms.common.pojo.qo;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 为供应商设置用户参数(多对多)
|
||||
*/
|
||||
@Data
|
||||
public class QmsSetUserQO {
|
||||
|
||||
/**
|
||||
* 供应商ID(user_supplier.id)
|
||||
*/
|
||||
@NotNull(message = "供应商ID不能为空")
|
||||
private Long supplierId;
|
||||
|
||||
/**
|
||||
* 用户ID列表(user.id)
|
||||
*/
|
||||
@NotEmpty(message = "用户列表不能为空")
|
||||
private List<Long> userIds;
|
||||
}
|
||||
|
|
@ -28,6 +28,11 @@ public interface IQmsSupplierSqeMapService extends IService<QmsSupplierSqeMap> {
|
|||
*/
|
||||
void setSupplier(Long userId, List<Long> supplierIds);
|
||||
|
||||
/**
|
||||
* 为供应商重新设置用户(追加式,以供应商为主体,跳过已存在的记录)
|
||||
*/
|
||||
void setUser(Long supplierId, List<Long> userIds);
|
||||
|
||||
/**
|
||||
* 启用/禁用单条供应商-用户关联
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -66,6 +66,35 @@ public class QmsSupplierSqeMapServiceImpl extends ServiceImpl<QmsSupplierSqeMapM
|
|||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void setUser(Long supplierId, List<Long> userIds) {
|
||||
// 查询该供应商已存在的用户ID集合
|
||||
Set<Long> existUserIds = lambdaQuery()
|
||||
.eq(QmsSupplierSqeMap::getSupplierId, supplierId)
|
||||
.list()
|
||||
.stream()
|
||||
.map(QmsSupplierSqeMap::getUserId)
|
||||
.collect(Collectors.toSet());
|
||||
// 只插入不存在的记录,跳过重复的
|
||||
String operator = UserUtil.getUserName();
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
List<QmsSupplierSqeMap> toAdd = userIds.stream()
|
||||
.filter(userId -> !existUserIds.contains(userId))
|
||||
.map(userId -> new QmsSupplierSqeMap()
|
||||
.setSupplierId(supplierId)
|
||||
.setUserId(userId)
|
||||
.setState(1)
|
||||
.setCreateBy(operator)
|
||||
.setCreateTime(now)
|
||||
.setUpdateBy(operator)
|
||||
.setUpdateTime(now))
|
||||
.collect(Collectors.toList());
|
||||
if (!toAdd.isEmpty()) {
|
||||
saveBatch(toAdd);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void enable(Long id, Boolean enable) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue