|
@@ -0,0 +1,408 @@
|
|
|
|
+package com.huimv.dataprocess2;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.huimv.eartag2.common.dao.entity.*;
|
|
|
|
+import com.huimv.eartag2.common.dao.repo.*;
|
|
|
|
+import com.huimv.eartag2.common.service.IBaseConfigService;
|
|
|
|
+import com.huimv.eartag2.common.utils.DateUtil;
|
|
|
|
+import org.junit.Test;
|
|
|
|
+import org.junit.runner.RunWith;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
+import org.springframework.data.domain.Example;
|
|
|
|
+import org.springframework.test.context.junit4.SpringRunner;
|
|
|
|
+
|
|
|
|
+import java.io.*;
|
|
|
|
+import java.sql.Array;
|
|
|
|
+import java.sql.Date;
|
|
|
|
+import java.sql.Timestamp;
|
|
|
|
+import java.text.ParseException;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.Optional;
|
|
|
|
+import java.util.regex.Matcher;
|
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @Project : huimv.shiwan
|
|
|
|
+ * @Package : com.huimv.biosafety.uface.controller
|
|
|
|
+ * @Description : TODO
|
|
|
|
+ * @Version : 1.0
|
|
|
|
+ * @Author : ZhuoNing
|
|
|
|
+ * @Create : 2020-12-25
|
|
|
|
+ **/
|
|
|
|
+@SpringBootTest
|
|
|
|
+@RunWith(SpringRunner.class)
|
|
|
|
+public class DataProcess2Test {
|
|
|
|
+ @Autowired
|
|
|
|
+ private EartagDataRepo2 eartagDataRepo2;
|
|
|
|
+ private static String eartagFile = "D:/6/goldpig.txt";
|
|
|
|
+ @Autowired
|
|
|
|
+ private IBaseConfigService iBaseConfigService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private EartagHourActEntityRepo eartagHourActEntityRepo;
|
|
|
|
+ @Autowired
|
|
|
|
+ private EartagResetEntityRepo eartagResetEntityRepo;
|
|
|
|
+ @Autowired
|
|
|
|
+ private EartagResetCountEntityRepo eartagResetCountEntityRepo;
|
|
|
|
+ @Autowired
|
|
|
|
+ private EartagEartagRegister2EntityRepo eartagEartagRegister2EntityRepo;
|
|
|
|
+
|
|
|
|
+// @Test
|
|
|
|
+// public void exportData() throws IOException {
|
|
|
|
+// System.out.println("开始导出数据...");
|
|
|
|
+// List<EartagDataEntity2> EartagDataEntityList = eartagDataRepo2.findAll();
|
|
|
|
+// System.out.println("EartagDataEntityList.size=" + EartagDataEntityList.size());
|
|
|
|
+// for (EartagDataEntity2 eartagDataEntity : EartagDataEntityList) {
|
|
|
|
+// System.out.println("" + eartagDataEntity.toString());
|
|
|
|
+// writeTxt(JSON.toJSONString(eartagDataEntity));
|
|
|
|
+// }
|
|
|
|
+// System.out.println("完成导出数据.");
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+ // 导入耳标注册表
|
|
|
|
+ @Test
|
|
|
|
+ public void buildEartagRegisterData() throws IOException, ParseException {
|
|
|
|
+ List<EartagDataEntity2> EartagDataEntityList = eartagDataRepo2.findAllByGoldPig();
|
|
|
|
+ System.out.println("EartagDataEntityList.size="+EartagDataEntityList.size());
|
|
|
|
+ String farmCode = "330112004";
|
|
|
|
+ List<EartagEartagRegister2Entity> eartagRegisterList = eartagEartagRegister2EntityRepo.getEartagRegisterByFarmCode(farmCode);
|
|
|
|
+ System.out.println("eartagRegisterList.size="+eartagRegisterList.size());
|
|
|
|
+ List<EartagDataEntity2> newList = new ArrayList();
|
|
|
|
+ for(EartagDataEntity2 eartagDataEntity2:EartagDataEntityList) {
|
|
|
|
+// System.out.println(a+" "+eartagDataEntity2.getEarmark()+","+eartagDataEntity2.getAddTime());
|
|
|
|
+ if (eartagDataEntity2.getEarmark().length() == 15 && (eartagDataEntity2.getEarmark().indexOf("1332022109003") != -1 || eartagDataEntity2.getEarmark().indexOf("1332022109004") != -1) && !judgeContainsStr(eartagDataEntity2.getEarmark())) {
|
|
|
|
+// String earmark = eartagDataEntity2.getEarmark();
|
|
|
|
+ boolean isExist = false;
|
|
|
|
+ for(EartagDataEntity2 lastEartagDataEntity2:newList){
|
|
|
|
+ if(eartagDataEntity2.getEarmark().trim().equalsIgnoreCase(lastEartagDataEntity2.getEarmark())){
|
|
|
|
+ newList.remove(lastEartagDataEntity2);
|
|
|
|
+ isExist = true;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(!isExist){
|
|
|
|
+ newList.add(eartagDataEntity2);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ System.out.println("newList.size="+newList.size());
|
|
|
|
+ List<EartagDataEntity2> newList2 = new ArrayList();
|
|
|
|
+ for(EartagDataEntity2 eartagDataEntity2:newList){
|
|
|
|
+ boolean isExist = false;
|
|
|
|
+ for(EartagEartagRegister2Entity eartagEartagRegister2Entity:eartagRegisterList){
|
|
|
|
+ if(eartagEartagRegister2Entity.getEarmark().trim().equalsIgnoreCase(eartagDataEntity2.getEarmark())){
|
|
|
|
+ isExist = true;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(!isExist){
|
|
|
|
+ newList2.add(eartagDataEntity2);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ System.out.println("newList2.size="+newList2.size());
|
|
|
|
+ // 迁移之后未上传数据的耳标(未注册的耳标)
|
|
|
|
+ List<EartagEartagRegister2Entity> unregisterEartagList = new ArrayList();
|
|
|
|
+ for(EartagDataEntity2 uneartagDataEntity2:newList2){
|
|
|
|
+ System.out.println(""+uneartagDataEntity2.toString());
|
|
|
|
+ EartagEartagRegister2Entity newEartagEartagRegister2Entity = new EartagEartagRegister2Entity();
|
|
|
|
+ unregisterEartagList.add(newEartagEartagRegister2Entity);
|
|
|
|
+// System.out.println("newEartagEartagRegister2Entity.getEarmark="+newEartagEartagRegister2Entity.getEarmark());
|
|
|
|
+// if(newEartagEartagRegister2Entity.getEarmark() == null){
|
|
|
|
+// System.out.println("==null");
|
|
|
|
+// }else{
|
|
|
|
+// System.out.println("!=null");
|
|
|
|
+// }
|
|
|
|
+ for(EartagDataEntity2 eartagDataEntity2:EartagDataEntityList) {
|
|
|
|
+ if(uneartagDataEntity2.getEarmark().trim().equalsIgnoreCase(eartagDataEntity2.getEarmark())){
|
|
|
|
+ if(newEartagEartagRegister2Entity.getEarmark() == null){
|
|
|
|
+ newEartagEartagRegister2Entity.setEarmark(uneartagDataEntity2.getEarmark());
|
|
|
|
+ newEartagEartagRegister2Entity.setFirstTime(eartagDataEntity2.getAddTime());
|
|
|
|
+ newEartagEartagRegister2Entity.setFirstDevice(eartagDataEntity2.getDevice());
|
|
|
|
+ newEartagEartagRegister2Entity.setRegisterTime(eartagDataEntity2.getAddTime());
|
|
|
|
+ newEartagEartagRegister2Entity.setFarmId(farmCode);
|
|
|
|
+ newEartagEartagRegister2Entity.setActiveStatus(1);
|
|
|
|
+ newEartagEartagRegister2Entity.setActiveTime(eartagDataEntity2.getAddTime());
|
|
|
|
+ newEartagEartagRegister2Entity.setLiveStatus(1);
|
|
|
|
+ newEartagEartagRegister2Entity.setCreateDate(eartagDataEntity2.getCreateDate());
|
|
|
|
+ newEartagEartagRegister2Entity.setBat(eartagDataEntity2.getBat());
|
|
|
|
+ newEartagEartagRegister2Entity.setEarTemp1(eartagDataEntity2.getEarTemp1());
|
|
|
|
+ newEartagEartagRegister2Entity.setEnvTemp1(eartagDataEntity2.getEnvTemp1());
|
|
|
|
+ newEartagEartagRegister2Entity.setAct(new Long(eartagDataEntity2.getAct()));
|
|
|
|
+ newEartagEartagRegister2Entity.setSignal1(eartagDataEntity2.getSignal1());
|
|
|
|
+ newEartagEartagRegister2Entity.setOther(eartagDataEntity2.getOther());
|
|
|
|
+ newEartagEartagRegister2Entity.setAskTime(eartagDataEntity2.getAskTime());
|
|
|
|
+ newEartagEartagRegister2Entity.setPigpenId(51);
|
|
|
|
+ newEartagEartagRegister2Entity.setPigpenName("测试一栋");
|
|
|
|
+ newEartagEartagRegister2Entity.setUnitId(52);
|
|
|
|
+ newEartagEartagRegister2Entity.setUnitName("测试一单元");
|
|
|
|
+ newEartagEartagRegister2Entity.setStageCode("4");
|
|
|
|
+ newEartagEartagRegister2Entity.setStageName("育成育肥");
|
|
|
|
+ }else{
|
|
|
|
+ newEartagEartagRegister2Entity.setLastTime(eartagDataEntity2.getAddTime());
|
|
|
|
+ newEartagEartagRegister2Entity.setBelongDevice(eartagDataEntity2.getDevice());
|
|
|
|
+ newEartagEartagRegister2Entity.setLastDevice(eartagDataEntity2.getDevice());
|
|
|
|
+ newEartagEartagRegister2Entity.setActiveStatus(1);
|
|
|
|
+ newEartagEartagRegister2Entity.setActiveTime(eartagDataEntity2.getAddTime());
|
|
|
|
+ newEartagEartagRegister2Entity.setLiveStatus(1);
|
|
|
|
+ newEartagEartagRegister2Entity.setBat(eartagDataEntity2.getBat());
|
|
|
|
+ newEartagEartagRegister2Entity.setEarTemp1(eartagDataEntity2.getEarTemp1());
|
|
|
|
+ newEartagEartagRegister2Entity.setEnvTemp1(eartagDataEntity2.getEnvTemp1());
|
|
|
|
+ newEartagEartagRegister2Entity.setAct(new Long(eartagDataEntity2.getAct()));
|
|
|
|
+ newEartagEartagRegister2Entity.setSignal1(eartagDataEntity2.getSignal1());
|
|
|
|
+ newEartagEartagRegister2Entity.setOther(eartagDataEntity2.getOther());
|
|
|
|
+ newEartagEartagRegister2Entity.setAskTime(eartagDataEntity2.getAskTime());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ int b=0;
|
|
|
|
+ for(EartagEartagRegister2Entity eartagEartagRegister2Entity:unregisterEartagList){
|
|
|
|
+ System.out.println((++b)+","+eartagEartagRegister2Entity.toString());
|
|
|
|
+ eartagEartagRegister2EntityRepo.saveAndFlush(eartagEartagRegister2Entity);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testList(){
|
|
|
|
+
|
|
|
|
+// List<String> newList = new ArrayList();
|
|
|
|
+// newList.add("1");
|
|
|
|
+// newList.add("2");
|
|
|
|
+// newList.add("3");
|
|
|
|
+// newList.add("4");
|
|
|
|
+//
|
|
|
|
+// for(int a=0;a<newList.size();a++){
|
|
|
|
+// if(newList.get(a).trim().equalsIgnoreCase("3")){
|
|
|
|
+// newList.remove(a);
|
|
|
|
+// newList.add("5");
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+// System.out.println("newList.toString()="+newList.toString());
|
|
|
|
+
|
|
|
|
+ System.out.println("133202210900369a="+judgeContainsStr("133202210900369a"));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 生成小时运动量数据
|
|
|
|
+ @Test
|
|
|
|
+ public void buildHourActData() throws IOException, ParseException {
|
|
|
|
+ DateUtil du = new DateUtil();
|
|
|
|
+// int nowHour = du.getNowHour();
|
|
|
|
+ String farmId = "330112004";
|
|
|
|
+ // 小时
|
|
|
|
+ int eartagOfflineTime = 24;
|
|
|
|
+// Optional<SysBaseConfigEntity> optionalConfig = sysBaseConfigEntityRepo.getConfigValue("dropDataEartagOffLineTime");
|
|
|
|
+// if (optionalConfig.isPresent()) {
|
|
|
|
+// eartagOfflineTime = Integer.parseInt(optionalConfig.get().getConfigValue());
|
|
|
|
+// log.info("耳标离线过程丢弃数据时长=" + eartagOfflineTime);
|
|
|
|
+// } else {
|
|
|
|
+// log.error("耳标离线过程丢弃数据时长属性未配置.");
|
|
|
|
+// }
|
|
|
|
+ Map configMap = iBaseConfigService.getConfigValue("dropDataEartagOffLineTime",farmId,"0");
|
|
|
|
+ System.out.println("configMap >>>>>>>>>>>>>>>>>>>>> "+configMap.toString());
|
|
|
|
+ if(configMap == null){
|
|
|
|
+ System.out.println("耳标离线过程丢弃数据时长属性未配置.采用默认配置参数 eartagOfflineTime="+eartagOfflineTime);
|
|
|
|
+ }else{
|
|
|
|
+ eartagOfflineTime = Integer.parseInt(configMap.get("configValue")+"");
|
|
|
|
+ System.out.println("eartagOfflineTime >>>>>>>>>>>> "+eartagOfflineTime);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<EartagDataEntity2> EartagDataEntityList = eartagDataRepo2.findAllByGoldPig();
|
|
|
|
+ System.out.println("EartagDataEntityList.size="+EartagDataEntityList.size());
|
|
|
|
+ int a=0;
|
|
|
|
+// String todayDateText = new DateUtil().getTodayDateText();
|
|
|
|
+// java.sql.Date todayDate = new java.sql.Date(new java.util.Date().getTime());
|
|
|
|
+// Timestamp nowTimestamp = new Timestamp(new java.util.Date().getTime());
|
|
|
|
+ List<EartagDataEntity2> newList = new ArrayList();
|
|
|
|
+ for(EartagDataEntity2 eartagDataEntity2:EartagDataEntityList){
|
|
|
|
+// System.out.println(a+" "+eartagDataEntity2.getEarmark()+","+eartagDataEntity2.getAddTime());
|
|
|
|
+ if(eartagDataEntity2.getEarmark().length() == 15 && (eartagDataEntity2.getEarmark().indexOf("1332022109003") != -1 || eartagDataEntity2.getEarmark().indexOf("1332022109004") != -1) && !judgeContainsStr(eartagDataEntity2.getEarmark())){
|
|
|
|
+ String earmark = eartagDataEntity2.getEarmark();
|
|
|
|
+ Integer act = eartagDataEntity2.getAct();
|
|
|
|
+ System.out.println("earmark=" + earmark);
|
|
|
|
+ System.out.println("本次运动量=" + act);
|
|
|
|
+ System.out.println("farmId=" + farmId);
|
|
|
|
+ Timestamp nowTimestamp = eartagDataEntity2.getAddTime();
|
|
|
|
+ Date date = eartagDataEntity2.getCreateDate();
|
|
|
|
+ int nowHour = du.setCalendarNewTime(eartagDataEntity2.getAddTime());
|
|
|
|
+ System.out.println("nowHour=" + nowHour);
|
|
|
|
+
|
|
|
|
+ //生成运动量
|
|
|
|
+ for(EartagDataEntity2 lastEartagDataEntity2:newList){
|
|
|
|
+ if(eartagDataEntity2.getEarmark().trim().equalsIgnoreCase(lastEartagDataEntity2.getEarmark())){
|
|
|
|
+ Integer lastAct = lastEartagDataEntity2.getAct();
|
|
|
|
+ System.out.println("上次运动量=" + lastAct);
|
|
|
|
+ Timestamp lastAddTime = lastEartagDataEntity2.getAddTime();
|
|
|
|
+ long timeDiff = nowTimestamp.getTime() - lastAddTime.getTime();
|
|
|
|
+ if (timeDiff / (1000 * 60 * 60) < eartagOfflineTime) {
|
|
|
|
+ long act1 = 0;
|
|
|
|
+ boolean resetStatus = false;
|
|
|
|
+ if (act < lastAct) {
|
|
|
|
+ act1 = act;
|
|
|
|
+ resetStatus = true;
|
|
|
|
+ } else {
|
|
|
|
+ act1 = act - lastAct;
|
|
|
|
+ }
|
|
|
|
+ System.out.println("本次运动量增量=" + act1);
|
|
|
|
+ //{保存耳标小时运动量}
|
|
|
|
+ saveEartagHourAct(farmId, earmark, act1, nowHour, date);
|
|
|
|
+ //{保存耳标复位记录}
|
|
|
|
+ saveEartagReset(resetStatus, farmId, earmark, nowTimestamp, date, null, lastAct, act);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //删除上一次数据
|
|
|
|
+ newList.remove(lastEartagDataEntity2);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ newList.add(eartagDataEntity2);
|
|
|
|
+
|
|
|
|
+// if(a==100){
|
|
|
|
+// break;
|
|
|
|
+// }
|
|
|
|
+ a++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ System.out.println("newList.size="+newList.size());
|
|
|
|
+ for(EartagDataEntity2 newEartagDataEntity2:newList){
|
|
|
|
+ System.out.println(""+newEartagDataEntity2.toString());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //{保存耳标复位记录}
|
|
|
|
+ private void saveEartagReset(boolean resetStatus, String farmId, String earmark, Timestamp nowTimestamp, java.sql.Date todayDate, Integer lastId, int lastAct, int act) {
|
|
|
|
+ if (resetStatus) {
|
|
|
|
+ // 保存复位记录
|
|
|
|
+ EartagResetEntity eartagResetEntity = new EartagResetEntity();
|
|
|
|
+ eartagResetEntity.setEarmark(earmark);
|
|
|
|
+ eartagResetEntity.setAddDate(todayDate);
|
|
|
|
+ eartagResetEntity.setResetTime(nowTimestamp);
|
|
|
|
+ eartagResetEntity.setFarmCode(farmId);
|
|
|
|
+ eartagResetEntity.setLastId(lastId);
|
|
|
|
+ eartagResetEntity.setLastAct(new Long(lastAct));
|
|
|
|
+ eartagResetEntity.setAct(new Long(act));
|
|
|
|
+ System.out.println("saveEartagReset:1 "+eartagResetEntity.toString());
|
|
|
|
+ eartagResetEntityRepo.save(eartagResetEntity);
|
|
|
|
+
|
|
|
|
+ // 复位统计次数
|
|
|
|
+ EartagResetCountEntity eartagResetCountEntity = new EartagResetCountEntity();
|
|
|
|
+ eartagResetCountEntity.setEarmark(earmark);
|
|
|
|
+ eartagResetCountEntity.setFarmCode(farmId);
|
|
|
|
+ eartagResetCountEntity.setAddDate(todayDate);
|
|
|
|
+ Example<EartagResetCountEntity> example = Example.of(eartagResetCountEntity);
|
|
|
|
+ Optional<EartagResetCountEntity> optionEartagResetCountEntity = eartagResetCountEntityRepo.findOne(example);
|
|
|
|
+ if (!optionEartagResetCountEntity.isPresent()) {
|
|
|
|
+ eartagResetCountEntity.setTimes(1);
|
|
|
|
+ System.out.println("saveEartagReset:2 "+eartagResetCountEntity.toString());
|
|
|
|
+ eartagResetCountEntityRepo.save(eartagResetCountEntity);
|
|
|
|
+ } else {
|
|
|
|
+ EartagResetCountEntity existEartagResetCountEntity = optionEartagResetCountEntity.get();
|
|
|
|
+ existEartagResetCountEntity.setTimes(existEartagResetCountEntity.getTimes() + 1);
|
|
|
|
+ System.out.println("saveEartagReset:3 "+existEartagResetCountEntity.toString());
|
|
|
|
+ eartagResetCountEntityRepo.save(existEartagResetCountEntity);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // {保存耳标小时运动量}
|
|
|
|
+ private void saveEartagHourAct(String farmId, String earmark, long act1, int nowHour, java.sql.Date todayDate) {
|
|
|
|
+ Optional<EartagHourActEntity> optionalHourAct = eartagHourActEntityRepo.findByFarmIdAndEarmarkAndHourAndDate(farmId, earmark, nowHour, todayDate);
|
|
|
|
+ if (!optionalHourAct.isPresent()) {
|
|
|
|
+ EartagHourActEntity newEartagHourActEntity = new EartagHourActEntity();
|
|
|
|
+ newEartagHourActEntity.setFarmCode(farmId);
|
|
|
|
+ newEartagHourActEntity.setEarmark(earmark);
|
|
|
|
+ newEartagHourActEntity.setAddDate(todayDate);
|
|
|
|
+ newEartagHourActEntity.setHour(nowHour);
|
|
|
|
+ newEartagHourActEntity.setAct(act1);
|
|
|
|
+ System.out.println("saveEartagHourAct:1 "+newEartagHourActEntity.toString());
|
|
|
|
+ eartagHourActEntityRepo.save(newEartagHourActEntity);
|
|
|
|
+ } else {
|
|
|
|
+ EartagHourActEntity eartagHourActEntity = optionalHourAct.get();
|
|
|
|
+ eartagHourActEntity.setAct(eartagHourActEntity.getAct() + act1);
|
|
|
|
+ System.out.println("saveEartagHourAct:2 "+eartagHourActEntity.toString());
|
|
|
|
+ eartagHourActEntityRepo.save(eartagHourActEntity);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public boolean judgeContainsStr(String str) {
|
|
|
|
+ String regex=".*[a-zA-Z]+.*";
|
|
|
|
+ Matcher m= Pattern.compile(regex).matcher(str);
|
|
|
|
+ return m.matches();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void importData() throws IOException, ParseException {
|
|
|
|
+ System.out.println("开始导入数据>>");
|
|
|
|
+ JSONArray eartagJa = readLineTxt();
|
|
|
|
+ System.out.println("eartagJa.size=" + eartagJa.size());
|
|
|
|
+ for(int a=0;a<eartagJa.size();a++){
|
|
|
|
+ JSONObject dataJo =eartagJa.getJSONObject(a);
|
|
|
|
+// System.out.println("time="+dataJo.getString("time"));
|
|
|
|
+ DateUtil du = new DateUtil();
|
|
|
|
+ String datetime = du.formatLongToDate(dataJo.getLong("time"));
|
|
|
|
+// System.out.println("datetime="+datetime);
|
|
|
|
+ String date = du.formatDateText(datetime);
|
|
|
|
+// System.out.println("date="+date);
|
|
|
|
+// du.parseDate(date);
|
|
|
|
+// System.out.println("time2 = "+new Date(dataJo.getLong("time")));
|
|
|
|
+// if(a == 5){
|
|
|
|
+// break;
|
|
|
|
+// }
|
|
|
|
+ System.out.println(""+dataJo.toString());
|
|
|
|
+ EartagDataEntity2 eartagDataEntity2 = new EartagDataEntity2();
|
|
|
|
+ eartagDataEntity2.setAct(dataJo.getInteger("oldExercise"));
|
|
|
|
+ eartagDataEntity2.setAct1(dataJo.getInteger("exercise"));
|
|
|
|
+ eartagDataEntity2.setAddTime(new Timestamp(du.parseDateTime(datetime).getTime()));
|
|
|
|
+ eartagDataEntity2.setCreateDate(new Date(dataJo.getLong("time")));
|
|
|
|
+ eartagDataEntity2.setAskTime(datetime);
|
|
|
|
+ eartagDataEntity2.setAskDate(new Date(dataJo.getLong("time")));
|
|
|
|
+ eartagDataEntity2.setBat(dataJo.getInteger("bat"));
|
|
|
|
+ eartagDataEntity2.setCmdHeader(dataJo.getString("head"));
|
|
|
|
+
|
|
|
|
+ eartagDataEntity2.setDevice(dataJo.getString("deviceCode"));
|
|
|
|
+ eartagDataEntity2.setEarmark(dataJo.getString("eartagNo"));
|
|
|
|
+ eartagDataEntity2.setEarTemp(1);
|
|
|
|
+ eartagDataEntity2.setEarTemp1(dataJo.getFloat("earTemp"));
|
|
|
|
+// eartagDataEntity2.setEnvTemp();
|
|
|
|
+ eartagDataEntity2.setEnvTemp1(dataJo.getFloat("envTemp"));
|
|
|
|
+ eartagDataEntity2.setFarmId("330112004");
|
|
|
|
+ eartagDataEntity2.setOther(dataJo.getString("prepareField"));
|
|
|
|
+ eartagDataEntity2.setSignal1(dataJo.getInteger("rssi"));
|
|
|
|
+// eartagDataRepo2.saveAndFlush(eartagDataEntity2);
|
|
|
|
+ }
|
|
|
|
+ System.out.println("完成导出数据<<");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public JSONArray readLineTxt() throws IOException {
|
|
|
|
+ String s = "";
|
|
|
|
+ InputStreamReader in = new InputStreamReader(new FileInputStream(new File(eartagFile)), "UTF-8");
|
|
|
|
+ BufferedReader br = new BufferedReader(in);
|
|
|
|
+ StringBuffer content = new StringBuffer();
|
|
|
|
+ JSONArray eartaJa = new JSONArray();
|
|
|
|
+ while ((s = br.readLine()) != null) {
|
|
|
|
+// content = content.append(s);
|
|
|
|
+// System.out.println("content=" + s);
|
|
|
|
+ JSONObject dataJo = JSON.parseObject(s);
|
|
|
|
+ eartaJa.add(dataJo);
|
|
|
|
+ }
|
|
|
|
+ return eartaJa;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void writeTxt(String conent) throws IOException {
|
|
|
|
+ File f = new File(eartagFile);
|
|
|
|
+ if (f.exists()) {
|
|
|
|
+ } else {
|
|
|
|
+ f.createNewFile();// 不存在则创建
|
|
|
|
+ }
|
|
|
|
+ BufferedWriter output = new BufferedWriter(new FileWriter(f, true));//true,则追加写入text文本
|
|
|
|
+ output.write(conent);
|
|
|
|
+ output.write("\r\n");//换行
|
|
|
|
+ output.flush();
|
|
|
|
+ output.close();
|
|
|
|
+ }
|
|
|
|
+}
|