|
|
@@ -0,0 +1,402 @@
|
|
|
+package cn.vber.breeding.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
+import cn.vber.base.enums.EggTypeEnum;
|
|
|
+import cn.vber.breeding.domain.CoopBatchReport;
|
|
|
+import cn.vber.breeding.domain.CoopBatchReportDetail;
|
|
|
+import cn.vber.breeding.domain.bo.statistic.QueryStaBo;
|
|
|
+import cn.vber.breeding.domain.bo.statistic.QueryStaScopeParam;
|
|
|
+import cn.vber.breeding.domain.bo.statistic.QueryStaScopeParamBo;
|
|
|
+import cn.vber.breeding.domain.vo.CoopBatchReportVo;
|
|
|
+import cn.vber.breeding.domain.vo.statistic.*;
|
|
|
+import cn.vber.breeding.mapper.CoopBatchReportDetailMapper;
|
|
|
+import cn.vber.breeding.mapper.CoopBatchReportMapper;
|
|
|
+import cn.vber.breeding.service.ICommonService;
|
|
|
+import cn.vber.breeding.service.IStatisticsHelperService;
|
|
|
+import cn.vber.common.core.exception.ServiceException;
|
|
|
+import cn.vber.common.core.utils.DateUtils;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class StatisticsHelperServiceImpl implements IStatisticsHelperService {
|
|
|
+
|
|
|
+ private final CoopBatchReportMapper reportMapper;
|
|
|
+ private final CoopBatchReportDetailMapper reportDetailMapper;
|
|
|
+ private final CoopBatchReportDetailMapper coopBatchReportDetailMapper;
|
|
|
+ private final ICommonService commonService;
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public void statisticDay(QueryStaBo input){
|
|
|
+ log.info("--------------开始日统计--------------");
|
|
|
+ QueryStaScopeParam param = commonService.convertQueryStaToParam(input);
|
|
|
+ Map<String, StatisticTmpResultDto> tmpResultMap = new HashMap<>();
|
|
|
+ //统计出当日个体个数
|
|
|
+ List<CoopBatchChickenStatisticResultVo> chickenStatistics = reportDetailMapper.selectChickenCount(param);
|
|
|
+ for (CoopBatchChickenStatisticResultVo resultVo : chickenStatistics) {
|
|
|
+ String key = resultVo.getCoopId() + "_" + resultVo.getBatchNum();
|
|
|
+ StatisticTmpResultDto tmpResult = tmpResultMap.computeIfAbsent(key,k->new StatisticTmpResultDto());
|
|
|
+ tmpResult.setCoopId(resultVo.getCoopId());
|
|
|
+ tmpResult.setBatchNum(resultVo.getBatchNum());
|
|
|
+ if(resultVo.getGender() == 0){
|
|
|
+ tmpResult.setChicken0(resultVo.getChickenCount());
|
|
|
+ }else if(resultVo.getGender() == 1){
|
|
|
+ tmpResult.setChicken1(resultVo.getChickenCount());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //统计出淘汰数,转入,转出,蛋的统计
|
|
|
+ statisticCommon(tmpResultMap,param);
|
|
|
+ //fillFemaleCountAll(tmpResultMap,param);
|
|
|
+ fillLastCycle(tmpResultMap,param);
|
|
|
+
|
|
|
+ tmpResultMap.forEach((k,v)->{
|
|
|
+ calcCommon(v);
|
|
|
+ });
|
|
|
+ insertReport(input,tmpResultMap);
|
|
|
+ }
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public void statisticMonthOrYearOrQuarter(QueryStaBo input){
|
|
|
+ log.info("--------------开始月/年/季度统计--------------");
|
|
|
+ QueryStaScopeParam param = commonService.convertQueryStaToParam(input);
|
|
|
+ Map<String, StatisticTmpResultDto> tmpResultMap = new HashMap<>();
|
|
|
+ //统计出淘汰数,转入,转出,蛋的统计
|
|
|
+ statisticCommon(tmpResultMap,param);
|
|
|
+ //填充母鸡数量的每日总和
|
|
|
+ fillFemaleCountAll(tmpResultMap,param);
|
|
|
+ //填充上一次周期的统计
|
|
|
+ fillLastCycle(tmpResultMap,param);
|
|
|
+
|
|
|
+ tmpResultMap.forEach((k,v)->{
|
|
|
+ calcCommon(v);
|
|
|
+ });
|
|
|
+ insertReport(input,tmpResultMap);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //插入统计表中
|
|
|
+
|
|
|
+ private void insertReport(QueryStaBo input, Map<String, StatisticTmpResultDto> tmpResultMap){
|
|
|
+ deleteHistory(input);
|
|
|
+ CoopBatchReport report = new CoopBatchReport();
|
|
|
+ String title = Objects.equals(input.getReportCycle(), "Y") ? "年" : Objects.equals(input.getReportCycle(), "Q")
|
|
|
+ ? "季度" : Objects.equals(input.getReportCycle(), "M") ? "月" : "日" + "统计";
|
|
|
+ String reportId = IdUtil.simpleUUID();
|
|
|
+ report.setId(reportId);
|
|
|
+ report.setTitle(title);
|
|
|
+ report.setYear(input.getYear());
|
|
|
+ report.setReportCycle(input.getReportCycle());
|
|
|
+ report.setMonth(input.getMonth());
|
|
|
+ report.setDay(input.getDay());
|
|
|
+ report.setQuarter(input.getQuarter());
|
|
|
+ report.setReportType(input.getCoopType());
|
|
|
+ //临时头报表统计数据
|
|
|
+ StatisticTmpResultDto tmpAll = new StatisticTmpResultDto();
|
|
|
+ // 1. 使用entrySet()遍历键值对
|
|
|
+ for (Map.Entry<String, StatisticTmpResultDto> entry : tmpResultMap.entrySet()) {
|
|
|
+ String key = entry.getKey();
|
|
|
+ StatisticTmpResultDto value = entry.getValue();
|
|
|
+ // 处理key和value
|
|
|
+ //System.out.println("Key: " + key + ", Value: " + value);
|
|
|
+ CoopBatchReportDetail detail = new CoopBatchReportDetail();
|
|
|
+ detail.setReportId(reportId);
|
|
|
+ detail.setCoopId(value.getCoopId());
|
|
|
+ detail.setBatchNum(value.getBatchNum());
|
|
|
+ detail.setReportDate(getReportDate(input));
|
|
|
+ detail.setReportCycle(input.getReportCycle());
|
|
|
+ detail.setLastSave0(value.getLastSave0());
|
|
|
+ tmpAll.setLastSave0(tmpAll.getLastSave0() + value.getLastSave0());
|
|
|
+ detail.setLastSave1(value.getLastSave1());
|
|
|
+ tmpAll.setLastSave1(tmpAll.getLastSave1() + value.getLastSave1());
|
|
|
+ detail.setSave0(value.getSave0());
|
|
|
+ detail.setSave1(value.getSave1());
|
|
|
+ detail.setCull0(value.getCull0());
|
|
|
+ tmpAll.setCull0(tmpAll.getCull0() + value.getCull0());
|
|
|
+ detail.setCull1(value.getCull1());
|
|
|
+ tmpAll.setCull1(tmpAll.getCull1() + value.getCull1());
|
|
|
+ detail.setIn0(value.getIn0());
|
|
|
+ tmpAll.setIn0(tmpAll.getIn0() + value.getIn0());
|
|
|
+ detail.setIn1(value.getIn1());
|
|
|
+ tmpAll.setIn1(tmpAll.getIn1() + value.getIn1());
|
|
|
+ detail.setOut0(value.getOut0());
|
|
|
+ tmpAll.setOut0(tmpAll.getOut0() + value.getOut0());
|
|
|
+ detail.setOut1(value.getOut1());
|
|
|
+ tmpAll.setOut1(tmpAll.getOut1() + value.getOut1());
|
|
|
+ detail.setChicken0(value.getChicken0());
|
|
|
+ tmpAll.setChicken0(tmpAll.getChicken0() + value.getChicken0());
|
|
|
+ detail.setChicken1(value.getChicken1());
|
|
|
+ tmpAll.setChicken1(tmpAll.getChicken1() + value.getChicken1());
|
|
|
+ detail.setQualifiedEgg(value.getQualifiedEgg());
|
|
|
+ tmpAll.setQualifiedEgg(tmpAll.getQualifiedEgg() + value.getQualifiedEgg());
|
|
|
+ detail.setDeformedEgg(value.getDeformedEgg());
|
|
|
+ tmpAll.setDeformedEgg(tmpAll.getDeformedEgg() + value.getDeformedEgg());
|
|
|
+ detail.setBreakEgg(value.getBreakEgg());
|
|
|
+ tmpAll.setBreakEgg(tmpAll.getBreakEgg() + value.getBreakEgg());
|
|
|
+ detail.setEggPassRate(value.getEggPassRate());
|
|
|
+ detail.setEggProductionRate(value.getEggProductionRate());
|
|
|
+ detail.setLifeRate(value.getLifeRate());
|
|
|
+ detail.setCullRate(value.getCullRate());
|
|
|
+ detail.setCreateOrg(201L);
|
|
|
+ reportDetailMapper.insert(detail);
|
|
|
+ }
|
|
|
+ calcCommon(tmpAll);
|
|
|
+ report.setLastSave0(tmpAll.getLastSave0());
|
|
|
+ report.setLastSave1(tmpAll.getLastSave1());
|
|
|
+ report.setSave0(tmpAll.getSave0());
|
|
|
+ report.setSave1(tmpAll.getSave1());
|
|
|
+ report.setCull0(tmpAll.getCull0());
|
|
|
+ report.setCull1(tmpAll.getCull1());
|
|
|
+ report.setIn0(tmpAll.getIn0());
|
|
|
+ report.setIn1(tmpAll.getIn1());
|
|
|
+ report.setOut0(tmpAll.getOut0());
|
|
|
+ report.setOut1(tmpAll.getOut1());
|
|
|
+ report.setChicken0(tmpAll.getChicken0());
|
|
|
+ report.setChicken1(tmpAll.getChicken1());
|
|
|
+ report.setQualifiedEgg(tmpAll.getQualifiedEgg());
|
|
|
+ report.setDeformedEgg(tmpAll.getDeformedEgg());
|
|
|
+ report.setBreakEgg(tmpAll.getBreakEgg());
|
|
|
+ report.setEggPassRate(tmpAll.getEggPassRate());
|
|
|
+ report.setEggProductionRate(tmpAll.getEggProductionRate());
|
|
|
+ report.setLifeRate(tmpAll.getLifeRate());
|
|
|
+ report.setCullRate(tmpAll.getCullRate());
|
|
|
+ reportMapper.insert(report);
|
|
|
+ }
|
|
|
+ //删除之前统计数据
|
|
|
+ private void deleteHistory(QueryStaBo input){
|
|
|
+ LambdaQueryWrapper<CoopBatchReport> law = new LambdaQueryWrapper<>(CoopBatchReport.class)
|
|
|
+ .eq(CoopBatchReport::getReportCycle, input.getReportCycle())
|
|
|
+ .eq(CoopBatchReport::getYear, input.getYear())
|
|
|
+ .eq(input.getMonth()!=null &&input.getMonth() > 0,CoopBatchReport::getMonth, input.getMonth())
|
|
|
+ .eq(input.getDay()!=null &&input.getDay() > 0,CoopBatchReport::getDay, input.getDay())
|
|
|
+ .eq(input.getQuarter()!=null &&input.getQuarter() > 0,CoopBatchReport::getQuarter, input.getQuarter());
|
|
|
+ List<CoopBatchReport> coopBatchReports = reportMapper.selectList(law);
|
|
|
+ if(!coopBatchReports.isEmpty()){
|
|
|
+ //reportMapper.deleteBatchIds(coopBatchReports);
|
|
|
+ coopBatchReports.forEach(report -> {
|
|
|
+ reportDetailMapper.delete(new LambdaQueryWrapper<>(CoopBatchReportDetail.class)
|
|
|
+ .eq(CoopBatchReportDetail::getReportId, report.getId()));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ reportMapper.delete(law);
|
|
|
+ }
|
|
|
+ //统计月/季度/年 中所有天数中母鸡的总数 chicken1 ,日的不统计
|
|
|
+ private void fillFemaleCountAll(Map<String, StatisticTmpResultDto> map,QueryStaScopeParam queryScopeParam) {
|
|
|
+ Map<String, SumFemaleCountTmpDto> sumFemaleCountTmpDtoMap = queryFemaleCountAll(queryScopeParam);
|
|
|
+ map.forEach((k,v)->{
|
|
|
+ SumFemaleCountTmpDto sumFemaleDto = sumFemaleCountTmpDtoMap.get(k);
|
|
|
+ if(sumFemaleDto != null){
|
|
|
+ v.setChicken1(sumFemaleDto.getChickenAll1());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ private void fillLastCycle(Map<String, StatisticTmpResultDto> map,QueryStaScopeParam queryScopeParam) {
|
|
|
+ Map<String, CoopBatchReportDetail> coopBatchReportDetailMap = queryLastCycleReportDetail(queryScopeParam);
|
|
|
+ if(coopBatchReportDetailMap==null || coopBatchReportDetailMap.isEmpty()){
|
|
|
+ log.info("--------------没有上一周期数据--------------");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ map.forEach((k,v)->{
|
|
|
+ CoopBatchReportDetail detail = coopBatchReportDetailMap.get(k);
|
|
|
+ if(detail != null){
|
|
|
+ v.setLastSave0(detail.getSave0());
|
|
|
+ v.setLastSave1(detail.getSave1());
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, SumFemaleCountTmpDto> queryFemaleCountAll(QueryStaScopeParam queryScopeParam){
|
|
|
+ List<ChickenStatisticDayResultVo> chickenStatisticDayResultVos =
|
|
|
+ coopBatchReportDetailMapper.selectChickenCountDay(queryScopeParam);
|
|
|
+ Map<String, SumFemaleCountTmpDto> map = new HashMap<>();
|
|
|
+ for (ChickenStatisticDayResultVo chickenStatisticDayResultVo : chickenStatisticDayResultVos) {
|
|
|
+ String key = chickenStatisticDayResultVo.getCoopId() + "_" + chickenStatisticDayResultVo.getBatchNum();
|
|
|
+ SumFemaleCountTmpDto sumFemaleDto = map.computeIfAbsent(key, k -> new SumFemaleCountTmpDto());
|
|
|
+ sumFemaleDto.setBatchNum(chickenStatisticDayResultVo.getBatchNum());
|
|
|
+ sumFemaleDto.setCoopId(chickenStatisticDayResultVo.getCoopId());
|
|
|
+ Integer chickenAll1 = sumFemaleDto.getChickenAll1();
|
|
|
+ sumFemaleDto.setChickenAll1(chickenAll1 + chickenStatisticDayResultVo.getChicken1());
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取上一周期数据
|
|
|
+ * @param queryScopeParam
|
|
|
+ * @return Map<String,CoopBatchReportDetail>
|
|
|
+ */
|
|
|
+ private Map<String,CoopBatchReportDetail> queryLastCycleReportDetail(QueryStaScopeParam queryScopeParam){
|
|
|
+ QueryStaBo queryLastStaBo = commonService.getLastCycle(queryScopeParam.getStartDate(), queryScopeParam.getReportCycle());
|
|
|
+ LambdaQueryWrapper<CoopBatchReport> law = new LambdaQueryWrapper<>(CoopBatchReport.class)
|
|
|
+ .eq(CoopBatchReport::getReportCycle, queryLastStaBo.getReportCycle())
|
|
|
+ .eq(CoopBatchReport::getYear, queryLastStaBo.getYear())
|
|
|
+ .eq((queryLastStaBo.getMonth()!=null && queryLastStaBo.getMonth() > 0),CoopBatchReport::getMonth, queryLastStaBo.getMonth())
|
|
|
+ .eq(queryLastStaBo.getDay()!=null && queryLastStaBo.getDay() > 0,CoopBatchReport::getDay, queryLastStaBo.getDay())
|
|
|
+ .eq(queryLastStaBo.getQuarter()!=null && queryLastStaBo.getQuarter() > 0,CoopBatchReport::getQuarter, queryLastStaBo.getQuarter());
|
|
|
+ try {
|
|
|
+ CoopBatchReport coopBatchReport = reportMapper.selectOne(law);
|
|
|
+ if(coopBatchReport == null){
|
|
|
+ log.error("没有查询到上一周期数据-{}-{}-{}-{}-{}"
|
|
|
+ ,queryLastStaBo.getReportCycle(),queryLastStaBo.getYear()
|
|
|
+ ,queryLastStaBo.getMonth(),queryLastStaBo.getDay()
|
|
|
+ ,queryLastStaBo.getQuarter());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<CoopBatchReportDetail> law1 = new LambdaQueryWrapper<>(CoopBatchReportDetail.class)
|
|
|
+ .eq(CoopBatchReportDetail::getReportId, coopBatchReport.getId());
|
|
|
+
|
|
|
+ List<CoopBatchReportDetail> coopBatchReportDetails = reportDetailMapper.selectList(law1);
|
|
|
+ Map<String, CoopBatchReportDetail> map = new HashMap<>();
|
|
|
+ for (CoopBatchReportDetail coopBatchReportDetail : coopBatchReportDetails) {
|
|
|
+ String key = coopBatchReportDetail.getCoopId() + "_" + coopBatchReportDetail.getBatchNum();
|
|
|
+ map.computeIfAbsent(key, k->coopBatchReportDetail);
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("查询上一周期数据失败",e);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算通用数据
|
|
|
+ * @param tmpResult
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void calcCommon(StatisticTmpResultDto tmpResult){
|
|
|
+ tmpResult.setSave0(tmpResult.getIn0() - tmpResult.getOut0() - tmpResult.getCull0());
|
|
|
+ tmpResult.setSave1(tmpResult.getIn1() - tmpResult.getOut1() - tmpResult.getCull1());
|
|
|
+ int cultCount = tmpResult.getCull0() + tmpResult.getCull1();
|
|
|
+ int lastSave = tmpResult.getLastSave0() + tmpResult.getLastSave1();
|
|
|
+ int inCount = tmpResult.getIn0() + tmpResult.getIn1();
|
|
|
+ int outCount = tmpResult.getOut0() + tmpResult.getOut1();
|
|
|
+ int d2 = lastSave + inCount - outCount;
|
|
|
+ if(cultCount == 0 || d2 == 0){
|
|
|
+ tmpResult.setCullRate(0f);
|
|
|
+ }
|
|
|
+ if(d2==0 || cultCount==0){
|
|
|
+ tmpResult.setCullRate(0f);
|
|
|
+ tmpResult.setLifeRate(0f);
|
|
|
+ }else{
|
|
|
+ float cultRate = (float) cultCount / d2;
|
|
|
+ float lifeRate = 1 - cultRate;
|
|
|
+ tmpResult.setCullRate(cultRate);
|
|
|
+ tmpResult.setLifeRate(lifeRate);
|
|
|
+ }
|
|
|
+ int qualifiedEgg = tmpResult.getQualifiedEgg();
|
|
|
+ int allEgg = tmpResult.getQualifiedEgg() + tmpResult.getDeformedEgg() + tmpResult.getBreakEgg();
|
|
|
+ //每日母鸡总数之和
|
|
|
+ Integer chickenAll1 = tmpResult.getChicken1();
|
|
|
+ if(qualifiedEgg == 0){
|
|
|
+ tmpResult.setEggPassRate(0f);
|
|
|
+ }else{
|
|
|
+ //种蛋合格率
|
|
|
+ tmpResult.setEggPassRate((float) (qualifiedEgg / allEgg));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(allEgg <= 0 || chickenAll1 <= 0){
|
|
|
+ tmpResult.setEggProductionRate(0f);
|
|
|
+ }else{
|
|
|
+ //产蛋率
|
|
|
+ tmpResult.setEggProductionRate((float) (allEgg / chickenAll1));
|
|
|
+ }
|
|
|
+// tmpResult.setLifeRateStr(convertFloatToStr(tmpResult.getLifeRate()));
|
|
|
+// tmpResult.setCullRateStr(convertFloatToStr(tmpResult.getCullRate()));
|
|
|
+// tmpResult.setEggProductionRate-Str(convertFloatToStr(tmpResult.getEggProductionRate()));
|
|
|
+// tmpResult.setEggPassRateStr(convertFloatToStr(tmpResult.getEggPassRate()));
|
|
|
+ }
|
|
|
+// private String convertFloatToStr(Float f){
|
|
|
+// if(f == null){
|
|
|
+// return "-";
|
|
|
+// }
|
|
|
+// return String.format("%.4f", f * 100) + "%";
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通用统计
|
|
|
+ * @param tmpResultMap
|
|
|
+ * @param param
|
|
|
+ */
|
|
|
+ public void statisticCommon(Map<String, StatisticTmpResultDto> tmpResultMap,QueryStaScopeParam param){
|
|
|
+
|
|
|
+ List<CoopBatchChickenStatisticResultVo> cullStatistics = reportDetailMapper.selectCullCount(param);
|
|
|
+ for (CoopBatchChickenStatisticResultVo resultVo : cullStatistics) {
|
|
|
+ String key = resultVo.getCoopId() + "_" + resultVo.getBatchNum();
|
|
|
+ StatisticTmpResultDto tmpResult = tmpResultMap.computeIfAbsent(key,k->new StatisticTmpResultDto());
|
|
|
+ tmpResult.setCoopId(resultVo.getCoopId());
|
|
|
+ tmpResult.setBatchNum(resultVo.getBatchNum());
|
|
|
+ if(resultVo.getGender() == 0){
|
|
|
+ tmpResult.setCull0(resultVo.getChickenCount());
|
|
|
+ }else if(resultVo.getGender() == 1){
|
|
|
+ tmpResult.setCull1(resultVo.getChickenCount());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<CoopBatchChickenStatisticResultVo> statisticsIn = reportDetailMapper.selectChickenIn(param);
|
|
|
+ for (CoopBatchChickenStatisticResultVo resultVo : statisticsIn) {
|
|
|
+ String key = resultVo.getCoopId() + "_" + resultVo.getBatchNum();
|
|
|
+ StatisticTmpResultDto tmpResult = tmpResultMap.computeIfAbsent(key,k->new StatisticTmpResultDto());
|
|
|
+ tmpResult.setCoopId(resultVo.getCoopId());
|
|
|
+ tmpResult.setBatchNum(resultVo.getBatchNum());
|
|
|
+ if(resultVo.getGender() == 0){
|
|
|
+ tmpResult.setIn0(resultVo.getChickenCount());
|
|
|
+ }else if(resultVo.getGender() == 1){
|
|
|
+ tmpResult.setIn1(resultVo.getChickenCount());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<CoopBatchChickenStatisticResultVo> statisticsOut = reportDetailMapper.selectChickenOut(param);
|
|
|
+ for (CoopBatchChickenStatisticResultVo resultVo : statisticsOut) {
|
|
|
+ String key = resultVo.getCoopId() + "_" + resultVo.getBatchNum();
|
|
|
+ StatisticTmpResultDto tmpResult = tmpResultMap.computeIfAbsent(key,k->new StatisticTmpResultDto());
|
|
|
+ tmpResult.setCoopId(resultVo.getCoopId());
|
|
|
+ tmpResult.setBatchNum(resultVo.getBatchNum());
|
|
|
+ if(resultVo.getGender() == 0){
|
|
|
+ tmpResult.setOut0(resultVo.getChickenCount());
|
|
|
+ }else if(resultVo.getGender() == 1){
|
|
|
+ tmpResult.setOut1(resultVo.getChickenCount());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<CoopBatchEggStatisticResultVo> eggStatistics = reportDetailMapper.selectStatisticEgg(param);
|
|
|
+ for (CoopBatchEggStatisticResultVo resultVo : eggStatistics) {
|
|
|
+ String key = resultVo.getCoopId() + "_" + resultVo.getBatchNum();
|
|
|
+ StatisticTmpResultDto tmpResult = tmpResultMap.computeIfAbsent(key,k->new StatisticTmpResultDto());
|
|
|
+ tmpResult.setCoopId(resultVo.getCoopId());
|
|
|
+ tmpResult.setBatchNum(resultVo.getBatchNum());
|
|
|
+ if(Objects.equals(resultVo.getEggType(), EggTypeEnum.INCUBATION_EGG.getCode())){
|
|
|
+ tmpResult.setEggCount0(resultVo.getEggCount());
|
|
|
+ }else if(Objects.equals(resultVo.getEggType(), EggTypeEnum.VEGETABLE_EGG.getCode())){
|
|
|
+ tmpResult.setEggCount1(resultVo.getEggCount());
|
|
|
+ }else if (Objects.equals(resultVo.getEggType(), EggTypeEnum.DEFORMED_EGG.getCode())){
|
|
|
+ tmpResult.setDeformedEgg(resultVo.getEggCount());
|
|
|
+ }else if (Objects.equals(resultVo.getEggType(), EggTypeEnum.BREAK_EGG.getCode())){
|
|
|
+ tmpResult.setBreakEgg(resultVo.getEggCount());
|
|
|
+ }
|
|
|
+ tmpResult.setQualifiedEgg((tmpResult.getEggCount0()>0 ? tmpResult.getEggCount0() : 0) +
|
|
|
+ (tmpResult.getEggCount1()>0? tmpResult.getEggCount1() : 0));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Date getReportDate(QueryStaBo input) {
|
|
|
+ String reportCycle = input.getReportCycle();
|
|
|
+ return switch (reportCycle) {
|
|
|
+ case "Y", "Q", "M" -> DateUtils.getNowDate();
|
|
|
+ case "D" -> DateUtils.createDate(input.getYear(), input.getMonth(), input.getDay());
|
|
|
+ default -> throw new ServiceException("不支持的报表周期: " + reportCycle);
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|