|
@@ -1,5 +1,6 @@
|
|
|
package com.huimv.guowei.admin.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -8,6 +9,7 @@ import com.huimv.guowei.admin.common.utils.Result;
|
|
|
import com.huimv.guowei.admin.common.utils.ResultCode;
|
|
|
import com.huimv.guowei.admin.entity.*;
|
|
|
import com.huimv.guowei.admin.mapper.BaseBuildingMapper;
|
|
|
+import com.huimv.guowei.admin.mapper.BaseDuckInfoMapper;
|
|
|
import com.huimv.guowei.admin.mapper.EnvRegularCallFeedingMapper;
|
|
|
import com.huimv.guowei.admin.service.IEnvRegularCallFeedingService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -38,6 +40,8 @@ public class EnvRegularCallFeedingServiceImpl extends ServiceImpl<EnvRegularCall
|
|
|
private EnvRegularCallFeedingMapper feedingMapper;
|
|
|
@Resource
|
|
|
private BaseBuildingMapper baseBuildingMapper;
|
|
|
+ @Autowired
|
|
|
+ private BaseDuckInfoMapper infoMapper;
|
|
|
|
|
|
@Override
|
|
|
public Result listById(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
|
|
@@ -56,7 +60,7 @@ public class EnvRegularCallFeedingServiceImpl extends ServiceImpl<EnvRegularCall
|
|
|
QueryWrapper<EnvRegularCallFeeding> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.eq("duck_id", duckCode).eq("farm_id", farmId);
|
|
|
Page<EnvRegularCallFeeding> page = new Page<>(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
|
|
|
- return new Result(ResultCode.SUCCESS,feedingMapper.listPage(page, queryWrapper));
|
|
|
+ return new Result(ResultCode.SUCCESS, feedingMapper.listPage(page, queryWrapper));
|
|
|
} else {
|
|
|
String dateType = paramsMap.get("dateType");
|
|
|
QueryWrapper<EnvRegularCallFeeding> queryWrapper = new QueryWrapper<>();
|
|
@@ -81,17 +85,18 @@ public class EnvRegularCallFeedingServiceImpl extends ServiceImpl<EnvRegularCall
|
|
|
endDate = endDate + " 23:59:59";
|
|
|
queryWrapper.between("call_date", startDate, endDate);
|
|
|
}
|
|
|
- return new Result(ResultCode.SUCCESS,feedingMapper.listDay(queryWrapper));
|
|
|
+ return new Result(ResultCode.SUCCESS, feedingMapper.listDay(queryWrapper));
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
@Override
|
|
|
public Result listByH5(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
|
|
|
String farmId = paramsMap.get("farmId");
|
|
|
String unitName = paramsMap.get("unitName");
|
|
|
QueryWrapper<EnvRegularCallFeeding> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.eq("farm_id", farmId)
|
|
|
- .like(StringUtils.isNotBlank(unitName),"unit_name", unitName).orderByDesc("call_date").last(" limit 10");
|
|
|
+ .like(StringUtils.isNotBlank(unitName), "unit_name", unitName).orderByDesc("call_date").last(" limit 10");
|
|
|
return new Result(ResultCode.SUCCESS, feedingMapper.selectList(queryWrapper));
|
|
|
}
|
|
|
|
|
@@ -107,12 +112,32 @@ public class EnvRegularCallFeedingServiceImpl extends ServiceImpl<EnvRegularCall
|
|
|
if (pageSize == null || "".equals(pageSize)) {
|
|
|
pageSize = "10";
|
|
|
}
|
|
|
+ QueryWrapper<EnvRegularCallFeeding> queryWrapper1 = new QueryWrapper<>();
|
|
|
+ queryWrapper1.eq("farm_id", farmId).groupBy("duck_id");
|
|
|
+ List<EnvRegularCallFeeding> feedings = feedingMapper.selectList(queryWrapper1);
|
|
|
+ List<Integer> list = new ArrayList<>();
|
|
|
+ if (feedings.size() != 0) {
|
|
|
+ for (EnvRegularCallFeeding feeding : feedings) {
|
|
|
+ QueryWrapper<BaseDuckInfo> infoQueryWrapper = new QueryWrapper<>();
|
|
|
+ infoQueryWrapper.eq("farm_id", farmId).eq("id", feeding.getDuckId());
|
|
|
+ BaseDuckInfo baseDuckInfo = infoMapper.selectOne(infoQueryWrapper);
|
|
|
+ if (ObjectUtil.isNotEmpty(baseDuckInfo)) {
|
|
|
+ list.add(feeding.getDuckId());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
Date timesMonthmorning = DataUill.getTimesmorning();
|
|
|
QueryWrapper<EnvRegularCallFeeding> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("farm_id", farmId).like(StringUtils.isNotBlank(unitName), "unit_name", unitName)
|
|
|
- .select("SUM(duck_weight) duckWeight,duck_num duckNum,call_date callDate,unit_name unitName,duck_id duckId")
|
|
|
- .ge("call_date", timesMonthmorning)
|
|
|
- .orderByDesc("call_date");
|
|
|
+ if (list.size() != 0) {
|
|
|
+ queryWrapper.eq("farm_id", farmId).like(StringUtils.isNotBlank(unitName), "unit_name", unitName).in("duck_id", list)
|
|
|
+ .select("SUM(duck_weight) duckWeight,duck_num duckNum,call_date callDate,unit_name unitName,duck_id duckId")
|
|
|
+ .ge("call_date", timesMonthmorning)
|
|
|
+ .orderByDesc("call_date");
|
|
|
+ } else {
|
|
|
+ return new Result(ResultCode.SUCCESS, null);
|
|
|
+ }
|
|
|
Page<EnvRegularCallFeeding> page = new Page<>(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
|
|
|
return new Result(ResultCode.SUCCESS, feedingMapper.selectPage(page, queryWrapper));
|
|
|
}
|
|
@@ -124,10 +149,10 @@ public class EnvRegularCallFeedingServiceImpl extends ServiceImpl<EnvRegularCall
|
|
|
QueryWrapper<EnvRegularCallFeeding> queryWrapper = new QueryWrapper<>();
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 7);
|
|
|
- queryWrapper.eq("farm_id", farmId).eq("event_type",0)
|
|
|
- .eq(StringUtils.isNotBlank(duckId),"duck_id", duckId)
|
|
|
+ queryWrapper.eq("farm_id", farmId).eq("event_type", 0)
|
|
|
+ .eq(StringUtils.isNotBlank(duckId), "duck_id", duckId)
|
|
|
.ge("call_date", calendar.getTime());
|
|
|
- return new Result(ResultCode.SUCCESS, feedingMapper.listDay(queryWrapper));
|
|
|
+ return new Result(ResultCode.SUCCESS, feedingMapper.listDayDesc(queryWrapper));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -136,7 +161,7 @@ public class EnvRegularCallFeedingServiceImpl extends ServiceImpl<EnvRegularCall
|
|
|
String farmId = paramsMap.get("farmId");
|
|
|
Date timesmorning = DataUill.getTimesmorning();
|
|
|
Date timesMonthmorning = DataUill.getTimesMonthmorning();
|
|
|
- BigDecimal dayGap,monthGap;
|
|
|
+ BigDecimal dayGap, monthGap;
|
|
|
Map resultMap = new HashMap();
|
|
|
List<Integer> unitList = new ArrayList<>();
|
|
|
List<BaseBuilding> baseBuildingList = baseBuildingMapper.selectList(new QueryWrapper<BaseBuilding>().eq("parent_id", unitId));
|
|
@@ -145,53 +170,53 @@ public class EnvRegularCallFeedingServiceImpl extends ServiceImpl<EnvRegularCall
|
|
|
}
|
|
|
//今日
|
|
|
QueryWrapper<EnvRegularCallFeeding> queryWrapper1 = new QueryWrapper<>();
|
|
|
- queryWrapper1.in("d.unit_id",unitList).eq("f.farm_id",farmId).eq("f.event_type",0).ge("f.call_date",timesmorning);
|
|
|
+ queryWrapper1.in("d.unit_id", unitList).eq("f.farm_id", farmId).eq("f.event_type", 0).ge("f.call_date", timesmorning);
|
|
|
BigDecimal dayFeed = feedingMapper.getFeed(queryWrapper1);
|
|
|
//昨日
|
|
|
LocalDate yesterday = LocalDate.now().minusDays(1);
|
|
|
LocalDateTime startOfDay = yesterday.atStartOfDay();
|
|
|
LocalDateTime endOfDay = yesterday.atTime(LocalTime.MAX);
|
|
|
QueryWrapper<EnvRegularCallFeeding> queryWrapper2 = new QueryWrapper<>();
|
|
|
- queryWrapper2.in("d.unit_id",unitList).eq("f.farm_id",farmId).eq("f.event_type",0).between("f.call_date",startOfDay,endOfDay);
|
|
|
+ queryWrapper2.in("d.unit_id", unitList).eq("f.farm_id", farmId).eq("f.event_type", 0).between("f.call_date", startOfDay, endOfDay);
|
|
|
BigDecimal lastDayFeed = feedingMapper.getFeed(queryWrapper2);
|
|
|
//日环比
|
|
|
- if (lastDayFeed.toString().equals("0.0")){
|
|
|
+ if (lastDayFeed.toString().equals("0.0")) {
|
|
|
dayGap = BigDecimal.valueOf(100);
|
|
|
- if (dayFeed.toString().equals("0.0")){
|
|
|
+ if (dayFeed.toString().equals("0.0")) {
|
|
|
dayGap = BigDecimal.valueOf(0);
|
|
|
}
|
|
|
- }else {
|
|
|
- dayGap = dayFeed.subtract(lastDayFeed).divide(lastDayFeed,BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.UP);
|
|
|
+ } else {
|
|
|
+ dayGap = dayFeed.subtract(lastDayFeed).divide(lastDayFeed, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.UP);
|
|
|
}
|
|
|
//本月
|
|
|
QueryWrapper<EnvRegularCallFeeding> queryWrapper3 = new QueryWrapper<>();
|
|
|
- queryWrapper3.in("d.unit_id",unitList).eq("f.farm_id",farmId).eq("f.event_type",0).ge("f.call_date",timesMonthmorning);
|
|
|
+ queryWrapper3.in("d.unit_id", unitList).eq("f.farm_id", farmId).eq("f.event_type", 0).ge("f.call_date", timesMonthmorning);
|
|
|
BigDecimal monthFeed = feedingMapper.getFeed(queryWrapper3);
|
|
|
//上月
|
|
|
Date lastMonthStartMorning = DataUill.getLastMonthStartMorning();
|
|
|
Date lastMonthEndNight = DataUill.getLastMonthEndNight();
|
|
|
QueryWrapper<EnvRegularCallFeeding> queryWrapper4 = new QueryWrapper<>();
|
|
|
- queryWrapper4.in("d.unit_id",unitList).eq("f.farm_id",farmId).eq("f.event_type",0).between("f.call_date",lastMonthStartMorning,lastMonthEndNight);
|
|
|
+ queryWrapper4.in("d.unit_id", unitList).eq("f.farm_id", farmId).eq("f.event_type", 0).between("f.call_date", lastMonthStartMorning, lastMonthEndNight);
|
|
|
BigDecimal lastMonthFeed = feedingMapper.getFeed(queryWrapper4);
|
|
|
//月环比
|
|
|
- if (lastMonthFeed.toString().equals("0.0")){
|
|
|
+ if (lastMonthFeed.toString().equals("0.0")) {
|
|
|
monthGap = BigDecimal.valueOf(100);
|
|
|
- if (monthFeed.toString().equals("0.0")){
|
|
|
+ if (monthFeed.toString().equals("0.0")) {
|
|
|
monthGap = BigDecimal.valueOf(0);
|
|
|
}
|
|
|
- }else {
|
|
|
- monthGap = monthFeed.subtract(lastMonthFeed).divide(lastMonthFeed,BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.UP);
|
|
|
+ } else {
|
|
|
+ monthGap = monthFeed.subtract(lastMonthFeed).divide(lastMonthFeed, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.UP);
|
|
|
}
|
|
|
- int dayTrend =dayFeed.compareTo(lastDayFeed);
|
|
|
- int monthTrend =monthFeed.compareTo(lastMonthFeed);
|
|
|
- resultMap.put("dayFeed",dayFeed);
|
|
|
- resultMap.put("dayTrend",dayTrend);
|
|
|
- resultMap.put("dayFeedGap",dayGap+"%");
|
|
|
- resultMap.put("monthFeed",monthFeed);
|
|
|
- resultMap.put("monthTrend",monthTrend);
|
|
|
- resultMap.put("monthFeedGap",monthGap+"%");
|
|
|
-
|
|
|
- return new Result(ResultCode.SUCCESS,resultMap);
|
|
|
+ int dayTrend = dayFeed.compareTo(lastDayFeed);
|
|
|
+ int monthTrend = monthFeed.compareTo(lastMonthFeed);
|
|
|
+ resultMap.put("dayFeed", dayFeed);
|
|
|
+ resultMap.put("dayTrend", dayTrend);
|
|
|
+ resultMap.put("dayFeedGap", dayGap + "%");
|
|
|
+ resultMap.put("monthFeed", monthFeed);
|
|
|
+ resultMap.put("monthTrend", monthTrend);
|
|
|
+ resultMap.put("monthFeedGap", monthGap + "%");
|
|
|
+
|
|
|
+ return new Result(ResultCode.SUCCESS, resultMap);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -205,17 +230,17 @@ public class EnvRegularCallFeedingServiceImpl extends ServiceImpl<EnvRegularCall
|
|
|
for (BaseBuilding building : baseBuildingList) {
|
|
|
unitList.add(building.getId().toString());
|
|
|
}
|
|
|
- String units = String.join(",",unitList);
|
|
|
- units = "("+units+")";
|
|
|
+ String units = String.join(",", unitList);
|
|
|
+ units = "(" + units + ")";
|
|
|
//六个月
|
|
|
- if ("1".equals(type)){
|
|
|
+ if ("1".equals(type)) {
|
|
|
envRegularCallFeedingList = feedingMapper.listSixMonthFeed(farmId, units);
|
|
|
}
|
|
|
//七天
|
|
|
else {
|
|
|
envRegularCallFeedingList = feedingMapper.listSevenDayFeed(farmId, units);
|
|
|
}
|
|
|
- return new Result(ResultCode.SUCCESS,envRegularCallFeedingList);
|
|
|
+ return new Result(ResultCode.SUCCESS, envRegularCallFeedingList);
|
|
|
}
|
|
|
|
|
|
}
|