From 7cdea6d16a8b9f74800792ea412ad8b51c4df7f4 Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期二, 22 十月 2024 17:48:38 +0800
Subject: [PATCH] 最新版本541200007

---
 server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/PlatformWaterGasServiceImpl.java |  120 +++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 111 insertions(+), 9 deletions(-)

diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/PlatformWaterGasServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/PlatformWaterGasServiceImpl.java
index e55c968..a8a7570 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/PlatformWaterGasServiceImpl.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/PlatformWaterGasServiceImpl.java
@@ -1,5 +1,6 @@
 package com.doumee.service.business.impl;
 
+import com.doumee.core.annotation.excel.ExcelImporter;
 import com.doumee.core.constants.ResponseStatus;
 import com.doumee.core.exception.BusinessException;
 import com.doumee.core.model.LoginUserInfo;
@@ -8,31 +9,38 @@
 import com.doumee.core.model.PageWrap;
 import com.doumee.core.utils.Constants;
 import com.doumee.core.utils.DateUtil;
+import com.doumee.core.utils.ScientificNotationTUtil;
 import com.doumee.core.utils.Utils;
+import com.doumee.dao.admin.request.MemberImport;
+import com.doumee.dao.admin.request.PlatformGasImport;
 import com.doumee.dao.business.PlatformWaterGasMapper;
+import com.doumee.dao.business.model.Company;
+import com.doumee.dao.business.model.Member;
 import com.doumee.dao.business.model.PlatformReason;
 import com.doumee.dao.business.model.PlatformWaterGas;
 import com.doumee.dao.openapi.request.GasByMonthRequest;
 import com.doumee.dao.openapi.request.WaterByMonthRequest;
 import com.doumee.dao.openapi.response.GasByMonthResponse;
+import com.doumee.dao.openapi.response.PlatformLastMonthListResponse;
 import com.doumee.dao.openapi.response.WaterByMonthResponse;
 import com.doumee.service.business.PlatformWaterGasService;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import org.apache.commons.lang3.StringUtils;
 import org.checkerframework.checker.units.qual.C;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.math.BigDecimal;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
 
 /**
  * 鏈堝彴_鐢ㄦ按鐢ㄦ皵淇℃伅璁板綍琛⊿ervice瀹炵幇
@@ -49,11 +57,12 @@
     public Integer create(PlatformWaterGas platformWaterGas) {
         if(platformWaterGas.getTimeInfo() ==null || platformWaterGas.getNum()==null
         ||(Constants.equalsInteger(platformWaterGas.getType(),Constants.TWO) && StringUtils.isBlank(platformWaterGas.getCarCode()))){
-            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝璇ュ勾鏈堟暟鎹凡瀛樺湪锛岃鍕块噸鏂板綍鍏ワ紝鍙互灏濊瘯鎼滅储鍚庤繘琛屾暟鎹慨鏀癸紒");
+            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝鍙傛暟閿欒锛�");
         }
         if( platformWaterGasMapper.selectCount(new QueryWrapper<PlatformWaterGas>().lambda()
                 .eq(PlatformWaterGas::getIsdeleted, Constants.ZERO)
                 .apply("to_days(time_info) = to_days('"+ DateUtil.getPlusTime2(platformWaterGas.getTimeInfo()) +"')")
+                .eq(PlatformWaterGas::getType,platformWaterGas.getType())
                 .eq(Constants.equalsInteger(platformWaterGas.getType(),Constants.TWO),PlatformWaterGas::getCarCode,platformWaterGas.getCarCode()))>0){
             throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝璇ュ勾鏈堟暟鎹凡瀛樺湪锛岃鍕块噸鏂板綍鍏ワ紝鍙互灏濊瘯鎼滅储鍚庤繘琛屾暟鎹慨鏀癸紒");
         }
@@ -117,6 +126,7 @@
                 .eq(PlatformWaterGas::getIsdeleted, Constants.ZERO)
                 .ne(PlatformWaterGas::getId,platformWaterGas.getId())
                 .apply("to_days(time_info) = to_days('"+ DateUtil.getPlusTime2(platformWaterGas.getTimeInfo()) +"')")
+                .eq(PlatformWaterGas::getType, platformWaterGas.getType())
                 .eq(Constants.equalsInteger(platformWaterGas.getType(),Constants.TWO),PlatformWaterGas::getCarCode,platformWaterGas.getCarCode()))>0){
             throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝璇ュ勾鏈堟暟鎹凡瀛樺湪锛岃鍕块噸鏂板綍鍏ワ紝鍙互灏濊瘯鎼滅储鍚庤繘琛屾暟鎹慨鏀癸紒");
         }
@@ -243,7 +253,7 @@
         list = platformWaterGasMapper.selectList(new QueryWrapper<PlatformWaterGas>().lambda()
                 .eq(PlatformWaterGas::getIsdeleted,Constants.ZERO)
                 .eq(PlatformWaterGas::getType,Constants.ZERO)
-                .like(PlatformWaterGas::getTimeInfo,beforMonth)
+                .like(PlatformWaterGas::getTimeInfo,DateUtil.getDate(beforMonth,"yyyy-MM"))
         );
         if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(list)){
             waterByMonthResponse.setLastMonth(list.stream().map(m->m.getNum()).reduce(BigDecimal.ZERO,BigDecimal::add));
@@ -252,7 +262,7 @@
         list = platformWaterGasMapper.selectList(new QueryWrapper<PlatformWaterGas>().lambda()
                 .eq(PlatformWaterGas::getIsdeleted,Constants.ZERO)
                 .eq(PlatformWaterGas::getType,Constants.ZERO)
-                .like(PlatformWaterGas::getTimeInfo,beforYearMonth)
+                .like(PlatformWaterGas::getTimeInfo,DateUtil.getDate(beforYearMonth,"yyyy-MM"))
         );
         if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(list)){
             waterByMonthResponse.setLastYearMonth(list.stream().map(m->m.getNum()).reduce(BigDecimal.ZERO,BigDecimal::add));
@@ -286,7 +296,7 @@
         list = platformWaterGasMapper.selectList(new QueryWrapper<PlatformWaterGas>().lambda()
                 .eq(PlatformWaterGas::getIsdeleted,Constants.ZERO)
                 .eq(PlatformWaterGas::getType,Constants.ONE)
-                .like(PlatformWaterGas::getTimeInfo,beforMonth)
+                .like(PlatformWaterGas::getTimeInfo,DateUtil.getDate(beforMonth,"yyyy-MM"))
         );
         if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(list)){
             response.setLastMonth(list.stream().map(m->m.getNum()).reduce(BigDecimal.ZERO,BigDecimal::add));
@@ -295,7 +305,7 @@
         list = platformWaterGasMapper.selectList(new QueryWrapper<PlatformWaterGas>().lambda()
                 .eq(PlatformWaterGas::getIsdeleted,Constants.ZERO)
                 .eq(PlatformWaterGas::getType,Constants.ONE)
-                .like(PlatformWaterGas::getTimeInfo,beforYearMonth)
+                .like(PlatformWaterGas::getTimeInfo,DateUtil.getDate(beforYearMonth,"yyyy-MM"))
         );
         if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(list)){
             response.setLastYearMonth(list.stream().map(m->m.getNum()).reduce(BigDecimal.ZERO,BigDecimal::add));
@@ -303,4 +313,96 @@
         return response;
     }
 
+
+    /**
+     *
+     * @param type 0鐢ㄦ按 1鐢ㄦ皵
+     * @return
+     */
+    @Override
+    public List<PlatformLastMonthListResponse> getPlatformLastMonthListResponse(Integer type){
+        List<PlatformLastMonthListResponse> lastMonthListResponses = new ArrayList<>();
+
+        List<PlatformWaterGas> platformWaterGasList = platformWaterGasMapper.selectList(new QueryWrapper<PlatformWaterGas>().lambda()
+                .eq(PlatformWaterGas::getIsdeleted,Constants.ZERO)
+                .eq(PlatformWaterGas::getType,type)
+        );
+        List<String> monthList = DateUtil.getBeforMonth(new Date(),12);
+        for (String str:monthList) {
+            PlatformLastMonthListResponse platformLastMonthListResponse = new PlatformLastMonthListResponse();
+            platformLastMonthListResponse.setNum(platformWaterGasList.stream().filter(i->DateUtil.dateToString(i.getTimeInfo(),"yyyy-MM").equals(str)).map(i->i.getNum()).reduce(BigDecimal.ZERO,BigDecimal::add));
+            platformLastMonthListResponse.setTimeInfo(str);
+            lastMonthListResponses.add(platformLastMonthListResponse);
+        }
+        return lastMonthListResponses;
+    }
+
+
+
+    @Autowired
+    private RedisTemplate<String, Object> redisTemplate;
+
+    @Override
+    @Transactional(rollbackFor = {BusinessException.class,Exception.class})
+    public String importBatch(MultipartFile file, LoginUserInfo loginUserInfo){
+        try {
+            ExcelImporter ie = null;
+            List<PlatformGasImport> dataList =null;
+            try {
+                ie = new ExcelImporter(file,0,0);
+                dataList = ie.getDataList(PlatformGasImport.class,null);
+            }  catch (Exception e) {
+                e.printStackTrace();
+            }
+            if(dataList == null || dataList.size() ==0){
+                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝褰曞叆鏁版嵁涓虹┖锛�");
+            }
+            List<PlatformWaterGas> newList = new ArrayList<>();
+            for(int i=0;i<dataList.size();i++){
+                PlatformGasImport model = dataList.get(i);
+                if(Objects.isNull(model.getTimeInfo())
+                || StringUtils.isBlank(model.getCarCode())
+                || StringUtils.isBlank(model.getNum()) ){
+                    throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝绗�"+i+2+"琛屾暟鎹弬鏁伴敊璇紒");
+                }
+                PlatformWaterGas platformWaterGas = new PlatformWaterGas();
+                try {
+                    BigDecimal num = new BigDecimal(model.getNum());
+                    platformWaterGas.setNum(num);
+                }catch (Exception e){
+                    throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝绗�"+i+2+"琛屾暟閲忛敊璇紒");
+                }
+                if( platformWaterGasMapper.selectCount(new QueryWrapper<PlatformWaterGas>().lambda()
+                        .eq(PlatformWaterGas::getIsdeleted, Constants.ZERO)
+                        .apply("to_days(time_info) = to_days('"+ DateUtil.getPlusTime2(model.getTimeInfo()) +"')")
+                        .eq(PlatformWaterGas::getType,Constants.TWO)
+                        .eq(PlatformWaterGas::getCarCode,model.getCarCode()))>0){
+                    throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝璇"+DateUtil.getPlusTime2(model.getTimeInfo())+"]鏁版嵁宸插瓨鍦紝璇峰嬁閲嶆柊褰曞叆锛屽彲浠ュ皾璇曟悳绱㈠悗杩涜鏁版嵁淇敼锛�");
+                }
+
+                platformWaterGas.setTimeInfo(model.getTimeInfo());
+                platformWaterGas.setCarCode(model.getCarCode());
+                platformWaterGas.setContent(model.getContent());
+                platformWaterGas.setIsdeleted(Constants.ZERO);
+                platformWaterGas.setType(Constants.TWO);
+                platformWaterGas.setCreator(loginUserInfo.getId());
+                platformWaterGas.setCreateDate(new Date());
+                platformWaterGas.setEditDate(platformWaterGas.getCreateDate());
+                platformWaterGas.setEditor(platformWaterGas.getCreator());
+                newList.add(platformWaterGas);
+            }
+            if(newList == null || newList.size() ==0){
+                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝褰曞叆鏈夋晥鏁版嵁涓虹┖锛�");
+            }
+            platformWaterGasMapper.insert(newList);
+            return "瀵煎叆鎴愬姛";
+        }catch (BusinessException e){
+            throw e;
+        }catch (Exception e){
+            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"淇℃伅瀵煎叆澶辫触锛岃绋嶅悗閲嶈瘯");
+        }finally {
+            redisTemplate.delete(Constants.RedisKeys.IMPORTING_MEMBER);
+        }
+    }
+
 }

--
Gitblit v1.9.3