From 8d4ad0d13ef71e22cc1036e2c6c00aafb20ed597 Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期二, 10 十二月 2024 17:41:58 +0800
Subject: [PATCH] 电路试验的驻波比csv报告解析

---
 inspect-server/src/main/java/com/yuanchu/mom/service/impl/ReportServiceImpl.java |  178 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 152 insertions(+), 26 deletions(-)

diff --git a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/ReportServiceImpl.java b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/ReportServiceImpl.java
index 820ae14..db0d87e 100644
--- a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/ReportServiceImpl.java
+++ b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/ReportServiceImpl.java
@@ -2,36 +2,37 @@
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.yuanchu.mom.common.GetLook;
 import com.yuanchu.mom.dto.CostStatisticsDto;
-import com.yuanchu.mom.mapper.InsOrderMapper;
-import com.yuanchu.mom.mapper.InsProductMapper;
-import com.yuanchu.mom.mapper.InsProductUserMapper;
-import com.yuanchu.mom.pojo.InsOrder;
-import com.yuanchu.mom.pojo.InsProduct;
-import com.yuanchu.mom.pojo.InsProductUser;
+import com.yuanchu.mom.mapper.*;
+import com.yuanchu.mom.pojo.*;
 import com.yuanchu.mom.service.ReportService;
-import com.yuanchu.mom.utils.QueryWrappers;
 import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
-import java.time.LocalTime;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
+import java.util.stream.Collectors;
 
 @Service
 @AllArgsConstructor
 public class ReportServiceImpl implements ReportService {
 
     private InsOrderMapper insOrderMapper;
+    private InsSampleMapper insSampleMapper;
     private InsProductUserMapper insProductUserMapper;
     private InsProductMapper insProductMapper;
+    private GetLook getLook;
+    private ScheduleMapper scheduleMapper;
+    private UserMapper userMapper;
+    private RoleMapper roleMapper;
+    private InsSampleUserMapper insSampleUserMapper;
 
     //姣忔棩涓氬姟缁熻
     @Override
@@ -43,9 +44,8 @@
         map.put("RECEIVE", receive);
         //鏄ㄦ棩浠诲姟鎺ユ敹
         Long received = insOrderMapper.selectCount(Wrappers.<InsOrder>lambdaQuery().eq(InsOrder::getState, 1).apply("DATE(create_time) = CURDATE() - INTERVAL 1 DAY"));
-        received = received == 0 ? 1 : received;
         //姣斾緥=(浠婂ぉ-鏄ㄥぉ)/鏄ㄥぉ
-        BigDecimal ratio = new BigDecimal(receive - received).divide(new BigDecimal(received), 2, BigDecimal.ROUND_HALF_UP);
+        BigDecimal ratio = new BigDecimal(receive - received).divide(new BigDecimal(received == 0 ? 1 : received), 2, BigDecimal.ROUND_HALF_UP);
         map.put("RECEIVE_RATIO", ratio);
 
         /*浠诲姟宸插畬鎴�*/
@@ -54,9 +54,8 @@
         map.put("FINISHE", finishe);
         //鏄ㄦ棩浠诲姟瀹屾垚
         Long finished = insOrderMapper.selectCount(Wrappers.<InsOrder>lambdaQuery().eq(InsOrder::getState, 4).apply("DATE(create_time) = CURDATE() - INTERVAL 1 DAY"));
-        finished = finished == 0 ? 1 : finished;
         //浠诲姟瀹屾垚姣斾緥=(浠婂ぉ-鏄ㄥぉ)/鏄ㄥぉ
-        BigDecimal finishedRatio = new BigDecimal(finishe - finished).divide(new BigDecimal(finished), 2, BigDecimal.ROUND_HALF_UP);
+        BigDecimal finishedRatio = new BigDecimal(finishe - finished).divide(new BigDecimal(finished == 0 ? 1 : finished), 2, BigDecimal.ROUND_HALF_UP);
         map.put("FINISHE_RATIO", finishedRatio);
 
         /*浠诲姟鍓╀綑*/
@@ -65,9 +64,8 @@
         map.put("SURPLUS", surplus);
         //鏄ㄦ棩浠诲姟鍓╀綑
         long surplused = received - finished;
-        surplused = surplused == 0 ? 1 : surplused;
         //鍓╀綑姣斾緥=(浠婂ぉ-鏄ㄥぉ)/鏄ㄥぉ
-        BigDecimal surplusRatio = new BigDecimal(surplus - surplused).divide(new BigDecimal(surplused), 2, BigDecimal.ROUND_HALF_UP);
+        BigDecimal surplusRatio = new BigDecimal(surplus - surplused).divide(new BigDecimal(surplused == 0 ? 1 : surplused), 2, BigDecimal.ROUND_HALF_UP);
         map.put("SURPLUS_RATIO", surplusRatio);
 
         /*妫�娴嬭垂鐢�*/
@@ -91,9 +89,8 @@
         for (CostStatisticsDto record : dtoIPage.getRecords()) {
             priced.add(record.getPrice());
         }
-        priced = priced.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ONE : priced;
         //姣斾緥=(浠婃棩-鏄ㄦ棩)/鏄ㄦ棩
-        BigDecimal priceRatio = (price.subtract(priced)).divide(priced, 2, BigDecimal.ROUND_HALF_UP);
+        BigDecimal priceRatio = (price.subtract(priced)).divide(priced.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ONE : priced, 2, BigDecimal.ROUND_HALF_UP);
         map.put("PRICE_RATIO", priceRatio);
 
         /*妫�娴嬪伐鏃�*/
@@ -108,21 +105,21 @@
         for (CostStatisticsDto record : dtoIPage.getRecords()) {
             costed += record.getCost();
         }
-        costed = costed == 0 ? 1 : costed;
         //姣斾緥=(浠婃棩-鏄ㄦ棩)/鏄ㄦ棩
-        BigDecimal costRatio = new BigDecimal(cost - costed).divide(new BigDecimal(costed), 2, BigDecimal.ROUND_HALF_UP);
+        BigDecimal costRatio = new BigDecimal(cost - costed).divide(new BigDecimal(costed == 0 ? 1 : costed), 2, BigDecimal.ROUND_HALF_UP);
         map.put("COST_RATIO", costRatio);
 
 
         /*妫�娴嬩汉鍛�*/
         //浠婃棩妫�娴嬩汉鍛�
-        Long person = insProductUserMapper.selectCount(Wrappers.<InsProductUser>lambdaQuery().apply("DATE(create_time) = CURDATE()"));
+        List<InsProductUser> insProductUsers = insProductUserMapper.selectList(Wrappers.<InsProductUser>lambdaQuery().apply("DATE(create_time) = CURDATE()"));
+        long person = insProductUsers.stream().map(InsProductUser::getCreateUser).distinct().count();
         map.put("PERSON", person);
         //鏄ㄦ棩妫�娴嬩汉鍛�
-        Long persons = insProductUserMapper.selectCount(Wrappers.<InsProductUser>lambdaQuery().apply("DATE(create_time) = CURDATE() - INTERVAL 1 DAY"));
-        persons = persons == 0 ? 1 : persons;
+        List<InsProductUser> insProductUserss = insProductUserMapper.selectList(Wrappers.<InsProductUser>lambdaQuery().apply("DATE(create_time) = CURDATE() - INTERVAL 1 DAY"));
+        long persons = insProductUserss.stream().map(InsProductUser::getCreateUser).distinct().count();
         //姣斾緥=(浠婂ぉ-鏄ㄥぉ)/鏄ㄥぉ
-        BigDecimal personRatio = new BigDecimal(person - persons).divide(new BigDecimal(persons), 2, BigDecimal.ROUND_HALF_UP);
+        BigDecimal personRatio = new BigDecimal(person - persons).divide(new BigDecimal(persons == 0 ? 1 : persons), 2, BigDecimal.ROUND_HALF_UP);
         map.put("PERSON_RATIO", personRatio);
 
         /*杩戝崄鏃ヤ换鍔℃帴鏀堕噺涓庡畬鎴愰噺*/
@@ -149,12 +146,141 @@
         /*椤圭洰鎺ユ敹*/
         //浠婃棩椤圭洰鎺ユ敹閲�
         Long receive = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery().eq(InsProduct::getState, 1).apply("DATE(create_time) = CURDATE()"));
+        map.put("RECEVICE", receive);
+        //鏄ㄦ棩椤圭洰鎺ユ敹閲�
+        Long received = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery().eq(InsProduct::getState, 1).apply("DATE(create_time) = CURDATE() - INTERVAL 1 DAY"));
+        //姣斾緥=(浠婂ぉ-鏄ㄥぉ)/鏄ㄥぉ
+        BigDecimal ratio = new BigDecimal(receive - received).divide(new BigDecimal(received == 0 ? 1 : received), 2, BigDecimal.ROUND_HALF_UP);
+        map.put("RECEIVE_RATIO", ratio);
+
         /*椤圭洰瀹屾垚*/
+        //浠婃棩椤圭洰瀹屾垚閲�
+        Long finishe = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery().eq(InsProduct::getState, 1).isNotNull(InsProduct::getInsResult).apply("DATE(create_time) = CURDATE()"));
+        map.put("FINISHE", finishe);
+        //鏄ㄦ棩椤圭洰瀹屾垚閲�
+        Long finished = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery().eq(InsProduct::getState, 1).isNotNull(InsProduct::getInsResult).apply("DATE(create_time) = CURDATE() - INTERVAL 1 DAY"));
+        //浠诲姟瀹屾垚姣斾緥=(浠婂ぉ-鏄ㄥぉ)/鏄ㄥぉ
+        BigDecimal finishedRatio = new BigDecimal(finishe - finished).divide(new BigDecimal(finished == 0 ? 1 : finished), 2, BigDecimal.ROUND_HALF_UP);
+        map.put("FINISHE_RATIO", finishedRatio);
+
         /*椤圭洰鍓╀綑*/
+        //浠婃棩椤圭洰鍓╀綑閲�
+        long surplus = receive - finishe;
+        map.put("SURPLUS", surplus);
+        //鏄ㄦ棩椤圭洰鍓╀綑
+        long surplused = received - finished;
+        //鍓╀綑姣斾緥=(浠婂ぉ-鏄ㄥぉ)/鏄ㄥぉ
+        BigDecimal surplusRatio = new BigDecimal(surplus - surplused).divide(new BigDecimal(surplused == 0 ? 1 : surplused), 2, BigDecimal.ROUND_HALF_UP);
+        map.put("SURPLUS_RATIO", surplusRatio);
+
         /*浠婃棩椤圭洰鍚堟牸鐜�*/
+        //浠婃棩瀹屾垚閲忎腑鐨勫悎鏍奸噺/浠婃棩瀹屾垚閲�
+        Long accept = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery().eq(InsProduct::getState, 1).eq(InsProduct::getInsResult,1).apply("DATE(create_time) = CURDATE()"));
+        map.put("ACCEPT", accept);
+        BigDecimal acceptRate = new BigDecimal(accept).divide(new BigDecimal(finishe == 0 ? 1 : finishe), 2, BigDecimal.ROUND_HALF_UP);
+        map.put("ACCEPT_RATE_TODAY", acceptRate);
+
         /*浠婃棩椤圭洰瀹屾垚鐜�*/
+        //浠婃棩瀹屾垚閲�/浠婃棩鎺ユ敹閲�
+        BigDecimal finishRate = new BigDecimal(finishe).divide(new BigDecimal(receive == 0 ? 1 : receive), 2, BigDecimal.ROUND_HALF_UP);
+        map.put("FINISH_RATE_TODAY", finishRate);
+
         /*浠婃棩椤圭洰寤舵湡鐜�*/
+        //浠婃棩椤圭洰鍓╀綑/浠婃棩椤圭洰鎺ユ敹閲�
+        BigDecimal delayRate = new BigDecimal(surplus).divide(new BigDecimal(received == 0 ? 1 : received), 2, BigDecimal.ROUND_HALF_UP);
+        map.put("DELAY_RATE_TODAY", delayRate);
+
         /*杩戝崄鏃ョ殑椤圭洰鎺ユ敹閲忎笌瀹屾垚閲�*/
+        //鑾峰彇杩戝崄鏃ョ殑妯潗鏍�
+        LocalDate currentDate = LocalDate.now();
+        List<LocalDate> lastTenDays = new ArrayList<>();
+        List<Long> receTenDays = new ArrayList<>();
+        List<Long> finTenDays = new ArrayList<>();
+        for (int i = 9; i > -1; i--) {
+            lastTenDays.add(currentDate.minusDays(i));
+            receTenDays.add(insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery().eq(InsProduct::getState, 1).apply("DATE(create_time) = CURDATE() - INTERVAL " + i + " DAY")));
+            finTenDays.add(insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery().eq(InsProduct::getState, 1).isNotNull(InsProduct::getInsResult).apply("DATE(create_time) = CURDATE() - INTERVAL " + i + " DAY")));
+        }
+        map.put("DAYS", lastTenDays);
+        map.put("RECETENDAYS", receTenDays);
+        map.put("FINISHTENDAYS", finTenDays);
+
         return map;
     }
+
+    //棣栭〉-->鏃ュ巻浠诲姟鍥�
+    @Override
+    public Map<String, Object> calendarWorkByWeek() {
+        Integer userId = getLook.selectPowerByMethodAndUserId(null).get("userId");
+        String name = roleMapper.selectById(userMapper.selectById(userId).getRoleId()).getName();
+        Map<String, Object> map = new HashMap<>();
+        List<Integer> insState = new ArrayList<>();
+        insState.add(0);
+        insState.add(1);
+        /*鑾峰彇鍚庝竴鍛ㄦ棩鏈�*/
+        LocalDate currentDate = LocalDate.now();
+        List<LocalDate> weekDays = new ArrayList<>();
+        for (int i = 6, j = 0; i >= 0; i--, j++) {
+            weekDays.add(currentDate.minusDays(i));
+            //鏌ヨ褰撳ぉ闇�瑕佹娴嬬殑濮旀墭璁㈠崟
+            List<InsOrder> insOrders = insOrderMapper.selectList(Wrappers.<InsOrder>lambdaQuery()
+                    .eq(InsOrder::getState, 1)
+                    .in(InsOrder::getInsState, insState)
+                    .apply("DATE(create_time) = CURDATE() - INTERVAL " + j + " DAY"));
+            //濡傛灉褰撳墠鐧诲綍浜烘槸娴嬭瘯宸ョ▼甯堟垨鑰呮槸妫�娴嬬粍闀�,闇�瑕佽繃婊ゅ嚭妫�楠屼汉鏄粬浠殑璁㈠崟鎴栬�呮槸杩樻病妫�楠岀殑璁㈠崟
+            if (name.equals("娴嬭瘯宸ョ▼甯�") || name.equals("妫�娴嬬粍闀�")){
+                insOrders = insOrders.stream().filter(insOrder -> {
+                    List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, insOrder.getId()));
+                    List<Integer> sampleId = insSamples.stream().map(InsSample::getId).collect(Collectors.toList());
+                    List<InsSampleUser> insSampleUsers = insSampleUserMapper.selectList(Wrappers.<InsSampleUser>lambdaQuery()
+                            .eq(InsSampleUser::getState, 0)  //妫�楠屼汉
+                            .in(InsSampleUser::getInsSampleId, sampleId));
+                    return insSampleUsers.size() == 0 || insSampleUsers.stream().map(InsSampleUser::getUserId).collect(Collectors.toList()).contains(userId);
+                }).collect(Collectors.toList());
+            }
+            //濡傛灉褰撳墠鐧诲綍浜烘槸閫佹牱鍛�,闇�杩囨护鍑哄崟瀛愮殑閫佹牱鍛樻槸褰撳墠浜虹殑璁㈠崟
+            else if (name.equals("閫佹牱鍛�")){
+                insOrders = insOrders.stream().filter(insOrder ->
+                        ObjectUtils.isNotEmpty(insOrder.getIssueUser()) && insOrder.getIssueUser().equals(userId)
+                ).collect(Collectors.toList());
+            }
+            List<Map<String, Object>> works = insOrders.stream().map(insOrder -> {
+                List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, insOrder.getId()));
+                HashMap<String, Object> hashMap = new HashMap<>();
+                hashMap.put("text", insOrder.getEntrustCode());
+                hashMap.put("sample", insSamples.stream().map(InsSample::getSample).collect(Collectors.joining(",")));
+                hashMap.put("type", insOrder.getType());
+                hashMap.put("state", insOrder.getState());
+                User user = userMapper.selectById(insOrder.getCreateUser());
+                hashMap.put("name", user.getName());
+                return hashMap;
+            }).collect(Collectors.toList());
+            map.put("work" + i, works);
+        }
+        map.put("weekDays", weekDays);
+        return map;
+    }
+
+    //棣栭〉-->娣诲姞鏃ョ▼
+    @Override
+    public int addSchedule(String time, String text) {
+        //鑾峰彇褰撳墠鐢ㄦ埛id
+        Integer userId = getLook.selectPowerByMethodAndUserId(null).get("userId");
+        Schedule schedule = new Schedule();
+        schedule.setUserId(userId);
+        schedule.setScheduleTime(LocalDateTime.parse(time, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+        schedule.setText(text);
+        return scheduleMapper.insert(schedule);
+    }
+
+    //棣栭〉-->鎴戠殑鏃ョ▼
+    @Override
+    public List<Schedule> ScheduleByMe(String date) {
+        //鑾峰彇褰撳墠鐢ㄦ埛id
+        Integer userId = getLook.selectPowerByMethodAndUserId(null).get("userId");
+        LocalDate localDate = LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+        LocalDateTime startTime = localDate.atStartOfDay();
+        LocalDateTime endTime = localDate.plusDays(1).atStartOfDay().minusSeconds(1);
+        return scheduleMapper.selectList(Wrappers.<Schedule>lambdaQuery().eq(Schedule::getUserId, userId).between(Schedule::getScheduleTime, startTime, endTime));
+    }
 }

--
Gitblit v1.9.3