HydomcAssetspecServiceImpl.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package com.persagy.transfer.service.impl;
  2. import java.util.Date;
  3. import org.apache.commons.lang3.StringUtils;
  4. import org.springframework.stereotype.Service;
  5. import org.springframework.transaction.annotation.Transactional;
  6. import com.alibaba.fastjson.JSONObject;
  7. import com.baomidou.dynamic.datasource.annotation.DS;
  8. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  9. import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
  10. import com.persagy.common.service.impl.SuperServiceImpl;
  11. import com.persagy.common.utils.DateUtil;
  12. import com.persagy.common.utils.StringUtil;
  13. import com.persagy.transfer.constant.InfosKeyConstant;
  14. import com.persagy.transfer.constant.SwitchConstant;
  15. import com.persagy.transfer.mapper.HydomcAssetspecMapper;
  16. import com.persagy.transfer.pojo.dto.HydomcAssetspec;
  17. import com.persagy.transfer.pojo.dto.RwdObjectWd;
  18. import com.persagy.transfer.pojo.dto.WdfacilityRelPersagy;
  19. import com.persagy.transfer.service.IHydomcAssetspecService;
  20. import com.persagy.transfer.utils.StringTool;
  21. /**
  22. * 设备参数信息
  23. *
  24. * @version 1.0.0
  25. * @company persagy
  26. * @author zhangqiankun
  27. * @date 2021-09-16 10:45:41
  28. */
  29. @Service
  30. @DS(value = SwitchConstant.DS_MASTER_2)
  31. public class HydomcAssetspecServiceImpl extends SuperServiceImpl<HydomcAssetspecMapper, HydomcAssetspec> implements IHydomcAssetspecService {
  32. public static final String IS_NUMBER = "数字";
  33. public static final String IS_LETTER = "字母数字";
  34. @Override
  35. public HydomcAssetspec getHydomcAssetspec(String sbybm, String siteId, String assetAttrId) {
  36. LambdaQueryWrapper<HydomcAssetspec> queryWrapper = new HydomcAssetspec.BuilderQueryWrapper().sbybmEq(sbybm)
  37. .siteidEq(siteId).assetattridEq(assetAttrId).builder();
  38. return this.baseMapper.selectOne(queryWrapper);
  39. }
  40. @Override
  41. @Transactional
  42. public boolean saveHydomcAssetspec(WdfacilityRelPersagy wdfacilityRelPersagy, RwdObjectWd rwdObjectWd, JSONObject infos, String wdProjectid, String classstructureid, String sbybm) {
  43. Date updateTime = rwdObjectWd.getUpdateTime() == null ? DateUtil.date().toJdkDate() : rwdObjectWd.getUpdateTime();
  44. Integer result = null;
  45. // 根据万达设备信息表的SITEID、SBYBM、ASSETATTRID查询数据是否存在
  46. HydomcAssetspec hydomcAssetspec = this.getHydomcAssetspec(sbybm, wdProjectid, wdfacilityRelPersagy.getAssetattrid());
  47. if (hydomcAssetspec == null) {
  48. hydomcAssetspec = this.buildHydomcAssetspec(infos, wdfacilityRelPersagy, null, wdProjectid, classstructureid, updateTime);
  49. result = this.baseMapper.insert(hydomcAssetspec);
  50. return SqlHelper.retBool(result);
  51. }
  52. // key为wdfacility_rel_persagy的code值从debugs取 有值update 无值(空、空字符串)就是delete
  53. if (StringUtils.isBlank(StringTool.object2String(infos.get(wdfacilityRelPersagy.getCode())))) {
  54. hydomcAssetspec.setDatastatus(SwitchConstant.IS_DELETE); // 数据状态 update/delete
  55. hydomcAssetspec.setChangedate(updateTime); // 数据更新时间 增量字段
  56. } else {
  57. hydomcAssetspec = this.buildHydomcAssetspec(infos, wdfacilityRelPersagy, hydomcAssetspec.getAssetspecid(), wdProjectid, classstructureid, updateTime);
  58. }
  59. result = this.baseMapper.updateById(hydomcAssetspec);
  60. return SqlHelper.retBool(result);
  61. }
  62. @Override
  63. public HydomcAssetspec buildHydomcAssetspec(JSONObject infos, WdfacilityRelPersagy wdfacilityRelPersagy, String assetspecid,
  64. String wdProjectid, String classstructureid, Date changedate) {
  65. HydomcAssetspec hydomcAssetspec = HydomcAssetspec.builder().siteid(wdProjectid) // 广场id 关联设备信息 Pj4403070003
  66. // 设备编码 关联设备信息 wD_gongchengxinxihua
  67. .sbybm(StringTool.object2String(infos.get(InfosKeyConstant.EQUIPMENT_CODE)))
  68. // 设备分类id 1507
  69. .classstructureid(classstructureid)
  70. // 设备分类名称 电梯系统/扶梯/人行步道 (取自中间表wdfacility_rel_persagy)
  71. .classqc(wdfacilityRelPersagy.getClassqc())
  72. // 设备参数id 1106 (取自中间表wdfacility_rel_persagy)
  73. .assetattrid(wdfacilityRelPersagy.getAssetattrid())
  74. // 设备参数名称 (取自中间表wdfacility_rel_persagy)
  75. .csdesc(wdfacilityRelPersagy.getCsdesc())
  76. // 设备参数类型 (取自中间表wdfacility_rel_persagy)
  77. .datatype(wdfacilityRelPersagy.getDatatype())
  78. // 设备参数单位编码 (取自中间表wdfacility_rel_persagy)
  79. .measureunitid(wdfacilityRelPersagy.getMeasureunitid())
  80. // 设备参数单位名称 (取自中间表wdfacility_rel_persagy)
  81. .csjldw(wdfacilityRelPersagy.getCsjldw())
  82. // 数据更新时间 增量字段
  83. .changedate(changedate).build();
  84. // 根据Datatype判断设置设备参数数字值还是设备参数文本值 key为wdfacility_rel_persagy的code值从debugs取
  85. if (IS_NUMBER.equals(wdfacilityRelPersagy.getDatatype())) { // 是数字
  86. hydomcAssetspec.setNumvalue(StringTool.object2Double(infos.get(wdfacilityRelPersagy.getCode()))); // 设备参数数字值
  87. } else {
  88. // 默认字符串
  89. hydomcAssetspec.setAlnvalue(StringTool.object2String(infos.get(wdfacilityRelPersagy.getCode()))); // 设备参数文本值
  90. }
  91. // key为wdfacility_rel_persagy的code值从debugs取 有值update 无值(空、空字符串)就是delete
  92. if (StringUtils.isBlank(StringTool.object2String(infos.get(wdfacilityRelPersagy.getCode())))) {
  93. hydomcAssetspec.setDatastatus(SwitchConstant.IS_DELETE); // 数据状态 update/delete
  94. } else {
  95. hydomcAssetspec.setDatastatus(SwitchConstant.IS_UPDATE); // 数据状态 update/delete
  96. }
  97. // 主键ID 赋值
  98. if (StringUtil.isNotBlank(assetspecid)) {
  99. hydomcAssetspec.setAssetspecid(assetspecid);
  100. }
  101. return hydomcAssetspec;
  102. }
  103. }