物资配置管理--业务逻辑抽离,遍历修改

This commit is contained in:
syruan 2024-10-16 19:17:53 +08:00
parent 16e4db25c9
commit cdcba68d85
3 changed files with 131 additions and 45 deletions

View File

@ -12,6 +12,7 @@ import com.bonus.material.ma.domain.TypeRepair;
import com.bonus.material.ma.service.ITypeKeeperService; import com.bonus.material.ma.service.ITypeKeeperService;
import com.bonus.material.ma.service.ITypeRepairService; import com.bonus.material.ma.service.ITypeRepairService;
import com.bonus.material.ma.service.ITypeService; import com.bonus.material.ma.service.ITypeService;
import com.bonus.material.ma.service.MaTypeConfigService;
import com.bonus.material.ma.vo.MaTypeConfigVo; import com.bonus.material.ma.vo.MaTypeConfigVo;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -55,6 +56,9 @@ public class MaTypeConfigController extends BaseController {
private ITypeService typeService; private ITypeService typeService;
@Resource
private MaTypeConfigService maTypeConfigService;
@ApiOperation(value = "配置物资类型绑定信息") @ApiOperation(value = "配置物资类型绑定信息")
@PreventRepeatSubmit @PreventRepeatSubmit
@RequiresPermissions("ma:typeConfig:edit") @RequiresPermissions("ma:typeConfig:edit")
@ -66,62 +70,19 @@ public class MaTypeConfigController extends BaseController {
if (maTypeConfigDto.getBindFlag() == null) { if (maTypeConfigDto.getBindFlag() == null) {
return error("绑定标识不能为空"); return error("绑定标识不能为空");
} }
// 2.判断绑定角色类型是否为空 // 2.判断绑定角色类型是否为空
if (maTypeConfigDto.getBindRoleType() == null) { if (maTypeConfigDto.getBindRoleType() == null) {
return error("绑定角色类型不能为空"); return error("绑定角色类型不能为空");
} }
// 3.判断用户id是否为空 // 3.判断用户id是否为空
if (maTypeConfigDto.getUserId() == null) { if (maTypeConfigDto.getUserId() == null) {
return error("用户id不能为空"); return error("用户id不能为空");
} }
// ---------------- 数据校验结束 --------------------- // ---------------- 数据校验结束 ---------------------
int result;
switch (maTypeConfigDto.getBindFlag()) {
case 1:
result = handleBind(maTypeConfigDto.getBindFlag(), maTypeConfigDto.getTypeId(), maTypeConfigDto.getUserId());
return result == 1 ? AjaxResult.success("绑定成功") : error("绑定失败");
case 2:
result = handleUnBind(maTypeConfigDto.getBindFlag(), maTypeConfigDto.getTypeId(), maTypeConfigDto.getUserId());
return result == 1 ? AjaxResult.success("解绑成功") : error("解绑失败");
default:
// 处理其他情况或抛出异常
return error("输入值不合法 bindFlag: " + maTypeConfigDto.getBindFlag());
}
}
private int handleBind(int bindRoleType, Long typeId, Long userId) { // 执行业务逻辑
switch (bindRoleType) { return maTypeConfigService.updateMaTypeBindInfo(maTypeConfigDto);
case 1:
// 处理 bindFlag 1:绑定 bindRoleType 1:库管员 的情况
// TODO: 实现具体逻辑
return typeKeeperService.insertTypeKeeper(new TypeKeeper(typeId, userId));
case 2:
// 处理 bindFlag 1:绑定 bindRoleType 2:维修员 的情况
// TODO: 实现具体逻辑
return typeRepairService.insertTypeRepair(new TypeRepair(typeId, userId));
default:
// 处理其他情况或抛出异常
throw new IllegalArgumentException("Unsupported bindRoleType: " + bindRoleType);
}
}
private int handleUnBind(int bindRoleType, Long typeId, Long userId) {
switch (bindRoleType) {
case 1:
// 处理 bindFlag 2:解绑 bindRoleType 1:库管员 的情况
// TODO: 实现具体逻辑
return typeKeeperService.deleteTypeKeeperByUserIdAndTypeId(new TypeKeeper(typeId, userId));
case 2:
// 处理 bindFlag 2:解绑 bindRoleType 2:维修员 的情况
// TODO: 实现具体逻辑
return typeRepairService.deleteTypeRepairByUserIdAndTypeId(new TypeRepair(typeId, userId));
default:
// 处理其他情况或抛出异常
throw new IllegalArgumentException("Unsupported bindRoleType: " + bindRoleType);
}
} }
@ -152,6 +113,17 @@ public class MaTypeConfigController extends BaseController {
maTypeConfigVo1.setRepairUserId(typeRepair.getUserId()); maTypeConfigVo1.setRepairUserId(typeRepair.getUserId());
maTypeConfigVo1.setRepairUserName(typeRepair.getUserName()); maTypeConfigVo1.setRepairUserName(typeRepair.getUserName());
} }
// 判断当前maTypeConfigVo1对象是否有子节点如果有再继续循环
if (maTypeConfigVo1.getChildren() != null) {
for (MaTypeConfigVo maTypeConfigVo2 : maTypeConfigVo1.getChildren()) {
// 5.判断当前维修配置信息中的物资类型id是否等于当前物资类型配置信息中的物资类型id
if (typeRepair.getTypeId().equals(maTypeConfigVo2.getTypeId())) {
// 6.如果相等把维修员信息设置到物资类型配置信息中
maTypeConfigVo2.setRepairUserId(typeRepair.getUserId());
maTypeConfigVo2.setRepairUserName(typeRepair.getUserName());
}
}
}
} }
} }
@ -165,6 +137,17 @@ public class MaTypeConfigController extends BaseController {
maTypeConfigVo1.setKeeperUserId(typeKeeper.getUserId()); maTypeConfigVo1.setKeeperUserId(typeKeeper.getUserId());
maTypeConfigVo1.setKeeperUserName(typeKeeper.getUserName()); maTypeConfigVo1.setKeeperUserName(typeKeeper.getUserName());
} }
// 判断当前maTypeConfigVo1对象是否有子节点如果有再继续循环
if (maTypeConfigVo1.getChildren() != null) {
for (MaTypeConfigVo maTypeConfigVo2 : maTypeConfigVo1.getChildren()) {
// 5.判断当前库管配置信息中的物资类型id是否等于当前物资类型配置信息中的物资类型id
if (typeKeeper.getTypeId().equals(maTypeConfigVo2.getTypeId())) {
// 6.如果相等把库管员信息设置到物资类型配置信息中
maTypeConfigVo2.setKeeperUserId(typeKeeper.getUserId());
maTypeConfigVo2.setKeeperUserName(typeKeeper.getUserName());
}
}
}
} }
} }

View File

@ -0,0 +1,18 @@
package com.bonus.material.ma.service;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.material.ma.MaTypeConfigDto;
/**
* @author : 阮世耀
* @version : 1.0
* @PackagePath: com.bonus.material.ma.service
* @CreateTime: 2024-10-16 18:50
* @Description: 物资类型配置Service
*/
public interface MaTypeConfigService{
AjaxResult updateMaTypeBindInfo(MaTypeConfigDto maTypeConfigDto);
}

View File

@ -0,0 +1,85 @@
package com.bonus.material.ma.service.impl;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.material.ma.MaTypeConfigDto;
import com.bonus.material.ma.domain.TypeKeeper;
import com.bonus.material.ma.domain.TypeRepair;
import com.bonus.material.ma.service.ITypeKeeperService;
import com.bonus.material.ma.service.ITypeRepairService;
import com.bonus.material.ma.service.MaTypeConfigService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* @author : 阮世耀
* @version : 1.0
* @PackagePath: com.bonus.material.ma.service.impl
* @CreateTime: 2024-10-16 18:50
* @Description: 描述
*/
@Service
public class MaTypeConfigServiceImpl implements MaTypeConfigService {
/**
* 物资类型库管员配置Service
*/
@Resource
private ITypeKeeperService typeKeeperService;
/**
* 物资类型维修员配置Service
*/
@Resource
private ITypeRepairService typeRepairService;
@Override
public AjaxResult updateMaTypeBindInfo(MaTypeConfigDto maTypeConfigDto) {
int result;
switch (maTypeConfigDto.getBindFlag()) {
case 1:
result = handleBind(maTypeConfigDto.getBindFlag(), maTypeConfigDto.getTypeId(), maTypeConfigDto.getUserId());
return result == 1 ? AjaxResult.success("绑定成功") : AjaxResult.error("绑定失败");
case 2:
result = handleUnBind(maTypeConfigDto.getBindFlag(), maTypeConfigDto.getTypeId(), maTypeConfigDto.getUserId());
return result == 1 ? AjaxResult.success("解绑成功") : AjaxResult.error("解绑失败");
default:
// 处理其他情况或抛出异常
return AjaxResult.error("输入值不合法 bindFlag: " + maTypeConfigDto.getBindFlag());
}
}
private int handleBind(int bindRoleType, Long typeId, Long userId) {
switch (bindRoleType) {
case 1:
// 处理 bindFlag 1:绑定 bindRoleType 1:库管员 的情况
// TODO: 实现具体逻辑
return typeKeeperService.insertTypeKeeper(new TypeKeeper(typeId, userId));
case 2:
// 处理 bindFlag 1:绑定 bindRoleType 2:维修员 的情况
// TODO: 实现具体逻辑
return typeRepairService.insertTypeRepair(new TypeRepair(typeId, userId));
default:
// 处理其他情况或抛出异常
throw new IllegalArgumentException("Unsupported bindRoleType: " + bindRoleType);
}
}
private int handleUnBind(int bindRoleType, Long typeId, Long userId) {
switch (bindRoleType) {
case 1:
// 处理 bindFlag 2:解绑 bindRoleType 1:库管员 的情况
// TODO: 实现具体逻辑
return typeKeeperService.deleteTypeKeeperByUserIdAndTypeId(new TypeKeeper(typeId, userId));
case 2:
// 处理 bindFlag 2:解绑 bindRoleType 2:维修员 的情况
// TODO: 实现具体逻辑
return typeRepairService.deleteTypeRepairByUserIdAndTypeId(new TypeRepair(typeId, userId));
default:
// 处理其他情况或抛出异常
throw new IllegalArgumentException("Unsupported bindRoleType: " + bindRoleType);
}
}
}