|
@@ -0,0 +1,215 @@
|
|
|
+package com.ruoyi.web.controller.business;
|
|
|
+
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
+import com.ruoyi.business.domain.*;
|
|
|
+import com.ruoyi.business.mapper.BizDeviceMapper;
|
|
|
+import com.ruoyi.business.mapper.TOrganizationMapper;
|
|
|
+import com.ruoyi.business.mapper.TPositionMapper;
|
|
|
+import com.ruoyi.business.mapper.TQualityConfMapper;
|
|
|
+import com.ruoyi.common.core.domain.R;
|
|
|
+import com.ruoyi.common.utils.DateUtils;
|
|
|
+import com.ruoyi.common.utils.StringUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import static com.ruoyi.common.constant.Constants.HTTP_GET_TIME_OUT_MILLION_SECONDS;
|
|
|
+import static com.ruoyi.common.constant.Constants.SQL_SERVER_REMOTE_INTERFACE_ADDR;
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * 手动处理数据相关的,大部分都是只需要同步一次即可完成的任务
|
|
|
+ *
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@Slf4j
|
|
|
+public class HandleDataController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BizDeviceMapper bizDeviceMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TOrganizationMapper organizationMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TPositionMapper positionMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TQualityConfMapper qualityConfMapper;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 同步 组织【设备信息】列表
|
|
|
+ */
|
|
|
+ @GetMapping("/bizDeviceList")
|
|
|
+ public R<String> bizDeviceList(BizDevice reqBean)
|
|
|
+ {
|
|
|
+ String result;
|
|
|
+ List<BizDevice> list;
|
|
|
+ try {
|
|
|
+ result = HttpUtil.get(SQL_SERVER_REMOTE_INTERFACE_ADDR + "/bizDeviceList", HTTP_GET_TIME_OUT_MILLION_SECONDS);
|
|
|
+ log.info("调用同步设备接口返回的结果为{}", result);
|
|
|
+ list = JSON.parseArray(result, BizDevice.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("调用同步设备接口异常,异常信息为:" + e.getMessage());
|
|
|
+ }
|
|
|
+ log.info("调用同步设备接口转换完对象以后,获取到的需要同步的数据为{}", JSON.toJSONString(list));
|
|
|
+ //执行插入本地数据的操作
|
|
|
+ //后续的设备状态更新定时任务参考此功能
|
|
|
+ return R.ok("同步成功");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 同步 组织【水厂信息】列表
|
|
|
+ */
|
|
|
+ @GetMapping("/syncWaterWorkList")
|
|
|
+ public R<String> syncWaterWorkList(BizWaterWork reqBean)
|
|
|
+ {
|
|
|
+ String result;
|
|
|
+ List<BizWaterWork> list;
|
|
|
+ try {
|
|
|
+ result = HttpUtil.get(SQL_SERVER_REMOTE_INTERFACE_ADDR + "/bizWaterWorkList", HTTP_GET_TIME_OUT_MILLION_SECONDS);
|
|
|
+ log.info("调用同步组织接口接口返回的结果为{}", result);
|
|
|
+ list = JSON.parseArray(result, BizWaterWork.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("调用同步组织接口异常,异常信息为:" + e.getMessage());
|
|
|
+ }
|
|
|
+ log.info("调用同步组织接口转换完对象以后,获取到的需要同步的数据为{}", JSON.toJSONString(list));
|
|
|
+ //执行插入本地数据的操作
|
|
|
+ if(!CollectionUtils.isEmpty(list)){
|
|
|
+ for (BizWaterWork bizWaterWork : list) {
|
|
|
+ TOrganization organization = new TOrganization();
|
|
|
+ Long parentId = bizWaterWork.getParentId();
|
|
|
+ organization.setId(bizWaterWork.getWorksId());
|
|
|
+ organization.setName(bizWaterWork.getWorksName());
|
|
|
+ organization.setCode(bizWaterWork.getWorksNo());
|
|
|
+ organization.setType(212L == parentId ? 0 : 1);
|
|
|
+ organization.setProvinceCode(bizWaterWork.getWorksProvince());
|
|
|
+ organization.setCityCode(bizWaterWork.getWorksCity());
|
|
|
+ organization.setCountryCode(bizWaterWork.getWorksArea());
|
|
|
+ organization.setConcat(bizWaterWork.getWorksMaintainer());
|
|
|
+ organization.setPhone(bizWaterWork.getWorksTel());
|
|
|
+ organization.setStatus(Integer.valueOf(bizWaterWork.getWorksStatus()));
|
|
|
+ organization.setParentId(parentId);
|
|
|
+ organization.setTopId(parentId);//因为只有2级
|
|
|
+ organization.setSort(bizWaterWork.getOrderNum());
|
|
|
+ organization.setAddress(bizWaterWork.getWorksAddress());
|
|
|
+ organization.setLongitude(bizWaterWork.getWorksLongitude());
|
|
|
+ organization.setLatitude(bizWaterWork.getWorksLatitude());
|
|
|
+ organization.setCreateBy("sys");
|
|
|
+ organization.setCreateTime(DateUtils.getNowDate());
|
|
|
+ this.organizationMapper.insertTOrganization(organization);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.ok("同步成功");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 同步 组织【取样点位】列表
|
|
|
+ */
|
|
|
+ @GetMapping("/syncDeviceSampleList")
|
|
|
+ @Transactional
|
|
|
+ public R<String> syncDeviceSampleList(ZDeviceSample reqBean)
|
|
|
+ {
|
|
|
+ String result;
|
|
|
+ List<ZDeviceSample> list;
|
|
|
+ try {
|
|
|
+ result = HttpUtil.get(SQL_SERVER_REMOTE_INTERFACE_ADDR + "/deviceSampleList", HTTP_GET_TIME_OUT_MILLION_SECONDS);
|
|
|
+ log.info("调用同步取样点位接口接口返回的结果为{}", result);
|
|
|
+ list = JSON.parseArray(result, ZDeviceSample.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("调用同步取样点位接口异常,异常信息为:" + e.getMessage());
|
|
|
+ }
|
|
|
+ log.info("调用同步取样点位接口转换完对象以后,获取到的需要同步的数据为{}", JSON.toJSONString(list));
|
|
|
+ //执行插入本地数据的操作
|
|
|
+ if(!CollectionUtils.isEmpty(list)){
|
|
|
+ for (ZDeviceSample deviceSample : list) {
|
|
|
+ TPosition tPosition = new TPosition();
|
|
|
+ String deviceNo = deviceSample.getDeviceNo();
|
|
|
+ //通过设备编号去查询设备ID和水厂ID
|
|
|
+ if(StringUtils.isBlank(deviceNo)){
|
|
|
+ log.error("查询到的点位信息对应的设备编号时,因为没有配置设备编号导致无法获取水厂和设备信息!跳过该条数据,此数据为{}", JSON.toJSONString(deviceSample));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //查询设备
|
|
|
+ List<BizDevice> deviceList = this.bizDeviceMapper.selectBizDeviceList(BizDevice.builder().deviceNo(deviceNo).build());
|
|
|
+ if(CollectionUtils.isEmpty(deviceList)){
|
|
|
+ log.error("查询到的点位信息对应的设备编号时,因为没有通过设备编号查询到设备信息导致无法获取水厂和设备信息!跳过该条数据,此数据为{}", JSON.toJSONString(deviceSample));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(deviceList.size() > 1){
|
|
|
+ log.error("通过设备编号查询设备详情时,查出多个设备信息,异常数据为{}", JSON.toJSONString(deviceSample));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ BizDevice bizDevice = deviceList.get(0);
|
|
|
+ tPosition.setOrganizationId(bizDevice.getDeviceWorks());
|
|
|
+ tPosition.setDeviceId(bizDevice.getDeviceId());
|
|
|
+ tPosition.setCode(deviceSample.getAssayType());
|
|
|
+ tPosition.setName(deviceSample.getItemName());
|
|
|
+ tPosition.setCreateBy("sys");
|
|
|
+ tPosition.setCreateTime(DateUtils.getNowDate());
|
|
|
+ this.positionMapper.insertTPosition(tPosition);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.ok("同步成功");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //化验项目表比较简单,直接SQL语句处理了
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 同步 组织【质控样配置】列表
|
|
|
+ */
|
|
|
+ @GetMapping("/syncQualityValueList")
|
|
|
+ @Transactional
|
|
|
+ public R<String> syncQualityValueList(ZQualityValue reqBean)
|
|
|
+ {
|
|
|
+ String result;
|
|
|
+ List<ZQualityValue> list;
|
|
|
+ try {
|
|
|
+ result = HttpUtil.get(SQL_SERVER_REMOTE_INTERFACE_ADDR + "/qualityValueList", HTTP_GET_TIME_OUT_MILLION_SECONDS);
|
|
|
+ log.info("调用同步质控样配置接口接口返回的结果为{}", result);
|
|
|
+ list = JSON.parseArray(result, ZQualityValue.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("调用同步质控样配置接口异常,异常信息为:" + e.getMessage());
|
|
|
+ }
|
|
|
+ log.info("调用同步质控样配置接口转换完对象以后,获取到的需要同步的数据为{}", JSON.toJSONString(list));
|
|
|
+ //执行插入本地数据的操作
|
|
|
+ if(!CollectionUtils.isEmpty(list)){
|
|
|
+ for (ZQualityValue qualityValue : list) {
|
|
|
+ TQualityConf qualityConf = new TQualityConf();
|
|
|
+ qualityConf.setOrganizationId(qualityValue.getDeviceWorks());
|
|
|
+ qualityConf.setItemId(Long.valueOf(qualityValue.getAssayItem()));
|
|
|
+ qualityConf.setResultValue(BigDecimal.valueOf(qualityValue.getResultValue()));
|
|
|
+ qualityConf.setFloatRate(null);
|
|
|
+ qualityConf.setHighValue(BigDecimal.valueOf(qualityValue.getHighValue()));
|
|
|
+ qualityConf.setLowValue(BigDecimal.valueOf(qualityValue.getLowValue()));
|
|
|
+ qualityConf.setBeginTime(qualityValue.getBeginTime());
|
|
|
+ qualityConf.setEndTime(qualityValue.getEndTime());
|
|
|
+ qualityConf.setCreateBy("sys");
|
|
|
+ qualityConf.setCreateTime(DateUtils.getNowDate());
|
|
|
+ this.qualityConfMapper.insertTQualityConf(qualityConf);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.ok("同步成功");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|