Browse Source

新建获取批次数据接口

zhuoning 3 years ago
parent
commit
81fd203df2

+ 12 - 3
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/controller/WeightController.java

@@ -79,6 +79,8 @@ public class WeightController {
         log.info("farmId>>" + farmId);
         log.info("farmId>>" + farmId);
         String startDate = dateUtil.getYearStart();
         String startDate = dateUtil.getYearStart();
         String endDate = dateUtil.getYearEnd();
         String endDate = dateUtil.getYearEnd();
+        log.info("startDate>>" + startDate);
+        log.info("endDate>>" + endDate);
         log.info("pageNo>>" + pageNo);
         log.info("pageNo>>" + pageNo);
         log.info("pageSize>>" + pageSize);
         log.info("pageSize>>" + pageSize);
         //
         //
@@ -105,9 +107,16 @@ public class WeightController {
         log.info("farmId>>" + farmId);
         log.info("farmId>>" + farmId);
         log.info("pageNo>>" + pageNo);
         log.info("pageNo>>" + pageNo);
         log.info("pageSize>>" + pageSize);
         log.info("pageSize>>" + pageSize);
-        log.info("startDate>>" + startDate);
-        log.info("endDate>>" + endDate);
+        if(startDate == null){
+            startDate = dateUtil.getYearStart();
+        }
+        if(endDate == null){
+            endDate = dateUtil.getYearEnd();
+        }
+        log.info("startDate>>" + startDate+"-");
+        log.info("endDate>>" + endDate+"-");
         //
         //
-        return weight.getBatchWeightOnPage(farmId, dateUtil.parseDate(startDate),dateUtil.parseDate(endDate), pageNo, pageSize);
+        return weight.getBatchWeightOnPage2(farmId, dateUtil.parseDate(startDate),dateUtil.parseDate(endDate), pageNo, pageSize);
+//        return weight.getBatchWeightOnPage4(farmId, startDate,endDate, pageNo, pageSize);
     }
     }
 }
 }

+ 8 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/repo/ProdBatchWeightRepo.java

@@ -1,8 +1,16 @@
 package com.huimv.produce.repo;
 package com.huimv.produce.repo;
 
 
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Query;
+
+import java.util.Date;
 
 
 public interface ProdBatchWeightRepo extends JpaRepository<ProdBatchWeightEntity, Integer>, JpaSpecificationExecutor<ProdBatchWeightEntity> {
 public interface ProdBatchWeightRepo extends JpaRepository<ProdBatchWeightEntity, Integer>, JpaSpecificationExecutor<ProdBatchWeightEntity> {
 
 
+    @Query(nativeQuery = true,value = "SELECT * FROM prod_batch_weight WHERE farm_id=?1 AND DATE_FORMAT(add_time,'%Y-%m-%d')>=DATE_FORMAT(?2,'%Y-%m-%d') AND DATE_FORMAT(add_time,'%Y-%m-%d')<=DATE_FORMAT(?3,'%Y-%m-%d') ORDER BY id DESC",
+            countQuery = "SELECT COUNT(*) FROM prod_batch_weight WHERE farm_id=?1 AND DATE_FORMAT(add_time,'%Y-%m-%d')>=DATE_FORMAT(?2,'%Y-%m-%d') AND DATE_FORMAT(add_time,'%Y-%m-%d')<=DATE_FORMAT(?3,'%Y-%m-%d')")
+    Page<ProdBatchWeightEntity> findByFarmIdAndStartDateAndEndDate(Integer farmId, Date startDate, Date endDate, Pageable pageable);
 }
 }

+ 8 - 1
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/IWeight.java

@@ -2,6 +2,7 @@ package com.huimv.produce.service;
 
 
 import com.huimv.common.utils.Result;
 import com.huimv.common.utils.Result;
 
 
+import java.text.ParseException;
 import java.util.Date;
 import java.util.Date;
 
 
 public interface IWeight {
 public interface IWeight {
@@ -18,5 +19,11 @@ public interface IWeight {
     Result getBatchWeightOnPage(Integer farmId, Date parseDate, Integer pageNo, Integer pageSize);
     Result getBatchWeightOnPage(Integer farmId, Date parseDate, Integer pageNo, Integer pageSize);
 
 
     //分页查询批次称重记录
     //分页查询批次称重记录
-    Result getBatchWeightOnPage(Integer farmId, Date parseDate, Date parseDate1, Integer pageNo, Integer pageSize);
+    Result getBatchWeightOnPage(Integer farmId, Date parseDate, Date parseDate1, Integer pageNo, Integer pageSize) throws ParseException;
+
+    Result getBatchWeightOnPage2(Integer farmId, Date startDate, Date endDate, Integer pageNo, Integer pageSize) throws ParseException;
+
+    Result getBatchWeightOnPage3(Integer farmId, Date parseDate, Date parseDate1, Integer pageNo, Integer pageSize);
+
+    Result getBatchWeightOnPage4(Integer farmId, String startDate, String endDate, Integer pageNo, Integer pageSize);
 }
 }

+ 192 - 69
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/impl/WeightImpl.java

@@ -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);
+    }
 }
 }

+ 1 - 1
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/timer/SaveEventFromEventTimmer.java

@@ -29,7 +29,7 @@ public class SaveEventFromEventTimmer {
 
 
 
 
     //每小时执行一次
     //每小时执行一次
-    @Scheduled(cron = " 0 */59 * * * ?")
+//    @Scheduled(cron = " 0 */59 * * * ?")
     private void updateBox() {
     private void updateBox() {
 
 
 
 

+ 1 - 1
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/timer/SysTelcomEnentTimmer.java

@@ -25,7 +25,7 @@ public class SysTelcomEnentTimmer {
     private ISysTelecomEventService sysTelecomEventService;
     private ISysTelecomEventService sysTelecomEventService;
 
 
        //每小时执行一次
        //每小时执行一次
-       @Scheduled(cron = " 0 */59 * * * ? ")
+//       @Scheduled(cron = " 0 */59 * * * ? ")
        private void updateBox() {
        private void updateBox() {
            //获得设备列表 查找烘干数据
            //获得设备列表 查找烘干数据
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

+ 20 - 1
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/utils/DateUtil.java

@@ -99,7 +99,7 @@ public class DateUtil {
         calendar.set(Calendar.MONTH,calendar.getActualMaximum(Calendar.MONTH));
         calendar.set(Calendar.MONTH,calendar.getActualMaximum(Calendar.MONTH));
         calendar.set(Calendar.DAY_OF_MONTH,calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
         calendar.set(Calendar.DAY_OF_MONTH,calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
         Date currYearLast = calendar.getTime();
         Date currYearLast = calendar.getTime();
-        return new SimpleDateFormat("yyyy-MM-dd").format(currYearLast)+" 23:59:59";
+        return new SimpleDateFormat("yyyy-MM-dd").format(currYearLast);
     }
     }
 
 
     //Long转换为Date格式
     //Long转换为Date格式
@@ -148,6 +148,20 @@ public class DateUtil {
         return sdf.format(date);
         return sdf.format(date);
     }
     }
 
 
+    public String formatDateText(String dateText) throws ParseException {
+        if(dateText.indexOf("T") != -1){
+            dateText = dateText.replace("T"," ");
+        }
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        Date date = sdf.parse(dateText);
+        return sdf.format(date);
+    }
+
+    public String formatDateText(Date date) throws ParseException {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        return sdf.format(date);
+    }
+
     public Date parseDateTime(String dateText) throws ParseException {
     public Date parseDateTime(String dateText) throws ParseException {
         if(dateText.indexOf("T") != -1){
         if(dateText.indexOf("T") != -1){
             dateText = dateText.replace("T"," ");
             dateText = dateText.replace("T"," ");
@@ -164,6 +178,11 @@ public class DateUtil {
         return sdf.parse(dateText);
         return sdf.parse(dateText);
     }
     }
 
 
+    public Date parseDate2(String dateText) throws ParseException {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        return sdf.parse(dateText);
+    }
+
     public Long parseDateTimeLong(String dateText) throws ParseException {
     public Long parseDateTimeLong(String dateText) throws ParseException {
         if(dateText.indexOf("T") != -1){
         if(dateText.indexOf("T") != -1){
             dateText = dateText.replace("T"," ");
             dateText = dateText.replace("T"," ");