From 9f19d3a24f8474bf6f9eb9401888c44b34b381e6 Mon Sep 17 00:00:00 2001 From: zss <zss@example.com> Date: 星期四, 21 十一月 2024 14:29:50 +0800 Subject: [PATCH] 第一次改动(检验任务与样品关联,附件与样品关联,报告与样品关联) --- inspect-server/src/main/java/com/yuanchu/mom/service/impl/ReportServiceImpl.java | 152 ++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 126 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..910e29f 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 @@ -4,26 +4,20 @@ import com.baomidou.mybatisplus.core.metadata.IPage; 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 @@ -32,6 +26,9 @@ private InsOrderMapper insOrderMapper; private InsProductUserMapper insProductUserMapper; private InsProductMapper insProductMapper; + private GetLook getLook; + private ScheduleMapper scheduleMapper; + private UserMapper userMapper; //姣忔棩涓氬姟缁熻 @Override @@ -43,9 +40,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 +50,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 +60,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 +85,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 +101,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 +142,119 @@ /*椤圭洰鎺ユ敹*/ //浠婃棩椤圭洰鎺ユ敹閲� 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() { + 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")); + List<Map<String, Object>> works = insOrders.stream().map(insOrder -> { + HashMap<String, Object> hashMap = new HashMap<>(); + hashMap.put("text", insOrder.getEntrustCode()); + hashMap.put("type", insOrder.getType()); + 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