根据类型加载属性

This commit is contained in:
sxu 2024-12-10 18:34:52 +08:00
parent 0c4d7efde2
commit fda3089c7e
6 changed files with 35 additions and 18 deletions

View File

@ -3,6 +3,7 @@ package com.bonus.material.device.domain;
import com.bonus.common.biz.domain.BmFileInfo;
import com.bonus.common.core.annotation.Excel;
import com.bonus.common.core.web.domain.BaseEntity;
import com.bonus.material.device.domain.vo.DevInfoPropertyVo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ -255,4 +256,6 @@ public class DevInfo extends BaseEntity {
@ApiModelProperty(value = "是否上传安全证书0否 1")
private Integer isSafeBook;
@ApiModelProperty(value = "自定义属性列表")
private List<DevInfoPropertyVo> devInfoProperties;
}

View File

@ -6,10 +6,6 @@ import lombok.Data;
@Data
public class DevInfoPropertyVo {
/** 物资ID */
@ApiModelProperty(value = "物资ID")
private Long maId;
/** 属性名称 */
@ApiModelProperty(value = "属性名称")
private String propertyName;

View File

@ -151,7 +151,4 @@ public class DevInfoVo extends DevInfo {
@ApiModelProperty(value = "结束时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private String endTime;
@ApiModelProperty(value = "自定义属性列表")
private List<DevInfoPropertyVo> devInfoProperties;
}

View File

@ -128,10 +128,12 @@ public interface DevInfoMapper {
List<DevInfoVo> selectDevInfoLists(DevInfoVo devInfo);
List<DevInfoPropertyVo> selectDevInfoProperties();
List<DevInfoPropertyVo> selectDevInfoProperties(@Param("maId")Long maId);
int deleteDevInfoProperties(@Param("maId")Long maId);
int batchDeleteDevInfoProperties(@Param("maIds")Long[] maIds);
int insertDevInfoProperties(@Param("maId")Long maId, @Param("list") List<DevInfoPropertyVo> list);
/**

View File

@ -22,7 +22,6 @@ import com.bonus.material.device.domain.vo.LeaseVo;
import com.bonus.material.device.mapper.BmFileInfoMapper;
import com.bonus.material.device.mapper.DevInfoMapper;
import com.bonus.material.device.service.DevInfoService;
import com.bonus.material.ma.vo.MaTypeProperty;
import com.bonus.system.api.model.LoginUser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
@ -138,6 +137,9 @@ public class DevInfoServiceImpl implements DevInfoService {
if (!CollectionUtils.isEmpty(leaseList)) {
devInfoVo.setLeaseList(leaseList);
}
//查询自定义属性
List<DevInfoPropertyVo> properties = devInfoMapper.selectDevInfoProperties(maId);
devInfoVo.setDevInfoProperties(properties);
}
return devInfoVo;
}
@ -337,6 +339,10 @@ public class DevInfoServiceImpl implements DevInfoService {
if (saveSuccessNum == 0) {
return AjaxResult.error("设备信息SQL保存失败请修改后重试");
}
//保存自定义属性值
if (!CollectionUtils.isEmpty(devInfo.getDevInfoProperties())) {
devInfoMapper.insertDevInfoProperties(devInfo.getMaId(), devInfo.getDevInfoProperties());
}
//把文件保存到附件中
AjaxResult error = uploadFiles(devInfo, userId, i);
if (error != null) {
@ -370,6 +376,11 @@ public class DevInfoServiceImpl implements DevInfoService {
if (insertedDraft == 0) {
return AjaxResult.error("装备草稿保存失败,请修改后重试");
}
//保存自定义属性值
if (!CollectionUtils.isEmpty(devInfo.getDevInfoProperties())) {
devInfoMapper.insertDevInfoProperties(devInfo.getMaId(), devInfo.getDevInfoProperties());
}
//把文件保存到附件中
AjaxResult error = uploadFiles(devInfo, userId, i);
if (error != null) {
return error;
@ -453,6 +464,7 @@ public class DevInfoServiceImpl implements DevInfoService {
* @param devInfo 设备信息
*/
@Override
@Transactional(rollbackFor = Exception.class)
public AjaxResult updateDevInfo(DevInfo devInfo) {
if (devInfo.getMaId() == null) {
return AjaxResult.error("设备ID为空,请携带设备信息修改");
@ -461,6 +473,10 @@ public class DevInfoServiceImpl implements DevInfoService {
if (deviceId != null && !deviceId.getMaId().equals(devInfo.getMaId())) {
return AjaxResult.error("设备名称已存在,请修改后重试!");
}*/
devInfoMapper.deleteDevInfoProperties(devInfo.getMaId());
if (!CollectionUtils.isEmpty(devInfo.getDevInfoProperties())) {
devInfoMapper.insertDevInfoProperties(devInfo.getMaId(), devInfo.getDevInfoProperties());
}
return devInfoMapper.updateDevInfo(devInfo) > 0 ? AjaxResult.success("修改成功") : AjaxResult.error("修改失败");
}
@ -471,7 +487,9 @@ public class DevInfoServiceImpl implements DevInfoService {
* @return 结果
*/
@Override
@Transactional(rollbackFor = Exception.class)
public int deleteDevInfoByMaIds(Long[] maIds) {
devInfoMapper.batchDeleteDevInfoProperties(maIds);
return devInfoMapper.deleteDevInfoByMaIds(maIds);
}
@ -533,13 +551,7 @@ public class DevInfoServiceImpl implements DevInfoService {
@Override
public List<DevInfoVo> selectDevInfoLists(DevInfoVo devInfo) {
devInfo.setCompanyId(SecurityUtils.getLoginUser().getSysUser().getCompanyId().toString());
List<DevInfoVo> devInfoVos = devInfoMapper.selectDevInfoLists(devInfo);
List<DevInfoPropertyVo> devInfoProperties = devInfoMapper.selectDevInfoProperties();
Map<Long, List<DevInfoPropertyVo>> map = devInfoProperties.stream().collect(Collectors.groupingBy(DevInfoPropertyVo::getMaId));
for (DevInfoVo devInfos : devInfoVos) {
devInfos.setDevInfoProperties(map.get(devInfos.getMaId()));
}
return devInfoVos;
return devInfoMapper.selectDevInfoLists(devInfo);
}
/**

View File

@ -532,16 +532,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectDevInfoProperties" resultType="com.bonus.material.device.domain.vo.DevInfoPropertyVo">
select ma_id as maId,
property_name as propertyName,
select property_name as propertyName,
property_value as propertyValue
from ma_dev_info_properties
where ma_id = #{maId}
</select>
<delete id="deleteDevInfoProperties">
delete from ma_dev_info_properties where ma_id = #{maId}
</delete>
<delete id="batchDeleteDevInfoProperties">
delete from ma_dev_info_properties where ma_id in
<foreach item="maId" collection="maIds" open="(" separator="," close=")">
#{maId}
</foreach>
</delete>
<insert id="insertDevInfoProperties">
insert into
ma_dev_info_properties(ma_id, property_name, property_value, create_time)