Prechádzať zdrojové kódy

2021/5/17对接修改接口

yinhao 4 rokov pred
rodič
commit
438e1ac50b

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

@@ -10,6 +10,7 @@ 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;
@@ -53,7 +54,7 @@ public class PigController {
      */
     @GetMapping("/getImage")
     public R getImage(@RequestParam(value = "accessToken") String accessToken,
-                      @NotBlank(message = "耳标号111不能为空!") @RequestParam("pigEarTagNo") String pigEarTagNo) {
+                      @NotBlank(message = "耳标号不能为空!") @RequestParam("pigEarTagNo") String pigEarTagNo) {
         PigImageVo pigImageVo = pigService.getImageByEarTagNo(pigEarTagNo);
         return Objects.requireNonNull(R.ok().put("code", 1000)).put("data", pigImageVo);
     }
@@ -67,8 +68,11 @@ public class PigController {
      */
     @GetMapping("/getListByBreed")
     public R getListByBreed(@RequestParam(value = "accessToken") String accessToken,
-                            @RequestParam("breedName") @NotBlank(message = "品种名称不能为空!") String breedName) {
-        PageUtils page = pigService.getListByBreed(breedName);
+                            @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) {
+        PageUtils page = pigService.getPageByBreedAndFence(breedName, currentPage, pageSize, period);
         return Objects.requireNonNull(R.ok().put("code", 1000)).put("page", page);
     }
 
@@ -95,7 +99,7 @@ public class PigController {
      */
     @GetMapping("/adopt")
     public R adopt(@RequestParam(value = "accessToken") String accessToken,
-                   @RequestParam("pigEarTagNo") @NotBlank(message = "耳标号不能为空!") String pigEarTagNo) {
+                   @NotBlank(message = "耳标号不能为空!") @RequestParam("pigEarTagNo") String pigEarTagNo) {
         pigService.adopt(pigEarTagNo);
         return Objects.requireNonNull(R.ok().put("code", 1000)).put("msg", "认养成功!");
     }
@@ -109,8 +113,8 @@ public class PigController {
      */
     @GetMapping("/outFence")
     public R outFence(@RequestParam(value = "accessToken", required = false) String accessToken,
-                      @RequestParam("pigEarTagNo") @NotBlank(message = "耳标号不能为空!") String pigEarTagNo,
-                      @ListValue(vals = {1, 2, 3}) @NotNull(message = "出栏状态不能为空!") @RequestParam("status") Integer status) {
+                      @NotBlank(message = "耳标号不能为空!") @RequestParam("pigEarTagNo") String pigEarTagNo,
+                      @NotNull(message = "出栏状态不能为空!") @ListValue(vals = {1, 2, 3}) Integer status) {
         pigService.outFence(pigEarTagNo, status);
         return Objects.requireNonNull(R.ok().put("code", 1000)).put("msg", "更新出栏状态成功!");
     }

+ 4 - 1
huimv-smart-apiservice/src/main/java/com/huimv/apiservice/dao/PeriodDao.java

@@ -3,6 +3,7 @@ package com.huimv.apiservice.dao;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.huimv.apiservice.entity.PeriodEntity;
 import org.apache.ibatis.annotations.Mapper;
+import org.springframework.stereotype.Repository;
 
 /**
  * 栏期信息表
@@ -12,6 +13,8 @@ import org.apache.ibatis.annotations.Mapper;
  * @date 2021-05-07 15:32:42
  */
 @Mapper
+@Repository
 public interface PeriodDao extends BaseMapper<PeriodEntity> {
-	
+
+    Integer selectIdByPeriodNumber(String period);
 }

+ 9 - 4
huimv-smart-apiservice/src/main/java/com/huimv/apiservice/dao/PigDao.java

@@ -5,13 +5,15 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.huimv.apiservice.entity.EmployeeEntity;
 import com.huimv.apiservice.entity.YearPigBaseEntity;
 import com.huimv.apiservice.entity.vo.PigBaseVo;
+import org.apache.ibatis.annotations.Param;
 import org.mapstruct.Mapper;
 import org.springframework.stereotype.Repository;
 
 /**
- * @Author yinhao
- * @Date 2021/5/8 17:22
- * @Description
+ * 数据访问层
+ *
+ * @author yinhao
+ * @date 2021/5/8 17:22
  */
 @Mapper
 @Repository
@@ -21,5 +23,8 @@ public interface PigDao extends BaseMapper<YearPigBaseEntity> {
 
     String selectPastureNameByPigstyId(Integer pigstyId);
 
-    IPage<PigBaseVo> selectPagePigBaseVoByBreedName(IPage<PigBaseVo> page, String breedName);
+    IPage<PigBaseVo> selectPagePigBaseVoByBreedName(IPage<PigBaseVo> page, @Param("breedName") String breedName, @Param("periodId") Integer periodId);
+
+    boolean selectHealthStatus(String pigEarTagNo);
+
 }

+ 4 - 1
huimv-smart-apiservice/src/main/java/com/huimv/apiservice/service/PigService.java

@@ -34,9 +34,12 @@ public interface PigService extends IService<YearPigBaseEntity> {
     /**
      * 根据品种名称获取猪的数量和基本信息
      * @param breedName 品种名称
+     * @param currentPage 当前页
+     * @param pageSize 每页条数
+     * @param period 栏期
      * @return
      */
-    PageUtils getListByBreed(String breedName);
+    PageUtils getPageByBreedAndFence(String breedName,Integer currentPage,Integer pageSize,String period);
 
     /**
      * 根据猪耳标号获取环境数据

+ 25 - 16
huimv-smart-apiservice/src/main/java/com/huimv/apiservice/service/impl/PigServiceImpl.java

@@ -18,7 +18,6 @@ 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;
 
@@ -42,6 +41,9 @@ public class PigServiceImpl extends ServiceImpl<PigDao, YearPigBaseEntity> imple
     private EatTimeDao eatTimeDao;
 
     @Autowired
+    private PeriodDao periodDao;
+
+    @Autowired
     private IndoorEnvironmentDao indoorEnvironmentDao;
 
     @Autowired
@@ -63,16 +65,19 @@ public class PigServiceImpl extends ServiceImpl<PigDao, YearPigBaseEntity> imple
 
         Map<String, Object> result = new LinkedHashMap<>(16);
         List<Map<String, Object>> temperature = new ArrayList<>();
-//        List<Map<String, Object>> healthStatus = new ArrayList<>();
         List<Map<String, Object>> feedingStatus = new ArrayList<>();
         List<Map<String, Object>> sleepStatus = new ArrayList<>();
         List<Map<String, Object>> sportStatus = new ArrayList<>();
         result.put("temperature", temperature);
-//        result.put("healthStatus", healthStatus);
         result.put("feedingStatus", feedingStatus);
+
+        boolean health = baseMapper.selectHealthStatus(pigEarTagNo);
+        result.put("healthStatus", health ? "健康" : "不健康");
+
         result.put("sleepStatus", sleepStatus);
         result.put("sportStatus", sportStatus);
 
+
         //公用时间 -> 当前日期
         String today = DateUtil.format(DateUtil.date(), "yyyy-MM-dd");
 
@@ -180,19 +185,25 @@ public class PigServiceImpl extends ServiceImpl<PigDao, YearPigBaseEntity> imple
 
 
     @Override
-    public PageUtils getListByBreed(String breedName) {
+    public PageUtils getPageByBreedAndFence(String breedName, Integer currentPage, Integer pageSize, String period) {
 
-        if (StringUtils.isEmpty(breedName)) {
-            throw new RRException("品种名称不能为空!",1001);
-        }
+//        if (StringUtils.isEmpty(breedName)) {
+//            throw new RRException("品种名称不能为空!", 1001);
+//        }
 
         Integer count = baseMapper.selectCount(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getBreed, breedName));
         if (count <= 0) {
-            throw new RRException("品种名称不存在,请检查!",1001);
+            throw new RRException("品种名称不存在,请检查!", 1001);
+        }
+
+        Integer periodId = periodDao.selectIdByPeriodNumber(period);
+        if (periodId == null) {
+            throw new RRException("栏期编号不存在,请检查!", 1001);
         }
 
-        IPage<PigBaseVo> page = new Page<>(1, 10);
-        IPage<PigBaseVo> pigBaseVoList = baseMapper.selectPagePigBaseVoByBreedName(page, breedName);
+
+        IPage<PigBaseVo> page = new Page<>(currentPage, pageSize);
+        IPage<PigBaseVo> pigBaseVoList = baseMapper.selectPagePigBaseVoByBreedName(page, breedName, periodId);
 
         return new PageUtils(pigBaseVoList);
     }
@@ -273,18 +284,18 @@ public class PigServiceImpl extends ServiceImpl<PigDao, YearPigBaseEntity> imple
     }
 
     @Override
-    public void  outFence(String pigEarTagNo, Integer status) {
+    public void outFence(String pigEarTagNo, Integer status) {
 
         checkPigEarTagNo(pigEarTagNo);
 
         if (!status.equals(1) && !status.equals(2) && !status.equals(3)) {
-            throw new RRException("出栏状态有误,请检查!",1001);
+            throw new RRException("出栏状态有误,请检查!", 1001);
         }
 
         LambdaUpdateWrapper<YearPigBaseEntity> pigBaseLambdaUpdate = Wrappers.lambdaUpdate();
         pigBaseLambdaUpdate.eq(YearPigBaseEntity::getEartag, pigEarTagNo)
-                .set(YearPigBaseEntity::getDeleted,true)
-                .set(YearPigBaseEntity::getFosterStatus,false)
+                .set(YearPigBaseEntity::getDeleted, true)
+                .set(YearPigBaseEntity::getFosterStatus, false)
                 .set(YearPigBaseEntity::getOutFenceStatus, status);
 
         update(pigBaseLambdaUpdate);
@@ -298,8 +309,6 @@ public class PigServiceImpl extends ServiceImpl<PigDao, YearPigBaseEntity> imple
      */
     private void checkPigEarTagNo(String pigEarTagNo) {
 
-//
-
         Integer count = baseMapper.selectCount(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, pigEarTagNo));
         if (count <= 0) {
             throw new RRException("耳标信息不存在,请检查!", 1001);

+ 4 - 0
huimv-smart-apiservice/src/main/resources/mapper/apiservice/PeriodDao.xml

@@ -14,5 +14,9 @@
         <result property="gmtModified" column="gmt_modified"/>
     </resultMap>
 
+    <select id="selectIdByPeriodNumber" parameterType="string" resultType="java.lang.Integer">
+        SELECT id FROM mgt_period WHERE number = #{period} AND deleted = 0 limit 1
+    </select>
+
 
 </mapper>

+ 6 - 1
huimv-smart-apiservice/src/main/resources/mapper/apiservice/YearPigBaseDao.xml

@@ -69,6 +69,10 @@
         WHERE zs.id = #{pigstyId}
     </select>
 
+    <select id="selectHealthStatus" parameterType="string" resultType="java.lang.Boolean">
+        SELECT health_status FROM mgt_year_pig_base WHERE eartag = #{pigEarTagNo} AND deleted = 0
+    </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,
@@ -79,8 +83,9 @@
         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}
+        WHERE child.deleted = 0 AND child.breed = #{breedName} AND child.period_id = #{periodId}
     </select>
 
 
+
 </mapper>

+ 3 - 1
huimv-smart-common/src/main/java/com/huimv/common/validate/ListValueConstraintValidator.java

@@ -33,7 +33,9 @@ public class ListValueConstraintValidator implements ConstraintValidator<ListVal
      */
     @Override
     public boolean isValid(Integer value, ConstraintValidatorContext context) {
-
+        if (value == null) {
+            return true;
+        }
         return set.contains(value);
     }
 }