package com.yuanchu.mom.service.impl; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.yuanchu.mom.mapper.FinishedInspectMapper; import com.yuanchu.mom.mapper.RawInspectMapper; import com.yuanchu.mom.pojo.ProReport; import com.yuanchu.mom.pojo.RawInspect; import com.yuanchu.mom.pojo.StatisticsData; import com.yuanchu.mom.service.ResportService; import lombok.Data; import org.apache.tomcat.util.buf.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Date; @Service public class ResportServiceImpl implements ResportService { @Resource RawInspectMapper rawInspectMapper; @Resource FinishedInspectMapper finishedInspectMapper; //计算合格与不合格数量 @Override public StatisticsData turno(String begin, String end) { StatisticsData statisticsData = new StatisticsData(); //原材料合格 Integer material = rawInspectMapper.selCountRaw(begin, end, 1); statisticsData.setMaterial(material); //原材料不合格 Integer unmaterial = rawInspectMapper.selCountRaw(begin, end, 0); statisticsData.setUnmaterial(unmaterial); //过程合格数 Integer process = finishedInspectMapper.selCountFin(begin, end, 1, 1); statisticsData.setProcess(process); //过程不合格 Integer unprocess = finishedInspectMapper.selCountFin(begin, end, 1, 0); statisticsData.setUnprocess(unprocess); //成品合格数 Integer finished = finishedInspectMapper.selCountFin(begin, end, 0, 1); statisticsData.setFinished(finished); //成品不合格 Integer unfinished = finishedInspectMapper.selCountFin(begin, end, 0, 0); statisticsData.setUnfinished(unfinished); return statisticsData; } //计算产品总量 @Override public ProReport allNum() { // 获取当前日期的前两个月的日期 ArrayList dateList = new ArrayList<>(); LocalDate now = LocalDate.now(); LocalDate oneAgo = now.minusMonths(1); LocalDate twoAgo = now.minusMonths(2); // 格式化日期对象 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM"); dateList.add(twoAgo.format(formatter)); dateList.add(oneAgo.format(formatter)); dateList.add(now.format(formatter)); //获取原材料月产量 Long cLong = rawInspectMapper.seAllCount(now.withDayOfMonth(1).toString(), now.plusMonths(1).withDayOfMonth(1).minusDays(1).toString()); Long bLong = rawInspectMapper.seAllCount(oneAgo.withDayOfMonth(1).toString(), oneAgo.plusMonths(1).withDayOfMonth(1).minusDays(1).toString()); Long aLong = rawInspectMapper.seAllCount(twoAgo.withDayOfMonth(1).toString(), twoAgo.plusMonths(1).withDayOfMonth(1).minusDays(1).toString()); ArrayList materialList = new ArrayList<>(); materialList.add(aLong.toString()); materialList.add(bLong.toString()); materialList.add(cLong.toString()); //获取过程月产量 Long c1Long = finishedInspectMapper.seAllCount(now.withDayOfMonth(1).toString(), now.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 1); Long b1Long = finishedInspectMapper.seAllCount(oneAgo.withDayOfMonth(1).toString(), oneAgo.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 1); Long a1Long = finishedInspectMapper.seAllCount(twoAgo.withDayOfMonth(1).toString(), twoAgo.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 1); ArrayList processList = new ArrayList<>(); processList.add(a1Long.toString()); processList.add(b1Long.toString()); processList.add(c1Long.toString()); //获取成品月产量 Long c2Long = finishedInspectMapper.seAllCount(now.withDayOfMonth(1).toString(), now.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 0); Long b2Long = finishedInspectMapper.seAllCount(oneAgo.withDayOfMonth(1).toString(), oneAgo.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 0); Long a2Long = finishedInspectMapper.seAllCount(twoAgo.withDayOfMonth(1).toString(), twoAgo.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 0); ArrayList finishedList = new ArrayList<>(); finishedList.add(a2Long.toString()); finishedList.add(b2Long.toString()); finishedList.add(c2Long.toString()); return ProReport.builder() .dateList(StringUtils.join(dateList, ',')) .materialList(StringUtils.join(materialList, ',')) .processList(StringUtils.join(processList, ',')) .finishedList(StringUtils.join(finishedList, ',')) .build(); } //计算达标总量 @Override public ProReport statisNum() { // 获取当前日期的前两个月的日期 ArrayList dateList = new ArrayList<>(); LocalDate now = LocalDate.now(); LocalDate oneAgo = now.minusMonths(1); LocalDate twoAgo = now.minusMonths(2); // 格式化日期对象 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM"); dateList.add(twoAgo.format(formatter)); dateList.add(oneAgo.format(formatter)); dateList.add(now.format(formatter)); //获取原材料月达标产量 Integer c = rawInspectMapper.selCountRaw(now.withDayOfMonth(1).toString(), now.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 1); Integer b = rawInspectMapper.selCountRaw(oneAgo.withDayOfMonth(1).toString(), oneAgo.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 1); Integer a = rawInspectMapper.selCountRaw(twoAgo.withDayOfMonth(1).toString(), twoAgo.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 1); ArrayList materialList = new ArrayList<>(); materialList.add(a.toString()); materialList.add(b.toString()); materialList.add(c.toString()); //获取过程月达标产量 Integer c1 = finishedInspectMapper.selCountFin(now.withDayOfMonth(1).toString(), now.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 1, 1); Integer b1 = finishedInspectMapper.selCountFin(oneAgo.withDayOfMonth(1).toString(), oneAgo.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 1, 1); Integer a1 = finishedInspectMapper.selCountFin(twoAgo.withDayOfMonth(1).toString(), twoAgo.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 1, 1); ArrayList processList = new ArrayList<>(); processList.add(a1.toString()); processList.add(b1.toString()); processList.add(c1.toString()); //获取成品月达标产量 Integer c2 = finishedInspectMapper.selCountFin(now.withDayOfMonth(1).toString(), now.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 0, 1); Integer b2 = finishedInspectMapper.selCountFin(oneAgo.withDayOfMonth(1).toString(), oneAgo.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 0, 1); Integer a2 = finishedInspectMapper.selCountFin(twoAgo.withDayOfMonth(1).toString(), twoAgo.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 0, 1); ArrayList finishedList = new ArrayList<>(); finishedList.add(a2.toString()); finishedList.add(b2.toString()); finishedList.add(c2.toString()); return ProReport.builder() .dateList(StringUtils.join(dateList, ',')) .materialList(StringUtils.join(materialList, ',')) .processList(StringUtils.join(processList, ',')) .finishedList(StringUtils.join(finishedList, ',')) .build(); } }