|  |  |  | 
|---|
|  |  |  | import com.fzzy.api.utils.ContextUtil; | 
|---|
|  |  |  | import com.fzzy.api.view.repository.Api1302Rep; | 
|---|
|  |  |  | import com.fzzy.api.view.repository.ApiLogRep; | 
|---|
|  |  |  | import com.fzzy.async.fzzy35.entity.Grain; | 
|---|
|  |  |  | import com.fzzy.async.fzzy35.entity.Fz35Grain; | 
|---|
|  |  |  | import com.fzzy.async.fzzy35.repository.Fzzy35Sync1302Rep; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.apache.commons.lang.StringUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Component; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 温湿度检测数据同步 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @author chen | 
|---|
|  |  |  | * @author czt | 
|---|
|  |  |  | * @date 2022-09-07 14:41 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | 
|---|
|  |  |  | apiLog.setStatus(99); | 
|---|
|  |  |  | apiLog.setId(ContextUtil.getUUID()); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | List<Grain> list = fzzySync1302Rep.findByReceiveDate(start, end); | 
|---|
|  |  |  | List<Fz35Grain> list = fzzySync1302Rep.findByReceiveDate(start, end); | 
|---|
|  |  |  | log.info(DateUtils.format("yyyy-MM-dd HH:mm:ss",start)); | 
|---|
|  |  |  | log.info(DateUtils.format("yyyy-MM-dd HH:mm:ss",end)); | 
|---|
|  |  |  | if (null == list || list.isEmpty()) { | 
|---|
|  |  |  | log.info("1302---同步数据:没有查询到需要同步的数据"); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | log.info(JSONObject.toJSONString(list)); | 
|---|
|  |  |  | Date syncTime = new Date(); | 
|---|
|  |  |  | Api1302 api1302; | 
|---|
|  |  |  | Api1105 api1105; | 
|---|
|  |  |  | //int index = 10001; | 
|---|
|  |  |  | for (Grain grain : list) { | 
|---|
|  |  |  | List<Api1302> api1302List; | 
|---|
|  |  |  | for (Fz35Grain fz35Grain : list) { | 
|---|
|  |  |  | //获取货位信息 | 
|---|
|  |  |  | api1105 = commonService.getApi1105Cache(grain.getDepotId()); | 
|---|
|  |  |  | api1105 = commonService.getApi1105Cache(fz35Grain.getDepotId()); | 
|---|
|  |  |  | if (null == api1105) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | //由货位代码+检测日期     (yyyyMMdd) +4 位顺序号组成  --2019 1128 0819 | 
|---|
|  |  |  | api1302 = new Api1302(); | 
|---|
|  |  |  | //api1302.setWsdjcdh(api1105.getHwdm() + DateFormatUtils.format(grain.getReceiveDate(), "yyyyMMdd") + String.valueOf(index).substring(1)); | 
|---|
|  |  |  | api1302.setWsdjcdh(api1105.getHwdm() + grain.getBatchId()); | 
|---|
|  |  |  | api1302.setJcsj(grain.getReceiveDate()); | 
|---|
|  |  |  | api1302.setWsdjcdh(api1105.getHwdm() + fz35Grain.getBatchId()); | 
|---|
|  |  |  | api1302.setJcsj(fz35Grain.getReceiveDate()); | 
|---|
|  |  |  | api1302.setHwdm(api1105.getHwdm()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | api1302.setCfww(grain.getTempOut() == null ? 0.00:grain.getTempOut()); | 
|---|
|  |  |  | if(null == grain.getHumidityOut() || grain.getHumidityOut() < 0){ | 
|---|
|  |  |  | api1302.setCfws(-1); | 
|---|
|  |  |  | api1302.setCfww(fz35Grain.getTempOut() == null ? 0.00: fz35Grain.getTempOut()); | 
|---|
|  |  |  | if(null == fz35Grain.getHumidityOut() || fz35Grain.getHumidityOut() < 0){ | 
|---|
|  |  |  | api1302.setCfws(0); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | api1302.setCfws(grain.getHumidityOut()); | 
|---|
|  |  |  | api1302.setCfws(fz35Grain.getHumidityOut()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | api1302.setCfnw(grain.getTempIn() == null ? 0.00:grain.getTempIn()); | 
|---|
|  |  |  | if(null == grain.getHumidityIn() || grain.getHumidityIn() < 0){ | 
|---|
|  |  |  | api1302.setCfns(-1); | 
|---|
|  |  |  | api1302.setCfnw(fz35Grain.getTempIn() == null ? 0.00: fz35Grain.getTempIn()); | 
|---|
|  |  |  | if(null == fz35Grain.getHumidityIn() || fz35Grain.getHumidityIn() < 0){ | 
|---|
|  |  |  | api1302.setCfns(0); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | api1302.setCfns(grain.getHumidityIn()); | 
|---|
|  |  |  | api1302.setCfns(fz35Grain.getHumidityIn()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | api1302.setLszgw(grain.getTempMax() == null ? 0.00:grain.getTempMax()); | 
|---|
|  |  |  | api1302.setLspjw(grain.getTempAve() == null ? 0.00:grain.getTempAve()); | 
|---|
|  |  |  | api1302.setLszdw(grain.getTempMin() == null ? 0.00:grain.getTempMin()); | 
|---|
|  |  |  | api1302.setLszgw(fz35Grain.getTempMax() == null ? 0.00: fz35Grain.getTempMax()); | 
|---|
|  |  |  | api1302.setLspjw(fz35Grain.getTempAve() == null ? 0.00: fz35Grain.getTempAve()); | 
|---|
|  |  |  | api1302.setLszdw(fz35Grain.getTempMin() == null ? 0.00: fz35Grain.getTempMin()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //判断粮食最低温、平均温、最高温是否符合逻辑 | 
|---|
|  |  |  | if(api1302.getLszdw() >= api1302.getLspjw()){ | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(api1302.getLspjw() >= api1302.getLszgw()){ | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //温度集合 | 
|---|
|  |  |  | if (StringUtils.isEmpty(grain.getCableCir())) { | 
|---|
|  |  |  | api1302.setLswdzjh(getTempPointList1(grain.getPoints(), grain.getCable())); | 
|---|
|  |  |  | api1302.setLssdzjh(getHumPointList1(grain.getPoints(), grain.getCable())); | 
|---|
|  |  |  | if (StringUtils.isEmpty(fz35Grain.getCableCir())) { | 
|---|
|  |  |  | api1302.setLswdzjh(getTempPointList1(fz35Grain.getPoints(), fz35Grain.getCable())); | 
|---|
|  |  |  | api1302.setLssdzjh(getHumPointList1(fz35Grain.getPoints(), fz35Grain.getCable())); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | api1302.setLswdzjh(getTempPointList2(grain.getPoints(), grain.getCable(), grain.getCableCir())); | 
|---|
|  |  |  | api1302.setLssdzjh(getHumPointList2(grain.getPoints(), grain.getCable(), grain.getCableCir())); | 
|---|
|  |  |  | api1302.setLswdzjh(getTempPointList2(fz35Grain.getPoints(), fz35Grain.getCable(), fz35Grain.getCableCir())); | 
|---|
|  |  |  | api1302.setLssdzjh(getHumPointList2(fz35Grain.getPoints(), fz35Grain.getCable(), fz35Grain.getCableCir())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | api1302.setCzbz(Constant.CZBZ_I); | 
|---|
|  |  |  | api1302.setZhgxsj(syncTime); | 
|---|
|  |  |  | api1302.setZhgxsj(fz35Grain.getReceiveDate()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | api1302.setBizId(grain.getBatchId()); | 
|---|
|  |  |  | api1302.setBizId(fz35Grain.getBatchId()); | 
|---|
|  |  |  | api1302.setKqdm(api1105.getKqdm()); | 
|---|
|  |  |  | api1302.setSyncTime(syncTime); | 
|---|
|  |  |  | api1302List = api1302Rep.getDataByWsdjcdh(api1302.getWsdjcdh()); | 
|---|
|  |  |  | if(null == api1302List || api1302List.isEmpty()){ | 
|---|
|  |  |  | api1302.setCzbz(Constant.CZBZ_I); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | api1302.setCzbz(api1302List.get(0).getCzbz()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | log.info("1302---同步数据:" + api1302.toString()); | 
|---|
|  |  |  | api1302Rep.save(api1302); | 
|---|
|  |  |  | // index++; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String[] points = point.split(","); | 
|---|
|  |  |  | String result = ""; | 
|---|
|  |  |  | if (c * h * l > points.length) { | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (int i = 1; i <= l; i++) { | 
|---|
|  |  |  | for (int j = 1; j <= h; j++) { | 
|---|
|  |  |  | for (int z = 1; z <= c; z++) { | 
|---|
|  |  |  | result += ("|" + points[(i * j - 1) * c + z - 1] + "," + z + "," + j + "," + i); | 
|---|
|  |  |  | result += ("|" + points[((i-1)*h+j-1)*c + z -1] + "," + z + "," + j + "," + i); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | int g = 0;  //圈根数 | 
|---|
|  |  |  | int g1 = 1;  //圈起始根数 | 
|---|
|  |  |  | int g2 = 0;  //圈截止根数 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | int genNum = 0; | 
|---|
|  |  |  | for (String s : cab) { | 
|---|
|  |  |  | genNum += Integer.valueOf(s); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String[] points = point.split(","); | 
|---|
|  |  |  | String result = ""; | 
|---|
|  |  |  | if (c * genNum > points.length) { | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (int i = 1; i <= q; i++) { | 
|---|
|  |  |  | g1 += g2; | 
|---|
|  |  |  | g = Integer.valueOf(cab[i - 1]); | 
|---|