瀏覽代碼

2021/8/13 待转代码上传

yinhao 3 年之前
父節點
當前提交
ae35048156

+ 17 - 12
smart.eartag.data.platform/huimv-smart-eartag-data-manager/src/main/java/com/huimv/manager/controller/PreparePigController.java

@@ -15,13 +15,12 @@ import com.huimv.manager.result.RRException;
 import com.huimv.manager.utils.Constant;
 import com.huimv.manager.utils.PageUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.validation.annotation.Validated;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.CrossOrigin;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
-import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Objects;
@@ -40,9 +39,12 @@ import java.util.stream.Collectors;
 @RequestMapping("/prepareTrans")
 public class PreparePigController {
 
-    private final int breeding = 50;
-    private final int childbirth = 50;
-    private final int threadshold = 5;
+    @Value("${local.prepare-trans.breeding}")
+    private int breeding;
+    @Value("${local.prepare-trans.childbirth}")
+    private int childbirth;
+    @Value("${local.prepare-trans.threshold}")
+    private int threshold;
 
     @Autowired
     private MovePigpenDao movePigpenDao;
@@ -51,16 +53,17 @@ public class PreparePigController {
     private PigBasicInformationDao pigBasicInformationDao;
 
     @RequestMapping("/prepareCountAndDetail")
-    public R countPrepareAmountAndListPigDetail(Integer type,
+    public R countPrepareAmountAndListPigDetail(@RequestParam(name = "type") Integer type,
                                                 @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                                 @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
         int breed = Constant.Stage.PEIZHONG.getType();
-        if (type != null && type != breed && type != Constant.Stage.FENMIAN.getType()) {
+        if (type != 0 && type != breed && type != Constant.Stage.FENMIAN.getType()) {
             throw new RRException("type参数有误,请检查");
         }
 
         LambdaQueryWrapper<MovePigpenEntity> lambdaQuery = Wrappers.lambdaQuery();
         lambdaQuery.eq(MovePigpenEntity::getStage, breed);
+
         List<MovePigpenEntity> breedingList = movePigpenDao.selectList(lambdaQuery);
 
         List<String> prepareToTransList = filterEligibleEartags(breedingList, breeding);
@@ -73,8 +76,8 @@ public class PreparePigController {
         List<String> weaningList = filterEligibleEartags(childbirthList, childbirth);
         int weaningNum = weaningList.size();
 
-        List<String> list = CollUtil.newArrayList(prepareToTransList);
-        if (type == null) {
+        List<String> list = CollUtil.newArrayList();
+        if (type == 0) {
             list.addAll(prepareToTransList);
             list.addAll(weaningList);
         } else if (type == breed) {
@@ -89,7 +92,9 @@ public class PreparePigController {
         IPage<PigBasicInformationEntity> page = new Page<>(pageNum, pageSize);
         if (CollUtil.isNotEmpty(list)) {
             eartagLambdaQuery.in(PigBasicInformationEntity::getEartagNo, list);
-             page = pigBasicInformationDao.selectPage(iPage, eartagLambdaQuery);
+            page = pigBasicInformationDao.selectPage(iPage, eartagLambdaQuery);
+//            List<PigBasicInformationEntity> records = page.getRecords();
+//            records.forEach(PigBasicInformationEntity::setDayAge);
         }
 
         PageUtils pageUtils = new PageUtils(page);
@@ -98,8 +103,8 @@ public class PreparePigController {
 
     private List<String> filterEligibleEartags(List<MovePigpenEntity> list, Integer type) {
         return list.stream()
-                .filter(movePigpenEntity -> DateUtil.betweenDay(movePigpenEntity.getMoveDate(), new Date(), false) > type - threadshold)
-                .sorted((o1, o2) -> (int) (o2.getMoveDate().getTime() - o1.getMoveDate().getTime()))
+                .filter(movePigpenEntity -> DateUtil.betweenDay(movePigpenEntity.getMoveDate(), new Date(), false) >= type - threshold && DateUtil.betweenDay(movePigpenEntity.getMoveDate(), new Date(), false) <= type)
+                .sorted((o1, o2) -> (int) (o1.getMoveDate().getTime() - o2.getMoveDate().getTime()))
                 .map(MovePigpenEntity::getEartagNo)
                 .collect(Collectors.toList());
     }

+ 99 - 69
smart.eartag.data.platform/huimv-smart-eartag-data-manager/src/main/java/com/huimv/manager/entity/PigBasicInformationEntity.java

@@ -1,15 +1,16 @@
 package com.huimv.manager.entity;
 
+import cn.hutool.core.date.DateUtil;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonIgnore;
 import lombok.Data;
 
 import java.io.Serializable;
 import java.util.Date;
 
 /**
- * 
- * 
  * @author yinhao
  * @version ${version}
  * @date 2021-08-11 17:05:02
@@ -17,75 +18,104 @@ import java.util.Date;
 @Data
 @TableName("pig_basic_information")
 public class PigBasicInformationEntity implements Serializable {
-	private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
 
-	/**
-	 * 
-	 */
-	@TableId
-	private Integer id;
-	/**
-	 * 耳标号
-	 */
-	private String eartagNo;
-	/**
-	 * 创建时间
-	 */
-	private Date createTime;
-	/**
-	 * 更新时间
-	 */
-	private Date updateTime;
-	/**
-	 * 机器编码
-	 */
-	private String deviceCode;
-	/**
-	 * 猪的出生日期
-	 */
-	private Date birthDay;
-	/**
-	 * 佩标日期
-	 */
-	private Date wearTagTime;
-	/**
-	 * 牧场编号
-	 */
-	private String farmCode;
-	/**
-	 * 牧场名称
-	 */
-	private String farmName;
-	/**
-	 * 猪舍id
-	 */
-	private Integer penId;
-	/**
-	 * 猪舍名称
-	 */
-	private String penName;
-	/**
-	 * 单元id
-	 */
-	private Integer unitId;
-	/**
-	 * 单元名称
-	 */
-	private String unitName;
-	/**
-	 * 县id
-	 */
-	private Integer countyId;
-	/**
-	 * 县名称
-	 */
-	private String countyName;
-	/**
-	 * 备注
-	 */
-	private String remark;
+    /**
+     *
+     */
+    @TableId
+    @JsonIgnore
+    private Integer id;
+    /**
+     * 耳标号
+     */
+    private String eartagNo;
+    /**
+     * 创建时间
+     */
+    @JsonIgnore
+    private Date createTime;
+    /**
+     * 更新时间
+     */
+    @JsonIgnore
+    private Date updateTime;
+    /**
+     * 机器编码
+     */
+    private String deviceCode;
+    /**
+     * 猪的出生日期
+     */
+    @JsonIgnore
+    private Date birthDay;
+    /**
+     * 佩标日期
+     */
+    @JsonIgnore
+    private Date wearTagTime;
+    /**
+     * 牧场编号
+     */
+    private String farmCode;
+    /**
+     * 牧场名称
+     */
+    private String farmName;
+    /**
+     * 猪舍id
+     */
+    @JsonIgnore
+    private Integer penId;
+    /**
+     * 猪舍名称
+     */
+    private String penName;
+    /**
+     * 单元id
+     */
+    @JsonIgnore
+    private Integer unitId;
+    /**
+     * 单元名称
+     */
+    private String unitName;
+    /**
+     * 县id
+     */
+    @JsonIgnore
+    private Integer countyId;
+    /**
+     * 县名称
+     */
+    private String countyName;
+    /**
+     * 备注
+     */
+    @JsonIgnore
+    private String remark;
 
 
-	private Integer stage;
+    private Integer stage;
 
+    @TableField(exist = false)
+    private Integer dayAge;
+
+    @TableField(exist = false)
+    private Integer wearEartagDayAge;
+
+
+    public void setBirthDay(Date birthDay) {
+        this.birthDay = birthDay;
+        this.dayAge = (int) DateUtil.betweenDay(birthDay, new Date(), false);
+    }
+
+    public void setWearTagTime(Date wearTagTime) {
+        this.wearTagTime = wearTagTime;
+        this.wearEartagDayAge = (int) DateUtil.betweenDay(wearTagTime, new Date(), false);
+    }
+
+    //    public void setDayAge() {
+//        this.dayAge = DateUtil.betweenDay(birthDay, new Date(), false);
+//    }
 }

+ 7 - 1
smart.eartag.data.platform/huimv-smart-eartag-data-manager/src/main/resources/application-dev.yml

@@ -52,4 +52,10 @@ mybatis-plus:
     cache-enabled: false
     call-setters-on-nulls: true
     jdbc-type-for-null: 'null'
-    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+
+local:
+  prepare-trans:
+     breeding: 50
+     childbirth: 50
+     threshold: 5