change(device): 设备类型列表增加设备大类名称字段,新增祖先节点的插入逻辑

- 在 BaseDeviceType 模型中添加 deviceCategoryName 字段用于映射设备大类名称
- 在 BaseDeviceTypeBo 和 BaseDeviceTypeVo 中添加相应的字段和注解- 修改 BaseDeviceTypeServiceImpl 中的查询方法,增加设备大类名称的关联查询
- 优化设备类型插入逻辑,处理父节点为空的情况
master
zch 1 week ago
parent aeb72a2501
commit 477ebb304d

@ -24,6 +24,7 @@ public class BaseDeviceType extends TenantEntity {
/** /**
* ID * ID
*/ */
@TableId(value = "device_type_id", type = IdType.AUTO)
private Long deviceTypeId; private Long deviceTypeId;
/** /**
@ -61,5 +62,11 @@ public class BaseDeviceType extends TenantEntity {
*/ */
private String remark; private String remark;
/**
*
*/
@TableField(exist = false)
private String deviceCategoryName;//join映射字段
} }

@ -23,7 +23,7 @@ public class BaseDeviceTypeBo extends BaseEntity {
/** /**
* ID * ID
*/ */
@NotNull(message = "物料类型ID不能为空", groups = { AddGroup.class, EditGroup.class }) /* @NotNull(message = "物料类型ID不能为空", groups = { AddGroup.class, EditGroup.class })*/
private Long deviceTypeId; private Long deviceTypeId;
/** /**
@ -35,13 +35,13 @@ public class BaseDeviceTypeBo extends BaseEntity {
/** /**
* *
*/ */
@NotBlank(message = "设备类型编号不能为空", groups = { AddGroup.class, EditGroup.class }) /* @NotBlank(message = "设备类型编号不能为空", groups = { AddGroup.class, EditGroup.class })*/
private String deviceTypeCode; private String deviceTypeCode;
/** /**
* *
*/ */
@NotBlank(message = "设备类型名称不能为空", groups = { AddGroup.class, EditGroup.class }) /* @NotBlank(message = "设备类型名称不能为空", groups = { AddGroup.class, EditGroup.class })*/
private String deviceTypeName; private String deviceTypeName;
/** /**
@ -53,13 +53,13 @@ public class BaseDeviceTypeBo extends BaseEntity {
/** /**
* IDIDbase_categorycategory_type2 * IDIDbase_categorycategory_type2
*/ */
@NotNull(message = "设备大类不能为空", groups = { AddGroup.class, EditGroup.class }) /* @NotNull(message = "设备大类不能为空", groups = { AddGroup.class, EditGroup.class })*/
private Long deviceCategoryId; private Long deviceCategoryId;
/** /**
* 1 0 * 1 0
*/ */
@NotBlank(message = "激活标识不能为空", groups = { AddGroup.class, EditGroup.class }) /* @NotBlank(message = "激活标识不能为空", groups = { AddGroup.class, EditGroup.class })*/
private String activeFlag; private String activeFlag;
/** /**
@ -68,5 +68,9 @@ public class BaseDeviceTypeBo extends BaseEntity {
/* @NotBlank(message = "备注不能为空", groups = { AddGroup.class, EditGroup.class })*/ /* @NotBlank(message = "备注不能为空", groups = { AddGroup.class, EditGroup.class })*/
private String remark; private String remark;
/**
*
*/
private String deviceCategoryName;//join映射字段
} }

@ -78,5 +78,9 @@ public class BaseDeviceTypeVo implements Serializable {
@ExcelProperty(value = "备注") @ExcelProperty(value = "备注")
private String remark; private String remark;
/**
*
*/
@ExcelProperty(value = "设备大类名称")
private String deviceCategoryName;//join映射字段
} }

@ -1,5 +1,6 @@
package org.dromara.mes.service.impl; package org.dromara.mes.service.impl;
import org.apache.commons.lang3.ObjectUtils;
import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils; import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.common.mybatis.core.page.TableDataInfo;
@ -9,6 +10,8 @@ import com.github.yulichang.toolkit.JoinWrappers;
import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.dromara.mes.domain.BaseDeviceCategory;
import org.dromara.mes.domain.vo.BaseMaterialTypeVo;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.dromara.mes.domain.bo.BaseDeviceTypeBo; import org.dromara.mes.domain.bo.BaseDeviceTypeBo;
import org.dromara.mes.domain.vo.BaseDeviceTypeVo; import org.dromara.mes.domain.vo.BaseDeviceTypeVo;
@ -73,6 +76,11 @@ public class BaseDeviceTypeServiceImpl implements IBaseDeviceTypeService {
Map<String, Object> params = bo.getParams(); Map<String, Object> params = bo.getParams();
MPJLambdaWrapper<BaseDeviceType> lqw = JoinWrappers.lambda(BaseDeviceType.class) MPJLambdaWrapper<BaseDeviceType> lqw = JoinWrappers.lambda(BaseDeviceType.class)
.selectAll(BaseDeviceType.class) .selectAll(BaseDeviceType.class)
// 关联查询设备大类信息
.select(BaseDeviceCategory::getDeviceCategoryName)
.leftJoin(BaseDeviceCategory.class,BaseDeviceCategory::getDeviceCategoryId,BaseDeviceType::getDeviceCategoryId)
.eq(bo.getDeviceTypeId() != null, BaseDeviceType::getDeviceTypeId, bo.getDeviceTypeId()) .eq(bo.getDeviceTypeId() != null, BaseDeviceType::getDeviceTypeId, bo.getDeviceTypeId())
.eq(bo.getParentId() != null, BaseDeviceType::getParentId, bo.getParentId()) .eq(bo.getParentId() != null, BaseDeviceType::getParentId, bo.getParentId())
.eq(StringUtils.isNotBlank(bo.getDeviceTypeCode()), BaseDeviceType::getDeviceTypeCode, bo.getDeviceTypeCode()) .eq(StringUtils.isNotBlank(bo.getDeviceTypeCode()), BaseDeviceType::getDeviceTypeCode, bo.getDeviceTypeCode())
@ -94,6 +102,15 @@ public class BaseDeviceTypeServiceImpl implements IBaseDeviceTypeService {
public Boolean insertByBo(BaseDeviceTypeBo bo) { public Boolean insertByBo(BaseDeviceTypeBo bo) {
BaseDeviceType add = MapstructUtils.convert(bo, BaseDeviceType.class); BaseDeviceType add = MapstructUtils.convert(bo, BaseDeviceType.class);
validEntityBeforeSave(add); validEntityBeforeSave(add);
//获取父节点信息
BaseDeviceTypeVo query = baseMapper.selectVoById(bo.getParentId());
if (ObjectUtils.isNotEmpty(query)) {
//若父节点不为空则将父节点的ancestors拼接父节点id拼接成ancestors
add.setAncestors(query.getAncestors() + "," + bo.getParentId());
}else{
//若父节点为空则ancestors仅有父节点id
add.setAncestors(bo.getParentId().toString());
}
boolean flag = baseMapper.insert(add) > 0; boolean flag = baseMapper.insert(add) > 0;
if (flag) { if (flag) {
bo.setDeviceTypeId(add.getDeviceTypeId()); bo.setDeviceTypeId(add.getDeviceTypeId());

Loading…
Cancel
Save