Просмотр исходного кода

2021/5/19获取猪page添加入栏出栏时间

yinhao 4 лет назад
Родитель
Сommit
03828f0560

+ 5 - 5
huimv-smart-apiservice/src/main/java/com/huimv/apiservice/controller/PigController.java

@@ -6,11 +6,11 @@ import com.huimv.apiservice.service.PigService;
 import com.huimv.common.utils.PageUtils;
 import com.huimv.common.utils.R;
 import com.huimv.common.validate.ListValue;
+import org.hibernate.validator.constraints.Range;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
-import javax.validation.constraints.Max;
 import javax.validation.constraints.NotBlank;
 import javax.validation.constraints.NotNull;
 import java.util.Map;
@@ -70,8 +70,8 @@ public class PigController {
     public R getListByBreed(@RequestParam(value = "accessToken") String accessToken,
                             @NotBlank(message = "品种名称不能为空!") @RequestParam("breedName") String breedName,
                             @RequestParam(value = "currentPage", defaultValue = "1") Integer currentPage,
-                            @Max(value = 1000, message = "每页条数不能大于1000") @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
-                            @NotBlank(message = "栏期编号不能为空!") @RequestParam("period") String period) {
+                            @Range(min = 1, max = 1000, message = "每页条数的范围为1-1000") @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
+                            @RequestParam(value = "period", required = false) String period) {
         PageUtils page = pigService.getPageByBreedAndFence(breedName, currentPage, pageSize, period);
         return Objects.requireNonNull(R.ok().put("code", 1000)).put("page", page);
     }
@@ -114,8 +114,8 @@ public class PigController {
     @GetMapping("/outFence")
     public R outFence(@RequestParam(value = "accessToken", required = false) String accessToken,
                       @NotBlank(message = "耳标号不能为空!") @RequestParam("pigEarTagNo") String pigEarTagNo,
-                      @NotNull(message = "出栏状态不能为空!") @ListValue(vals = {1, 2, 3}) Integer status) {
+                      @NotNull(message = "出栏状态不能为空!") @ListValue(vals = {1, 2, 3}) @RequestParam("status") Integer status) {
         pigService.outFence(pigEarTagNo, status);
-        return Objects.requireNonNull(R.ok().put("code", 1000)).put("msg", "更新出栏状态成功!");
+        return Objects.requireNonNull(R.ok().put("code", 1000)).put("msg", "出栏成功!");
     }
 }

+ 10 - 0
huimv-smart-apiservice/src/main/java/com/huimv/apiservice/entity/YearPigBaseEntity.java

@@ -83,6 +83,16 @@ public class YearPigBaseEntity implements Serializable {
     private Integer periodId;
 
     /**
+     * 入栏时间
+     */
+    private Date inFenceTime;
+
+    /**
+     * 出栏时间
+     */
+    private Date outFenceTime;
+
+    /**
      * 出栏状态
      */
     private Integer outFenceStatus;

+ 15 - 0
huimv-smart-apiservice/src/main/java/com/huimv/apiservice/entity/vo/PigBaseVo.java

@@ -50,6 +50,21 @@ public class PigBaseVo {
     private String pigsty;
 
     /**
+     * 栏期编号
+     */
+    private String periodNumber;
+
+    /**
+     * 入栏时间
+     */
+    private Date inFenceTime;
+
+    /**
+     * 出栏时间
+     */
+    private Date outFenceTime;
+
+    /**
      * 母亲
      */
     private PigPedigreeMotherVo mother;

+ 19 - 6
huimv-smart-apiservice/src/main/java/com/huimv/apiservice/service/impl/PigServiceImpl.java

@@ -18,6 +18,7 @@ import com.huimv.apiservice.entity.vo.*;
 import com.huimv.apiservice.service.PigService;
 import com.huimv.common.exception.RRException;
 import com.huimv.common.utils.PageUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -73,7 +74,6 @@ public class PigServiceImpl extends ServiceImpl<PigDao, YearPigBaseEntity> imple
 
         boolean health = baseMapper.selectHealthStatus(pigEarTagNo);
         result.put("healthStatus", health ? "健康" : "不健康");
-
         result.put("sleepStatus", sleepStatus);
         result.put("sportStatus", sportStatus);
 
@@ -196,9 +196,12 @@ public class PigServiceImpl extends ServiceImpl<PigDao, YearPigBaseEntity> imple
             throw new RRException("品种名称不存在,请检查!", 1001);
         }
 
-        Integer periodId = periodDao.selectIdByPeriodNumber(period);
-        if (periodId == null) {
-            throw new RRException("栏期编号不存在,请检查!", 1001);
+        Integer periodId = null;
+        if (StringUtils.isNotEmpty(period)) {
+            periodId = periodDao.selectIdByPeriodNumber(period);
+            if (periodId == null) {
+                throw new RRException("栏期编号不存在,请检查!", 1001);
+            }
         }
 
 
@@ -288,14 +291,24 @@ public class PigServiceImpl extends ServiceImpl<PigDao, YearPigBaseEntity> imple
 
         checkPigEarTagNo(pigEarTagNo);
 
-        if (!status.equals(1) && !status.equals(2) && !status.equals(3)) {
-            throw new RRException("出栏状态有误,请检查!", 1001);
+//        if (!status.equals(1) && !status.equals(2) && !status.equals(3)) {
+//            throw new RRException("出栏状态有误,请检查!", 1001);
+//        }
+        LambdaQueryWrapper<YearPigBaseEntity> pigBaseLambdaQuery = Wrappers.lambdaQuery();
+        pigBaseLambdaQuery.eq(YearPigBaseEntity::getEartag, pigEarTagNo);
+        YearPigBaseEntity yearPigBaseEntity = baseMapper.selectOne(pigBaseLambdaQuery);
+        Integer outFenceStatus = yearPigBaseEntity.getOutFenceStatus();
+        if (outFenceStatus != null) {
+            if (outFenceStatus.equals(1) || outFenceStatus.equals(2) || outFenceStatus.equals(3)) {
+                throw new RRException("该猪已出栏,不可重复出栏!", 1001);
+            }
         }
 
         LambdaUpdateWrapper<YearPigBaseEntity> pigBaseLambdaUpdate = Wrappers.lambdaUpdate();
         pigBaseLambdaUpdate.eq(YearPigBaseEntity::getEartag, pigEarTagNo)
                 .set(YearPigBaseEntity::getDeleted, true)
                 .set(YearPigBaseEntity::getFosterStatus, false)
+                .set(YearPigBaseEntity::getOutFenceTime,new Date())
                 .set(YearPigBaseEntity::getOutFenceStatus, status);
 
         update(pigBaseLambdaUpdate);

+ 10 - 5
huimv-smart-apiservice/src/main/resources/mapper/apiservice/YearPigBaseDao.xml

@@ -32,6 +32,9 @@
         <result property="birthday" column="birthday" />
         <result property="feeder" column="feeder" />
         <result property="pigsty" column="pigsty" />
+        <result property="periodNumber" column="period_number" />
+        <result property="inFenceTime" column="in_fence_time" />
+        <result property="outFenceTime" column="out_fence_time" />
 
         <association property="mother" javaType="com.huimv.apiservice.entity.vo.PigPedigreeMotherVo">
             <result property="eartag" column="m_eartag" />
@@ -74,18 +77,20 @@
     </select>
 
     <select id="selectPagePigBaseVoByBreedName" resultMap="pigBaseVoMap">
-        SELECT child.eartag c_eartag,child.weight,child.day_age,child.breed,child.birthday,feeder.`name` feeder,zs.number pigsty,
-               mother.eartag m_eartag,m.breed m_breed,mother.childbirth_weight m_weight,m.origin_place m_origin_place,mother.pregnancy_date pregnancy_date,mother.childbirth_count child_count,
+        SELECT child.eartag c_eartag,child.weight,child.day_age,child.breed,child.birthday,feeder.`name` feeder,zs.number pigsty,p.number period_number,child.in_fence_time,child.out_fence_time,
+               m.eartag m_eartag,m.breed m_breed,mother.childbirth_weight m_weight,m.origin_place m_origin_place,mother.pregnancy_date pregnancy_date,mother.childbirth_count child_count,
                father.eartag f_eartag,father.breed f_breed,father.origin_place f_origin_place
         FROM mgt_year_pig_base child
         LEFT JOIN mgt_pigsty zs ON child.pigsty_id = zs.id
+        LEFT JOIN mgt_period p ON child.period_id = p.id
         LEFT JOIN mgt_employee feeder ON zs.feeder_id = feeder.id
         LEFT JOIN mgt_sow_childbirth mother ON child.mother_eartag = mother.eartag
         LEFT JOIN mgt_year_pig_base m ON child.mother_eartag = m.eartag
         LEFT JOIN mgt_year_pig_base father ON child.father_eartag = father.eartag
-        WHERE child.deleted = 0 AND child.breed = #{breedName} AND child.period_id = #{periodId}
+        WHERE child.deleted = 0 AND child.breed = #{breedName}
+        <if test="periodId != null">
+            AND child.period_id = #{periodId}
+        </if>
     </select>
 
-
-
 </mapper>

+ 7 - 0
huimv-smart-common/src/main/java/com/huimv/common/exception/RRExceptionHandler.java

@@ -16,6 +16,7 @@ import org.springframework.dao.DuplicateKeyException;
 import org.springframework.validation.FieldError;
 import org.springframework.validation.ObjectError;
 import org.springframework.web.bind.MethodArgumentNotValidException;
+import org.springframework.web.bind.MissingServletRequestParameterException;
 import org.springframework.web.bind.annotation.ExceptionHandler;
 import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.bind.annotation.RestControllerAdvice;
@@ -90,6 +91,12 @@ public class RRExceptionHandler {
 		return R.error(1001,sb.toString().substring(0,sb.length() - 1));
 	}
 
+	@ExceptionHandler(MissingServletRequestParameterException.class)
+	public R handMissingServletRequestParameterException(MissingServletRequestParameterException e) {
+		logger.error(e.getMessage(),e);
+		return R.error(1001,e.getMessage());
+	}
+
 	@ExceptionHandler(Exception.class)
 	public R handleException(Exception e){
 		logger.error(e.getMessage(), e);