|
@@ -13,6 +13,7 @@ import com.huimv.input.utils.ModBusUtils;
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
import io.netty.buffer.Unpooled;
|
|
|
import io.netty.channel.*;
|
|
|
+import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
@@ -21,9 +22,13 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import javax.lang.model.element.VariableElement;
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.nio.channels.SocketChannel;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.time.LocalTime;
|
|
|
+import java.time.ZoneOffset;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
@@ -41,7 +46,7 @@ import java.util.stream.Collectors;
|
|
|
@ChannelHandler.Sharable
|
|
|
@Component
|
|
|
@Slf4j
|
|
|
-public class EnvInputServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
+public class EnvInputServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
private StringBuilder askTextSb = null;
|
|
|
|
|
|
@Autowired
|
|
@@ -64,7 +69,10 @@ public class EnvInputServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
@Autowired
|
|
|
private DeviceFarmConfigMapper farmConfigMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private EggProductionMapper eggProductionMapper;
|
|
|
|
|
|
+ private static String str = "";
|
|
|
|
|
|
//
|
|
|
public void appendClientAsk(String text) {
|
|
@@ -75,74 +83,111 @@ public class EnvInputServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+
|
|
|
+ String str =
|
|
|
+
|
|
|
+ "55 86 38 00 4A 00 01 52 00 78 BC 56 B9 56 BC 56 BC 56 BA 56 BB 56 BB 56 BB 56 BA 56 BC 56 BA 56 BB 56 B9 56 BA 56 BC 56 BE 56 BB 56 BB 56 BB 56 BA 56 BA 56 BB 56 B9 56 B7 56 B8 56 B7 56 CC 56 CB 56 C9 56 CB 56 CB 56 CC 56 CB 56 CB 56 CB 56 CB 56 CA 56 CA 56 C9 56 CA 56 CB 56 CB 56 C9 56 C9 56 C8 56 CB 56 C9 56 C9 56 C9 56 C8 56 C8 56 CA 56 C9 56 C9 56 C8 56 C9 56 C9 56 C9 56 CB 56 CA 56 17 0C 07 15 0F 03 AA ";
|
|
|
+ String[] s = str.split(" ");
|
|
|
+ String dateTimeString = "2023-12-07 23:22:54";
|
|
|
+ // 创建 DateTimeFormatter 对象,指定日期时间格式
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
+ // 将字符串解析为 LocalDateTime 对象
|
|
|
+ LocalDateTime dateTime = LocalDateTime.parse(dateTimeString, formatter);
|
|
|
+
|
|
|
+ // 获取时间戳(以秒为单位)
|
|
|
+ long timestamp = dateTime.toEpochSecond(ZoneOffset.of("+8"));
|
|
|
+
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ System.out.println(timestamp);
|
|
|
+
|
|
|
+ for (int i = 0; i < 60; i++) {
|
|
|
+
|
|
|
+ long l = timestamp - ((60 - i) * 5 * 60); // 修正此行
|
|
|
+ Date thenTime = new Date(l * 1000); // 将秒转换为毫秒
|
|
|
+ String str1 = s[i * 2 + 11] + s[i * 2 + 10];
|
|
|
+ BigDecimal weight = new BigDecimal(Integer.parseInt(str1, 16));
|
|
|
+ System.out.println("" + sdf.format(thenTime)+" 重量:" +weight );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
|
|
- ByteBuf byteBuf = (ByteBuf) msg;
|
|
|
- byte[] bytes = new byte[byteBuf.readableBytes()];
|
|
|
- byteBuf.readBytes(bytes);
|
|
|
- String str = ModBusUtils.bytes2HexString(bytes);
|
|
|
- int length = str.length();
|
|
|
-
|
|
|
- System.out.println("收到的数据:"+str+" "+ length);
|
|
|
- if(length>100){
|
|
|
- saveWeight(str,bytes);
|
|
|
- }else if (length== 24 ){
|
|
|
- String[] s = str.split(" ");
|
|
|
- String hexId = s[5] + s[4] + s[3] + s[2] ;
|
|
|
- System.out.println("十六进制id"+hexId);
|
|
|
- int decId = Integer.parseInt(hexId, 16);
|
|
|
- System.out.println("十进制id"+decId);
|
|
|
- EnvDevice envDevice = envDeviceMapper.selectOne(new QueryWrapper<EnvDevice>().eq("device_code", decId));
|
|
|
-
|
|
|
- if(ObjectUtil.isNotEmpty(envDevice)){
|
|
|
- List<DeviceFarmConfig> farm_id = farmConfigMapper.selectList(new QueryWrapper<DeviceFarmConfig>().eq("farm_id", envDevice.getFarmId()));
|
|
|
- if (ObjectUtil.isNotEmpty(farm_id)){
|
|
|
- String timestr = farm_id.stream()
|
|
|
- .map(config -> String.format("%02X%02X", config.getStartHour(), config.getEndHour()))
|
|
|
- .collect(Collectors.joining());
|
|
|
- ctx.writeAndFlush(Unpooled.copiedBuffer(hexStringToByteArray("550B02"+getDateX()+timestr+"AA")));
|
|
|
- }
|
|
|
- if (envDevice.getDeviceStatus() != 1){
|
|
|
- envDevice.setDeviceStatus(1);
|
|
|
- envDeviceMapper.updateById(envDevice);
|
|
|
+// if (msg instanceof ByteBuf) {
|
|
|
+ ByteBuf byteBuf = (ByteBuf) msg;
|
|
|
+ byte[] bytes = new byte[byteBuf.readableBytes()];
|
|
|
+ byteBuf.readBytes(bytes);
|
|
|
+ str += ModBusUtils.bytes2HexString(bytes);
|
|
|
+ int length = str.length();
|
|
|
+ if (length != 18 && length != 24 && length <411){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (length > 411){
|
|
|
+ str = "";
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ System.out.println("收到的数据:" + str + " " + length );
|
|
|
+ if (length > 300) {
|
|
|
+ saveWeight(str, bytes);
|
|
|
+ } else if (length == 24) {
|
|
|
+ String[] s = str.split(" ");
|
|
|
+ String hexId = s[5] + s[4] + s[3] + s[2];
|
|
|
+ System.out.println("十六进制id" + hexId);
|
|
|
+ int decId = Integer.parseInt(hexId, 16);
|
|
|
+ System.out.println("十进制id" + decId);
|
|
|
+ EnvDevice envDevice = envDeviceMapper.selectOne(new QueryWrapper<EnvDevice>().eq("device_code", decId));
|
|
|
+
|
|
|
+ if (ObjectUtil.isNotEmpty(envDevice)) {
|
|
|
+ List<DeviceFarmConfig> farm_id = farmConfigMapper.selectList(new QueryWrapper<DeviceFarmConfig>().eq("farm_id", envDevice.getFarmId()));
|
|
|
+ if (ObjectUtil.isNotEmpty(farm_id)) {
|
|
|
+ String timestr = farm_id.stream()
|
|
|
+ .map(config -> String.format("%02X%02X", config.getStartHour(), config.getEndHour()))
|
|
|
+ .collect(Collectors.joining());
|
|
|
+ ctx.writeAndFlush(Unpooled.copiedBuffer(hexStringToByteArray("550B02" + getDateX() + timestr + "AA")));
|
|
|
+ }
|
|
|
+ if (envDevice.getDeviceStatus() != 1) {
|
|
|
+ envDevice.setDeviceStatus(1);
|
|
|
+ envDeviceMapper.updateById(envDevice);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ List<DeviceFarmConfig> farm_id = farmConfigMapper.selectList(new QueryWrapper<DeviceFarmConfig>().eq("farm_id", 21));
|
|
|
+ if (ObjectUtil.isNotEmpty(farm_id)) {
|
|
|
+ String timestr = farm_id.stream()
|
|
|
+ .map(config -> String.format("%02X%02X", config.getStartHour(), config.getEndHour()))
|
|
|
+ .collect(Collectors.joining());
|
|
|
+ ctx.writeAndFlush(Unpooled.copiedBuffer(hexStringToByteArray("550B02" + getDateX() + timestr + "AA")));
|
|
|
+ }
|
|
|
}
|
|
|
- }else {
|
|
|
- List<DeviceFarmConfig> farm_id = farmConfigMapper.selectList(new QueryWrapper<DeviceFarmConfig>().eq("farm_id",24));
|
|
|
- if (ObjectUtil.isNotEmpty(farm_id)){
|
|
|
+
|
|
|
+ } else {
|
|
|
+ List<DeviceFarmConfig> farm_id = farmConfigMapper.selectList(new QueryWrapper<DeviceFarmConfig>().like("device_id", str));
|
|
|
+ if (ObjectUtil.isNotEmpty(farm_id)) {
|
|
|
String timestr = farm_id.stream()
|
|
|
.map(config -> String.format("%02X%02X", config.getStartHour(), config.getEndHour()))
|
|
|
.collect(Collectors.joining());
|
|
|
- ctx.writeAndFlush(Unpooled.copiedBuffer(hexStringToByteArray("550B02"+getDateX()+timestr+"AA")));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }/*else if (length== 18 ) {*/
|
|
|
- List<DeviceFarmConfig> farm_id = farmConfigMapper.selectList(new QueryWrapper<DeviceFarmConfig>().like("device_id",str ));
|
|
|
- if (ObjectUtil.isNotEmpty(farm_id)) {
|
|
|
- String timestr = farm_id.stream()
|
|
|
- .map(config -> String.format("%02X%02X", config.getStartHour(), config.getEndHour()))
|
|
|
- .collect(Collectors.joining());
|
|
|
- String str1 = "550B02" + getDateX() + timestr + "AA";
|
|
|
- for (int i = 0; i < 10; i++) {
|
|
|
+ String str1 = "550B02" + getDateX() + timestr + "AA";
|
|
|
+// for (int i = 0; i < 10; i++) {
|
|
|
ctx.writeAndFlush(Unpooled.copiedBuffer(hexStringToByteArray(str1)));
|
|
|
- System.out.println(i+" : 下发数据:"+str1);
|
|
|
- Thread.sleep(3000);
|
|
|
+// System.out.println(i+" : 下发数据:"+str1);
|
|
|
+// Thread.sleep(3000);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// }
|
|
|
-
|
|
|
- System.out.println("保存成功");
|
|
|
+ str = "";
|
|
|
+ System.out.println("保存成功");
|
|
|
+// }else {
|
|
|
+// System.err.println("Unexpected message type: " + msg.getClass().getName());
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
- System.out.println(String.format("%02X%02X", 8, 10));
|
|
|
|
|
|
- }
|
|
|
- private boolean isTimeInRange(LocalTime currentTime, LocalTime startTime, LocalTime endTime) {
|
|
|
- return !currentTime.isBefore(startTime) && !currentTime.isAfter(endTime);
|
|
|
- }
|
|
|
+
|
|
|
private static byte[] hexStringToByteArray(String hexString) {
|
|
|
int len = hexString.length();
|
|
|
byte[] dataBytes = new byte[len / 2];
|
|
@@ -206,13 +251,32 @@ public class EnvInputServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
rawData.setCreateTime(new Date(l));
|
|
|
rawData.setLastWeight(new BigDecimal(Integer.parseInt(s[sLength -8]+s[sLength-9], 16)));
|
|
|
rawData.setBattery(batStr);
|
|
|
+ int year = Integer.parseInt(s[s.length - 7], 16);
|
|
|
+ int month = Integer.parseInt(s[s.length - 6], 16);
|
|
|
+ int day = Integer.parseInt(s[s.length - 5], 16);
|
|
|
+ int hour = Integer.parseInt(s[s.length - 4], 16);
|
|
|
+ int minut = Integer.parseInt(s[s.length - 3], 16);
|
|
|
+ int sco = Integer.parseInt(s[s.length - 2], 16);
|
|
|
+
|
|
|
+ rawData.setLastTime(
|
|
|
+ year +"-" +
|
|
|
+ month+"-"+
|
|
|
+ day+" "+
|
|
|
+ hour+":" +
|
|
|
+ minut+":" +
|
|
|
+ sco);
|
|
|
rawDataMapper.insert(rawData);
|
|
|
+ if(year>30 || year<10){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
//获取设备
|
|
|
EnvDevice envDevice = envDeviceMapper.selectOne(new QueryWrapper<EnvDevice>().eq("device_code", decId).eq("device_type", 3));
|
|
|
if (ObjectUtil.isEmpty(envDevice)){
|
|
|
System.out.println("固定电子称不存在,数据抛弃");
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
//获取鸭子
|
|
|
Integer unitId = envDevice.getUnitId();
|
|
|
BaseDuckInfo baseDuckInfo = baseDuckInfoMapper.selectOne(new QueryWrapper<BaseDuckInfo>().eq("unit_id", unitId).eq("is_cage", 0));
|
|
@@ -220,18 +284,257 @@ public class EnvInputServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
System.out.println("该位置不存在鸭子,数据抛弃");
|
|
|
return;
|
|
|
}
|
|
|
+ List<EggProduction> farm_id = eggProductionMapper.selectList(new QueryWrapper<EggProduction>().eq("farm_id", envDevice.getFarmId()));
|
|
|
+
|
|
|
+
|
|
|
+ LocalTime jianStartTime = LocalTime.of(7, 30); // 开始时间
|
|
|
+ LocalTime jianEndTime = LocalTime.of(8, 30); // 结束时间
|
|
|
+
|
|
|
+ LocalTime liaoStartTime = LocalTime.of(6, 0); // 开始时间
|
|
|
+ LocalTime liaoEndTime = LocalTime.of(7, 29); // 结束时间
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if(ObjectUtil.isNotEmpty(farm_id)){
|
|
|
+ for (EggProduction eggProduction : farm_id) {
|
|
|
+ if (eggProduction.getEventType() == 0){
|
|
|
+ //检蛋
|
|
|
+ jianStartTime = eggProduction.getStartTime();
|
|
|
+ jianEndTime = eggProduction.getEndTime();
|
|
|
+ }else {
|
|
|
+ //上料
|
|
|
+ liaoStartTime = eggProduction.getStartTime();
|
|
|
+ liaoEndTime = eggProduction.getEndTime();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal bigDecimal3 = new BigDecimal(3);
|
|
|
+ BigDecimal bigDecimala3 = new BigDecimal(-3);
|
|
|
+ BigDecimal bigDecimal0 = new BigDecimal(0);
|
|
|
+
|
|
|
+ BigDecimal bigDecimal800 = new BigDecimal(-800);
|
|
|
+ BigDecimal bigDecimal2 = new BigDecimal(2);
|
|
|
+ Boolean flag = true;
|
|
|
+ LocalTime currentTime = LocalTime.now();
|
|
|
+ //检蛋
|
|
|
+ if(currentTime.isAfter(jianStartTime) && currentTime.isBefore(jianEndTime)){
|
|
|
+ for (int i = 0; i < 60; i++) {
|
|
|
+ String str1 = s[i * 2 + 11] + s[i * 2 + 10];
|
|
|
+ BigDecimal weight = new BigDecimal(Integer.parseInt(str1, 16));
|
|
|
+
|
|
|
+ BigDecimal subtract = lastWeight.subtract(weight);
|
|
|
+ int i1 = subtract.intValue();
|
|
|
+ if(i1<-400) {
|
|
|
+ EnvRegularCallEgg envRegularCallEgg = new EnvRegularCallEgg();
|
|
|
+ envRegularCallEgg.setBattery(bat);
|
|
|
+ envRegularCallEgg.setCallDate(new Date());
|
|
|
+ envRegularCallEgg.setCallCode(decId + "");
|
|
|
+ envRegularCallEgg.setCallName(envDevice.getDeviceName());
|
|
|
+ envRegularCallEgg.setDuckId(baseDuckInfo.getId());
|
|
|
+ envRegularCallEgg.setDuckNum(baseDuckInfo.getDuckNum());
|
|
|
+ envRegularCallEgg.setFarmId(baseDuckInfo.getFarmId());
|
|
|
+ envRegularCallEgg.setUnitId(baseDuckInfo.getUnitId());
|
|
|
+ envRegularCallEgg.setUnitName(baseDuckInfo.getUnitName());
|
|
|
+ envRegularCallEgg.setChiNum(baseDuckInfo.getChiNum());
|
|
|
+ envRegularCallEgg.setJiaoNum(baseDuckInfo.getJiaoNum());
|
|
|
+ envRegularCallEgg.setBatchNum(baseDuckInfo.getBatchNum());
|
|
|
+ if ( i1 >-800) {
|
|
|
+ envRegularCallEgg.setEggNum(1);
|
|
|
+ } if (i1 <-800) {
|
|
|
+ envRegularCallEgg.setEggNum(2);
|
|
|
+ }
|
|
|
+ if (weight.compareTo(bigDecimal0) == 0) {
|
|
|
+ envRegularCallEgg.setDuckFeedingOriginal(bigDecimal0);
|
|
|
+ } else {
|
|
|
+ envRegularCallEgg.setDuckFeedingOriginal(weight.divide(bigDecimal10, 1, BigDecimal.ROUND_HALF_UP));
|
|
|
+ }
|
|
|
+ if (subtract.compareTo(bigDecimal0) == 0) {
|
|
|
+ envRegularCallEgg.setDuckWeight(bigDecimal0);
|
|
|
+ } else {
|
|
|
+ envRegularCallEgg.setDuckWeight(subtract.divide(bigDecimal10, 1, BigDecimal.ROUND_HALF_UP));
|
|
|
+ }
|
|
|
+ envRegularCallEggMapper.insert(envRegularCallEgg);
|
|
|
+ lastWeight = weight;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //上料
|
|
|
+ else if(currentTime.isAfter(liaoStartTime) && currentTime.isBefore(liaoEndTime)){
|
|
|
+ for (int i = 0; i < 60; i++) {
|
|
|
+ String str1 = s[i * 2 + 11] + s[i * 2 + 10];
|
|
|
+ BigDecimal weight = new BigDecimal(Integer.parseInt(str1,16));
|
|
|
+ if (flag){
|
|
|
+ //当时时间
|
|
|
+ String str2 = "";
|
|
|
+ BigDecimal weight2 ;
|
|
|
+ if(i<59){
|
|
|
+ str2 = s[(i+1) * 2 + 11] + s[(i+1) * 2 + 10];
|
|
|
+ weight2 = new BigDecimal(Integer.parseInt(str2,16));
|
|
|
+ BigDecimal subtract2 = weight2.subtract(lastWeight);
|
|
|
+ if (subtract2.compareTo(bigDecimal800) < 0){
|
|
|
+ System.out.println("连续两次减重之和小于-80,舍弃");
|
|
|
+ flag = false;
|
|
|
+ lastWeight = weight;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal subtract = lastWeight.subtract(weight);
|
|
|
+
|
|
|
+
|
|
|
+ if (subtract.compareTo(bigDecimal3)<0&& subtract.compareTo(bigDecimal0)>0){
|
|
|
+ System.out.println("波动小于0.3g,舍弃");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (subtract.compareTo(bigDecimala3)>0 && subtract.compareTo(bigDecimal0)<0){
|
|
|
+ System.out.println("波动小于0.3g,舍弃");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (subtract.compareTo(bigDecimal0)<0){
|
|
|
+ System.out.println("波动小于0.3g,舍弃");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ int compare = subtract.compareTo(new BigDecimal(1500));
|
|
|
+ System.out.println(subtract +"------>"+weight+"----------->"+lastWeight);
|
|
|
+ EnvRegularCallFeeding envRegularCallFeeding = new EnvRegularCallFeeding();
|
|
|
+ envRegularCallFeeding.setBattery(batStr);
|
|
|
+ envRegularCallFeeding.setCallDate(new Date());
|
|
|
+ envRegularCallFeeding.setCallCode(decId+"");
|
|
|
+ envRegularCallFeeding.setCallName(envDevice.getDeviceName());
|
|
|
+ envRegularCallFeeding.setDuckId(baseDuckInfo.getId());
|
|
|
+ envRegularCallFeeding.setDuckNum(baseDuckInfo.getDuckNum());
|
|
|
+ envRegularCallFeeding.setFarmId(baseDuckInfo.getFarmId());
|
|
|
+ envRegularCallFeeding.setUnitId(baseDuckInfo.getUnitId());
|
|
|
+ envRegularCallFeeding.setUnitName(baseDuckInfo.getUnitName());
|
|
|
+ if (weight.compareTo(bigDecimal0 )==0){
|
|
|
+ envRegularCallFeeding.setDuckFeedingOriginal(bigDecimal0);
|
|
|
+ }else {
|
|
|
+ envRegularCallFeeding.setDuckFeedingOriginal(weight.divide(bigDecimal10, 1, BigDecimal.ROUND_HALF_UP) );
|
|
|
+ }
|
|
|
+ if (subtract.compareTo(bigDecimal0 )==0){
|
|
|
+ envRegularCallFeeding.setDuckWeight(bigDecimal0);
|
|
|
+ }else {
|
|
|
+ envRegularCallFeeding.setDuckWeight(subtract.divide(bigDecimal10, 1, BigDecimal.ROUND_HALF_UP) );
|
|
|
+ }
|
|
|
+
|
|
|
+ //加料
|
|
|
+ if (compare>0){
|
|
|
+ EnvRegularCallFeedingCopy envRegularCallFeedingCopy = new EnvRegularCallFeedingCopy();
|
|
|
+ envRegularCallFeedingCopy.setBattery(new BigDecimal(Integer.parseInt(bat, 16)).divide(bigDecimal10, 1, BigDecimal.ROUND_HALF_UP).toString());
|
|
|
+ envRegularCallFeedingCopy.setCallDate(new Date());
|
|
|
+ envRegularCallFeedingCopy.setCallCode(decId+"");
|
|
|
+ envRegularCallFeedingCopy.setCallName(envDevice.getDeviceName());
|
|
|
+ envRegularCallFeedingCopy.setDuckId(baseDuckInfo.getId());
|
|
|
+ envRegularCallFeedingCopy.setDuckNum(baseDuckInfo.getDuckNum());
|
|
|
+ envRegularCallFeedingCopy.setFarmId(baseDuckInfo.getFarmId());
|
|
|
+ envRegularCallFeedingCopy.setUnitId(baseDuckInfo.getUnitId());
|
|
|
+ envRegularCallFeedingCopy.setUnitName(baseDuckInfo.getUnitName());
|
|
|
+ if (weight.compareTo(bigDecimal0)==0){
|
|
|
+ envRegularCallFeedingCopy.setDuckFeedingOriginal(bigDecimal0);
|
|
|
+ }else {
|
|
|
+ envRegularCallFeedingCopy.setDuckFeedingOriginal(weight.divide(bigDecimal10, 1, BigDecimal.ROUND_HALF_UP) );
|
|
|
+ }
|
|
|
+ if (subtract.compareTo(bigDecimal0 )==0){
|
|
|
+ envRegularCallFeedingCopy.setDuckWeight(bigDecimal0);
|
|
|
+ }else {
|
|
|
+ envRegularCallFeedingCopy.setDuckWeight(subtract.divide(bigDecimal10, 1, BigDecimal.ROUND_HALF_UP) );
|
|
|
+ }
|
|
|
+
|
|
|
+ envRegularCallFeedingCopy.setEventType(1);
|
|
|
+ envRegularCallFeedingCopyMapper.insert(envRegularCallFeedingCopy);
|
|
|
+ lastWeight =weight;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ int compare0 = subtract.compareTo(bigDecimal0);
|
|
|
+ //小于零大于负八十
|
|
|
+ int compare80 = subtract.compareTo(bigDecimal800);
|
|
|
+ //吃料
|
|
|
+ if (compare0<0 && compare80 >=0){
|
|
|
+ if (subtract.compareTo(bigDecimal0 )==0){
|
|
|
+ envRegularCallFeeding.setDuckWeight(bigDecimal0);
|
|
|
+ }else {
|
|
|
+ envRegularCallFeeding.setDuckWeight(subtract.subtract(subtract.multiply(bigDecimal2)).divide(bigDecimal10, 1, BigDecimal.ROUND_HALF_UP));
|
|
|
+ }
|
|
|
+ envRegularCallFeeding.setEventType(0);
|
|
|
+ envRegularCallFeedingMapper.insert(envRegularCallFeeding);
|
|
|
+ lastWeight =weight;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ lastWeight = weight;
|
|
|
+ flag = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ BigDecimal minweight = lastWeight;
|
|
|
+ for (int i = 0; i < 60; i++) {
|
|
|
+ String str1 = s[i * 2 + 11] + s[i * 2 + 10];
|
|
|
+ BigDecimal weight = new BigDecimal(Integer.parseInt(str1, 16));
|
|
|
+
|
|
|
+ if (weight.compareTo(lastWeight) <0) {
|
|
|
+ minweight = weight;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ BigDecimal subtract = lastWeight.subtract(minweight);
|
|
|
+ if (subtract.compareTo(bigDecimal0)<0){
|
|
|
+ System.out.println("波动小于0.3g,舍弃");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ EnvRegularCallFeeding envRegularCallFeeding = new EnvRegularCallFeeding();
|
|
|
+ envRegularCallFeeding.setBattery(batStr);
|
|
|
+ envRegularCallFeeding.setCallDate(new Date());
|
|
|
+ envRegularCallFeeding.setCallCode(decId+"");
|
|
|
+ envRegularCallFeeding.setCallName(envDevice.getDeviceName());
|
|
|
+ envRegularCallFeeding.setDuckId(baseDuckInfo.getId());
|
|
|
+ envRegularCallFeeding.setDuckNum(baseDuckInfo.getDuckNum());
|
|
|
+ envRegularCallFeeding.setFarmId(baseDuckInfo.getFarmId());
|
|
|
+ envRegularCallFeeding.setUnitId(baseDuckInfo.getUnitId());
|
|
|
+ envRegularCallFeeding.setUnitName(baseDuckInfo.getUnitName());
|
|
|
+ envRegularCallFeeding.setChiNum(baseDuckInfo.getChiNum());
|
|
|
+ envRegularCallFeeding.setJiaoNum(baseDuckInfo.getJiaoNum());
|
|
|
+ envRegularCallFeeding.setBatchNum(baseDuckInfo.getBatchNum());
|
|
|
+ if (minweight.compareTo(bigDecimal0 )==0){
|
|
|
+ envRegularCallFeeding.setDuckFeedingOriginal(bigDecimal0);
|
|
|
+ }else {
|
|
|
+ envRegularCallFeeding.setDuckFeedingOriginal(minweight.divide(bigDecimal10, 1, BigDecimal.ROUND_HALF_UP) );
|
|
|
+ }
|
|
|
+ if (subtract.compareTo(bigDecimal0 )==0){
|
|
|
+ envRegularCallFeeding.setDuckWeight(bigDecimal0);
|
|
|
+ }else {
|
|
|
+ envRegularCallFeeding.setDuckWeight(subtract.divide(bigDecimal10, 1, BigDecimal.ROUND_HALF_UP) );
|
|
|
+ }
|
|
|
|
|
|
- try {
|
|
|
- BigDecimal bigDecimal3 = new BigDecimal(3);
|
|
|
- BigDecimal bigDecimala3 = new BigDecimal(-3);
|
|
|
- BigDecimal bigDecimal0 = new BigDecimal(0);
|
|
|
+ envRegularCallFeeding.setEventType(0);
|
|
|
+ envRegularCallFeedingMapper.insert(envRegularCallFeeding);
|
|
|
|
|
|
- BigDecimal bigDecimal800 = new BigDecimal(-800);
|
|
|
- BigDecimal bigDecimal1600 = new BigDecimal(1600);
|
|
|
- BigDecimal bigDecimal2 = new BigDecimal(2);
|
|
|
- Boolean flag = true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// try {
|
|
|
+// BigDecimal bigDecimal3 = new BigDecimal(3);
|
|
|
+// BigDecimal bigDecimala3 = new BigDecimal(-3);
|
|
|
+// BigDecimal bigDecimal0 = new BigDecimal(0);
|
|
|
+//
|
|
|
+// BigDecimal bigDecimal800 = new BigDecimal(-800);
|
|
|
+// BigDecimal bigDecimal1600 = new BigDecimal(1600);
|
|
|
+// BigDecimal bigDecimal2 = new BigDecimal(2);
|
|
|
+// Boolean flag = true;
|
|
|
//循环获取体重
|
|
|
- for (int i = 0; i < 60; i++) {
|
|
|
+ /* for (int i = 0; i < 60; i++) {
|
|
|
String str1 = s[i * 2 + 11] + s[i * 2 + 10];
|
|
|
BigDecimal weight = new BigDecimal(Integer.parseInt(str1,16));
|
|
|
if (flag){
|
|
@@ -423,7 +726,7 @@ public class EnvInputServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
}catch (Exception e){
|
|
|
System.out.println(e);
|
|
|
}
|
|
|
-
|
|
|
+*/
|
|
|
}
|
|
|
|
|
|
|