HydomcAssetspecServiceImpl.java 6.4 KB

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