Newspaper 1 年之前
父節點
當前提交
e69f44d727

+ 10 - 0
huimv-admin/src/main/java/com/huimv/guowei/admin/entity/vo/EggVo.java

@@ -0,0 +1,10 @@
+package com.huimv.guowei.admin.entity.vo;
+
+import lombok.Data;
+
+@Data
+public class EggVo {
+    private String totalEgg;
+    private String totalWeight;
+    private String avgWeight;
+}

+ 4 - 0
huimv-admin/src/main/java/com/huimv/guowei/admin/mapper/EnvRegularCallEggMapper.java

@@ -7,8 +7,10 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.huimv.guowei.admin.entity.EnvRegularCallEgg;
 import com.huimv.guowei.admin.entity.EnvRegularCallFeeding;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.huimv.guowei.admin.entity.vo.EggVo;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -29,4 +31,6 @@ public interface EnvRegularCallEggMapper extends BaseMapper<EnvRegularCallEgg> {
     String getTotalEgg (String farmId);
 
     IPage<EnvRegularCallEgg> listAll(Page<EnvRegularCallEgg> page,@Param(Constants.WRAPPER) QueryWrapper<EnvRegularCallEgg> queryWrapper);
+
+    EggVo print(String duckNum, Date startDate, Date endDate);
 }

+ 1 - 1
huimv-admin/src/main/java/com/huimv/guowei/admin/mapper/EnvRegularCallFeedingMapper.java

@@ -42,7 +42,7 @@ public interface EnvRegularCallFeedingMapper extends BaseMapper<EnvRegularCallFe
 
     List<EnvRegularCallFeeding> listDayDesc(@Param(Constants.WRAPPER) QueryWrapper<EnvRegularCallFeeding> queryWrapper);
 
-    List<EnvRegularCallEggVo> listCount(String duckNum, Date resultDate);
+    List<EnvRegularCallEggVo> listCount(String duckNum);
 
     IPage<EnvRegularCallFeeding> listSelect(Page<EnvRegularCallFeeding> page, Date date,String farmId);
     IPage<EnvRegularCallFeeding> listSelect1(Page<EnvRegularCallFeeding> page, Date date,String farmId,String num);

+ 49 - 20
huimv-admin/src/main/java/com/huimv/guowei/admin/service/impl/BaseDuckInfoServiceImpl.java

@@ -14,10 +14,7 @@ import com.huimv.guowei.admin.common.utils.Result;
 import com.huimv.guowei.admin.common.utils.ResultCode;
 import com.huimv.guowei.admin.common.utils.UploadImage;
 import com.huimv.guowei.admin.entity.*;
-import com.huimv.guowei.admin.entity.vo.BaseDuckInfoImportData;
-import com.huimv.guowei.admin.entity.vo.BaseDuckInfoVo;
-import com.huimv.guowei.admin.entity.vo.EnvMoveCallVo;
-import com.huimv.guowei.admin.entity.vo.EnvRegularCallFeedingVo;
+import com.huimv.guowei.admin.entity.vo.*;
 import com.huimv.guowei.admin.mapper.*;
 import com.huimv.guowei.admin.service.IBaseDuckInfoService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -399,26 +396,58 @@ public class BaseDuckInfoServiceImpl extends ServiceImpl<BaseDuckInfoMapper, Bas
             for (EnvRegularCallFeeding feeding : feedings) {
                 count = count + feeding.getDuckWeight();
             }
-            QueryWrapper<EnvRegularCallEgg> queryWrapper3 = new QueryWrapper<>();
-            queryWrapper3.eq("chi_num", baseDuckInfo.getChiNum()).
-                    between(StringUtils.isNotBlank(startTime), "call_date", startTime+" 00:00:00", endTime+" 23:59:59");
-            List<EnvRegularCallEgg> eggs = eggMapper.selectList(queryWrapper3);//产蛋
-            double count1 = 0;
-            Integer eggNum = 0;
-            double avgWeight = 0;
-            for (EnvRegularCallEgg egg : eggs) {
-                count1 = count1 + egg.getDuckWeight();
-                eggNum = eggNum + egg.getEggNum();
-                if (baseDuckInfo.getDayAge() > 298) {
-                    avgWeight = egg.getDuckWeight();
+
+            Date resultDate = null;
+            int totalEgg = 0;
+            Date duckBirthday = baseDuckInfo.getDuckBirthday();
+            DateTime date = DateUtil.offsetDay(duckBirthday, 298);
+            Date dateTime = new Date(date.getTime());
+            List<EnvRegularCallEgg> envRegularCallEggs = eggMapper.selectList(new QueryWrapper<EnvRegularCallEgg>().lambda()
+                    .eq(EnvRegularCallEgg::getDuckNum,baseDuckInfo.getDuckNum())
+                    .ge(EnvRegularCallEgg::getCallDate, dateTime));
+            if (ObjectUtil.isNotEmpty(envRegularCallEggs)){
+                for (EnvRegularCallEgg envRegularCallEgg : envRegularCallEggs) {
+                    totalEgg += envRegularCallEgg.getEggNum();
+                    if (totalEgg > 3){
+                        resultDate = envRegularCallEgg.getCallDate();
+                        System.out.println("满足日龄的日期为:"+ resultDate);
+                        break;
+                    }
                 }
             }
-
             printEntrty.setBaseDuckInfo(baseDuckInfo);
-            printEntrty.setEggNum(String.valueOf(eggNum));
             printEntrty.setFeeding(def.format(count));
-            printEntrty.setEgging(def.format(count1));
-            printEntrty.setAvgWeiht(def.format(avgWeight));
+            Date endDate = new SimpleDateFormat("yyyy-MM-dd").parse(endTime);
+            Date startDate = new SimpleDateFormat("yyyy-MM-dd").parse(startTime);
+            System.out.println("开始时间:" + startDate);
+            System.out.println("结束时间:" + endDate);
+            System.out.println("满足日龄日期:" + dateTime);
+            if (ObjectUtil.isNotEmpty(resultDate)){
+                if (resultDate.after(endDate)){
+                    System.out.println("满足日龄在结束日期之后");
+                    printEntrty.setEggNum("0");
+                    printEntrty.setEgging("0");
+                    printEntrty.setAvgWeiht("0");
+                }else {
+                    EggVo eggVo = new EggVo();
+                    if (resultDate.before(startDate)){
+                        System.out.println("满足日龄在开始日期之前");
+                        eggVo = eggMapper.print(baseDuckInfo.getDuckNum(),startDate,endDate);
+                    }else {
+                        System.out.println("满足日龄在开始日期之后");
+                        eggVo = eggMapper.print(baseDuckInfo.getDuckNum(),resultDate,endDate);
+                    }
+                    printEntrty.setEggNum(eggVo.getTotalEgg());
+                    printEntrty.setEgging(eggVo.getTotalWeight());
+                    printEntrty.setAvgWeiht(eggVo.getAvgWeight());
+                }
+            }else {
+                System.out.println("日龄不满足");
+                printEntrty.setEggNum("0");
+                printEntrty.setEgging("0");
+                printEntrty.setAvgWeiht("0");
+            }
+
             printEntrty.setEnvMoveCalls(envMoveCalls);
             list.add(printEntrty);
         }

+ 5 - 19
huimv-admin/src/main/java/com/huimv/guowei/admin/service/impl/EnvRegularCallEggServiceImpl.java

@@ -25,7 +25,10 @@ import javax.servlet.http.HttpServletResponse;
 import java.math.BigDecimal;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.*;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
 
 /**
  * <p>
@@ -148,24 +151,7 @@ public class EnvRegularCallEggServiceImpl extends ServiceImpl<EnvRegularCallEggM
     @Override
     public void printEgg(HttpServletResponse response, Map<String, String> paramsMap) throws Exception {
         String duckCode = paramsMap.get("duckCode");
-        Date duckBirthday = infoMapper.selectOne(new QueryWrapper<BaseDuckInfo>().lambda().eq(BaseDuckInfo::getDuckNum, duckCode)).getDuckBirthday();
-        DateTime dateTime = DateUtil.offsetDay(duckBirthday, 298);
-        List<EnvRegularCallEggVo> envRegularCallEggVos = new ArrayList<>();
-        int totalEgg = 0;
-        Date resultDate = null;
-        List<EnvRegularCallEgg> envRegularCallEggs = eggMapper.selectList(new QueryWrapper<EnvRegularCallEgg>().lambda()
-                .ge(EnvRegularCallEgg::getCallDate, dateTime));
-        if (ObjectUtil.isNotEmpty(envRegularCallEggs)){
-            for (EnvRegularCallEgg envRegularCallEgg : envRegularCallEggs) {
-                totalEgg += envRegularCallEgg.getEggNum();
-                if (totalEgg > 3){
-                    resultDate = envRegularCallEgg.getCallDate();
-                }
-            }
-        }
-        if (ObjectUtil.isNotEmpty(resultDate)){
-            envRegularCallEggVos = feedingMapper.listCount(duckCode,resultDate);
-        }
+        List<EnvRegularCallEggVo> envRegularCallEggVos = feedingMapper.listCount(duckCode);
         Print.printEgg(envRegularCallEggVos);
     }
 

+ 4 - 0
huimv-admin/src/main/resources/com/huimv/guowei/admin/mapper/EnvRegularCallEggMapper.xml

@@ -46,4 +46,8 @@
     <select id="getTotalEgg" resultType="java.lang.String">
         SELECT SUM(egg_num) FROM `env_regular_call_egg` WHERE farm_id = #{farmId} AND YEAR(call_date) = YEAR(CURDATE());
     </select>
+    <select id="print" resultType="com.huimv.guowei.admin.entity.vo.EggVo">
+        select sum(egg_num) as totalEgg,sum(duck_weight) as totalWeight,Round((SUM(duck_weight)/SUM(egg_num)),2) as 'avgWeight' from `env_regular_call_egg`
+        where duck_num = #{duckNum}  AND call_date between ${startDate} and ${endDate}
+    </select>
 </mapper>

+ 1 - 1
huimv-admin/src/main/resources/com/huimv/guowei/admin/mapper/EnvRegularCallFeedingMapper.xml

@@ -113,7 +113,7 @@ FROM (
 LEFT JOIN (
     SELECT IFNULL(SUM(egg_num), 0) AS eggNum, IFNULL(SUM(duck_weight), 0) AS eggWeight, DATE_FORMAT(call_date, "%Y-%m-%d") AS call_date
     FROM `env_regular_call_egg`
-    WHERE duck_num = #{duckNum} and call_date &gt;= #{resultDate}
+    WHERE duck_num = #{duckNum}
     GROUP BY DATE_FORMAT(call_date, "%Y-%m-%d")
 ) t2
 ON DATE_FORMAT(t1.call_date,"%Y-%m-%d") = DATE_FORMAT(t2.call_date,"%Y-%m-%d")