润阳项目
新增相关字段和判断
This commit is contained in:
parent
befc5d29e5
commit
81b850522d
@ -129,13 +129,10 @@ public class EquipmentController {
|
||||
|
||||
}
|
||||
|
||||
/** 设备导出 */
|
||||
/** 设备导入 */
|
||||
@PostMapping("/import")
|
||||
public R<Void> importSysIotModel(String id, @RequestParam("file") MultipartFile file) throws IOException, ParseException {
|
||||
boolean result = sysEquipmentService.importSysEquipment(id, file);
|
||||
if (result) {
|
||||
return R.success("导出成功");
|
||||
}
|
||||
return R.success("导出失败");
|
||||
sysEquipmentService.importSysEquipment(id, file);
|
||||
return R.success("导入成功");
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import java.util.Date;
|
||||
@Data
|
||||
public class SysEquipmentExcel {
|
||||
|
||||
private String tag;
|
||||
/**
|
||||
* 设备类型编码
|
||||
*/
|
||||
@ -17,6 +18,8 @@ public class SysEquipmentExcel {
|
||||
*/
|
||||
private String iotModelName;
|
||||
|
||||
private String iotModelCode;
|
||||
|
||||
/**
|
||||
* 设备编码
|
||||
*/
|
||||
@ -72,4 +75,14 @@ public class SysEquipmentExcel {
|
||||
*/
|
||||
private String parentEquipmentName;
|
||||
|
||||
private String belongLine;
|
||||
|
||||
private Integer standard;
|
||||
|
||||
private Double nominalCapacity;
|
||||
|
||||
private String mrid;
|
||||
|
||||
private String parentEquipmentCode;
|
||||
|
||||
}
|
||||
|
@ -11,12 +11,14 @@ import lombok.Data;
|
||||
@Data
|
||||
public class SysIotModelFieldExcel {
|
||||
|
||||
private String tag;
|
||||
|
||||
/**
|
||||
* 所属物模型ID
|
||||
*/
|
||||
private String iotModelName;
|
||||
|
||||
private String iotModelCode;
|
||||
|
||||
/**
|
||||
* 物模型动作编码
|
||||
|
@ -13,6 +13,7 @@ import java.io.Serializable;
|
||||
@Data
|
||||
public class SysIotModelServiceExcel implements Serializable {
|
||||
|
||||
private String tag;
|
||||
|
||||
/**
|
||||
* 所属物模型ID
|
||||
@ -20,6 +21,8 @@ public class SysIotModelServiceExcel implements Serializable {
|
||||
// @Excel(name = "所属物模型名称", width = 20.0)
|
||||
private String iotModelName;
|
||||
|
||||
private String iotModelCode;
|
||||
|
||||
|
||||
/**
|
||||
* 物模型动作编码
|
||||
|
@ -16,5 +16,5 @@ public interface SysIotModelFieldMapper extends BaseMapperPlus<SysIotModelField,
|
||||
|
||||
Long querySysIotModelFieldByModelId(Long id);
|
||||
|
||||
SysIotModelFieldVo selectByAttributeCode(String code);
|
||||
SysIotModelFieldVo selectByAttributeCode(Long iotModelId, String code);
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ public interface SysIotModelMapper extends BaseMapper<SysIotModel> {
|
||||
|
||||
List<SysIotModelServiceExcel> queryServiceByModelId(Long id);
|
||||
|
||||
Long queryIotModelIdByName(String name);
|
||||
Long queryIotModelIdByName(String code);
|
||||
|
||||
List<SysIotModelVo> getSysIotModelByType(Integer objectType);
|
||||
|
||||
|
@ -16,6 +16,6 @@ public interface SysIotModelServiceMapper extends BaseMapperPlus<SysIotModelServ
|
||||
|
||||
Long querySysIotModelServiceByModelId (Long id);
|
||||
|
||||
SysIotModelServiceVo selectByServiceCode(String code);
|
||||
SysIotModelServiceVo selectByServiceCode(Long iotModelId, String code);
|
||||
|
||||
}
|
||||
|
@ -26,6 +26,6 @@ public interface SysEquipmentService {
|
||||
|
||||
void exportSysEquipment(SysEquipmentDto sysEquipmentDto, HttpServletRequest request, HttpServletResponse response);
|
||||
|
||||
boolean importSysEquipment(String parentEquipmentId,MultipartFile file) throws IOException, ParseException;
|
||||
void importSysEquipment(String parentEquipmentId,MultipartFile file) throws IOException, ParseException;
|
||||
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import com.das.modules.equipment.service.SysEquipmentService;
|
||||
import jakarta.servlet.ServletOutputStream;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
||||
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -144,6 +145,7 @@ public class SysEquipmentServiceImpl implements SysEquipmentService {
|
||||
map.put("tag", "标识");
|
||||
map.put("objectType", "设备类型编码(10001:风电场,10002:机组)");
|
||||
map.put("iotModelName", "所属物模型名称");
|
||||
map.put("iotModelCode", "所属物模型编码");
|
||||
map.put("code", "设备编码");
|
||||
map.put("name", "设备名称");
|
||||
map.put("madeinFactory", "制造商");
|
||||
@ -188,60 +190,87 @@ public class SysEquipmentServiceImpl implements SysEquipmentService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean importSysEquipment(String parentEquipmentId, MultipartFile file) throws IOException, ParseException {
|
||||
boolean flag = false;
|
||||
public void importSysEquipment(String parentEquipmentId, MultipartFile file) throws IOException, ParseException {
|
||||
// 通过文件获取输入流
|
||||
InputStream is = file.getInputStream();
|
||||
// 借助hutool读取
|
||||
ExcelReader reader = ExcelUtil.getReader(is);
|
||||
List<List<Object>> list = reader.read(1); // 从第二行开始读
|
||||
// 创建一个List集合
|
||||
List<SysEquipment> sysEquipmentList = new ArrayList<>();
|
||||
List<SysEquipment> addSysEquipmentList = new ArrayList<>();
|
||||
List<SysEquipment> updateSysEquipmentList = new ArrayList<>();
|
||||
List<SysEquipment> delSysEquipmentList = new ArrayList<>();
|
||||
// 遍历
|
||||
for (List<Object> row : list) {
|
||||
SysEquipment field = new SysEquipment();
|
||||
|
||||
// 根据名称获取物模型id
|
||||
if (StringUtils.hasText(row.get(1).toString())) {
|
||||
Long iotModelId = sysIotModelMapper.queryIotModelIdByName(row.get(1).toString());
|
||||
// 根据编码获取物模型id
|
||||
if (StringUtils.hasText(row.get(3).toString())) {
|
||||
Long iotModelId = sysIotModelMapper.queryIotModelIdByName(row.get(3).toString());
|
||||
field.setIotModelId(iotModelId);
|
||||
}
|
||||
if (StringUtils.hasText(row.get(11).toString())) {
|
||||
Long orgId = sysOrgMapper.queryOrgIdByName(row.get(11).toString());
|
||||
if (StringUtils.hasText(row.get(18).toString())) {
|
||||
Long orgId = sysOrgMapper.queryOrgIdByName(row.get(18).toString());
|
||||
field.setOrgId(orgId);
|
||||
}
|
||||
// 转换成字符串
|
||||
field.setObjectType(Integer.valueOf(row.get(0).toString()));
|
||||
field.setCode(row.get(2).toString());
|
||||
field.setName(row.get(3).toString());
|
||||
field.setMadeinFactory(row.get(4).toString());
|
||||
field.setModel(row.get(5).toString());
|
||||
field.setLocation(row.get(6).toString());
|
||||
if (StringUtils.hasText(row.get(7).toString())) {
|
||||
field.setLongitude(Double.valueOf(row.get(7).toString()));
|
||||
field.setObjectType(Integer.valueOf(row.get(1).toString()));
|
||||
field.setCode(row.get(4).toString());
|
||||
field.setName(row.get(5).toString());
|
||||
field.setMadeinFactory(row.get(6).toString());
|
||||
field.setModel(row.get(7).toString());
|
||||
field.setLocation(row.get(8).toString());
|
||||
if (StringUtils.hasText(row.get(9).toString())) {
|
||||
field.setLongitude(Double.valueOf(row.get(9).toString()));
|
||||
}
|
||||
if (StringUtils.hasText(row.get(8).toString())) {
|
||||
field.setLatitude(Double.valueOf(row.get(8).toString()));
|
||||
if (StringUtils.hasText(row.get(10).toString())) {
|
||||
field.setLatitude(Double.valueOf(row.get(10).toString()));
|
||||
}
|
||||
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
if (StringUtils.hasText(row.get(9).toString())) {
|
||||
field.setInstallDate(sf.parse(row.get(9).toString()));
|
||||
if (StringUtils.hasText(row.get(11).toString())) {
|
||||
field.setInstallDate(sf.parse(row.get(11).toString()));
|
||||
}
|
||||
field.setRemarks(row.get(12).toString());
|
||||
field.setBelongLine(row.get(15).toString());
|
||||
field.setStandard(Integer.valueOf(row.get(16).toString()));
|
||||
if (StringUtils.hasText(row.get(17).toString())) {
|
||||
field.setNominalCapacity(Double.valueOf(row.get(17).toString()));
|
||||
}
|
||||
field.setRemarks(row.get(10).toString());
|
||||
field.setParentEquipmentId(Long.valueOf(parentEquipmentId));
|
||||
// 遍历完一个添加一个
|
||||
field.setRevision(1);
|
||||
field.setId(SequenceUtils.generateId());
|
||||
field.setCreatedTime(new Date());
|
||||
field.setUpdatedTime(new Date());
|
||||
field.setCreatedBy(StpUtil.getLoginIdAsString());
|
||||
field.setUpdatedBy(StpUtil.getLoginIdAsString());
|
||||
sysEquipmentList.add(field);
|
||||
}
|
||||
if(sysEquipmentMapper.insertBatch(sysEquipmentList)){
|
||||
flag = true;
|
||||
|
||||
SysEquipmentVo info = sysEquipmentMapper.queryEquipmentInfoByCode(field.getCode());
|
||||
if(info == null) {
|
||||
if ("I".equals(row.get(0))) {
|
||||
//加入集合
|
||||
// 遍历完一个添加一个
|
||||
field.setRevision(1);
|
||||
field.setId(SequenceUtils.generateId());
|
||||
field.setCreatedTime(new Date());
|
||||
field.setUpdatedTime(new Date());
|
||||
field.setCreatedBy(StpUtil.getLoginIdAsString());
|
||||
field.setUpdatedBy(StpUtil.getLoginIdAsString());
|
||||
addSysEquipmentList.add(field);
|
||||
}
|
||||
} else {
|
||||
field.setId(info.getId());
|
||||
field.setUpdatedTime(new Date());
|
||||
field.setUpdatedBy(StpUtil.getLoginIdAsString());
|
||||
if ("U".equals(row.get(0))) {
|
||||
//加入集合
|
||||
updateSysEquipmentList.add(field);
|
||||
} else if ("D".equals(row.get(0))) {
|
||||
delSysEquipmentList.add(field);
|
||||
}
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
sysEquipmentMapper.insertBatch(addSysEquipmentList);
|
||||
if (CollectionUtils.isNotEmpty(updateSysEquipmentList)) {
|
||||
sysEquipmentMapper.updateBatchById(updateSysEquipmentList);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(delSysEquipmentList)) {
|
||||
// 删除设备
|
||||
sysEquipmentMapper.deleteBatchIds(delSysEquipmentList);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import com.das.modules.equipment.service.SysIotModelService;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -82,10 +83,8 @@ public class SysIotModelServiceImpl implements SysIotModelService {
|
||||
SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY);
|
||||
|
||||
SysIotModelVo sysIotModelQuery = sysIotModelMapper.selectIotModelByCode(sysIotModelDto.getIotModelCode());
|
||||
if (!(sysIotModelQuery == null)) {
|
||||
if (sysIotModelQuery.getId() != sysIotModelDto.getId()){
|
||||
throw new ServiceException("物模型code已经存在");
|
||||
}
|
||||
if (!(Long.valueOf(sysIotModelQuery.getId()) == Long.valueOf(sysIotModelDto.getId())) && !(sysIotModelQuery == null)) {
|
||||
throw new ServiceException("物模型code已经存在");
|
||||
}
|
||||
sysIotModel.setUpdatedTime(new Date());
|
||||
sysIotModel.setUpdatedBy(sysUserVo.getAccount());
|
||||
@ -141,7 +140,7 @@ public class SysIotModelServiceImpl implements SysIotModelService {
|
||||
SysIotModelField sysIotModelField = new SysIotModelField();
|
||||
BeanCopyUtils.copy(sysIotModelFieldDto, sysIotModelField);
|
||||
|
||||
SysIotModelFieldVo sysIotModelFieldQuery = sysIotModelFieldMapper.selectByAttributeCode(sysIotModelFieldDto.getAttributeCode());
|
||||
SysIotModelFieldVo sysIotModelFieldQuery = sysIotModelFieldMapper.selectByAttributeCode(sysIotModelFieldDto.getIotModelId(), sysIotModelFieldDto.getAttributeCode());
|
||||
if (!(sysIotModelFieldQuery == null)) {
|
||||
throw new ServiceException("物模型属性code已经存在");
|
||||
}
|
||||
@ -175,7 +174,7 @@ public class SysIotModelServiceImpl implements SysIotModelService {
|
||||
if (sysIotModelFieldDto.getAttributeType() == 140) {
|
||||
sysIotModelField.setDataType("int4");
|
||||
}
|
||||
SysIotModelFieldVo sysIotModelFieldQuery = sysIotModelFieldMapper.selectByAttributeCode(sysIotModelFieldDto.getAttributeCode());
|
||||
SysIotModelFieldVo sysIotModelFieldQuery = sysIotModelFieldMapper.selectByAttributeCode(sysIotModelFieldDto.getIotModelId(), sysIotModelFieldDto.getAttributeCode());
|
||||
if (!(sysIotModelFieldQuery == null)) {
|
||||
if (sysIotModelFieldQuery.getId() != sysIotModelFieldDto.getId()){
|
||||
throw new ServiceException("物模型属性code已经存在");
|
||||
@ -207,7 +206,7 @@ public class SysIotModelServiceImpl implements SysIotModelService {
|
||||
SysIotModelServices sysIotModelServices = new SysIotModelServices();
|
||||
BeanCopyUtils.copy(sysIotModelServiceDto, sysIotModelServices);
|
||||
|
||||
SysIotModelServiceVo sysIotModelServiceQuery = sysIotModelServiceMapper.selectByServiceCode(sysIotModelServiceDto.getServiceCode());
|
||||
SysIotModelServiceVo sysIotModelServiceQuery = sysIotModelServiceMapper.selectByServiceCode(sysIotModelServiceDto.getIotModelId(), sysIotModelServiceDto.getServiceCode());
|
||||
if (!(sysIotModelServiceQuery == null)) {
|
||||
throw new ServiceException("物模型动作code已经存在");
|
||||
}
|
||||
@ -234,7 +233,7 @@ public class SysIotModelServiceImpl implements SysIotModelService {
|
||||
sysIotModelServices.setUpdatedBy(sysUserVo.getAccount());
|
||||
sysIotModelServices.setServiceCode(sysIotModelServiceDto.getServiceCode().toLowerCase());
|
||||
|
||||
SysIotModelServiceVo sysIotModelServiceQuery = sysIotModelServiceMapper.selectByServiceCode(sysIotModelServiceDto.getServiceCode());
|
||||
SysIotModelServiceVo sysIotModelServiceQuery = sysIotModelServiceMapper.selectByServiceCode(sysIotModelServiceDto.getIotModelId(), sysIotModelServiceDto.getServiceCode());
|
||||
if (!(sysIotModelServiceQuery == null)) {
|
||||
if(sysIotModelServiceQuery.getId() != sysIotModelServiceDto.getId()){
|
||||
throw new ServiceException("物模型动作code已经存在");
|
||||
@ -258,7 +257,9 @@ public class SysIotModelServiceImpl implements SysIotModelService {
|
||||
List<SysIotModelFieldExcel> sysIotModelFieldVoList = sysIotModelMapper.queryFieldByModelId(sysIotModelDto.getId());
|
||||
LinkedHashMap<String, String> map = new LinkedHashMap<>();
|
||||
SheetInfoBean sheetDTO = new SheetInfoBean();
|
||||
map.put("tag", "标识");
|
||||
map.put("iotModelName", "所属物模型名称");
|
||||
map.put("iotModelCode", "所属物模型编码");
|
||||
map.put("attributeCode", "物模型属性编码");
|
||||
map.put("attributeName", "物模型属性名称");
|
||||
map.put("attributeType", "属性类型(138:模拟量,139:累积量,140:离散量)");
|
||||
@ -275,7 +276,9 @@ public class SysIotModelServiceImpl implements SysIotModelService {
|
||||
List<SysIotModelServiceExcel> sysIotModelServiceVoList = sysIotModelMapper.queryServiceByModelId(sysIotModelDto.getId());
|
||||
LinkedHashMap<String, String> map1= new LinkedHashMap<>();
|
||||
SheetInfoBean sheetDTO1 = new SheetInfoBean();
|
||||
map1.put("tag", "标识");
|
||||
map1.put("iotModelName", "所属物模型名称");
|
||||
map1.put("iotModelCode", "所属物模型编码");
|
||||
map1.put("serviceCode", "物模型动作编码");
|
||||
map1.put("serviceName", "物模型动作名称");
|
||||
map1.put("serviceType", "动作类型(146:遥控,147:遥调)");
|
||||
@ -314,60 +317,103 @@ public class SysIotModelServiceImpl implements SysIotModelService {
|
||||
}
|
||||
private void saveIotModelServiceInfo(String iotModelId, List<List<Object>> list) {
|
||||
List<SysIotModelServices> sysIotModelServiceList = new ArrayList<>();
|
||||
List<SysIotModelServices> updateSysIotModelServiceList = new ArrayList<>();
|
||||
List<SysIotModelServices> delSysIotModelServiceList = new ArrayList<>();
|
||||
for (List<Object> row : list) {
|
||||
// 遍历sheet页中记录,构造需要导入的对象
|
||||
SysIotModelServices services = new SysIotModelServices();
|
||||
QueryWrapper<SysIotModelServices> sysIotModelServiceQueryWrapper = new QueryWrapper<>();
|
||||
sysIotModelServiceQueryWrapper.eq("service_code", row.get(1).toString().toLowerCase());
|
||||
SysIotModelServices sysIotModelServiceQuery = sysIotModelServiceMapper.selectOne(sysIotModelServiceQueryWrapper);
|
||||
services.setServiceCode(row.get(3).toString().toLowerCase());
|
||||
services.setServiceName(row.get(4).toString());
|
||||
services.setServiceType(Integer.valueOf(row.get(5).toString()));
|
||||
services.setPorder(Integer.valueOf(row.get(6).toString()));
|
||||
services.setIotModelId(Long.valueOf(iotModelId));
|
||||
|
||||
SysIotModelServiceVo sysIotModelServiceQuery = sysIotModelServiceMapper.selectByServiceCode(Long.valueOf(iotModelId), row.get(3).toString());
|
||||
if (sysIotModelServiceQuery == null) {
|
||||
services.setServiceCode(row.get(1).toString().toLowerCase());
|
||||
services.setServiceName(row.get(2).toString());
|
||||
services.setServiceType(Integer.valueOf(row.get(3).toString()));
|
||||
services.setPorder(Integer.valueOf(row.get(4).toString()));
|
||||
services.setIotModelId(Long.valueOf(iotModelId));
|
||||
services.setId(SequenceUtils.generateId());
|
||||
services.setCreatedTime(new Date());
|
||||
if ("I".equals(row.get(0))) {
|
||||
services.setCreatedTime(new Date());
|
||||
services.setUpdatedTime(new Date());
|
||||
services.setRevision(1);
|
||||
services.setCreatedBy(StpUtil.getLoginIdAsString());
|
||||
services.setUpdatedBy(StpUtil.getLoginIdAsString());
|
||||
//加入集合
|
||||
sysIotModelServiceList.add(services);
|
||||
}
|
||||
}else {
|
||||
services.setId(sysIotModelServiceQuery.getId());
|
||||
services.setUpdatedTime(new Date());
|
||||
services.setRevision(1);
|
||||
services.setCreatedBy(StpUtil.getLoginIdAsString());
|
||||
services.setUpdatedBy(StpUtil.getLoginIdAsString());
|
||||
sysIotModelServiceList.add(services);
|
||||
if ("U".equals(row.get(0))) {
|
||||
//加入集合
|
||||
updateSysIotModelServiceList.add(services);
|
||||
} else if ("D".equals(row.get(0))) {
|
||||
delSysIotModelServiceList.add(services);
|
||||
}
|
||||
}
|
||||
}
|
||||
sysIotModelServiceMapper.insertBatch(sysIotModelServiceList);
|
||||
if (CollectionUtils.isNotEmpty(updateSysIotModelServiceList)) {
|
||||
sysIotModelServiceMapper.updateBatchById(updateSysIotModelServiceList);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(delSysIotModelServiceList)) {
|
||||
sysIotModelServiceMapper.deleteBatchIds(delSysIotModelServiceList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void saveIotModelFieldInfo(String iotModelId, List<List<Object>> list) {
|
||||
List<SysIotModelField> sysIotModelFieldList = new ArrayList<>();
|
||||
List<SysIotModelField> delSysIotModelFieldList = new ArrayList<>();
|
||||
List<SysIotModelField> updateSysIotModelFieldList = new ArrayList<>();
|
||||
for (List<Object> row : list) {
|
||||
// 遍历sheet页中记录,构造需要导入的对象
|
||||
SysIotModelField field = new SysIotModelField();
|
||||
QueryWrapper<SysIotModelField> sysIotModelFieldQueryWrapper = new QueryWrapper<>();
|
||||
sysIotModelFieldQueryWrapper.eq("attribute_code", row.get(1).toString().toLowerCase());
|
||||
sysIotModelFieldQueryWrapper.eq("iot_model_id", Long.valueOf(iotModelId));
|
||||
SysIotModelField sysIotModelFieldQuery = sysIotModelFieldMapper.selectOne(sysIotModelFieldQueryWrapper);
|
||||
SysIotModelFieldVo sysIotModelFieldQuery = sysIotModelFieldMapper.selectByAttributeCode(Long.valueOf(iotModelId), row.get(3).toString());
|
||||
if (sysIotModelFieldQuery == null) {
|
||||
field.setAttributeCode(row.get(1).toString().toLowerCase());
|
||||
field.setAttributeName(row.get(2).toString());
|
||||
field.setAttributeType(Integer.valueOf(row.get(3).toString()));
|
||||
field.setPorder(Integer.valueOf(row.get(4).toString()));
|
||||
field.setSubSystem(row.get(5).toString());
|
||||
field.setDataType(row.get(6).toString());
|
||||
field.setVisible(Integer.valueOf(row.get(7).toString()));
|
||||
field.setHighSpeed(Integer.valueOf(row.get(8).toString()));
|
||||
field.setIotModelId(Long.valueOf(iotModelId));
|
||||
buildFieldInfo(iotModelId, row, field);
|
||||
field.setId(SequenceUtils.generateId());
|
||||
field.setCreatedTime(new Date());
|
||||
field.setUpdatedTime(new Date());
|
||||
field.setRevision(1);
|
||||
field.setCreatedBy(StpUtil.getLoginIdAsString());
|
||||
field.setUpdatedBy(StpUtil.getLoginIdAsString());
|
||||
sysIotModelFieldList.add(field);
|
||||
if ("I".equals(row.get(0))) {
|
||||
//加入集合
|
||||
sysIotModelFieldList.add(field);
|
||||
}
|
||||
}else {
|
||||
buildFieldInfo(iotModelId, row, field);
|
||||
field.setId(sysIotModelFieldQuery.getId());
|
||||
field.setUpdatedTime(new Date());
|
||||
field.setUpdatedBy(StpUtil.getLoginIdAsString());
|
||||
if ("U".equals(row.get(0))) {
|
||||
//加入集合
|
||||
updateSysIotModelFieldList.add(field);
|
||||
} else if ("D".equals(row.get(0))) {
|
||||
delSysIotModelFieldList.add(field);
|
||||
}
|
||||
}
|
||||
}
|
||||
sysIotModelFieldMapper.insertBatch(sysIotModelFieldList);
|
||||
if (CollectionUtils.isNotEmpty(updateSysIotModelFieldList)) {
|
||||
sysIotModelFieldMapper.updateBatchById(updateSysIotModelFieldList);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(delSysIotModelFieldList)) {
|
||||
sysIotModelFieldMapper.deleteBatchIds(delSysIotModelFieldList);
|
||||
}
|
||||
}
|
||||
|
||||
private static void buildFieldInfo(String iotModelId, List<Object> row, SysIotModelField field) {
|
||||
field.setAttributeCode(row.get(3).toString().toLowerCase());
|
||||
field.setAttributeName(row.get(4).toString());
|
||||
field.setAttributeType(Integer.valueOf(row.get(5).toString()));
|
||||
field.setPorder(Integer.valueOf(row.get(6).toString()));
|
||||
field.setSubSystem(row.get(7).toString());
|
||||
field.setDataType(row.get(8).toString());
|
||||
field.setVisible(Integer.valueOf(row.get(9).toString()));
|
||||
field.setHighSpeed(Integer.valueOf(row.get(10).toString()));
|
||||
field.setIotModelId(Long.valueOf(iotModelId));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,7 +24,11 @@ public class ImptabmappingVo {
|
||||
|
||||
private String equipmentName;
|
||||
|
||||
private String equipmentCode;
|
||||
|
||||
private Integer porder;
|
||||
|
||||
private String params;
|
||||
|
||||
private String code;
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Service
|
||||
@ -208,16 +209,22 @@ public class SysNodeServiceImpl implements SysNodeService {
|
||||
@Override
|
||||
public void bindDeviceMeas(List<BindEquipmentInfoDto> equipmentId, Long linkId) {
|
||||
List<SysImptabmapping> addList = new ArrayList<>();
|
||||
//获取已经绑定的设备
|
||||
List<SysImptabmappingVo> bindDeviceList = sysImptabmappingMapper.getBindDevice(linkId);
|
||||
SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY);
|
||||
if (CollectionUtils.isEmpty(bindDeviceList)) {
|
||||
addSysImptabmapping(equipmentId, linkId, sysUserVo, addList);
|
||||
} else {
|
||||
addSysImptabmapping(equipmentId, linkId, sysUserVo, addList);
|
||||
// 删除原来绑定的设备信息
|
||||
sysImptabmappingMapper.deleteBindDevice(linkId);
|
||||
List<Long> addList2 = new ArrayList<>();
|
||||
// 先更新设备地址
|
||||
for (BindEquipmentInfoDto info : equipmentId) {
|
||||
// 更新设备表里面的设备地址
|
||||
sysEquipmentMapper.updateIotAddr(info.getEquipmentId(), info.getIotAddr());
|
||||
}
|
||||
// 获取已经绑定的设备
|
||||
List<SysImptabmappingVo> bindDeviceList = sysImptabmappingMapper.getBindDevice(linkId);
|
||||
// 过滤已经绑定的设备
|
||||
for (SysImptabmappingVo bindDevice : bindDeviceList) {
|
||||
addList2.add(bindDevice.getEquipmentId());
|
||||
}
|
||||
//过滤
|
||||
equipmentId.removeIf(item -> addList2.contains(item.getEquipmentId()));
|
||||
SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY);
|
||||
addSysImptabmapping(equipmentId, linkId, sysUserVo, addList);
|
||||
if (!CollectionUtils.isEmpty(addList)) {
|
||||
sysImptabmappingMapper.insertBatch(addList);
|
||||
}
|
||||
@ -226,32 +233,37 @@ public class SysNodeServiceImpl implements SysNodeService {
|
||||
|
||||
@Override
|
||||
public void saveMappingList(List<ImptabmappingDto> impList) {
|
||||
if (!CollectionUtils.isEmpty(impList)) {
|
||||
List<SysImptabmapping> list = new ArrayList<>();
|
||||
SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY);
|
||||
for (ImptabmappingDto imp : impList) {
|
||||
SysImptabmapping sysImptabmapping = new SysImptabmapping();
|
||||
// 更新记录
|
||||
sysImptabmapping.setId(imp.getId());
|
||||
try {
|
||||
if (!CollectionUtils.isEmpty(impList)) {
|
||||
List<SysImptabmapping> list = new ArrayList<>();
|
||||
SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY);
|
||||
for (ImptabmappingDto imp : impList) {
|
||||
SysImptabmapping sysImptabmapping = new SysImptabmapping();
|
||||
// 更新记录
|
||||
sysImptabmapping.setId(imp.getId());
|
||||
|
||||
if (imp.getType() == 138 || imp.getType() == 139 || imp.getType() == 140) {
|
||||
// 获取属性编码
|
||||
String code = sysImptabmappingMapper.getAttributeCode(imp.getEquipmentId(), imp.getType(), imp.getName());
|
||||
sysImptabmapping.setEquipmentAttribute(code);
|
||||
} else if (imp.getType() == 146 || imp.getType() == 147) {
|
||||
// 获取动作编码
|
||||
String code = sysImptabmappingMapper.getServiceCode(imp.getEquipmentId(), imp.getType(), imp.getName());
|
||||
sysImptabmapping.setEquipmentService(code);
|
||||
if (imp.getType() == 138 || imp.getType() == 139 || imp.getType() == 140) {
|
||||
// 获取属性编码
|
||||
String code = sysImptabmappingMapper.getAttributeCode(imp.getEquipmentId(), imp.getType(), imp.getName());
|
||||
sysImptabmapping.setEquipmentAttribute(code);
|
||||
} else if (imp.getType() == 146 || imp.getType() == 147) {
|
||||
// 获取动作编码
|
||||
String code = sysImptabmappingMapper.getServiceCode(imp.getEquipmentId(), imp.getType(), imp.getName());
|
||||
sysImptabmapping.setEquipmentService(code);
|
||||
}
|
||||
sysImptabmapping.setUpdatedTime(new Date());
|
||||
sysImptabmapping.setUpdatedBy(sysUserVo.getAccount());
|
||||
sysImptabmapping.setParams(imp.getParams());
|
||||
list.add(sysImptabmapping);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
sysImptabmappingMapper.insertOrUpdateBatch(list);
|
||||
}
|
||||
sysImptabmapping.setUpdatedTime(new Date());
|
||||
sysImptabmapping.setUpdatedBy(sysUserVo.getAccount());
|
||||
sysImptabmapping.setParams(imp.getParams());
|
||||
list.add(sysImptabmapping);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
sysImptabmappingMapper.insertOrUpdateBatch(list);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("删除所有记录失败", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -369,8 +381,7 @@ public class SysNodeServiceImpl implements SysNodeService {
|
||||
addList.add(sysImptabmapping);
|
||||
}
|
||||
}
|
||||
// 更新设备表里面的设备地址
|
||||
sysEquipmentMapper.updateIotAddr(info.getEquipmentId(), info.getIotAddr());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -46,6 +46,7 @@
|
||||
<result property="parentEquipmentName" column="parent_equipment_name" jdbcType="VARCHAR"/>
|
||||
<result property="objectType" column="object_type" jdbcType="INTEGER"/>
|
||||
<result property="iotModelName" column="iot_model_name" jdbcType="VARCHAR"/>
|
||||
<result property="iotModelCode" column="iot_model_code" jdbcType="VARCHAR"/>
|
||||
<result property="code" column="code" jdbcType="VARCHAR"/>
|
||||
<result property="name" column="name" jdbcType="VARCHAR"/>
|
||||
<result property="model" column="model" jdbcType="VARCHAR"/>
|
||||
@ -99,7 +100,8 @@
|
||||
|
||||
|
||||
<select id="queryInfoById" resultMap="SysEquipmentExcelMap">
|
||||
select t.*,se."name" as parentEquipmentName,sim.iot_model_name as iotModelName, so."name" as orgName,
|
||||
select t.*,se."name" as parentEquipmentName,sim.iot_model_name as iotModelName,
|
||||
sim.iot_model_code, so."name" as orgName,
|
||||
so.mrid,se.code as parentEquipmentCode from sys_equipment t
|
||||
left join sys_equipment se on t.parent_equipment_id = se.id
|
||||
left join sys_iot_model sim on t.iot_model_id = sim.id
|
||||
|
@ -23,7 +23,8 @@
|
||||
</resultMap>
|
||||
|
||||
<select id="getMappingList" resultType="com.das.modules.node.domain.vo.ImptabmappingVo">
|
||||
select si.id, se."name" as equipmentName, simf.attribute_name as name,si.params,se.id as equipmentId from sys_imptabmapping si
|
||||
select si.id, se."name" as equipmentName,se.code as equipmentCode, simf.attribute_name as name,si.params,se.id as equipmentId,
|
||||
simf.attribute_code as code from sys_imptabmapping si
|
||||
left join sys_equipment se on si.equipment_id = se.id
|
||||
left join sys_iot_model_field simf on si.equipment_attribute = simf.attribute_code
|
||||
where si.link_id = #{linkId} and simf.attribute_type = #{type}
|
||||
@ -31,7 +32,8 @@
|
||||
</select>
|
||||
|
||||
<select id="getMappingControlList" resultType="com.das.modules.node.domain.vo.ImptabmappingVo">
|
||||
select si.id, se."name" as equipmentName, sims.service_name as name,si.params,se.id as equipmentId from sys_imptabmapping si
|
||||
select si.id, se."name" as equipmentName,se.code as equipmentCode, sims.service_name as name,si.params,se.id as equipmentId,
|
||||
sims.service_code as code from sys_imptabmapping si
|
||||
left join sys_equipment se on si.equipment_id = se.id
|
||||
left join sys_iot_model_service sims on si.equipment_service = sims.service_code
|
||||
where si.link_id = #{linkId} and sims.service_type = #{type}
|
||||
|
@ -32,7 +32,7 @@
|
||||
</select>
|
||||
|
||||
<select id="selectByAttributeCode" resultMap="SysIotModelFieldMap">
|
||||
select * from sys_iot_model_field simf where upper(simf.attribute_code) = upper(#{code})
|
||||
select * from sys_iot_model_field simf where simf.iot_model_id = #{iotModelId} and upper(simf.attribute_code) = upper(#{code})
|
||||
</select>
|
||||
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
<result property="serviceName" column="service_name" jdbcType="VARCHAR"/>
|
||||
<result property="serviceType" column="service_type" jdbcType="INTEGER"/>
|
||||
<result property="porder" column="porder" jdbcType="INTEGER"/>
|
||||
<result property="iotModelCode" column="iot_model_code" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
|
||||
@ -17,6 +18,11 @@
|
||||
<result property="attributeName" column="attribute_name" jdbcType="VARCHAR"/>
|
||||
<result property="attributeType" column="attribute_type" jdbcType="INTEGER"/>
|
||||
<result property="porder" column="porder" jdbcType="INTEGER"/>
|
||||
<result property="iotModelCode" column="iot_model_code" jdbcType="VARCHAR"/>
|
||||
<result property="highSpeed" column="highspeed" jdbcType="INTEGER"/>
|
||||
<result property="subSystem" column="subsystem" jdbcType="VARCHAR"/>
|
||||
<result property="dataType" column="datatype" jdbcType="VARCHAR"/>
|
||||
<result property="visible" column="visible" jdbcType="INTEGER"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap type="com.das.modules.equipment.domain.vo.SysIotModelVo" id="SysIotModelMap">
|
||||
@ -27,17 +33,19 @@
|
||||
</resultMap>
|
||||
|
||||
<select id="queryFieldByModelId" resultMap="SysIotModelFieldMap">
|
||||
select simf.*,sim.iot_model_name as iotModelName from sys_iot_model_field simf left join sys_iot_model sim on simf.iot_model_id = sim.id
|
||||
select simf.*,sim.iot_model_name as iotModelName,
|
||||
sim.iot_model_code from sys_iot_model_field simf left join sys_iot_model sim on simf.iot_model_id = sim.id
|
||||
where simf.iot_model_id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="queryServiceByModelId" resultMap="SysIotModelServiceMap">
|
||||
select sims.*,sim.iot_model_name as iotModelName from sys_iot_model_service sims left join sys_iot_model sim on sims.iot_model_id = sim.id
|
||||
select sims.*,sim.iot_model_name as iotModelName,
|
||||
sim.iot_model_code from sys_iot_model_service sims left join sys_iot_model sim on sims.iot_model_id = sim.id
|
||||
where sims.iot_model_id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="queryIotModelIdByName" resultType="java.lang.Long">
|
||||
select id from sys_iot_model where name = #{name}
|
||||
select id from sys_iot_model where iot_model_code = #{code}
|
||||
</select>
|
||||
|
||||
<select id="getSysIotModelByType" resultMap="SysIotModelMap">
|
||||
|
@ -32,6 +32,6 @@
|
||||
</select>
|
||||
|
||||
<select id="selectByServiceCode" resultMap="SysIotModelServiceMap">
|
||||
select t.* from sys_iot_model_service t where upper(t.service_code) = upper(#{code})
|
||||
select t.* from sys_iot_model_service t where t.iot_model_id = #{iotModelId} and upper(t.service_code) = upper(#{code})
|
||||
</select>
|
||||
</mapper>
|
||||
|
@ -56,7 +56,7 @@
|
||||
</select>
|
||||
|
||||
<select id="queryOrgIdByName" resultType="java.lang.Long">
|
||||
select t.id from sys_org t where t.name=#{name}
|
||||
select t.id from sys_org t where t.mrid=#{name}
|
||||
</select>
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user