|
@@ -8,16 +8,21 @@ import com.huimv.produce.repo.ProdBatchWeightRepo;
|
|
import com.huimv.produce.repo.ProdDayWeightEntity;
|
|
import com.huimv.produce.repo.ProdDayWeightEntity;
|
|
import com.huimv.produce.repo.ProdDayWeightRepo;
|
|
import com.huimv.produce.repo.ProdDayWeightRepo;
|
|
import com.huimv.produce.service.IWeight;
|
|
import com.huimv.produce.service.IWeight;
|
|
|
|
+import com.huimv.produce.utils.DateUtil;
|
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.data.domain.*;
|
|
import org.springframework.data.domain.*;
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import javax.persistence.EntityManager;
|
|
|
|
+import javax.persistence.PersistenceContext;
|
|
|
|
+import javax.persistence.Query;
|
|
import javax.persistence.criteria.*;
|
|
import javax.persistence.criteria.*;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.Date;
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
+import java.text.ParseException;
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @Project : huimv.shiwan
|
|
* @Project : huimv.shiwan
|
|
@@ -33,16 +38,17 @@ public class WeightImpl implements IWeight {
|
|
private ProdDayWeightRepo dayWeightRepo;
|
|
private ProdDayWeightRepo dayWeightRepo;
|
|
@Autowired
|
|
@Autowired
|
|
private ProdBatchWeightRepo batchWeightRepo;
|
|
private ProdBatchWeightRepo batchWeightRepo;
|
|
|
|
+ @Autowired
|
|
|
|
+ private DateUtil dateUtil;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @Method : getDayWeight
|
|
|
|
- * @Description :
|
|
|
|
- * @Params : [farmId, startDate, endDate]
|
|
|
|
- * @Return : com.huimv.common.utils.Result
|
|
|
|
- *
|
|
|
|
- * @Author : ZhuoNing
|
|
|
|
- * @Date : 2021/12/7
|
|
|
|
- * @Time : 13:58
|
|
|
|
|
|
+ * @Method : getDayWeight
|
|
|
|
+ * @Description :
|
|
|
|
+ * @Params : [farmId, startDate, endDate]
|
|
|
|
+ * @Return : com.huimv.common.utils.Result
|
|
|
|
+ * @Author : ZhuoNing
|
|
|
|
+ * @Date : 2021/12/7
|
|
|
|
+ * @Time : 13:58
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public Result getDayWeight(Integer farmId, String startDate, String endDate) {
|
|
public Result getDayWeight(Integer farmId, String startDate, String endDate) {
|
|
@@ -64,14 +70,13 @@ public class WeightImpl implements IWeight {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @Method : getDayWeightLastNtimes
|
|
|
|
- * @Description :
|
|
|
|
- * @Params : [farmId, days]
|
|
|
|
- * @Return : com.huimv.common.utils.Result
|
|
|
|
- *
|
|
|
|
- * @Author : ZhuoNing
|
|
|
|
- * @Date : 2021/12/7
|
|
|
|
- * @Time : 13:58
|
|
|
|
|
|
+ * @Method : getDayWeightLastNtimes
|
|
|
|
+ * @Description :
|
|
|
|
+ * @Params : [farmId, days]
|
|
|
|
+ * @Return : com.huimv.common.utils.Result
|
|
|
|
+ * @Author : ZhuoNing
|
|
|
|
+ * @Date : 2021/12/7
|
|
|
|
+ * @Time : 13:58
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public Result getDayWeightLastNtimes(Integer farmId, Integer days) {
|
|
public Result getDayWeightLastNtimes(Integer farmId, Integer days) {
|
|
@@ -80,7 +85,7 @@ public class WeightImpl implements IWeight {
|
|
if (dayWeightEntityList.size() > 0) {
|
|
if (dayWeightEntityList.size() > 0) {
|
|
//排序
|
|
//排序
|
|
List outList = new ArrayList();
|
|
List outList = new ArrayList();
|
|
- for(int a=dayWeightEntityList.size()-1;a>=0;a--){
|
|
|
|
|
|
+ for (int a = dayWeightEntityList.size() - 1; a >= 0; a--) {
|
|
outList.add(dayWeightEntityList.get(a));
|
|
outList.add(dayWeightEntityList.get(a));
|
|
}
|
|
}
|
|
//计算总重
|
|
//计算总重
|
|
@@ -99,52 +104,50 @@ public class WeightImpl implements IWeight {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @Method : getWeightOnPage
|
|
|
|
|
|
+ * @Method : getWeightOnPage
|
|
* @Description : 分页查询称重记录
|
|
* @Description : 分页查询称重记录
|
|
- * @Params : [farmId, startDate, endDate, pageNo, pageSize]
|
|
|
|
- * @Return : com.huimv.common.utils.Result
|
|
|
|
- *
|
|
|
|
- * @Author : ZhuoNing
|
|
|
|
- * @Date : 2021/12/7
|
|
|
|
- * @Time : 14:56
|
|
|
|
|
|
+ * @Params : [farmId, startDate, endDate, pageNo, pageSize]
|
|
|
|
+ * @Return : com.huimv.common.utils.Result
|
|
|
|
+ * @Author : ZhuoNing
|
|
|
|
+ * @Date : 2021/12/7
|
|
|
|
+ * @Time : 14:56
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public Result getWeightOnPage(Integer farmId, Date startDate, Date endDate, Integer pageNo, Integer pageSize) {
|
|
public Result getWeightOnPage(Integer farmId, Date startDate, Date endDate, Integer pageNo, Integer pageSize) {
|
|
- Specification<ProdDayWeightEntity> sf = (Specification<ProdDayWeightEntity>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
|
- //
|
|
|
|
- List<Predicate> predList = new ArrayList<>();
|
|
|
|
- if (null != farmId) {
|
|
|
|
- predList.add(criteriaBuilder.equal(root.get("farmId").as(Integer.class), farmId));
|
|
|
|
- }
|
|
|
|
- if (null != startDate) {
|
|
|
|
- predList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("addTime").as(Date.class), startDate));
|
|
|
|
- }
|
|
|
|
- if (null != endDate) {
|
|
|
|
- predList.add(criteriaBuilder.lessThanOrEqualTo(root.get("addTime").as(Date.class), endDate));
|
|
|
|
- }
|
|
|
|
- //
|
|
|
|
- Predicate[] pred = new Predicate[predList.size()];
|
|
|
|
- Predicate and = criteriaBuilder.and(predList.toArray(pred));
|
|
|
|
- criteriaQuery.where(and);
|
|
|
|
- //
|
|
|
|
- List<Order> orders = new ArrayList<>();
|
|
|
|
- orders.add(criteriaBuilder.desc(root.get("id")));
|
|
|
|
- return criteriaQuery.orderBy(orders).getRestriction();
|
|
|
|
- };
|
|
|
|
- Pageable pageable = PageRequest.of( pageNo - 1, pageSize);
|
|
|
|
|
|
+ Specification<ProdDayWeightEntity> sf = (Specification<ProdDayWeightEntity>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
|
+ //
|
|
|
|
+ List<Predicate> predList = new ArrayList<>();
|
|
|
|
+ if (null != farmId) {
|
|
|
|
+ predList.add(criteriaBuilder.equal(root.get("farmId").as(Integer.class), farmId));
|
|
|
|
+ }
|
|
|
|
+ if (null != startDate) {
|
|
|
|
+ predList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("addTime").as(Date.class), startDate));
|
|
|
|
+ }
|
|
|
|
+ if (null != endDate) {
|
|
|
|
+ predList.add(criteriaBuilder.lessThanOrEqualTo(root.get("addTime").as(Date.class), endDate));
|
|
|
|
+ }
|
|
|
|
+ //
|
|
|
|
+ Predicate[] pred = new Predicate[predList.size()];
|
|
|
|
+ Predicate and = criteriaBuilder.and(predList.toArray(pred));
|
|
|
|
+ criteriaQuery.where(and);
|
|
|
|
+ //
|
|
|
|
+ List<Order> orders = new ArrayList<>();
|
|
|
|
+ orders.add(criteriaBuilder.desc(root.get("id")));
|
|
|
|
+ return criteriaQuery.orderBy(orders).getRestriction();
|
|
|
|
+ };
|
|
|
|
+ Pageable pageable = PageRequest.of(pageNo - 1, pageSize);
|
|
// return new Result(ResultCode.SUCCESS,applyRepo.listApply(pageable,applyId));
|
|
// return new Result(ResultCode.SUCCESS,applyRepo.listApply(pageable,applyId));
|
|
- return new Result(ResultCode.SUCCESS, dayWeightRepo.findAll(sf, pageable));
|
|
|
|
|
|
+ return new Result(ResultCode.SUCCESS, dayWeightRepo.findAll(sf, pageable));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @Method : getBatchWeightOnPage
|
|
|
|
|
|
+ * @Method : getBatchWeightOnPage
|
|
* @Description : 分页查询批次重量记录
|
|
* @Description : 分页查询批次重量记录
|
|
- * @Params : [farmId, addTime, pageNo, pageSize]
|
|
|
|
- * @Return : com.huimv.common.utils.Result
|
|
|
|
- *
|
|
|
|
- * @Author : ZhuoNing
|
|
|
|
- * @Date : 2021/12/7
|
|
|
|
- * @Time : 20:31
|
|
|
|
|
|
+ * @Params : [farmId, addTime, pageNo, pageSize]
|
|
|
|
+ * @Return : com.huimv.common.utils.Result
|
|
|
|
+ * @Author : ZhuoNing
|
|
|
|
+ * @Date : 2021/12/7
|
|
|
|
+ * @Time : 20:31
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public Result getBatchWeightOnPage(Integer farmId, Date addTime, Integer pageNo, Integer pageSize) {
|
|
public Result getBatchWeightOnPage(Integer farmId, Date addTime, Integer pageNo, Integer pageSize) {
|
|
@@ -166,22 +169,23 @@ public class WeightImpl implements IWeight {
|
|
orders.add(criteriaBuilder.desc(root.get("id")));
|
|
orders.add(criteriaBuilder.desc(root.get("id")));
|
|
return criteriaQuery.orderBy(orders).getRestriction();
|
|
return criteriaQuery.orderBy(orders).getRestriction();
|
|
};
|
|
};
|
|
- Pageable pageable = PageRequest.of( pageNo - 1, pageSize);
|
|
|
|
|
|
+ Pageable pageable = PageRequest.of(pageNo - 1, pageSize);
|
|
return new Result(ResultCode.SUCCESS, batchWeightRepo.findAll(sf, pageable));
|
|
return new Result(ResultCode.SUCCESS, batchWeightRepo.findAll(sf, pageable));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @Method : getBatchWeightOnPage
|
|
|
|
- * @Description :
|
|
|
|
- * @Params : [farmId, startDate, endDate, pageNo, pageSize]
|
|
|
|
- * @Return : com.huimv.common.utils.Result
|
|
|
|
- *
|
|
|
|
- * @Author : ZhuoNing
|
|
|
|
- * @Date : 2021/12/7
|
|
|
|
- * @Time : 20:36
|
|
|
|
|
|
+ * @Method : getBatchWeightOnPage
|
|
|
|
+ * @Description :
|
|
|
|
+ * @Params : [farmId, startDate, endDate, pageNo, pageSize]
|
|
|
|
+ * @Return : com.huimv.common.utils.Result
|
|
|
|
+ * @Author : ZhuoNing
|
|
|
|
+ * @Date : 2021/12/7
|
|
|
|
+ * @Time : 20:36
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public Result getBatchWeightOnPage(Integer farmId, Date startDate, Date endDate, Integer pageNo, Integer pageSize) {
|
|
|
|
|
|
+ public Result getBatchWeightOnPage(Integer farmId, Date startDate, Date endDate, Integer pageNo, Integer pageSize) throws ParseException {
|
|
|
|
+ System.out.println("startDate 2>>" + startDate + " " + dateUtil.formatDateText(startDate));
|
|
|
|
+ System.out.println("endDate 2>>" + endDate + " " + dateUtil.formatDateText(endDate));
|
|
Specification<ProdBatchWeightEntity> sf = (Specification<ProdBatchWeightEntity>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
Specification<ProdBatchWeightEntity> sf = (Specification<ProdBatchWeightEntity>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
//
|
|
//
|
|
List<Predicate> predList = new ArrayList<>();
|
|
List<Predicate> predList = new ArrayList<>();
|
|
@@ -194,7 +198,7 @@ public class WeightImpl implements IWeight {
|
|
if (null != endDate) {
|
|
if (null != endDate) {
|
|
predList.add(criteriaBuilder.lessThanOrEqualTo(root.get("addTime").as(Date.class), endDate));
|
|
predList.add(criteriaBuilder.lessThanOrEqualTo(root.get("addTime").as(Date.class), endDate));
|
|
}
|
|
}
|
|
- //
|
|
|
|
|
|
+// //
|
|
Predicate[] pred = new Predicate[predList.size()];
|
|
Predicate[] pred = new Predicate[predList.size()];
|
|
Predicate and = criteriaBuilder.and(predList.toArray(pred));
|
|
Predicate and = criteriaBuilder.and(predList.toArray(pred));
|
|
criteriaQuery.where(and);
|
|
criteriaQuery.where(and);
|
|
@@ -203,7 +207,126 @@ public class WeightImpl implements IWeight {
|
|
orders.add(criteriaBuilder.desc(root.get("id")));
|
|
orders.add(criteriaBuilder.desc(root.get("id")));
|
|
return criteriaQuery.orderBy(orders).getRestriction();
|
|
return criteriaQuery.orderBy(orders).getRestriction();
|
|
};
|
|
};
|
|
- Pageable pageable = PageRequest.of( pageNo - 1, pageSize);
|
|
|
|
|
|
+ Pageable pageable = PageRequest.of(pageNo - 1, pageSize);
|
|
return new Result(ResultCode.SUCCESS, batchWeightRepo.findAll(sf, pageable));
|
|
return new Result(ResultCode.SUCCESS, batchWeightRepo.findAll(sf, pageable));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @Method : getBatchWeightOnPage2
|
|
|
|
+ * @Description :
|
|
|
|
+ * @Params : [farmId, startDate, endDate, pageNo, pageSize]
|
|
|
|
+ * @Return : com.huimv.common.utils.Result
|
|
|
|
+ * @Author : ZhuoNing
|
|
|
|
+ * @Date : 2021/12/8
|
|
|
|
+ * @Time : 10:43
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Result getBatchWeightOnPage2(Integer farmId, Date startDate, Date endDate, Integer pageNo, Integer pageSize) throws ParseException {
|
|
|
|
+ Pageable pageable = PageRequest.of(pageNo - 1, pageSize, Sort.Direction.DESC, "id");
|
|
|
|
+ //
|
|
|
|
+ return new Result(ResultCode.SUCCESS, batchWeightRepo.findByFarmIdAndStartDateAndEndDate(farmId, startDate, endDate, pageable));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @PersistenceContext
|
|
|
|
+ EntityManager entityManager;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Result getBatchWeightOnPage3(Integer farmId, Date startDate, Date endDate, Integer pageNo, Integer pageSize) {
|
|
|
|
+ StringBuilder countSelectSql = new StringBuilder();
|
|
|
|
+ countSelectSql.append("select count(*) from ProdBatchWeightEntity bw where 1=1 ");
|
|
|
|
+
|
|
|
|
+ StringBuilder selectSql = new StringBuilder();
|
|
|
|
+ selectSql.append("from ProdBatchWeightEntity bw where 1=1 ");
|
|
|
|
+
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
+ StringBuilder whereSql = new StringBuilder();
|
|
|
|
+ //farmId
|
|
|
|
+ if (farmId != null) {
|
|
|
|
+ whereSql.append(" and farmId=:farmId ");
|
|
|
|
+ params.put("farmId", farmId);
|
|
|
|
+ }
|
|
|
|
+ //startDate
|
|
|
|
+ if(startDate != null){
|
|
|
|
+ whereSql.append(" and addTime>=:startDate ");
|
|
|
|
+ params.put("startDate", startDate);
|
|
|
|
+ }
|
|
|
|
+ //endDate
|
|
|
|
+ if(endDate != null){
|
|
|
|
+ whereSql.append(" and addTime<=:endDate ");
|
|
|
|
+ params.put("endDate", endDate);
|
|
|
|
+ }
|
|
|
|
+ //加入排序顺序
|
|
|
|
+ whereSql.append(" ORDER BY id DESC");
|
|
|
|
+ String countSql = new StringBuilder().append(countSelectSql).append(whereSql).toString();
|
|
|
|
+ Query countQuery = this.entityManager.createQuery(countSql, Long.class);
|
|
|
|
+ this.setParameters(countQuery, params);
|
|
|
|
+ Long count = (Long) countQuery.getSingleResult();
|
|
|
|
+
|
|
|
|
+ String querySql = new StringBuilder().append(selectSql).append(whereSql).toString();
|
|
|
|
+ Query query = this.entityManager.createQuery(querySql, ProdBatchWeightEntity.class);
|
|
|
|
+ this.setParameters(query, params);
|
|
|
|
+ query.setFirstResult((pageNo - 1) * pageSize);
|
|
|
|
+ query.setMaxResults(pageSize);
|
|
|
|
+ List<ProdBatchWeightEntity> batchWeightList = query.getResultList();
|
|
|
|
+
|
|
|
|
+// Pageable pageable = PageRequest.of(pageNo - 1, pageSize, Sort.Direction.DESC, "id");
|
|
|
|
+ Pageable pageable = PageRequest.of(pageNo - 1, pageSize);
|
|
|
|
+ Page<ProdBatchWeightEntity> incomeDailyPage = new PageImpl<ProdBatchWeightEntity>(batchWeightList, pageable, count);
|
|
|
|
+
|
|
|
|
+ return new Result(ResultCode.SUCCESS, incomeDailyPage);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void setParameters(Query query, Map<String, Object> params) {
|
|
|
|
+ for (Map.Entry<String, Object> entry : params.entrySet()) {
|
|
|
|
+ query.setParameter(entry.getKey(), entry.getValue());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Result getBatchWeightOnPage4(Integer farmId, String startDate, String endDate, Integer pageNo, Integer pageSize) {
|
|
|
|
+ StringBuilder countSelectSql = new StringBuilder();
|
|
|
|
+ countSelectSql.append("select count(*) from prod_batch_weight bw where 1=1 ");
|
|
|
|
+
|
|
|
|
+ StringBuilder selectSql = new StringBuilder();
|
|
|
|
+ selectSql.append("from prod_batch_weight bw where 1=1 ");
|
|
|
|
+
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
+ StringBuilder whereSql = new StringBuilder();
|
|
|
|
+ //farmId
|
|
|
|
+ if (farmId != null) {
|
|
|
|
+ whereSql.append(" AND farm_id= :farmId");
|
|
|
|
+ params.put("farmId", farmId);
|
|
|
|
+ }
|
|
|
|
+ //startDate
|
|
|
|
+ if(startDate != null){
|
|
|
|
+ whereSql.append(" AND date_format(add_time,'%Y-%m-%d')>= :startDate ");
|
|
|
|
+ params.put("startDate", startDate);
|
|
|
|
+ }
|
|
|
|
+ //endDate
|
|
|
|
+ if(endDate != null){
|
|
|
|
+ whereSql.append(" AND date_format(add_time,'%Y-%m-%d')<= :endDate");
|
|
|
|
+ params.put("endDate", endDate);
|
|
|
|
+ }
|
|
|
|
+ //加入排序顺序
|
|
|
|
+ whereSql.append(" ORDER BY id DESC");
|
|
|
|
+ String countSql = new StringBuilder().append(countSelectSql).append(whereSql).toString();
|
|
|
|
+ Query countQuery = this.entityManager.createNativeQuery(countSql);
|
|
|
|
+ this.setParameters(countQuery, params);
|
|
|
|
+// Long count = (Long) countQuery.getSingleResult();
|
|
|
|
+ int size = countQuery.getResultList().size();
|
|
|
|
+// System.out.println("count>>"+count);
|
|
|
|
+ System.out.println("size>>"+size);
|
|
|
|
+
|
|
|
|
+ String querySql = new StringBuilder().append(selectSql).append(whereSql).toString();
|
|
|
|
+ Query query = this.entityManager.createNativeQuery(querySql);
|
|
|
|
+ this.setParameters(query, params);
|
|
|
|
+ query.setFirstResult((pageNo - 1) * pageSize);
|
|
|
|
+ query.setMaxResults(pageSize);
|
|
|
|
+ List<ProdBatchWeightEntity> batchWeightList = query.getResultList();
|
|
|
|
+// Pageable pageable = PageRequest.of(pageNo - 1, pageSize, Sort.Direction.DESC, "id");
|
|
|
|
+// Pageable pageable = PageRequest.of(pageNo - 1, pageSize);
|
|
|
|
+// Page<ProdBatchWeightEntity> incomeDailyPage = new PageImpl<ProdBatchWeightEntity>(batchWeightList, pageable);
|
|
|
|
+
|
|
|
|
+ return new Result(ResultCode.SUCCESS, batchWeightList);
|
|
|
|
+ }
|
|
}
|
|
}
|