123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- package com.persagy.transfer.service.impl;
- import java.util.Date;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.dynamic.datasource.annotation.DS;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
- import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
- import com.persagy.common.utils.DateUtil;
- import com.persagy.common.utils.StringUtil;
- import com.persagy.db.service.impl.SuperServiceImpl;
- import com.persagy.transfer.constant.InfosKeyConstant;
- import com.persagy.transfer.constant.SwitchConstant;
- import com.persagy.transfer.mapper.HydomcAssetspecMapper;
- import com.persagy.transfer.pojo.dto.HydomcAssetspec;
- import com.persagy.transfer.pojo.dto.RwdObjectWd;
- import com.persagy.transfer.pojo.dto.WdfacilityRelPersagy;
- import com.persagy.transfer.service.IHydomcAssetspecService;
- import com.persagy.transfer.utils.StringTool;
- /**
- * 设备参数信息
- *
- * @version 1.0.0
- * @company persagy
- * @author zhangqiankun
- * @date 2021-09-16 10:45:41
- */
- @Service
- @DS(value = SwitchConstant.DS_MASTER_2)
- public class HydomcAssetspecServiceImpl extends SuperServiceImpl<HydomcAssetspecMapper, HydomcAssetspec> implements IHydomcAssetspecService {
- public static final String IS_NUMBER = "数字";
- public static final String IS_LETTER = "字母数字";
- @Override
- public HydomcAssetspec getHydomcAssetspec(String sbybm, String siteId, String assetAttrId) {
- LambdaQueryWrapper<HydomcAssetspec> queryWrapper = new HydomcAssetspec.BuilderQueryWrapper().sbybmEq(sbybm)
- .siteidEq(siteId).assetattridEq(assetAttrId).builder();
- return this.baseMapper.selectOne(queryWrapper);
- }
- @Override
- @Transactional
- public boolean saveHydomcAssetspec(WdfacilityRelPersagy wdfacilityRelPersagy, RwdObjectWd rwdObjectWd, JSONObject infos, String wdProjectid, String classstructureid, String sbybm) {
- Date updateTime = rwdObjectWd.getUpdateTime() == null ? DateUtil.date().toJdkDate() : rwdObjectWd.getUpdateTime();
- String codeValue = StringTool.object2String(infos.get(wdfacilityRelPersagy.getCode()));
-
- Integer result = null;
- // 根据万达设备信息表的SITEID、SBYBM、ASSETATTRID查询数据是否存在
- HydomcAssetspec hydomcAssetspec = this.getHydomcAssetspec(sbybm, wdProjectid, wdfacilityRelPersagy.getAssetattrid());
- if (hydomcAssetspec == null) {
- if (StringUtil.isNotBlank(codeValue)) {
- // 查询不到时,且code 有值,走插入逻辑
- hydomcAssetspec = this.buildHydomcAssetspec(infos, wdfacilityRelPersagy, null, wdProjectid, classstructureid, updateTime);
- hydomcAssetspec.setDatastatus(SwitchConstant.IS_UPDATE); // 数据状态 update/delete
- result = this.baseMapper.insert(hydomcAssetspec);
- }
- return SqlHelper.retBool(result);
- }
-
- // key为wdfacility_rel_persagy的code值从debugs取 有值update 无值(空、空字符串)就是delete
- if (StringUtils.isBlank(StringTool.object2String(infos.get(wdfacilityRelPersagy.getCode())))) {
- hydomcAssetspec.setDatastatus(SwitchConstant.IS_DELETE); // 数据状态 update/delete
- hydomcAssetspec.setChangedate(updateTime); // 数据更新时间 增量字段
- } else {
- hydomcAssetspec = this.buildHydomcAssetspec(infos, wdfacilityRelPersagy, hydomcAssetspec.getAssetspecid(), wdProjectid, classstructureid, updateTime);
- hydomcAssetspec.setDatastatus(SwitchConstant.IS_UPDATE); // 数据状态 update/delete
- }
- result = this.baseMapper.updateById(hydomcAssetspec);
- return SqlHelper.retBool(result);
- }
- @Override
- @Transactional
- public boolean deleteHydomcAssetspec(String wdProjectId, String sbybm, Date updateTime) {
- updateTime = updateTime == null ? DateUtil.date().toJdkDate() : updateTime;
- LambdaUpdateWrapper<HydomcAssetspec> updateWrapper = new HydomcAssetspec.BuilderUpdateWrapper().sbybmEq(sbybm).siteidEq(wdProjectId).builder();
- updateWrapper.set(HydomcAssetspec::getDatastatus, SwitchConstant.IS_DELETE); // 数据状态 update/delete 当数据状态为delete时,设备状态需改为报废
- updateWrapper.set(HydomcAssetspec::getChangedate, updateTime); // 数据更新时间 增量字段
- Integer result = this.baseMapper.update(null, updateWrapper);
- return SqlHelper.retBool(result);
-
- }
-
- @Override
- public HydomcAssetspec buildHydomcAssetspec(JSONObject infos, WdfacilityRelPersagy wdfacilityRelPersagy, String assetspecid,
- String wdProjectid, String classstructureid, Date changedate) {
- HydomcAssetspec hydomcAssetspec = HydomcAssetspec.builder().siteid(wdProjectid) // 广场id 关联设备信息 Pj4403070003
- // 设备编码 关联设备信息 wD_gongchengxinxihua
- .sbybm(StringTool.object2String(infos.get(InfosKeyConstant.EQUIPMENT_CODE)))
- // 设备分类id 1507
- .classstructureid(StringTool.object2String(infos.get(InfosKeyConstant.EQUIPMENT_SORT)))
- // 设备分类名称 电梯系统/扶梯/人行步道 (取自中间表wdfacility_rel_persagy)
- .classqc(wdfacilityRelPersagy.getClassqc())
- // 设备参数id 1106 (取自中间表wdfacility_rel_persagy)
- .assetattrid(wdfacilityRelPersagy.getAssetattrid())
- // 设备参数名称 (取自中间表wdfacility_rel_persagy)
- .csdesc(wdfacilityRelPersagy.getCsdesc())
- // 设备参数类型 (取自中间表wdfacility_rel_persagy)
- .datatype(wdfacilityRelPersagy.getDatatype())
- // 设备参数单位编码 (取自中间表wdfacility_rel_persagy)
- .measureunitid(wdfacilityRelPersagy.getMeasureunitid())
- // 设备参数单位名称 (取自中间表wdfacility_rel_persagy)
- .csjldw(wdfacilityRelPersagy.getCsjldw())
- // 数据更新时间 增量字段
- .changedate(changedate).build();
- // 根据Datatype判断设置设备参数数字值还是设备参数文本值 key为wdfacility_rel_persagy的code值从debugs取
- if (IS_NUMBER.equals(wdfacilityRelPersagy.getDatatype())) { // 是数字
- hydomcAssetspec.setNumvalue(StringTool.object2Double(infos.get(wdfacilityRelPersagy.getCode()))); // 设备参数数字值
- } else {
- // 默认字符串
- hydomcAssetspec.setAlnvalue(StringTool.object2String(infos.get(wdfacilityRelPersagy.getCode()))); // 设备参数文本值
- }
- // 主键ID 赋值
- if (StringUtil.isNotBlank(assetspecid)) {
- hydomcAssetspec.setAssetspecid(assetspecid);
- }
- return hydomcAssetspec;
- }
- }
|