feat:添加设备台账产线相关接口及扫码器菜单字段

main
HuangHuiKang 3 weeks ago
parent 110ed1e424
commit a5698d1449

@ -1,7 +1,6 @@
package cn.iocoder.yudao.module.common.enums;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
@Getter
@ -10,6 +9,7 @@ public enum QrcodeBizTypeEnum {
PRODUCT("PRODUCTMATERIAL", "产品物料"),
EQUIPMENT("EQUIPMENT", "设备"),
DEVICE_LINE("DEVICE_LINE", "设备产线"),
KEY_PART("KEY_PART", "关键件"),
MOLD("MOLD", "模具"),
SPARE("SPARE", "备件");
@ -25,4 +25,4 @@ public enum QrcodeBizTypeEnum {
}
return null;
}
}
}

@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.common.enums.QrcodeBizTypeEnum;
import org.springframework.transaction.annotation.Transactional;
import javax.validation.Valid;
import java.util.Collection;
import java.io.UnsupportedEncodingException;
import java.util.Map;
@ -66,6 +67,8 @@ public interface QrcodeRecordService {
String selectQrcodeUrlByIdAndCode(String code, Long id, String code1);
Map<Long, String> selectQrcodeUrlMapByBizTypeAndIds(String bizType, Collection<Long> bizIds);
Map<String, Object> resolveScanBizId(String type, Long id, String code);
void deleteByBiz(QrcodeBizTypeEnum bizType, Long bizId);
@ -80,4 +83,4 @@ public interface QrcodeRecordService {
String scene,
CodeTypeEnum codeType
) throws UnsupportedEncodingException;
}
}

@ -35,6 +35,7 @@ import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -335,6 +336,27 @@ public class QrcodeRecordServiceImpl implements QrcodeRecordService {
}
@Override
public Map<Long, String> selectQrcodeUrlMapByBizTypeAndIds(String bizType, Collection<Long> bizIds) {
if (StrUtil.isBlank(bizType) || bizIds == null || bizIds.isEmpty()) {
return new HashMap<>();
}
List<QrcodeRecordDO> records = qrcodeRecordMapper.selectList(Wrappers.<QrcodeRecordDO>lambdaQuery()
.eq(QrcodeRecordDO::getBizType, bizType)
.in(QrcodeRecordDO::getBizId, bizIds)
.eq(QrcodeRecordDO::getStatus, 1)
.orderByDesc(QrcodeRecordDO::getId));
return records.stream()
.filter(record -> StrUtil.isNotBlank(record.getQrcodeFileUrl()))
.collect(Collectors.toMap(
QrcodeRecordDO::getBizId,
QrcodeRecordDO::getQrcodeFileUrl,
(first, second) -> first
));
}
@Override
public Map<String, Object> resolveScanBizId(String type, Long id, String code) {
Map<String, Object> result = new HashMap<>();
@ -602,4 +624,4 @@ public class QrcodeRecordServiceImpl implements QrcodeRecordService {
}
}
}

@ -205,4 +205,12 @@ public interface ErrorCodeConstants {
ErrorCode PRINT_TEMPLATE_CODE_EXISTS = new ErrorCode(100_401_0001, "模板编码已存在,请重新提交");
ErrorCode PRINT_TEMPLATE_TYPE_EXISTS = new ErrorCode(100_401_0002, "该模板类型已存在模板,请勿重复新增");
// ========== 设备产线 相关 100_501_0000 ==========
ErrorCode DEVICE_LINE_NOT_EXISTS = new ErrorCode(100_501_0001, "设备产线不存在");
ErrorCode DEVICE_LINE_PARENT_NOT_EXISTS = new ErrorCode(100_501_0002, "父级设备产线不存在");
ErrorCode DEVICE_LINE_PARENT_IS_SELF = new ErrorCode(100_501_0003, "不能设置自己为父级");
ErrorCode DEVICE_LINE_PARENT_IS_CHILD = new ErrorCode(100_501_0004, "不能设置子节点为父级");
ErrorCode DEVICE_LINE_EXITS_CHILDREN = new ErrorCode(100_501_0005, "存在子设备产线,无法删除");
ErrorCode DEVICE_LINE_CODE_EXISTS = new ErrorCode(100_501_0006, "设备产线编码已存在,请重新提交");
ErrorCode DEVICE_LINE_CODE_NOT_EXISTS = new ErrorCode(100_501_0007, "设备产线编码不能为空");
}

@ -7,6 +7,7 @@ import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@ -41,6 +42,12 @@ public class DeviceLedgerPageReqVO extends PageParam {
@Schema(description = "设备类型", example = "1")
private Long deviceType;
@Schema(description = "设备产线", example = "1")
private Integer deviceLine;
@Schema(description = "设备产线集合")
private List<Integer> deviceLineIds;
@Schema(description = "供应商")
private String supplier;
@ -92,4 +99,4 @@ public class DeviceLedgerPageReqVO extends PageParam {
@Schema(description = "产品Id")
private Long productId;
}
}

@ -44,6 +44,9 @@ public class DeviceLedgerRespVO extends BaseDO {
@Schema(description = "设备类型")
private String deviceType;
@Schema(description = "设备产线")
private Integer deviceLine;
@Schema(description = "设备类型名称", example = "1")
@ExcelProperty("类型")
private String typeName;
@ -172,4 +175,4 @@ public class DeviceLedgerRespVO extends BaseDO {
@Schema(description = "打印模板")
private String templateJson;
}
}

@ -37,6 +37,9 @@ public class DeviceLedgerSaveReqVO {
@Schema(description = "设备类型", example = "1")
private String deviceType;
@Schema(description = "设备产线", example = "1")
private Integer deviceLine;
@Schema(description = "供应商")
private String supplier;
@ -93,4 +96,4 @@ public class DeviceLedgerSaveReqVO {
@Schema(description = "数据采集产能")
private Integer dataCollectionCapacity;
}
}

@ -0,0 +1,210 @@
package cn.iocoder.yudao.module.mes.controller.admin.deviceline;
import cn.iocoder.yudao.module.common.enums.QrcodeBizTypeEnum;
import cn.iocoder.yudao.module.common.service.qrcordrecord.QrcodeRecordService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.io.IOException;
import java.util.stream.Collectors;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
import cn.iocoder.yudao.module.mes.controller.admin.deviceline.vo.*;
import cn.iocoder.yudao.module.mes.dal.dataobject.deviceline.DeviceLineDO;
import cn.iocoder.yudao.module.mes.service.deviceline.DeviceLineService;
@Tag(name = "管理后台 - 设备产线")
@RestController
@RequestMapping("/mes/device-line")
@Validated
public class DeviceLineController {
@Resource
private DeviceLineService deviceLineService;
@Resource
private QrcodeRecordService qrcodeService;
@PostMapping("/create")
@Operation(summary = "创建设备产线")
@PreAuthorize("@ss.hasPermission('mes:device-line:create')")
public CommonResult<Long> createDeviceLine(@Valid @RequestBody DeviceLineSaveReqVO createReqVO) throws UnsupportedEncodingException {
return success(deviceLineService.createDeviceLine(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新设备产线")
@PreAuthorize("@ss.hasPermission('mes:device-line:update')")
public CommonResult<Boolean> updateDeviceLine(@Valid @RequestBody DeviceLineSaveReqVO updateReqVO) {
deviceLineService.updateDeviceLine(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除设备产线")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('mes:device-line:delete')")
public CommonResult<Boolean> deleteDeviceLine(@RequestParam("id") Long id) {
deviceLineService.deleteDeviceLine(id);
return success(true);
}
@DeleteMapping("/delete-batch")
@Operation(summary = "批量删除设备产线")
@PreAuthorize("@ss.hasPermission('mes:device-line:delete')")
public CommonResult<Boolean> deleteDeviceLineBatch(@RequestParam("ids") List<Long> ids) {
deviceLineService.deleteDeviceLineBatch(ids);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得设备产线")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('mes:device-line:query')")
public CommonResult<DeviceLineRespVO> getDeviceLine(@RequestParam("id") Long id) {
DeviceLineDO deviceLine = deviceLineService.getDeviceLine(id);
DeviceLineRespVO deviceLineRespVO = BeanUtils.toBean(deviceLine, DeviceLineRespVO.class);
String qrcodeUrl = qrcodeService.selectQrcodeUrlByIdAndCode(QrcodeBizTypeEnum.DEVICE_LINE.getCode(),id,deviceLine.getCode());
deviceLineRespVO.setQrcodeUrl(qrcodeUrl);
return success(deviceLineRespVO);
}
@GetMapping("/page")
@Operation(summary = "获得设备产线分页")
@PreAuthorize("@ss.hasPermission('mes:device-line:query')")
public CommonResult<PageResult<DeviceLineRespVO>> getDeviceLinePage(@Valid DeviceLinePageReqVO pageReqVO) {
PageResult<DeviceLineDO> pageResult = deviceLineService.getDeviceLinePage(pageReqVO);
PageResult<DeviceLineRespVO> respVOPageResult = BeanUtils.toBean(pageResult, DeviceLineRespVO.class);
//添加二维码和打印模板
// if (respVOPageResult.getList() != null && !respVOPageResult.getList().isEmpty()) {
// String template = deviceLineService.selectPrintTemplate();
// Map<Long, String> qrcodeUrlMap = qrcodeService.selectQrcodeUrlMapByBizTypeAndIds(
// QrcodeBizTypeEnum.DEVICE_LINE.getCode(),
// respVOPageResult.getList().stream().map(DeviceLineRespVO::getId).collect(Collectors.toList()));
// for (DeviceLineRespVO deviceLineRespVO : respVOPageResult.getList()) {
// deviceLineRespVO.setQrcodeUrl(qrcodeUrlMap.get(deviceLineRespVO.getId()));
// deviceLineRespVO.setTemplateJson(template);
// }
// }
return success(respVOPageResult);
}
@GetMapping("/list")
@Operation(summary = "获得设备产线列表")
@PreAuthorize("@ss.hasPermission('mes:device-line:query')")
public CommonResult<List<DeviceLineRespVO>> getDeviceLineList(@Valid DeviceLineListReqVO listReqVO) {
List<DeviceLineDO> list = deviceLineService.getDeviceLineList(listReqVO);
return success(BeanUtils.toBean(list, DeviceLineRespVO.class));
}
@GetMapping("/tree")
@Operation(summary = "获得设备产线树")
@PreAuthorize("@ss.hasPermission('mes:device-line:query')")
public CommonResult<List<DeviceLineTreeRespVO>> getDeviceLineTree(@Valid DeviceLineListReqVO pageReqVO) {
List<DeviceLineTreeRespVO> tree = deviceLineService.getDeviceLineTree(pageReqVO);
if (tree != null && !tree.isEmpty()) {
String template = deviceLineService.selectPrintTemplate();
List<DeviceLineTreeRespVO> allNodes = new ArrayList<>(tree);
for (int i = 0; i < allNodes.size(); i++) {
List<DeviceLineTreeRespVO> children = allNodes.get(i).getChildren();
if (children != null && !children.isEmpty()) {
allNodes.addAll(children);
}
}
List<Long> ids = allNodes.stream().map(DeviceLineRespVO::getId).collect(Collectors.toList());
Map<Long, String> qrcodeUrlMap = qrcodeService.selectQrcodeUrlMapByBizTypeAndIds(
QrcodeBizTypeEnum.DEVICE_LINE.getCode(),
ids);
for (DeviceLineTreeRespVO deviceLineRespVO : allNodes) {
deviceLineRespVO.setQrcodeUrl(qrcodeUrlMap.get(deviceLineRespVO.getId()));
deviceLineRespVO.setTemplateJson(template);
}
}
return success(tree);
}
@GetMapping("/children")
@Operation(summary = "获得子设备产线列表")
@Parameter(name = "parentId", description = "父级ID", required = true, example = "0")
@PreAuthorize("@ss.hasPermission('mes:device-line:query')")
public CommonResult<List<DeviceLineRespVO>> getChildrenDeviceLines(@RequestParam("parentId") Long parentId) {
List<DeviceLineDO> list = deviceLineService.getChildrenDeviceLines(parentId);
return success(BeanUtils.toBean(list, DeviceLineRespVO.class));
}
@GetMapping("/ancestors")
@Operation(summary = "获得祖先设备产线列表")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('mes:device-line:query')")
public CommonResult<List<DeviceLineRespVO>> getAncestorDeviceLines(@RequestParam("id") Long id) {
List<DeviceLineDO> list = deviceLineService.getAncestorDeviceLines(id);
return success(BeanUtils.toBean(list, DeviceLineRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出设备产线 Excel")
@PreAuthorize("@ss.hasPermission('mes:device-line:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportDeviceLineExcel(@Valid DeviceLineListReqVO pageReqVO,
HttpServletResponse response) throws IOException {
List<DeviceLineDO> deviceLineList = deviceLineService.getDeviceLineList(pageReqVO);
List<DeviceLineRespVO> deviceLineRespVOList = BeanUtils.toBean(deviceLineList, DeviceLineRespVO.class);
Map<Long, String> idToNameMap = deviceLineList.stream()
.collect(Collectors.toMap(
DeviceLineDO::getId,
DeviceLineDO::getName,
(v1, v2) -> v1
));
for (DeviceLineRespVO deviceLineRespVO : deviceLineRespVOList) {
if (deviceLineRespVO.getParentId() != null && deviceLineRespVO.getParentId() > 0) {
deviceLineRespVO.setParentName(idToNameMap.getOrDefault(deviceLineRespVO.getParentId(), ""));
} else {
deviceLineRespVO.setParentName("顶级分类");
}
}
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
response.setHeader("Content-Disposition",
"attachment;filename=" + URLEncoder.encode("设备产线.xls", "UTF-8"));
response.setHeader("Content-Encoding", "identity");
String fileName = String.format("设备产线_%s.xls", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")));
ExcelUtils.write(response, fileName, "数据", DeviceLineRespVO.class, deviceLineRespVOList);
}
@PostMapping("/regenerate-code")
public CommonResult<Boolean> regenerateCode(@RequestParam("id") Long id,
@RequestParam("code") String code) throws UnsupportedEncodingException {
deviceLineService.regenerateCode(id, code);
return success(true);
}
}

@ -0,0 +1,32 @@
package cn.iocoder.yudao.module.mes.controller.admin.deviceline.vo;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Schema(description = "管理后台 - 设备产线列表 Request VO")
public class DeviceLineListReqVO extends PageParam {
@Schema(description = "父级ID")
private Long parentId;
@Schema(description = "父级链")
private String parentChain;
@Schema(description = "编码")
private String code;
@Schema(description = "名称")
private String name;
@Schema(description = "开始创建时间")
private String createStartTime;
@Schema(description = "结束创建时间")
private String createEndTime;
}

@ -0,0 +1,40 @@
package cn.iocoder.yudao.module.mes.controller.admin.deviceline.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 设备产线分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class DeviceLinePageReqVO extends PageParam {
@Schema(description = "编码")
private String code;
@Schema(description = "名称", example = "李四")
private String name;
@Schema(description = "备注", example = "你猜")
private String remark;
@Schema(description = "排序")
private Integer sort;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
@Schema(description = "父id", example = "22428")
private Long parentId;
@Schema(description = "父级路径")
private String parentChain;
}

@ -0,0 +1,58 @@
package cn.iocoder.yudao.module.mes.controller.admin.deviceline.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
@Schema(description = "管理后台 - 设备产线 Response VO")
@Data
@ExcelIgnoreUnannotated
public class DeviceLineRespVO {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "13899")
@ExcelProperty("id")
private Long id;
@Schema(description = "编码", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("编码")
private String code;
@Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
@ExcelProperty("名称")
private String name;
@Schema(description = "备注", example = "你猜")
@ExcelProperty("备注")
private String remark;
@Schema(description = "排序")
@ExcelProperty("排序")
private Integer sort;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
@Schema(description = "父id", requiredMode = Schema.RequiredMode.REQUIRED, example = "22428")
@ExcelProperty("父id")
private Long parentId;
@Schema(description = "父级名称", example = "顶级分类")
@ExcelProperty("父级名称")
private String parentName;
@Schema(description = "父级路径", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("父级路径")
private String parentChain;
@Schema(description = "二维码")
private String qrcodeUrl;
@Schema(description = "打印模板")
private String templateJson;
}

@ -0,0 +1,45 @@
package cn.iocoder.yudao.module.mes.controller.admin.deviceline.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.*;
@Schema(description = "管理后台 - 设备产线新增/修改 Request VO")
@Data
public class DeviceLineSaveReqVO {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "13899")
private Long id;
@Schema(description = "编码", requiredMode = Schema.RequiredMode.REQUIRED)
// @NotEmpty(message = "编码不能为空")
private String code;
@Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
@NotEmpty(message = "名称不能为空")
private String name;
@Schema(description = "备注", example = "你猜")
private String remark;
@Schema(description = "排序")
private Integer sort;
@Schema(description = "父id", requiredMode = Schema.RequiredMode.REQUIRED, example = "22428")
@NotNull(message = "父id不能为空")
private Long parentId;
@Schema(description = "父级路径", requiredMode = Schema.RequiredMode.REQUIRED)
// @NotEmpty(message = "父级路径不能为空")
private String parentChain;
@Schema(description = "二维码")
private String qrcodeUrl;
@Schema(description = "条形码")
private String barcodeUrl;
}

@ -0,0 +1,19 @@
package cn.iocoder.yudao.module.mes.controller.admin.deviceline.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
@Data
@EqualsAndHashCode(callSuper = true)
@Schema(description = "管理后台 - 设备产线树形结构 Response VO")
public class DeviceLineTreeRespVO extends DeviceLineRespVO {
@Schema(description = "子设备产线列表")
private List<DeviceLineTreeRespVO> children;
@Schema(description = "是否叶子节点", example = "true")
private Boolean leaf = true;
}

@ -66,6 +66,10 @@ public class DeviceLedgerDO extends BaseDO {
*
*/
private Long deviceType;
/**
* 线
*/
private Integer deviceLine;
/**
*
*/
@ -207,4 +211,4 @@ public class DeviceLedgerDO extends BaseDO {
}
}

@ -0,0 +1,61 @@
package cn.iocoder.yudao.module.mes.dal.dataobject.deviceline;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* 线 DO
*
* @author
*/
@TableName("mes_device_line")
@KeySequence("mes_device_line_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DeviceLineDO extends BaseDO {
/**
* id
*/
@TableId
private Long id;
/**
*
*/
private String code;
/**
*
*/
private String name;
/**
*
*/
private String remark;
/**
*
*/
private Integer sort;
/**
* id
*/
private Long parentId;
/**
*
*/
private String parentChain;
@TableField(exist = false)
private String qrcodeUrl;
@TableField(exist = false)
private String barcodeUrl;
}

@ -43,6 +43,12 @@ public interface DeviceLedgerMapper extends BaseMapperX<DeviceLedgerDO> {
.betweenIfPresent(DeviceLedgerDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(DeviceLedgerDO::getCreateTime);
if (reqVO.getDeviceLineIds() != null && !reqVO.getDeviceLineIds().isEmpty()) {
deviceLedgerDOLambdaQueryWrapperX.in(DeviceLedgerDO::getDeviceLine, reqVO.getDeviceLineIds());
} else {
deviceLedgerDOLambdaQueryWrapperX.eqIfPresent(DeviceLedgerDO::getDeviceLine, reqVO.getDeviceLine());
}
// 单独处理 ids 条件
if (StringUtils.isNotBlank(reqVO.getIds())) {
List<Long> idList = Arrays.stream(reqVO.getIds().split(","))
@ -60,4 +66,4 @@ public interface DeviceLedgerMapper extends BaseMapperX<DeviceLedgerDO> {
DeviceLedgerDO selectByIdWithDeleted(@Param("id") Long id);
String selectPrintTemplate();
}
}

@ -0,0 +1,45 @@
package cn.iocoder.yudao.module.mes.dal.mysql.deviceline;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.mes.dal.dataobject.deviceline.DeviceLineDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.mes.controller.admin.deviceline.vo.*;
/**
* 线 Mapper
*
* @author
*/
@Mapper
public interface DeviceLineMapper extends BaseMapperX<DeviceLineDO> {
default PageResult<DeviceLineDO> selectPage(DeviceLinePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<DeviceLineDO>()
.eqIfPresent(DeviceLineDO::getParentId, reqVO.getParentId())
.likeIfPresent(DeviceLineDO::getParentChain, reqVO.getParentChain())
.eqIfPresent(DeviceLineDO::getCode, reqVO.getCode())
.likeIfPresent(DeviceLineDO::getName, reqVO.getName())
.eqIfPresent(DeviceLineDO::getRemark, reqVO.getRemark())
.eqIfPresent(DeviceLineDO::getSort, reqVO.getSort())
.betweenIfPresent(DeviceLineDO::getCreateTime, reqVO.getCreateTime())
.orderByAsc(DeviceLineDO::getSort)
.orderByDesc(DeviceLineDO::getId));
}
default List<DeviceLineDO> selectList(DeviceLineListReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<DeviceLineDO>()
.eqIfPresent(DeviceLineDO::getParentId, reqVO.getParentId())
.likeIfPresent(DeviceLineDO::getParentChain, reqVO.getParentChain())
.likeIfPresent(DeviceLineDO::getCode, reqVO.getCode())
.likeIfPresent(DeviceLineDO::getName, reqVO.getName())
.betweenIfPresent(DeviceLineDO::getCreateTime, reqVO.getCreateStartTime(), reqVO.getCreateEndTime())
.orderByAsc(DeviceLineDO::getSort)
.orderByDesc(DeviceLineDO::getId));
}
String selectPrintTemplate();
}

@ -15,6 +15,7 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceDO;
import cn.iocoder.yudao.module.iot.service.device.DeviceService;
import cn.iocoder.yudao.module.iot.service.device.TDengineService;
import cn.iocoder.yudao.module.mes.dal.dataobject.devicetype.DeviceTypeDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.deviceline.DeviceLineDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.organization.OrganizationDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.plan.PlanDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
@ -33,6 +34,7 @@ import cn.iocoder.yudao.module.mes.dal.mysql.dvrepair.DvRepairMapper;
import cn.iocoder.yudao.module.mes.dal.mysql.ticketresults.TicketResultsMapper;
import cn.iocoder.yudao.module.mes.dal.mysql.workreportplan.ReportPlanSummaryMapper;
import cn.iocoder.yudao.module.mes.service.organization.OrganizationService;
import cn.iocoder.yudao.module.mes.service.deviceline.DeviceLineService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@ -121,6 +123,10 @@ public class DeviceLedgerServiceImpl implements DeviceLedgerService {
@Lazy
private OrganizationMapper organizationMapper;
@Resource
@Lazy
private DeviceLineService deviceLineService;
@Resource
private ErpProductUnitService productUnitService;
@ -346,6 +352,15 @@ public class DeviceLedgerServiceImpl implements DeviceLedgerService {
@Override
public PageResult<DeviceLedgerDO> getDeviceLedgerPage(DeviceLedgerPageReqVO pageReqVO) {
if (pageReqVO.getDeviceLine() != null) {
Set<Integer> deviceLineIds = new LinkedHashSet<>();
collectDeviceLineIds(Long.valueOf(pageReqVO.getDeviceLine()), deviceLineIds);
if (deviceLineIds.isEmpty()) {
return new PageResult<>(Collections.emptyList(), 0L);
}
pageReqVO.setDeviceLineIds(new ArrayList<>(deviceLineIds));
}
if(pageReqVO.getProductId() != null ){
List<ProductDeviceRelDO> relList = productDeviceRelMapper.selectList(
Wrappers.<ProductDeviceRelDO>lambdaQuery()
@ -372,6 +387,24 @@ public class DeviceLedgerServiceImpl implements DeviceLedgerService {
return deviceLedgerDOPageResult;
}
private void collectDeviceLineIds(Long deviceLineId, Set<Integer> results) {
if (deviceLineId == null) {
return;
}
DeviceLineDO deviceLine = deviceLineService.getDeviceLine(deviceLineId);
if (deviceLine == null) {
return;
}
results.add(deviceLineId.intValue());
List<DeviceLineDO> children = deviceLineService.getChildrenDeviceLines(deviceLineId);
if (CollUtil.isEmpty(children)) {
return;
}
for (DeviceLineDO child : children) {
collectDeviceLineIds(child.getId(), results);
}
}
@Override
public PageResult<DeviceCapacityReportRespVO> getDeviceCapacityReportPage(DeviceCapacityReportPageReqVO pageReqVO) {
DeviceLedgerPageReqVO queryReqVO = buildDeviceCapacityQuery(pageReqVO);

@ -0,0 +1,41 @@
package cn.iocoder.yudao.module.mes.service.deviceline;
import java.io.UnsupportedEncodingException;
import java.util.*;
import cn.iocoder.yudao.module.mes.controller.admin.deviceline.vo.*;
import cn.iocoder.yudao.module.mes.dal.dataobject.deviceline.DeviceLineDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import javax.validation.Valid;
/**
* 线 Service
*
* @author
*/
public interface DeviceLineService {
Long createDeviceLine(@Valid DeviceLineSaveReqVO createReqVO) throws UnsupportedEncodingException;
void updateDeviceLine(@Valid DeviceLineSaveReqVO updateReqVO);
void deleteDeviceLine(Long id);
void deleteDeviceLineBatch(List<Long> ids);
DeviceLineDO getDeviceLine(Long id);
PageResult<DeviceLineDO> getDeviceLinePage(DeviceLinePageReqVO pageReqVO);
List<DeviceLineDO> getDeviceLineList(DeviceLineListReqVO listReqVO);
List<DeviceLineTreeRespVO> getDeviceLineTree(DeviceLineListReqVO listReqVO);
List<DeviceLineDO> getChildrenDeviceLines(Long parentId);
List<DeviceLineDO> getAncestorDeviceLines(Long id);
void regenerateCode(Long id, String code) throws UnsupportedEncodingException;
String selectPrintTemplate();
}

@ -0,0 +1,341 @@
package cn.iocoder.yudao.module.mes.service.deviceline;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.common.enums.CodeTypeEnum;
import cn.iocoder.yudao.module.common.enums.QrcodeBizTypeEnum;
import cn.iocoder.yudao.module.common.service.qrcordrecord.QrcodeRecordService;
import cn.iocoder.yudao.module.erp.controller.admin.autocode.util.AutoCodeUtil;
import cn.iocoder.yudao.module.mes.dal.dataobject.deviceledger.DeviceLedgerDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.io.UnsupportedEncodingException;
import java.util.*;
import java.util.stream.Collectors;
import cn.iocoder.yudao.module.mes.controller.admin.deviceline.vo.*;
import cn.iocoder.yudao.module.mes.dal.dataobject.deviceline.DeviceLineDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.mes.dal.mysql.deviceline.DeviceLineMapper;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
/**
* 线 Service
*
* @author
*/
@Service
@Validated
@Slf4j
public class DeviceLineServiceImpl implements DeviceLineService {
@Resource
private DeviceLineMapper deviceLineMapper;
@Autowired
private AutoCodeUtil autoCodeUtil;
@Resource
private QrcodeRecordService qrcodeService;
@Override
public Long createDeviceLine(DeviceLineSaveReqVO createReqVO) throws UnsupportedEncodingException {
validateParentDeviceLine(createReqVO.getParentId());
if (StringUtils.isBlank(createReqVO.getCode())) {
createReqVO.setCode(autoCodeUtil.genSerialCode("DEVICE_LINE_GENERATE", null));
}
validateCodeOnly(createReqVO.getCode());
DeviceLineDO deviceLine = BeanUtils.toBean(createReqVO, DeviceLineDO.class);
if (createReqVO.getParentId() != null && createReqVO.getParentId() > 0) {
DeviceLineDO parent = getDeviceLine(createReqVO.getParentId());
deviceLine.setParentChain(buildParentChain(parent));
} else {
deviceLine.setParentChain("");
}
deviceLineMapper.insert(deviceLine);
updateChildrenParentChain(deviceLine);
// 生成二维码
CodeTypeEnum codeType = autoCodeUtil.queryCodeType("DEVICE_LINE_GENERATE");
if (codeType==null){
log.warn("[创建设备台账]未配置码类型跳过生产ruleCode={}","DEVICE_LINE_GENERATE");
return deviceLine.getId();
}
qrcodeService.generateOrRefresh(
QrcodeBizTypeEnum.DEVICE_LINE,
deviceLine.getId(),
deviceLine.getCode(),
"DETAIL",
codeType
);
return deviceLine.getId();
}
private void validateCodeOnly(String code) {
if (StringUtils.isBlank(code)) {
return;
}
if (deviceLineMapper.exists(Wrappers.<DeviceLineDO>lambdaQuery()
.eq(DeviceLineDO::getCode, code))) {
throw exception(DEVICE_LINE_CODE_EXISTS);
}
}
@Override
public void updateDeviceLine(DeviceLineSaveReqVO updateReqVO) {
DeviceLineDO deviceLineDO = deviceLineMapper.selectById(updateReqVO.getId());
validateDeviceLineExists(deviceLineDO);
Long count = deviceLineMapper.selectCount(new LambdaQueryWrapper<DeviceLineDO>()
.eq(DeviceLineDO::getCode, updateReqVO.getCode())
.ne(DeviceLineDO::getId, updateReqVO.getId()));
if (count > 0) {
throw exception(DEVICE_LINE_CODE_EXISTS);
}
validateParentDeviceLine(updateReqVO.getParentId());
if (updateReqVO.getParentId() != null) {
validateNotChildOfSelf(updateReqVO.getId(), updateReqVO.getParentId());
}
DeviceLineDO oldDeviceLine = getDeviceLine(updateReqVO.getId());
DeviceLineDO updateObj = BeanUtils.toBean(updateReqVO, DeviceLineDO.class);
if (!Objects.equals(oldDeviceLine.getParentId(), updateReqVO.getParentId())) {
if (updateReqVO.getParentId() != null && updateReqVO.getParentId() > 0) {
DeviceLineDO parent = getDeviceLine(updateReqVO.getParentId());
updateObj.setParentChain(buildParentChain(parent));
} else {
updateObj.setParentChain("");
}
updateChildrenParentChain(updateObj);
}
deviceLineMapper.updateById(updateObj);
}
@Override
public void deleteDeviceLine(Long id) {
DeviceLineDO deviceLine = deviceLineMapper.selectById(id);
validateDeviceLineExists(deviceLine);
if (hasChildren(id)) {
throw exception(DEVICE_LINE_EXITS_CHILDREN);
}
deviceLineMapper.deleteById(id);
}
@Override
public void deleteDeviceLineBatch(List<Long> ids) {
if (ids == null || ids.isEmpty()) {
return;
}
deviceLineMapper.deleteByIds(ids);
}
private void validateDeviceLineExists(DeviceLineDO deviceLine) {
if (deviceLine == null) {
throw exception(DEVICE_LINE_NOT_EXISTS);
}
}
@Override
public DeviceLineDO getDeviceLine(Long id) {
return deviceLineMapper.selectById(id);
}
@Override
public PageResult<DeviceLineDO> getDeviceLinePage(DeviceLinePageReqVO pageReqVO) {
return deviceLineMapper.selectPage(pageReqVO);
}
@Override
public List<DeviceLineDO> getDeviceLineList(DeviceLineListReqVO listReqVO) {
return deviceLineMapper.selectList(listReqVO);
}
@Override
public List<DeviceLineTreeRespVO> getDeviceLineTree(DeviceLineListReqVO listReqVO) {
List<DeviceLineDO> allDeviceLines = deviceLineMapper.selectList(listReqVO);
return buildDeviceLineTree(allDeviceLines);
}
@Override
public List<DeviceLineDO> getChildrenDeviceLines(Long parentId) {
List<DeviceLineDO> allDeviceLines = deviceLineMapper.selectList(Wrappers.<DeviceLineDO>lambdaQuery()
.eq(DeviceLineDO::getParentId, parentId));
if (allDeviceLines == null || allDeviceLines.isEmpty()) {
return Collections.emptyList();
}
return allDeviceLines.stream()
.sorted(Comparator.comparing(DeviceLineDO::getSort,
Comparator.nullsLast(Integer::compareTo)).thenComparing(DeviceLineDO::getId))
.collect(Collectors.toList());
}
@Override
public List<DeviceLineDO> getAncestorDeviceLines(Long id) {
DeviceLineDO current = deviceLineMapper.selectById(id);
if (current == null) {
return Collections.emptyList();
}
List<DeviceLineDO> ancestors = new ArrayList<>();
Long parentId = current.getParentId();
while (parentId != null && parentId > 0) {
DeviceLineDO parent = deviceLineMapper.selectById(parentId);
if (parent == null) {
break;
}
ancestors.add(parent);
parentId = parent.getParentId();
}
Collections.reverse(ancestors);
return ancestors;
}
private List<DeviceLineTreeRespVO> buildDeviceLineTree(List<DeviceLineDO> allDeviceLines) {
Map<Long, List<DeviceLineDO>> childrenMap = CollectionUtils.convertMultiMap(
allDeviceLines, DeviceLineDO::getParentId);
Map<Long, String> parentNameMap = allDeviceLines.stream()
.collect(Collectors.toMap(
DeviceLineDO::getId,
DeviceLineDO::getName,
(v1, v2) -> v1
));
List<DeviceLineDO> rootDeviceLines = new ArrayList<>(childrenMap.getOrDefault(0L, Collections.emptyList()));
rootDeviceLines.addAll(childrenMap.getOrDefault(null, Collections.emptyList()));
rootDeviceLines.sort(Comparator.comparing(DeviceLineDO::getSort,
Comparator.nullsLast(Integer::compareTo)).thenComparing(DeviceLineDO::getId));
return rootDeviceLines.stream()
.map(deviceLine -> convertToTree(deviceLine, childrenMap, parentNameMap))
.collect(Collectors.toList());
}
private DeviceLineTreeRespVO convertToTree(DeviceLineDO deviceLine,
Map<Long, List<DeviceLineDO>> childrenMap,
Map<Long, String> parentNameMap) {
DeviceLineTreeRespVO treeNode = BeanUtils.toBean(deviceLine, DeviceLineTreeRespVO.class);
if (deviceLine.getParentId() != null && deviceLine.getParentId() > 0) {
treeNode.setParentName(parentNameMap.getOrDefault(deviceLine.getParentId(), ""));
} else {
treeNode.setParentName("顶级分类");
}
List<DeviceLineDO> children = childrenMap.getOrDefault(deviceLine.getId(), Collections.emptyList());
if (!children.isEmpty()) {
children.sort(Comparator.comparing(DeviceLineDO::getSort,
Comparator.nullsLast(Integer::compareTo)).thenComparing(DeviceLineDO::getId));
List<DeviceLineTreeRespVO> childNodes = children.stream()
.map(child -> convertToTree(child, childrenMap, parentNameMap))
.collect(Collectors.toList());
treeNode.setChildren(childNodes);
treeNode.setLeaf(false);
}
return treeNode;
}
private void validateParentDeviceLine(Long parentId) {
if (parentId != null && parentId > 0) {
if (deviceLineMapper.selectById(parentId) == null) {
throw exception(DEVICE_LINE_PARENT_NOT_EXISTS);
}
}
}
private void validateNotChildOfSelf(Long id, Long parentId) {
if (id.equals(parentId)) {
throw exception(DEVICE_LINE_PARENT_IS_SELF);
}
DeviceLineDO parent = getDeviceLine(parentId);
if (parent != null && parent.getParentChain() != null) {
String parentChain = parent.getParentChain();
if (parentChain.contains("," + id + ",")
|| parentChain.startsWith(id + ",")
|| parentChain.endsWith("," + id)) {
throw exception(DEVICE_LINE_PARENT_IS_CHILD);
}
}
}
private boolean hasChildren(Long id) {
LambdaQueryWrapper<DeviceLineDO> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(DeviceLineDO::getParentId, id);
return deviceLineMapper.selectCount(queryWrapper) > 0;
}
private String buildParentChain(DeviceLineDO parent) {
if (parent == null) {
return "";
}
StringBuilder chain = new StringBuilder();
if (parent.getParentChain() != null && !parent.getParentChain().isEmpty()) {
chain.append(parent.getParentChain()).append(",");
}
chain.append(parent.getId());
return chain.toString();
}
private void updateChildrenParentChain(DeviceLineDO deviceLine) {
List<DeviceLineDO> children = getChildrenDeviceLines(deviceLine.getId());
for (DeviceLineDO child : children) {
String newParentChain = buildParentChain(deviceLine);
child.setParentChain(newParentChain);
deviceLineMapper.updateById(child);
updateChildrenParentChain(child);
}
}
@Override
public void regenerateCode(Long id, String code) throws UnsupportedEncodingException {
if(deviceLineMapper.selectById(id)==null){
throw exception(DEVICE_LINE_NOT_EXISTS);
}
if(StringUtils.isBlank(code)){
throw exception(DEVICE_LINE_CODE_NOT_EXISTS);
}
CodeTypeEnum codeGenerate = autoCodeUtil.queryCodeType("DEVICE_LINE_GENERATE");
qrcodeService.regenerateByCodeType(
QrcodeBizTypeEnum.DEVICE_LINE,
id,
code,
"DETAIL",
codeGenerate.getCode()
);
}
@Override
public String selectPrintTemplate() {
return deviceLineMapper.selectPrintTemplate();
}
}

@ -0,0 +1,20 @@
<?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="cn.iocoder.yudao.module.mes.dal.mysql.deviceline.DeviceLineMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
<select id="selectPrintTemplate" resultType="java.lang.String">
select template_json
from mes_print_template
where deleted = 0
and template_type = 6
and template_biz_type = 1
</select>
</mapper>

@ -96,6 +96,9 @@ public class AuthPermissionInfoRespVO {
*/
private List<MenuVO> children;
@Schema(description = "终端类型菜单设置为app时 1-移动端 2-扫码器")
private Integer terminalType;
}
}

@ -76,4 +76,6 @@ public class MenuRespVO {
@Schema(description = "菜单端类型,参见 MenuClientTypeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer clientType;
@Schema(description = "终端类型菜单设置为app时 1-移动端 2-扫码器", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer terminalType;
}

@ -71,4 +71,7 @@ public class MenuSaveVO {
@NotNull(message = "菜单端类型不能为空")
private Integer clientType = MenuClientTypeEnum.WEB.getType();
@Schema(description = "终端类型菜单设置为app时 1-移动端 2-扫码器", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer terminalType;
}

@ -29,4 +29,6 @@ public class MenuSimpleRespVO {
@Schema(description = "菜单端类型,参见 MenuClientTypeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer clientType;
@Schema(description = "终端类型菜单设置为app时 1-移动端 2-扫码器", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer terminalType;
}

@ -53,6 +53,7 @@ public interface AuthConvert {
.alwaysShow(menu.getAlwaysShow())
.enName(menu.getEnName())
.type(menu.getType())
.terminalType(menu.getTerminalType())
.build();
}

@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.system.enums.permission.MenuTypeEnum;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -116,5 +117,9 @@ public class MenuDO extends BaseDO {
*/
private Integer clientType;
/**
* app1- 2-
*/
private Integer terminalType;
}

@ -15,11 +15,12 @@ public interface MenuMapper extends BaseMapperX<MenuDO> {
return selectOne(MenuDO::getParentId, parentId, MenuDO::getName, name);
}
default MenuDO selectByParentIdAndNameAndClientType(Long parentId, String name, Integer clientType) {
default MenuDO selectByParentIdAndNameAndClientType(Long parentId, String name, Integer clientType, Integer terminalType) {
return selectOne(new LambdaQueryWrapperX<MenuDO>()
.eq(MenuDO::getParentId, parentId)
.eq(MenuDO::getName, name)
.eq(MenuDO::getClientType, clientType));
.eq(MenuDO::getClientType, clientType)
.eq(MenuDO::getTerminalType,terminalType));
}
default Long selectCountByParentId(Long parentId) {

@ -55,7 +55,7 @@ public class MenuServiceImpl implements MenuService {
// 校验父菜单存在
validateParentMenu(createReqVO.getParentId(), createReqVO.getClientType(), null);
// 校验菜单(自己)
validateMenu(createReqVO.getParentId(), createReqVO.getName(), createReqVO.getClientType(), null);
validateMenu(createReqVO.getParentId(), createReqVO.getName(), createReqVO.getClientType(), null,createReqVO.getTerminalType());
// 插入数据库
MenuDO menu = BeanUtils.toBean(createReqVO, MenuDO.class);
@ -77,7 +77,7 @@ public class MenuServiceImpl implements MenuService {
// 校验父菜单存在
validateParentMenu(updateReqVO.getParentId(), updateReqVO.getClientType(), updateReqVO.getId());
// 校验菜单(自己)
validateMenu(updateReqVO.getParentId(), updateReqVO.getName(), updateReqVO.getClientType(), updateReqVO.getId());
validateMenu(updateReqVO.getParentId(), updateReqVO.getName(), updateReqVO.getClientType(), updateReqVO.getId(),updateReqVO.getTerminalType());
// 更新到数据库
MenuDO updateObj = BeanUtils.toBean(updateReqVO, MenuDO.class);
@ -238,8 +238,8 @@ public class MenuServiceImpl implements MenuService {
* @param id
*/
@VisibleForTesting
void validateMenu(Long parentId, String name, Integer clientType, Long id) {
MenuDO menu = menuMapper.selectByParentIdAndNameAndClientType(parentId, name, clientType);
void validateMenu(Long parentId, String name, Integer clientType, Long id,Integer terminalType) {
MenuDO menu = menuMapper.selectByParentIdAndNameAndClientType(parentId, name, clientType,terminalType);
if (menu == null) {
return;
}

@ -244,20 +244,20 @@ public class MenuServiceImplTest extends BaseDbUnitTest {
Long parentId = menuDO.getId();
// 调用,无需断言
menuService.validateParentMenu(parentId, null);
menuService.validateParentMenu(parentId, null,null);
}
@Test
public void testValidateParentMenu_canNotSetSelfToBeParent() {
// 调用,并断言异常
assertServiceException(() -> menuService.validateParentMenu(1L, 1L),
assertServiceException(() -> menuService.validateParentMenu(1L, null,1L),
MENU_PARENT_ERROR);
}
@Test
public void testValidateParentMenu_parentNotExist() {
// 调用,并断言异常
assertServiceException(() -> menuService.validateParentMenu(randomLongId(), null),
assertServiceException(() -> menuService.validateParentMenu(randomLongId(), null,null),
MENU_PARENT_NOT_EXISTS);
}
@ -270,7 +270,7 @@ public class MenuServiceImplTest extends BaseDbUnitTest {
Long parentId = menuDO.getId();
// 调用,并断言异常
assertServiceException(() -> menuService.validateParentMenu(parentId, null),
assertServiceException(() -> menuService.validateParentMenu(parentId, null,null),
MENU_PARENT_NOT_DIR_OR_MENU);
}
@ -284,7 +284,7 @@ public class MenuServiceImplTest extends BaseDbUnitTest {
String otherSonMenuName = randomString();
// 调用,无需断言
menuService.validateMenu(parentId, otherSonMenuName, otherSonMenuId);
menuService.validateMenu(parentId, otherSonMenuName, null,otherSonMenuId,null);
}
@Test
@ -297,7 +297,7 @@ public class MenuServiceImplTest extends BaseDbUnitTest {
String otherSonMenuName = sonMenu.getName(); //相同名称
// 调用,并断言异常
assertServiceException(() -> menuService.validateMenu(parentId, otherSonMenuName, otherSonMenuId),
assertServiceException(() -> menuService.validateMenu(parentId, otherSonMenuName,null, otherSonMenuId,null),
MENU_NAME_DUPLICATE);
}

Loading…
Cancel
Save