|
@@ -1,119 +1,119 @@
|
|
-//package com.huimv.eartag2.api.service.impl;
|
|
|
|
-//
|
|
|
|
-//import com.alibaba.fastjson.JSONObject;
|
|
|
|
-//import com.huimv.eartag2.api.mapper.BaseFarmerMapper;
|
|
|
|
-//import com.huimv.eartag2.api.mapper.EartagDeviceRegisterMapper;
|
|
|
|
-//import com.huimv.eartag2.api.mapper.EartagEartagRegister2Mapper;
|
|
|
|
-//import com.huimv.eartag2.api.mapper.FarmerAssetMapper;
|
|
|
|
-//import com.huimv.eartag2.api.pojo.EartagEartagRegister2;
|
|
|
|
-//import com.huimv.eartag2.api.pojo.FarmerAsset;
|
|
|
|
-//import com.huimv.eartag2.common.utils.DateUtil;
|
|
|
|
-//import com.huimv.eartag2.common.utils.Result;
|
|
|
|
-//import com.huimv.eartag2.common.utils.ResultCode;
|
|
|
|
-//import com.huimv.eartag2.api.service.FarmerAssetService;
|
|
|
|
-//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
-//import lombok.extern.slf4j.Slf4j;
|
|
|
|
-//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
-//import org.springframework.beans.factory.annotation.Value;
|
|
|
|
-//import org.springframework.stereotype.Service;
|
|
|
|
-//
|
|
|
|
-//import java.math.BigDecimal;
|
|
|
|
-//import java.text.ParseException;
|
|
|
|
-//import java.util.*;
|
|
|
|
-//
|
|
|
|
-///**
|
|
|
|
-// * <p>
|
|
|
|
-// * 服务实现类
|
|
|
|
-// * </p>
|
|
|
|
-// *
|
|
|
|
-// * @author zn
|
|
|
|
-// * @since 2022-08-29
|
|
|
|
-// */
|
|
|
|
-//@Service
|
|
|
|
-//@Slf4j
|
|
|
|
-//public class FarmerAssetServiceImpl extends ServiceImpl<FarmerAssetMapper, FarmerAsset> implements FarmerAssetService {
|
|
|
|
-// @Autowired
|
|
|
|
-// private FarmerAssetMapper farmerAssetMapper;
|
|
|
|
-// @Autowired
|
|
|
|
-// private EartagEartagRegister2Mapper eartagEartagRegister2Mapper;
|
|
|
|
-// @Autowired
|
|
|
|
-// private EartagDeviceRegisterMapper eartagDeviceRegisterMapper;
|
|
|
|
-//
|
|
|
|
-// @Autowired
|
|
|
|
-// private BaseFarmerMapper baseFarmerMapper;
|
|
|
|
-// @Value("${farmer.pig.price}")
|
|
|
|
-// private String pigPrice;
|
|
|
|
-//
|
|
|
|
-// @Override
|
|
|
|
-// public List<FarmerAsset> getLastManyMonthAssets(String farmCode, String manyMonth) {
|
|
|
|
-// //{}
|
|
|
|
-// return farmerAssetMapper.getLastManyMonthAssets(farmCode,manyMonth);
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// @Override
|
|
|
|
-// public Result getAssetStatistics(Map<String, Object> paramsMap) throws ParseException {
|
|
|
|
-// //--农户
|
|
|
|
-// String farmerId = paramsMap.get("farmerId")+"";
|
|
|
|
-// System.out.println("farmerId="+farmerId);
|
|
|
|
-//
|
|
|
|
-// //{根据农户读取采集器}
|
|
|
|
-// String deviceCode = eartagDeviceRegisterMapper.getDeviceIdByFarmerId(farmerId);
|
|
|
|
-// //{读取最后一批猪信息}
|
|
|
|
-// JSONObject lastBatchJo = _getlastBatchAdoptPig(deviceCode);
|
|
|
|
-// //读取资产信息
|
|
|
|
-// List<FarmerAsset> farmerAssetList = farmerAssetMapper.getAssetByMonth(6,farmerId);
|
|
|
|
-// List reverseList = new ArrayList();
|
|
|
|
-// //--反转排序
|
|
|
|
-// for(int a=farmerAssetList.size()-1;a>=0;a--){
|
|
|
|
-// reverseList.add(farmerAssetList.get(a));
|
|
|
|
-// }
|
|
|
|
-// if(lastBatchJo != null){
|
|
|
|
-// lastBatchJo.put("estimated",reverseList);
|
|
|
|
-// return new Result(ResultCode.SUCCESS,lastBatchJo);
|
|
|
|
-// }else{
|
|
|
|
-// JSONObject nullLastBatchJo = new JSONObject();
|
|
|
|
-// nullLastBatchJo.put("adoptTime","");
|
|
|
|
-// nullLastBatchJo.put("husbandryTime","");
|
|
|
|
-// nullLastBatchJo.put("currentPrices",0);
|
|
|
|
-// nullLastBatchJo.put("expectedEarning",0);
|
|
|
|
-// nullLastBatchJo.put("estimated",reverseList);
|
|
|
|
-// return new Result(ResultCode.SUCCESS,nullLastBatchJo);
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-//
|
|
|
|
-//
|
|
|
|
-// //{读取最后一批猪信息}
|
|
|
|
-// private JSONObject _getlastBatchAdoptPig(String deviceCode) throws ParseException {
|
|
|
|
-// //{获取最后一条记录create_date日期}
|
|
|
|
-// Date createDate = eartagEartagRegister2Mapper.getLastBatchCreateDate(deviceCode);
|
|
|
|
-// if(createDate == null){
|
|
|
|
-// log.error("该采集器["+deviceCode+"]没有耳标注册数据.");
|
|
|
|
-// return null;
|
|
|
|
-// }else{
|
|
|
|
-// DateUtil dateUtil = new DateUtil();
|
|
|
|
-// List<EartagEartagRegister2> eartagEartagRegister2List = eartagEartagRegister2Mapper.getLastBatchPig(deviceCode,createDate);
|
|
|
|
-// if(eartagEartagRegister2List.size()>0){
|
|
|
|
-// long diff = dateUtil.getTodayDate().getTime()-createDate.getTime();
|
|
|
|
-// long days = diff / (1000 * 60 * 60 * 24);
|
|
|
|
-// //读取重量
|
|
|
|
-// BigDecimal weightBd = farmerAssetMapper.getPigWeightByDayage(days);
|
|
|
|
-// BigDecimal planValue = weightBd.multiply(new BigDecimal(pigPrice)).multiply(new BigDecimal(eartagEartagRegister2List.size())).setScale(2,BigDecimal.ROUND_HALF_UP);
|
|
|
|
-// JSONObject outJo = new JSONObject();
|
|
|
|
-// outJo.put("adoptTime",dateUtil.formatDateText(createDate));
|
|
|
|
-// outJo.put("husbandryTime",days);
|
|
|
|
-// outJo.put("currentPrices",pigPrice);
|
|
|
|
-// outJo.put("expectedEarning",planValue.toString());
|
|
|
|
-// return outJo;
|
|
|
|
-// }else{
|
|
|
|
-// JSONObject outJo = new JSONObject();
|
|
|
|
-// outJo.put("adoptTime",null);
|
|
|
|
-// outJo.put("husbandryTime",null);
|
|
|
|
-// outJo.put("currentPrices",0);
|
|
|
|
-// outJo.put("expectedEarning",0);
|
|
|
|
-// return outJo;
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-//}
|
|
|
|
|
|
+package com.huimv.eartag2.api.service.impl;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.huimv.eartag2.api.mapper.BaseFarmerMapper;
|
|
|
|
+import com.huimv.eartag2.api.mapper.EartagDeviceRegisterMapper;
|
|
|
|
+import com.huimv.eartag2.api.mapper.EartagEartagRegister2Mapper;
|
|
|
|
+import com.huimv.eartag2.api.mapper.FarmerAssetMapper;
|
|
|
|
+import com.huimv.eartag2.api.pojo.EartagEartagRegister2;
|
|
|
|
+import com.huimv.eartag2.api.pojo.FarmerAsset;
|
|
|
|
+import com.huimv.eartag2.common.utils.DateUtil;
|
|
|
|
+import com.huimv.eartag2.common.utils.Result;
|
|
|
|
+import com.huimv.eartag2.common.utils.ResultCode;
|
|
|
|
+import com.huimv.eartag2.api.service.FarmerAssetService;
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.text.ParseException;
|
|
|
|
+import java.util.*;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * <p>
|
|
|
|
+ * 服务实现类
|
|
|
|
+ * </p>
|
|
|
|
+ *
|
|
|
|
+ * @author zn
|
|
|
|
+ * @since 2022-08-29
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+@Slf4j
|
|
|
|
+public class FarmerAssetServiceImpl extends ServiceImpl<FarmerAssetMapper, FarmerAsset> implements FarmerAssetService {
|
|
|
|
+ @Autowired
|
|
|
|
+ private FarmerAssetMapper farmerAssetMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private EartagEartagRegister2Mapper eartagEartagRegister2Mapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private EartagDeviceRegisterMapper eartagDeviceRegisterMapper;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private BaseFarmerMapper baseFarmerMapper;
|
|
|
|
+ @Value("${farmer.pig.price}")
|
|
|
|
+ private String pigPrice;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<FarmerAsset> getLastManyMonthAssets(String farmCode, String manyMonth) {
|
|
|
|
+ //{}
|
|
|
|
+ return farmerAssetMapper.getLastManyMonthAssets(farmCode,manyMonth);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Result getAssetStatistics(Map<String, Object> paramsMap) throws ParseException {
|
|
|
|
+ //--农户
|
|
|
|
+ String farmerId = paramsMap.get("farmerId")+"";
|
|
|
|
+ System.out.println("farmerId="+farmerId);
|
|
|
|
+
|
|
|
|
+ //{根据农户读取采集器}
|
|
|
|
+ String deviceCode = eartagDeviceRegisterMapper.getDeviceIdByFarmerId(farmerId);
|
|
|
|
+ //{读取最后一批猪信息}
|
|
|
|
+ JSONObject lastBatchJo = _getlastBatchAdoptPig(deviceCode);
|
|
|
|
+ //读取资产信息
|
|
|
|
+ List<FarmerAsset> farmerAssetList = farmerAssetMapper.getAssetByMonth(6,farmerId);
|
|
|
|
+ List reverseList = new ArrayList();
|
|
|
|
+ //--反转排序
|
|
|
|
+ for(int a=farmerAssetList.size()-1;a>=0;a--){
|
|
|
|
+ reverseList.add(farmerAssetList.get(a));
|
|
|
|
+ }
|
|
|
|
+ if(lastBatchJo != null){
|
|
|
|
+ lastBatchJo.put("estimated",reverseList);
|
|
|
|
+ return new Result(ResultCode.SUCCESS,lastBatchJo);
|
|
|
|
+ }else{
|
|
|
|
+ JSONObject nullLastBatchJo = new JSONObject();
|
|
|
|
+ nullLastBatchJo.put("adoptTime","");
|
|
|
|
+ nullLastBatchJo.put("husbandryTime","");
|
|
|
|
+ nullLastBatchJo.put("currentPrices",0);
|
|
|
|
+ nullLastBatchJo.put("expectedEarning",0);
|
|
|
|
+ nullLastBatchJo.put("estimated",reverseList);
|
|
|
|
+ return new Result(ResultCode.SUCCESS,nullLastBatchJo);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //{读取最后一批猪信息}
|
|
|
|
+ private JSONObject _getlastBatchAdoptPig(String deviceCode) throws ParseException {
|
|
|
|
+ //{获取最后一条记录create_date日期}
|
|
|
|
+ Date createDate = eartagEartagRegister2Mapper.getLastBatchCreateDate(deviceCode);
|
|
|
|
+ if(createDate == null){
|
|
|
|
+ log.error("该采集器["+deviceCode+"]没有耳标注册数据.");
|
|
|
|
+ return null;
|
|
|
|
+ }else{
|
|
|
|
+ DateUtil dateUtil = new DateUtil();
|
|
|
|
+ List<EartagEartagRegister2> eartagEartagRegister2List = eartagEartagRegister2Mapper.getLastBatchPig(deviceCode,createDate);
|
|
|
|
+ if(eartagEartagRegister2List.size()>0){
|
|
|
|
+ long diff = dateUtil.getTodayDate().getTime()-createDate.getTime();
|
|
|
|
+ long days = diff / (1000 * 60 * 60 * 24);
|
|
|
|
+ //读取重量
|
|
|
|
+ BigDecimal weightBd = farmerAssetMapper.getPigWeightByDayage(days);
|
|
|
|
+ BigDecimal planValue = weightBd.multiply(new BigDecimal(pigPrice)).multiply(new BigDecimal(eartagEartagRegister2List.size())).setScale(2,BigDecimal.ROUND_HALF_UP);
|
|
|
|
+ JSONObject outJo = new JSONObject();
|
|
|
|
+ outJo.put("adoptTime",dateUtil.formatDateText(createDate));
|
|
|
|
+ outJo.put("husbandryTime",days);
|
|
|
|
+ outJo.put("currentPrices",pigPrice);
|
|
|
|
+ outJo.put("expectedEarning",planValue.toString());
|
|
|
|
+ return outJo;
|
|
|
|
+ }else{
|
|
|
|
+ JSONObject outJo = new JSONObject();
|
|
|
|
+ outJo.put("adoptTime",null);
|
|
|
|
+ outJo.put("husbandryTime",null);
|
|
|
|
+ outJo.put("currentPrices",0);
|
|
|
|
+ outJo.put("expectedEarning",0);
|
|
|
|
+ return outJo;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|