|
|
@@ -0,0 +1,496 @@
|
|
|
+package com.lc.ibps.business.thirtyparty.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.lc.ibps.base.core.util.*;
|
|
|
+import com.lc.ibps.base.core.util.Collections;
|
|
|
+import com.lc.ibps.base.framework.id.UniqueIdUtil;
|
|
|
+import com.lc.ibps.base.framework.table.ICommonDao;
|
|
|
+import com.lc.ibps.base.saas.token.ITenantTokenService;
|
|
|
+import com.lc.ibps.base.web.context.ContextUtil;
|
|
|
+import com.lc.ibps.base.web.util.AppFileUtil;
|
|
|
+import com.lc.ibps.bpmn.api.IBpmInstService;
|
|
|
+import com.lc.ibps.business.thirtyparty.service.HumitureService;
|
|
|
+import com.lc.ibps.cloud.entity.APIResult;
|
|
|
+import com.lc.ibps.components.poi.excel.ExcelImportUtil;
|
|
|
+import com.lc.ibps.components.poi.excel.entity.ImportParams;
|
|
|
+import com.lc.ibps.untils.SqlUtil;
|
|
|
+import lombok.extern.log4j.Log4j2;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Log4j2
|
|
|
+@Service
|
|
|
+public class HumitureServiceImpl implements HumitureService {
|
|
|
+
|
|
|
+ // 室内温湿度--t_snwsdjkjlb 冰箱温度--t_bxwdjkjlb 温浴箱(培养箱)温湿度--t_wyxwdjkywhjlb 阴凉柜温湿度记录---t_ylgwdjkjlb
|
|
|
+ private static final String SNWSD = "t_snwsdjkjlb";
|
|
|
+ private static final String BXWD = "t_bxwdjkjlb";
|
|
|
+ private static final String WYXWSD = "t_wyxwdjkywhjlb";
|
|
|
+ private static final String YLGWSD = "t_ylgwdjkjlb";
|
|
|
+ private static final String SKJLB = "t_sshjskycljlb";
|
|
|
+
|
|
|
+ private SimpleDateFormat shijian = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ private SimpleDateFormat minute = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
|
|
+ private SimpleDateFormat riqi = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ private SimpleDateFormat shifen = new SimpleDateFormat("HH:mm");
|
|
|
+ private SimpleDateFormat merge = new SimpleDateFormat("yyyyMMddHHmm");
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ICommonDao<?> commonDao;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public APIResult<Void> importHumiture(@RequestParam(name = "file", required = true) MultipartFile file) {
|
|
|
+ APIResult<Void> result = new APIResult<>();
|
|
|
+ String unZipFilePath = null;
|
|
|
+ try {
|
|
|
+ log.debug("com.lc.ibps.business.thirtyparty.service.impl.HumitureServiceImpl.importHumiture()--->file.size={}",
|
|
|
+ BeanUtils.isEmpty(file) ? 0 : file.getSize());
|
|
|
+ unZipFilePath = AppFileUtil.unZipFile(file);
|
|
|
+
|
|
|
+ Map<String,Object> main = new HashMap<>();
|
|
|
+ String id = UniqueIdUtil.getId();
|
|
|
+ main.put("id_", id);
|
|
|
+ main.put("create_by_", ContextUtil.getCurrentUserId());
|
|
|
+ main.put("create_time_", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
|
|
+ main.put("bian_zhi_ren_", ContextUtil.getCurrentUserId());
|
|
|
+ main.put("bian_zhi_bu_men_", ContextUtil.getCurrentPositionId());
|
|
|
+ main.put("bian_zhi_shi_jian", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
|
|
+
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ this.importData(unZipFilePath,id,map);
|
|
|
+ if (BeanUtils.isNotEmpty(map)) {
|
|
|
+ main.put("dao_ru_she_bei_", removeDuplicates(map.get("deviceName").toString()));
|
|
|
+ main.put("she_bei_lei_xing_", removeDuplicates(map.get("type").toString()));
|
|
|
+ main.put("dao_ru_shu_liang_", map.get("count"));
|
|
|
+ main.put("jie_guo_", "导入成功");
|
|
|
+ }else {
|
|
|
+ main.put("jie_guo_", "未读取到数据或数据格式异常!");
|
|
|
+ }
|
|
|
+
|
|
|
+ commonDao.execute(SqlUtil.buildInsertSql(main,"t_wsdsjdrjlb"));
|
|
|
+
|
|
|
+ // 处理数据到具体业务表
|
|
|
+ createDailyRecord(id);
|
|
|
+
|
|
|
+ // 处理失控开启失控流程
|
|
|
+ checkUncontrolBx(id);
|
|
|
+
|
|
|
+ result.setMessage("导入成功!");
|
|
|
+ } catch (Exception e) {
|
|
|
+ result.setMessage("导入失败!");
|
|
|
+ log.error(e);
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ File dir = new File(unZipFilePath);
|
|
|
+ if (dir.exists()) {
|
|
|
+ FileUtil.deleteDir(dir); // 删除解压后的目录
|
|
|
+ }
|
|
|
+ } catch (Exception ignore) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String removeDuplicates(String input) {
|
|
|
+ String[] items = input.split(",");
|
|
|
+ Set<String> uniqueItems = new LinkedHashSet<>(Arrays.asList(items));
|
|
|
+ return String.join(",", uniqueItems);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void importData(String filePath, String id, Map<String, Object> res) throws Exception {
|
|
|
+ File dir = new File(filePath);
|
|
|
+ File[] files = dir.listFiles();
|
|
|
+ if (files == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ StringBuilder nameBuilder = new StringBuilder(res.get("deviceName") == null ? "" : res.get("deviceName").toString());
|
|
|
+ int count = res.get("count") == null ? 0 : Integer.parseInt(res.get("count").toString());
|
|
|
+ StringBuilder typeBuilder = new StringBuilder(res.get("type") == null ? "" : res.get("type").toString());
|
|
|
+
|
|
|
+ for (File file : files) {
|
|
|
+ if (file.isDirectory()) {
|
|
|
+ importData(file.getAbsolutePath(), id, res);
|
|
|
+ if (res.get("deviceName") != null) {
|
|
|
+ if (nameBuilder.length() > 0) {
|
|
|
+ nameBuilder.append(",");
|
|
|
+ }
|
|
|
+ nameBuilder.append(res.get("deviceName").toString());
|
|
|
+ }
|
|
|
+ if (res.get("type") != null) {
|
|
|
+ if (typeBuilder.length() > 0) {
|
|
|
+ typeBuilder.append(",");
|
|
|
+ }
|
|
|
+ typeBuilder.append(res.get("type").toString());
|
|
|
+ }
|
|
|
+ count += res.get("count") == null ? 0 : Integer.parseInt(res.get("count").toString());
|
|
|
+ } else {
|
|
|
+ Map<String, Object> map = importFile(file, id);
|
|
|
+ if (BeanUtils.isNotEmpty(map)) {
|
|
|
+ if (nameBuilder.length() > 0) {
|
|
|
+ nameBuilder.append(",");
|
|
|
+ }
|
|
|
+ nameBuilder.append(map.get("deviceName").toString());
|
|
|
+ count += Integer.parseInt(map.get("count").toString());
|
|
|
+ if (typeBuilder.length() > 0) {
|
|
|
+ typeBuilder.append(",");
|
|
|
+ }
|
|
|
+ typeBuilder.append(map.get("type").toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ res.put("deviceName", nameBuilder.toString());
|
|
|
+ res.put("count", count);
|
|
|
+ res.put("type", typeBuilder.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String,Object> importFile(File file,String parentId) throws Exception {
|
|
|
+ ImportParams params = new ImportParams();
|
|
|
+ //params.setTitleRows(0);
|
|
|
+ params.setHeadRows(2);
|
|
|
+ List<Map<String,Object>> excelList = ExcelImportUtil.importExcel(file, Map.class, params);
|
|
|
+ String sql = "select di_dian_,bu_men_,she_bei_ming_chen,cai_ji_qi_id_,she_bei_lei_xing_,qu_yu_,fang_jian_,gang_wei_," +
|
|
|
+ "wen_du_shang_xian,wen_du_xia_xian_,shi_du_shang_xian,shi_du_xia_xian_ from `t_wsdcjpzb` where shi_fou_qi_yong_='是' ";
|
|
|
+ List<Map<String,Object>> configList = (List<Map<String, Object>>) commonDao.query(sql);
|
|
|
+ if(com.lc.ibps.base.core.util.Collections.isEmpty(excelList) && Collections.isEmpty(configList)){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Map<String,Object> equip = new HashMap<>();
|
|
|
+ equip.put("deviceName",excelList.get(0).get("设备名称"));
|
|
|
+ equip.put("count",excelList.size());
|
|
|
+ for (Map excel : excelList) {
|
|
|
+ for (Map<String,Object> config : configList) {
|
|
|
+ if (excel.get("设备地址").toString().equals(config.get("cai_ji_qi_id_").toString())){
|
|
|
+ equip.put("type",config.get("she_bei_lei_xing_"));
|
|
|
+ Map<String,Object> data = new HashMap<>();
|
|
|
+ String subId = (String) config.get("cai_ji_qi_id_");
|
|
|
+ String time = merge.format(minute.parse(excel.get("记录时间").toString()));
|
|
|
+ data.put("create_time_",shijian.format(new Date()));
|
|
|
+ data.put("cai_ji_shi_jian_",excel.get("记录时间"));
|
|
|
+ data.put("cai_ji_ri_qi_",riqi.format(minute.parse(excel.get("记录时间").toString())));
|
|
|
+ data.put("cai_ji_qi_id_",excel.get("设备地址"));
|
|
|
+ data.put("cai_ji_qi_ming_ch",excel.get("设备名称"));
|
|
|
+ data.put("wen_shi_du_zhi_",excel.get("数据"));
|
|
|
+ if (excel.get("因子名称").toString().equals("温度")){
|
|
|
+ subId = subId + "-1-" + time;
|
|
|
+ data.put("shu_ju_lei_xing_","温度");
|
|
|
+ data.put("zui_da_zhi_", BeanUtils.isEmpty(config.get("wen_du_shang_xian"))?"":config.get("wen_du_shang_xian").toString());
|
|
|
+ data.put("zui_xiao_zhi_", BeanUtils.isEmpty(config.get("wen_du_xia_xian_"))?"":config.get("wen_du_xia_xian_").toString());
|
|
|
+ }else if (excel.get("因子名称").toString().equals("湿度")){
|
|
|
+ subId = subId + "-2-" + time;
|
|
|
+ data.put("shu_ju_lei_xing_","湿度");
|
|
|
+ data.put("zui_da_zhi_", BeanUtils.isEmpty(config.get("shi_du_shang_xian"))?"":config.get("shi_du_shang_xian").toString());
|
|
|
+ data.put("zui_xiao_zhi_", BeanUtils.isEmpty(config.get("shi_du_xia_xian_"))?"":config.get("shi_du_xia_xian_").toString());
|
|
|
+ }
|
|
|
+ data.put("she_bei_lei_xing_",config.get("she_bei_lei_xing_"));
|
|
|
+ data.put("bu_men_id_",config.get("bu_men_"));
|
|
|
+ data.put("qu_yu_",config.get("qu_yu_"));
|
|
|
+ data.put("fang_jian_",config.get("fang_jian_"));
|
|
|
+ data.put("gang_wei_",config.get("gang_wei_"));
|
|
|
+ data.put("di_dian_",config.get("di_dian_"));
|
|
|
+ data.put("id_",subId);
|
|
|
+ data.put("parent_id_",parentId);
|
|
|
+ commonDao.execute(SqlUtil.buildInsertIgnorePrimarySql(data,"t_dsfwsdjlb"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return equip;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkUncontrolBx(String parentId) throws Exception {
|
|
|
+ String sql = "SELECT cai_ji_qi_id_,shu_ju_lei_xing_,COUNT(id_) total FROM t_dsfwsdjlb \n" +
|
|
|
+ "WHERE ((CONVERT(wen_shi_du_zhi_,SIGNED) > CONVERT(zui_da_zhi_,SIGNED) OR CONVERT(wen_shi_du_zhi_,SIGNED) < CONVERT(zui_xiao_zhi_,SIGNED)) \n" +
|
|
|
+ "and (wen_shi_du_zhi_<>'' and zui_da_zhi_ <>'' and zui_xiao_zhi_ <>'')) \n" +
|
|
|
+ "AND parent_id_='%s' GROUP BY cai_ji_qi_id_ HAVING total >='2' ";
|
|
|
+ sql = String.format(sql,parentId);
|
|
|
+ List<Map<String, Object>> bx = (List<Map<String, Object>>) commonDao.query(sql);
|
|
|
+ if (BeanUtils.isNotEmpty(bx)){
|
|
|
+ for (Map<String,Object> bxMap : bx){
|
|
|
+ outOfControlJudge(parentId,bxMap.get("cai_ji_qi_id_").toString(),bxMap.get("shu_ju_lei_xing_").toString());
|
|
|
+ }
|
|
|
+ startFlowStep();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void outOfControlJudge(String parentId,String deviceId,String type) throws Exception {
|
|
|
+ String sql = "SELECT *from t_dsfwsdjlb WHERE parent_id_='%s' and cai_ji_qi_id_='%s' and shu_ju_lei_xing_ ='%s' " +
|
|
|
+ "and (wen_shi_du_zhi_<>'' and zui_da_zhi_ <>'' and zui_xiao_zhi_ <>'') ORDER BY cai_ji_shi_jian_ desc";
|
|
|
+ sql = String.format(sql,parentId,deviceId,type);
|
|
|
+ List<Map<String, Object>> list = (List<Map<String, Object>>) commonDao.query(sql);
|
|
|
+ if (BeanUtils.isNotEmpty(list)){
|
|
|
+ int control = 0;
|
|
|
+ StringBuilder beiZhu = new StringBuilder();
|
|
|
+ StringBuilder idStr = new StringBuilder();
|
|
|
+ for (Map<String,Object> map : list){
|
|
|
+ double wenDu = Double.parseDouble(map.get("wen_shi_du_zhi_").toString());
|
|
|
+ double max = Double.parseDouble(map.get("zui_da_zhi_").toString());
|
|
|
+ double min = Double.parseDouble(map.get("zui_xiao_zhi_").toString());
|
|
|
+ if (wenDu>max || wenDu<min){
|
|
|
+ control=control+1;
|
|
|
+ idStr.append(map.get("id_")).append("_");
|
|
|
+ String typeStr = map.get("shu_ju_lei_xing_").toString().equals("温度")?",温度:":",湿度:";
|
|
|
+ String limits = map.get("shu_ju_lei_xing_").toString().equals("温度")?"温度范围:":"湿度范围:";
|
|
|
+ String unit = map.get("shu_ju_lei_xing_").toString().equals("温度")?"℃":"%";
|
|
|
+ beiZhu.append("采集时间:").append(map.get("cai_ji_shi_jian_")).append(typeStr).append(wenDu).
|
|
|
+ append("℃,").append(limits).append(min).append("~").append(max).append(unit).append("\n");
|
|
|
+ }else {
|
|
|
+ control=0;
|
|
|
+ }
|
|
|
+ if (control==2){
|
|
|
+ addWenDuSkData( map ,beiZhu.toString(), idStr.toString());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addWenDuSkData(Map<String,Object> map,String beiZhu,String idStr) throws Exception {
|
|
|
+ if (!exist(SKJLB,idStr,"yuan_shu_ju_id_")){
|
|
|
+ Map<String,Object> data = new HashMap<>();
|
|
|
+ data.put("id_", UniqueIdUtil.getId());
|
|
|
+ data.put("create_time_", shijian.format(new Date()));
|
|
|
+ data.put("bian_zhi_shi_jian", shijian.format(new Date()));
|
|
|
+ data.put("fa_xian_shi_jian_", map.get("cai_ji_shi_jian_"));
|
|
|
+ data.put("bian_zhi_bu_men_", map.get("bu_men_id_"));
|
|
|
+ data.put("fa_sheng_qu_yu_", map.get("qu_yu_"));
|
|
|
+ data.put("di_dian_", map.get("di_dian_"));
|
|
|
+ data.put("fang_jian_", map.get("fang_jian_"));
|
|
|
+ data.put("jie_guo_", "是");
|
|
|
+ data.put("qing_kuang_", "设备号为:"+map.get("cai_ji_qi_id_")+"-"+map.get("cai_ji_qi_ming_ch")+" 的设备在一小时内温湿度连续超出限定范围,\n失控记录:\n"+beiZhu);
|
|
|
+ data.put("shi_fou_guo_shen_", "待处理");
|
|
|
+ data.put("create_by_","1");
|
|
|
+ data.put("bian_zhi_ren_","1");
|
|
|
+ data.put("yuan_shu_ju_id_",idStr);
|
|
|
+ commonDao.execute(SqlUtil.buildInsertSql(data,SKJLB));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void startFlowStep() {
|
|
|
+ String fetchSql = "SELECT id_ FROM t_sshjskycljlb WHERE shi_fou_guo_shen_ ='待处理' and DATE_FORMAT(create_time_,'%Y-%m-%d %H')=DATE_FORMAT(CURRENT_TIME,'%Y-%m-%d %H')";
|
|
|
+ List<Map<String, Object>> list = (List<Map<String, Object>>) commonDao.query(fetchSql);
|
|
|
+ if (BeanUtils.isEmpty(list)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ IBpmInstService bpmInstService = AppUtil.getBean(IBpmInstService.class);
|
|
|
+ if (StringUtils.isBlank(ContextUtil.getCurrentAccessToken())) {
|
|
|
+ ITenantTokenService tenantTokenService = AppUtil.getBean(ITenantTokenService.class);
|
|
|
+ String accessToken = tenantTokenService.getAccessToken();
|
|
|
+ ContextUtil.setCurrentAccessToken(accessToken);
|
|
|
+ }
|
|
|
+ for (Map<String, Object> objectMap : list) {
|
|
|
+ APIResult<String> result = bpmInstService.startFlowFromList(new String[]{(String)objectMap.get("id_")}, "sshjskycljlb", "Process_19ckgrn");
|
|
|
+ result.getState();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createDailyRecord(String parentId) throws Exception {
|
|
|
+ String sql = "SELECT cai_ji_qi_id_,cai_ji_ri_qi_,di_dian_ from t_dsfwsdjlb WHERE parent_id_='%s' GROUP BY cai_ji_ri_qi_,cai_ji_qi_id_";
|
|
|
+ sql = String.format(sql,parentId);
|
|
|
+ List<Map<String, Object>> wsdList = (List<Map<String, Object>>) commonDao.query(sql);
|
|
|
+ if (BeanUtils.isNotEmpty(wsdList)){
|
|
|
+ for (Map<String,Object> map : wsdList){
|
|
|
+ String sql2 = "SELECT *from t_dsfwsdjlb WHERE parent_id_='%s' and cai_ji_qi_id_='%s' and cai_ji_ri_qi_='%s' and HOUR(cai_ji_shi_jian_)='8' " +
|
|
|
+ " or (DATE_FORMAT(cai_ji_shi_jian_,'%%Y-%%m-%%d %%H:%%i')>=DATE_FORMAT(CONCAT('%s',' 15:30'),'%%Y-%%m-%%d %%H:%%i') " +
|
|
|
+ " and DATE_FORMAT(cai_ji_shi_jian_,'%%Y-%%m-%%d %%H:%%i')<=DATE_FORMAT(CONCAT('%s',' 16:30'),'%%Y-%%m-%%d %%H:%%i') ) ORDER BY cai_ji_shi_jian_ desc ";
|
|
|
+ sql2 = String.format(sql2,parentId,map.get("cai_ji_qi_id_"),map.get("cai_ji_ri_qi_"),map.get("cai_ji_ri_qi_"),map.get("cai_ji_ri_qi_"));
|
|
|
+ List<Map<String, Object>> list = (List<Map<String, Object>>) commonDao.query(sql2);
|
|
|
+ if (BeanUtils.isNotEmpty(list)){
|
|
|
+ addWsdData(list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addWsdData(List<Map<String, Object>> list) throws Exception {
|
|
|
+ for (Map<String,Object> map : list){
|
|
|
+ String deptId = BeanUtils.isEmpty(map.get("bu_men_id_"))?"":map.get("bu_men_id_").toString();
|
|
|
+ String type = map.get("shu_ju_lei_xing_").toString();
|
|
|
+ String leiXing = map.get("she_bei_lei_xing_").toString();
|
|
|
+ Map<String,Object> data = new HashMap<>();
|
|
|
+ data.put("id_", UniqueIdUtil.getId());
|
|
|
+ data.put("create_time_", shijian.format(new Date()));
|
|
|
+ data.put("bian_zhi_bu_men_", deptId);
|
|
|
+ data.put("shi_fou_guo_shen_", "已完成");
|
|
|
+ data.put("bian_zhi_ren_", "1");
|
|
|
+ data.put("di_dian_", map.get("di_dian_"));
|
|
|
+ data.put("bian_zhi_shi_jian", map.get("cai_ji_shi_jian_"));
|
|
|
+ data.put("bu_men_", deptId);
|
|
|
+ data.put("qu_yu_ming_cheng_", BeanUtils.isEmpty(map.get("qu_yu_"))?"":map.get("qu_yu_").toString());
|
|
|
+ boolean add = BeanUtils.isNotEmpty(map.get("zui_xiao_zhi_")) && BeanUtils.isNotEmpty(map.get("zui_da_zhi_")) && BeanUtils.isNotEmpty(map.get("wen_shi_du_zhi_"));
|
|
|
+ if (add){
|
|
|
+ double humMax = 0;double humMin = 0;double hum = 0;String humStatus="";String humLimit="";
|
|
|
+ if (type.equals("湿度")){
|
|
|
+ humMax = Double.parseDouble(map.get("zui_da_zhi_").toString());
|
|
|
+ humMin = Double.parseDouble(map.get("zui_xiao_zhi_").toString());
|
|
|
+ hum = Double.parseDouble(map.get("wen_shi_du_zhi_").toString());
|
|
|
+ humStatus = hum > humMax || hum < humMin ? "失控" : "正常";
|
|
|
+ humLimit = humMin + "~" + humMax + "%";
|
|
|
+ }
|
|
|
+ double tempMax = 0;double tempMin = 0;double temp = 0;String tempStatus="";String tempLimit="";
|
|
|
+ if (type.equals("温度")){
|
|
|
+ tempMax = Double.parseDouble(map.get("zui_da_zhi_").toString());
|
|
|
+ tempMin = Double.parseDouble(map.get("zui_xiao_zhi_").toString());
|
|
|
+ temp = Double.parseDouble(map.get("wen_shi_du_zhi_").toString());
|
|
|
+ tempStatus = temp > tempMax || temp < tempMin ? "失控" : "正常";
|
|
|
+ tempLimit = tempMin + "~" + tempMax + "℃";
|
|
|
+ }
|
|
|
+ String tempPart = !tempLimit.isEmpty() ? "温度:" + tempLimit : "";
|
|
|
+ String humPart = !humLimit.isEmpty() ? "湿度:" + humLimit : "";
|
|
|
+ String wenDuJianKong = (tempPart.isEmpty() ? "" : tempPart) + (humPart.isEmpty() ? "" : humPart);
|
|
|
+ if (leiXing.equals("冰箱")){
|
|
|
+ // 冰箱 t_bxwdjkjlb
|
|
|
+ addBxData(data,map,wenDuJianKong,tempStatus,tempMax,tempMin,temp);
|
|
|
+ }
|
|
|
+ if (leiXing.equals("环境")){
|
|
|
+ // 室内温湿度 t_snwsdjkjlb
|
|
|
+ addSnwsdData(data,map,wenDuJianKong,humStatus,tempStatus,tempMax,tempMin,temp,humMax,humMin,hum);
|
|
|
+ }
|
|
|
+ if (leiXing.equals("温浴箱")){
|
|
|
+ // 温浴箱(培养箱)温湿度 t_wyxwdjkywhjlb
|
|
|
+ addPyxData(data,map,wenDuJianKong,humStatus,tempStatus,tempMax,tempMin,temp,humMax,humMin,hum);
|
|
|
+ }
|
|
|
+ if (leiXing.equals("阴凉柜")){
|
|
|
+ // 阴凉柜温湿度记录---t_ylgwdjkjlb
|
|
|
+ addYlgData(data,map,wenDuJianKong,humStatus,tempStatus,tempMax,tempMin,temp,humMax,humMin,hum);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addYlgData(Map<String, Object> data,Map<String, Object> map,String wenDuJianKong,String humStatus,
|
|
|
+ String tempStatus,double tempMax,double tempMin,double temp,double humMax,double humMin,double hum) throws Exception {
|
|
|
+ if (!exist(YLGWSD,map.get("id_").toString(),"config_id_")){
|
|
|
+ data.put("yin_liang_gui_bia",map.get("cai_ji_qi_id_")+" "+map.get("cai_ji_qi_ming_ch"));
|
|
|
+ data.put("fang_jian_",BeanUtils.isEmpty(map.get("fang_jian_"))?"":map.get("fang_jian_").toString());
|
|
|
+ data.put("qu_yu_ming_cheng_", BeanUtils.isEmpty(map.get("qu_yu_"))?"":map.get("qu_yu_").toString());
|
|
|
+ data.put("gang_wei_", BeanUtils.isEmpty(map.get("gang_wei_"))?"":map.get("gang_wei_").toString());
|
|
|
+ data.put("config_id_", map.get("id_"));
|
|
|
+ data.put("jian_kong_she_bei", map.get("cai_ji_qi_id_"));
|
|
|
+ data.put("jian_she_bian_hao", map.get("cai_ji_qi_ming_ch"));
|
|
|
+ data.put("jian_ce_shi_jian_",map.get("cai_ji_shi_jian_"));
|
|
|
+ data.put("jian_ce_zhou_qi_","每日");
|
|
|
+ data.put("jian_ce_ri_qi_","每天");
|
|
|
+ data.put("ri_qi_lie_biao_","1,2,3,4,5,6,7");
|
|
|
+ data.put("shi_ji_shi_jian_", map.get("cai_ji_shi_jian_"));
|
|
|
+ data.put("wen_du_jian_kong_", wenDuJianKong);
|
|
|
+ data.put("shi_kong_zhuang_t",(humStatus.equals("失控")||tempStatus.equals("失控"))?"失控":"正常");
|
|
|
+
|
|
|
+ JSONArray params = new JSONArray();
|
|
|
+ if (BeanUtils.isNotEmpty(temp)){
|
|
|
+ params.add(setJsonList("temp",tempStatus,tempMax,tempMin,temp));
|
|
|
+ }
|
|
|
+ if (BeanUtils.isNotEmpty(hum)){
|
|
|
+ params.add(setJsonList("hum",humStatus,humMax,humMin,hum));
|
|
|
+ }
|
|
|
+ data.put("lie_biao_shu_ju_",params);
|
|
|
+ commonDao.execute(SqlUtil.buildInsertSql(data,YLGWSD));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addPyxData(Map<String, Object> data,Map<String, Object> map,String wenDuJianKong,String humStatus,
|
|
|
+ String tempStatus,double tempMax,double tempMin,double temp,double humMax,double humMin,double hum) throws Exception {
|
|
|
+ if (!exist(WYXWSD,map.get("id_").toString(),"config_id_")){
|
|
|
+ data.put("she_bei_ming_chen",map.get("cai_ji_qi_ming_ch"));
|
|
|
+ data.put("she_bei_bian_hao_",map.get("cai_ji_qi_id_"));
|
|
|
+ data.put("fang_jian_",BeanUtils.isEmpty(map.get("fang_jian_"))?"":map.get("fang_jian_").toString());
|
|
|
+ data.put("qu_yu_ming_cheng_", BeanUtils.isEmpty(map.get("qu_yu_"))?"":map.get("qu_yu_").toString());
|
|
|
+ data.put("gang_wei_", BeanUtils.isEmpty(map.get("gang_wei_"))?"":map.get("gang_wei_").toString());
|
|
|
+ data.put("config_id_", map.get("id_"));
|
|
|
+ data.put("jian_ce_zhou_qi_","每日");
|
|
|
+ data.put("ri_qi_lie_biao_","1,2,3,4,5,6,7");
|
|
|
+ data.put("shi_ji_shi_jian_", map.get("cai_ji_shi_jian_"));
|
|
|
+ data.put("wen_kong_zhi_fan_", wenDuJianKong);
|
|
|
+ data.put("shi_kong_zhuang_t",(humStatus.equals("失控")||tempStatus.equals("失控"))?"失控":"正常");
|
|
|
+
|
|
|
+ JSONArray params = new JSONArray();
|
|
|
+ if (BeanUtils.isNotEmpty(temp)){
|
|
|
+ params.add(setJsonList("temp",tempStatus,tempMax,tempMin,temp));
|
|
|
+ }
|
|
|
+ if (BeanUtils.isNotEmpty(hum)){
|
|
|
+ params.add(setJsonList("hum",humStatus,humMax,humMin,hum));
|
|
|
+ }
|
|
|
+ data.put("lie_biao_shu_ju_",params);
|
|
|
+ commonDao.execute(SqlUtil.buildInsertSql(data,WYXWSD));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addSnwsdData(Map<String, Object> data,Map<String, Object> map,String wenDuJianKong,String humStatus,
|
|
|
+ String tempStatus,double tempMax,double tempMin,double temp,double humMax,double humMin,double hum) throws Exception {
|
|
|
+ if (!exist(SNWSD,map.get("id_").toString(),"wai_jian_")){
|
|
|
+ data.put("fang_jian_hao_",BeanUtils.isEmpty(map.get("fang_jian_"))?"":map.get("fang_jian_").toString());
|
|
|
+ data.put("qu_yu_ming_cheng_", BeanUtils.isEmpty(map.get("qu_yu_"))?"":map.get("qu_yu_").toString());
|
|
|
+ data.put("gang_wei_", BeanUtils.isEmpty(map.get("gang_wei_"))?"":map.get("gang_wei_").toString());
|
|
|
+ data.put("wai_jian_", map.get("id_"));
|
|
|
+ data.put("jian_ce_zhou_qi_","每日");
|
|
|
+ data.put("jian_ce_ri_qi_","每天");
|
|
|
+ data.put("ri_qi_lie_biao_","1,2,3,4,5,6,7");
|
|
|
+ data.put("shi_ji_cao_zuo_sh", map.get("cai_ji_shi_jian_"));
|
|
|
+ data.put("wen_shi_du_kong_z", wenDuJianKong);
|
|
|
+ data.put("shi_kong_zhuang_t",(humStatus.equals("失控")||tempStatus.equals("失控"))?"失控":"正常");
|
|
|
+
|
|
|
+ JSONArray params = new JSONArray();
|
|
|
+ if (BeanUtils.isNotEmpty(temp)){
|
|
|
+ params.add(setJsonList("temp",tempStatus,tempMax,tempMin,temp));
|
|
|
+ }
|
|
|
+ if (BeanUtils.isNotEmpty(hum)){
|
|
|
+ params.add(setJsonList("hum",humStatus,humMax,humMin,hum));
|
|
|
+ }
|
|
|
+ data.put("lie_biao_shu_ju_",params);
|
|
|
+ commonDao.execute(SqlUtil.buildInsertSql(data,SNWSD));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addBxData(Map<String, Object> data,Map<String, Object> map,String wenDuJianKong,String status,double tempMax,double tempMin,double temp) throws Exception {
|
|
|
+ if (!exist(BXWD,map.get("id_").toString(),"config_id_")){
|
|
|
+ data.put("config_id_", map.get("id_"));
|
|
|
+ data.put("bing_xiang_bian_h", map.get("cai_ji_qi_id_")+" "+map.get("cai_ji_qi_ming_ch"));
|
|
|
+ data.put("wen_kong_zhi_fan_", wenDuJianKong);
|
|
|
+ data.put("shi_ji_shi_jian_", minute.format(minute.parse(map.get("cai_ji_shi_jian_").toString())));
|
|
|
+ data.put("yue_ri_qi_", riqi.format(minute.parse(map.get("cai_ji_shi_jian_").toString())));
|
|
|
+ data.put("shi_jian_shi_fen_", shifen.format(minute.parse(map.get("cai_ji_shi_jian_").toString())));
|
|
|
+ data.put("shi_kong_zhuang_t",status);
|
|
|
+ data.put("fang_jian_",BeanUtils.isEmpty(map.get("fang_jian_"))?"":map.get("fang_jian_").toString());
|
|
|
+ data.put("qu_yu_ming_cheng_", BeanUtils.isEmpty(map.get("qu_yu_"))?"":map.get("qu_yu_").toString());
|
|
|
+ data.put("gang_wei_", BeanUtils.isEmpty(map.get("gang_wei_"))?"":map.get("gang_wei_").toString());
|
|
|
+ data.put("jian_ce_zhou_qi_","每日");
|
|
|
+ data.put("jian_ce_ri_qi_","每周1,2,3,4,5,6,7");
|
|
|
+ data.put("ri_qi_lie_biao_","1,2,3,4,5,6,7");
|
|
|
+ JSONArray params = new JSONArray();
|
|
|
+ params.add(setJsonList("temp",status,tempMax,tempMin,temp));
|
|
|
+ data.put("lie_biao_shu_ju_",params);
|
|
|
+ commonDao.execute(SqlUtil.buildInsertSql(data,BXWD));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private JSONObject setJsonList(String type, String status, double max, double min, double value){
|
|
|
+ JSONObject tempObj = new JSONObject();
|
|
|
+ JSONArray tempRange = new JSONArray();
|
|
|
+ tempRange.add(min);
|
|
|
+ tempRange.add(max);
|
|
|
+ tempObj.put("range",tempRange);
|
|
|
+ tempObj.put("fixValue","");
|
|
|
+ tempObj.put("value",value);
|
|
|
+ tempObj.put("result",value);
|
|
|
+ tempObj.put("status",status);
|
|
|
+ tempObj.put("unit",type.equals("temp")?"℃":"%");
|
|
|
+ tempObj.put("label",type.equals("temp")?"温度":"湿度");
|
|
|
+ tempObj.put("rate","每天");
|
|
|
+ return tempObj;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean exist(String tableName,String id,String field){
|
|
|
+ Map<String,Object> his = commonDao.queryOne("select id_ from "+tableName+" where "+field+"='"+id+"'");
|
|
|
+ if (BeanUtils.isNotEmpty(his)){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+}
|