Commit 7eeccc5a by lijingjing

霍煤报表 :

原铝铁含量台账统计;
原铝杂质台账统计;
parent b30d472d
package com.patzn.cloud.service.lims.common;
import com.patzn.cloud.commons.constant.CommonConstants;
import java.time.LocalDate;
import java.time.Period;
import java.time.ZoneId;
......@@ -72,4 +74,23 @@ public class DateKit {
}
return monthList;
}
public static List<String> dateBetweenTwoDates(LocalDate start, LocalDate end) {
if (null == start || null == end) {
return null;
}
String pattern = CommonConstants.YEAR_MONTH_DAY;
List<String> dateList = new ArrayList<>();
LocalDate localDate = start;
while (localDate.isBefore(end)) {
dateList.add(localDate.format(DateTimeFormatter.ofPattern(pattern)));
localDate = localDate.plusDays(1);
}
return dateList;
}
public static List<String> dateInMonth(String yearMonth) {
LocalDate start = LocalDate.parse(yearMonth + "-01", DateTimeFormatter.ofPattern(CommonConstants.YEAR_MONTH_DAY));
return dateBetweenTwoDates(start, start.plusMonths(1));
}
}
......@@ -15,7 +15,7 @@ import com.patzn.cloud.service.hmhj.entity.EntrustSample;
import com.patzn.cloud.service.hmhj.enums.EntrustSampleItemStatusEnum;
import com.patzn.cloud.service.hmhj.enums.EntrustSamplePrepareStatusEnum;
import com.patzn.cloud.service.hmhj.enums.EntrustSampleStatusEnum;
import com.patzn.cloud.service.hmhj.vo.AlTasteStatsVO;
import com.patzn.cloud.service.hmhj.vo.AlGradeStatsVO;
import com.patzn.cloud.service.hmhj.vo.ElectrolyteRatioStatsVO;
import com.patzn.cloud.service.hmhj.vo.EntrustSampleVO;
import com.patzn.cloud.service.lims.hmhj.service.IEntrustSampleService;
......@@ -588,9 +588,9 @@ public class EntrustSampleController extends ServiceController {
}
@ApiOperation("原铝品味统计查询")
@PostMapping("/al_taste_stats_query")
public RestResult<List<AlTasteStatsVO>> getAlTasteStatsQuery(StatsQueryDTO statsQueryDTO) {
return success(entrustSampleService.getAlTasteStatsQuery(statsQueryDTO));
@PostMapping("/al_grade_stats_query")
public RestResult<List<AlGradeStatsVO>> getAlGradeStatsQuery(StatsQueryDTO statsQueryDTO) {
return success(entrustSampleService.getAlGradeStatsQuery(statsQueryDTO));
}
@ApiOperation("电解质分子比统计查询")
......
......@@ -2,6 +2,7 @@ package com.patzn.cloud.service.lims.hmhj.controller;
import com.patzn.cloud.commons.api.RestResult;
import com.patzn.cloud.commons.controller.ServiceController;
import com.patzn.cloud.service.hmhj.dto.LedgerQueryDTO;
import com.patzn.cloud.service.hmhj.dto.QueryDTO;
import com.patzn.cloud.service.hmhj.dto.RangeStatsQueryDTO;
import com.patzn.cloud.service.hmhj.entity.Statistics;
......@@ -38,7 +39,7 @@ public class StatisticsController extends ServiceController {
@ApiOperation("报告发放量统计")
@PostMapping("/report_send_quantity")
public RestResult<Map<String,Object>> getReportSendQuantity(RangeStatsQueryDTO queryDTO) {
public RestResult<Map<String, Object>> getReportSendQuantity(RangeStatsQueryDTO queryDTO) {
return success(statsService.getReportSendQuantity(queryDTO));
}
......@@ -91,4 +92,41 @@ public class StatisticsController extends ServiceController {
return success(statsService.getAlBrandsRate(queryDTO));
}
@ApiOperation("原铝品味台账")
@PostMapping("/al_grade_ledger")
public RestResult<List<Map>> getAlGradeLedger(LedgerQueryDTO ledgerQueryDTO) {
return success(statsService.getAlGradeLedger(ledgerQueryDTO));
}
@ApiOperation("原铝品位台账统计表")
@PostMapping("/al_grade_ledger_stats")
public RestResult<List<Map>> getAlGradeLedgerStats(LedgerQueryDTO ledgerQueryDTO) {
return success(statsService.getAlGradeLedgerStats(ledgerQueryDTO));
}
@ApiOperation("原铝杂质含量台账")
@PostMapping("/al_impurity_ledger")
public RestResult<List<Map>> getAlImpurityLedger(LedgerQueryDTO ledgerQueryDTO) {
return success(statsService.getAlImpurityLedger(ledgerQueryDTO));
}
@ApiOperation("原铝杂质含量台账统计表")
@PostMapping("/al_impurity_ledger_stats")
public RestResult<List<Map>> getAlImpurityLedgerStats(LedgerQueryDTO ledgerQueryDTO) {
return success(statsService.getAlImpurityLedgerStats(ledgerQueryDTO));
}
@ApiOperation("原铝铁含量统计表")
@PostMapping("/al_fe_ledger_stats")
public RestResult<List<Map>> getAlFeLedgerStats(LedgerQueryDTO ledgerQueryDTO) {
return success(statsService.getAlFeLedgerStats(ledgerQueryDTO));
}
@ApiOperation("汇总统计表")
@PostMapping("/summary_ledger_stats")
public RestResult<List<Map>> getSummaryLedgerStats(LedgerQueryDTO ledgerQueryDTO) {
return success(statsService.getSummaryLedgerStats(ledgerQueryDTO));
}
}
package com.patzn.cloud.service.lims.hmhj.mapper;
import com.baomidou.mybatisplus.annotations.SqlParser;
import com.baomidou.mybatisplus.plugins.Page;
import com.patzn.cloud.commons.mapper.BatchMapper;
import com.patzn.cloud.service.hmhj.dto.QueryDTO;
import com.patzn.cloud.service.hmhj.dto.StatsQueryDTO;
import com.patzn.cloud.service.hmhj.entity.EntrustSample;
import com.patzn.cloud.commons.mapper.BatchMapper;
import com.patzn.cloud.service.hmhj.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.RowBounds;
......@@ -32,7 +31,7 @@ public interface EntrustSampleMapper extends BatchMapper<EntrustSample> {
List<EntrustSampleVO> selectTestResultQuery(RowBounds rowBounds, @Param("vo") EntrustSampleVO entrustSample);
@SqlParser(filter = true)
List<AlTasteStatsVO> selectAlTasteStats(@Param("vo") StatsQueryDTO queryDTO);
List<AlGradeStatsVO> selectAlGradeStats(@Param("vo") StatsQueryDTO queryDTO);
List<ElectrolyteRatioStatsVO> selectElectrolyteRatioStats(@Param("vo") QueryDTO queryDTO);
......
package com.patzn.cloud.service.lims.hmhj.mapper;
import com.baomidou.mybatisplus.annotations.SqlParser;
import com.patzn.cloud.commons.mapper.BatchMapper;
import com.patzn.cloud.service.hmhj.dto.LedgerQueryDTO;
import com.patzn.cloud.service.hmhj.dto.QueryDTO;
import com.patzn.cloud.service.hmhj.dto.RangeStatsQueryDTO;
import com.patzn.cloud.service.hmhj.entity.Statistics;
import com.patzn.cloud.service.hmhj.vo.DailyStatsLedgerVO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
......@@ -31,4 +34,20 @@ public interface StatisticsMapper extends BatchMapper<Statistics> {
Statistics selectReportSendQuantity(@Param("vo") RangeStatsQueryDTO queryDTO);
List<Statistics> selectEntrustedQuantity(QueryDTO queryDTO);
@SqlParser(filter = true)
List<DailyStatsLedgerVO> selectAlGradeLedger(@Param("vo") LedgerQueryDTO ledgerQueryDTO);
@SqlParser(filter = true)
List<DailyStatsLedgerVO> selectAlGradeLedgerStats(@Param("vo") LedgerQueryDTO ledgerQueryDTO);
@SqlParser(filter = true)
List<DailyStatsLedgerVO> selectAlImpurityLedger(@Param("vo") LedgerQueryDTO ledgerQueryDTO);
@SqlParser(filter = true)
List<DailyStatsLedgerVO> selectAlFeLedgerStats(@Param("vo") LedgerQueryDTO ledgerQueryDTO);
@SqlParser(filter = true)
List<DailyStatsLedgerVO> selectAlImpurityLedgerStats(@Param("vo") LedgerQueryDTO ledgerQueryDTO);
}
......@@ -11,7 +11,7 @@ import com.patzn.cloud.service.hmhj.dto.StatsQueryDTO;
import com.patzn.cloud.service.hmhj.entity.Entrust;
import com.patzn.cloud.service.hmhj.entity.EntrustSample;
import com.patzn.cloud.service.hmhj.enums.EntrustFlowEnum;
import com.patzn.cloud.service.hmhj.vo.AlTasteStatsVO;
import com.patzn.cloud.service.hmhj.vo.AlGradeStatsVO;
import com.patzn.cloud.service.hmhj.vo.ElectrolyteRatioStatsVO;
import com.patzn.cloud.service.hmhj.vo.EntrustSampleVO;
import com.patzn.cloud.service.hmhj.vo.ReportSampleVO;
......@@ -65,7 +65,7 @@ public interface IEntrustSampleService extends IBaseService<EntrustSample> {
int countByEntrustId(Long id);
List<AlTasteStatsVO> getAlTasteStatsQuery(StatsQueryDTO queryDTO);
List<AlGradeStatsVO> getAlGradeStatsQuery(StatsQueryDTO queryDTO);
List<ElectrolyteRatioStatsVO> getElectrolyteRatioStatsQuery(QueryDTO queryDTO);
......
package com.patzn.cloud.service.lims.hmhj.service;
import com.patzn.cloud.commons.service.IBaseService;
import com.patzn.cloud.service.hmhj.dto.LedgerQueryDTO;
import com.patzn.cloud.service.hmhj.dto.QueryDTO;
import com.patzn.cloud.service.hmhj.dto.RangeStatsQueryDTO;
import com.patzn.cloud.service.hmhj.entity.Statistics;
......@@ -33,4 +34,17 @@ public interface IStatisticsService extends IBaseService<Statistics> {
List<Statistics> getCurWeekAcceptanceQualified(QueryDTO queryDTO);
List<Statistics> getCurWeekCarbonBlocks(QueryDTO queryDTO);
List<Map> getAlGradeLedger(LedgerQueryDTO ledgerQueryDTO);
List<Map> getAlGradeLedgerStats(LedgerQueryDTO ledgerQueryDTO);
List<Map> getAlImpurityLedger(LedgerQueryDTO ledgerQueryDTO);
List<Map> getAlImpurityLedgerStats(LedgerQueryDTO ledgerQueryDTO);
List<Map> getAlFeLedgerStats(LedgerQueryDTO ledgerQueryDTO);
List<Map> getSummaryLedgerStats(LedgerQueryDTO ledgerQueryDTO);
}
......@@ -1117,7 +1117,7 @@ public class EntrustSampleItemServiceImpl extends BaseServiceImpl<EntrustSampleI
// 样品判定合格
updateSampleList.add(sample.setOkJudge("合格").setJudger(account.getUserName()).setJudgerId(account.getUserId())
.setJudgeCheckTime(new Date()).setJudgeStatus(0).setJudgeProgress(0)
.setJudgeTime(new Date()).setJudgeStatus(0).setJudgeProgress(0)
.setSampleGrading(product.getProductGrade()));
break;
}
......@@ -1262,7 +1262,7 @@ public class EntrustSampleItemServiceImpl extends BaseServiceImpl<EntrustSampleI
*/
private void updateJudgeNoPass(EntrustSample sample, Account account, List<EntrustSample> sampleList) {
sampleList.add(sample.setOkJudge("不合格").setJudger(account.getUserName()).setJudgerId(account.getUserId())
.setJudgeCheckTime(new Date()).setJudgeStatus(0).setJudgeProgress(0)
.setJudgeTime(new Date()).setJudgeStatus(0).setJudgeProgress(0)
.setSampleGrading("-"));
}
......
......@@ -253,11 +253,11 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
return new BigDecimal(d).setScale(2, RoundingMode.UP).doubleValue();
}
private AlTasteStatsVO getTotalData(List<AlTasteStatsVO> voList) {
AlTasteStatsVO bpStatsVO = new AlTasteStatsVO();
private AlGradeStatsVO getTotalData(List<AlGradeStatsVO> voList) {
AlGradeStatsVO bpStatsVO = new AlGradeStatsVO();
bpStatsVO.setPlant("合计");
bpStatsVO.setBranch(voList.get(0).getBranch());
for (AlTasteStatsVO t : voList) {
for (AlGradeStatsVO t : voList) {
bpStatsVO.setTotal(getValSum(bpStatsVO.getTotal(), t.getTotal()));
bpStatsVO.setSlotsNum(getValSum(bpStatsVO.getSlotsNum(), t.getSlotsNum()));
// ==
......@@ -289,26 +289,26 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
}
@Override
public List<AlTasteStatsVO> getAlTasteStatsQuery(StatsQueryDTO queryDTO) {
public List<AlGradeStatsVO> getAlGradeStatsQuery(StatsQueryDTO queryDTO) {
RestAssert.fail(null == queryDTO.getTimeS() || null == queryDTO.getTimeE(), "开始或结束时间为空");
long days = DateUtils.getDaysBetweenTwoDate(queryDTO.getTimeS(), queryDTO.getTimeE());
queryDTO.setDays(days);
List<AlTasteStatsVO> list = baseMapper.selectAlTasteStats(queryDTO);
List<AlGradeStatsVO> list = baseMapper.selectAlGradeStats(queryDTO);
if (CollectionUtils.isEmpty(list)) {
return list;
}
List<AlTasteStatsVO> resultList = new ArrayList<>();
Map<String, List<AlTasteStatsVO>> dataMap = new HashMap<>();
List<AlGradeStatsVO> resultList = new ArrayList<>();
Map<String, List<AlGradeStatsVO>> dataMap = new HashMap<>();
for (int i = 0; i < list.size(); i++) {
AlTasteStatsVO curr = list.get(i);
AlGradeStatsVO curr = list.get(i);
// 以【分厂】作为获取上一条记录的KEY
String key = curr.getBranch();
// 是否存在同KEY数据
if (dataMap.containsKey(key)) {
List<AlTasteStatsVO> voList = dataMap.get(key);
List<AlGradeStatsVO> voList = dataMap.get(key);
voList.add(curr);
// 若当前的条数为最后一条,那么处理统计数据
if (i == list.size() - 1) {
......@@ -322,15 +322,15 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
else {
// 是否需要取出数据处理
if (i > 0) {
AlTasteStatsVO prev = list.get(i - 1);
List<AlTasteStatsVO> voList = dataMap.get(prev.getBranch());
AlGradeStatsVO prev = list.get(i - 1);
List<AlGradeStatsVO> voList = dataMap.get(prev.getBranch());
// 将列表数据加入集合中
resultList.addAll(voList);
// 将统计数据加入集合中
resultList.add(getTotalData(voList));
}
// 将当前数据加入mapData中
List<AlTasteStatsVO> voList = new ArrayList<>();
List<AlGradeStatsVO> voList = new ArrayList<>();
if (i == list.size() - 1) {
resultList.add(curr);
voList.add(curr);
......@@ -342,9 +342,9 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
}
}
// 汇总所有查询出的列表数据
AlTasteStatsVO alTasteStatsVO = getTotalData(list);
alTasteStatsVO.setBranch(null);
resultList.add(alTasteStatsVO);
AlGradeStatsVO alGradeStatsVO = getTotalData(list);
alGradeStatsVO.setBranch(null);
resultList.add(alGradeStatsVO);
return resultList;
}
......
......@@ -3,13 +3,16 @@ package com.patzn.cloud.service.lims.hmhj.service.impl;
import com.baomidou.mybatisplus.toolkit.CollectionUtils;
import com.patzn.cloud.commons.api.RestAssert;
import com.patzn.cloud.commons.service.impl.BaseServiceImpl;
import com.patzn.cloud.service.hmhj.dto.LedgerQueryDTO;
import com.patzn.cloud.service.hmhj.dto.QueryDTO;
import com.patzn.cloud.service.hmhj.dto.RangeStatsQueryDTO;
import com.patzn.cloud.service.hmhj.entity.Statistics;
import com.patzn.cloud.service.hmhj.vo.DailyStatsLedgerVO;
import com.patzn.cloud.service.lims.common.DateKit;
import com.patzn.cloud.service.lims.hmhj.mapper.StatisticsMapper;
import com.patzn.cloud.service.lims.hmhj.service.IStatisticsService;
import org.apache.commons.lang.time.DateUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.*;
......@@ -19,6 +22,20 @@ import java.util.stream.Collectors;
@Service
public class StatisticsServiceImpl extends BaseServiceImpl<StatisticsMapper, Statistics> implements IStatisticsService {
private final static Map<String, String> elementMap = new HashMap<>();
static {
elementMap.put("Cu", "铜");
elementMap.put("Fe", "铁");
elementMap.put("Ga", "钙");
elementMap.put("Mg", "镁");
elementMap.put("Mn", "锰");
elementMap.put("Ni", "镍");
elementMap.put("Si", "硅");
elementMap.put("Zn", "锌");
elementMap.put("V", "钒");
}
private void handleQueryTime(QueryDTO queryDTO) {
RestAssert.fail(null == queryDTO.getTimeS(), "起始时间不为空");
// 截至时间若为空,默认当前时间
......@@ -32,20 +49,18 @@ public class StatisticsServiceImpl extends BaseServiceImpl<StatisticsMapper, Sta
queryDTO.setLastYearTimeS(DateUtils.addYears(queryDTO.getTimeS(), -1));
queryDTO.setLastYearTimeE(DateUtils.addYears(queryDTO.getTimeE(), -1));
Integer days = DateKit.monthsBetweenTwoDates(queryDTO.getTimeS(), queryDTO.getTimeE());
queryDTO.setPrevTimeS(DateUtils.addDays(queryDTO.getTimeS(), -days.intValue()));
queryDTO.setPrevTimeS(DateUtils.addDays(queryDTO.getTimeS(), -days));
queryDTO.setPrevTimeE(queryDTO.getTimeS());
}
private void handleMonthData(QueryDTO queryDTO, List<Statistics> statistics) {
private List<Statistics> handleMonthData(QueryDTO queryDTO, List<Statistics> statistics) {
List<String> months = DateKit.monthStrBetweenTwoDates(DateKit.date2Local(queryDTO.getTimeS()), DateKit.date2Local(queryDTO.getTimeE()));
List<Statistics> statsList = new ArrayList<>();
if (CollectionUtils.isEmpty(statistics)) {
statistics = months.stream().map(t -> {
return new Statistics().setOccurDate(t).setDoneNum(0);
}).collect(Collectors.toList());
statistics = months.stream().map(t -> new Statistics().setOccurDate(t).setDoneNum(0)).collect(Collectors.toList());
} else {
List<Statistics> finalStatistics = statistics;
months.stream().forEach(t -> {
months.forEach(t -> {
AtomicReference<Statistics> statsAtomic = new AtomicReference<>();
// 是否存在对应的月份数据
if (finalStatistics.stream().anyMatch(s -> {
......@@ -62,6 +77,7 @@ public class StatisticsServiceImpl extends BaseServiceImpl<StatisticsMapper, Sta
});
statistics = statsList;
}
return statistics;
}
@Override
......@@ -75,16 +91,13 @@ public class StatisticsServiceImpl extends BaseServiceImpl<StatisticsMapper, Sta
List<String> sampleNameList = Arrays.asList("电解质", "硅铁", "磷铁", "锰铁", "水", "纯铝", "铝合金", "石灰石");
List<Statistics> statistics = baseMapper.selectEntrustedQuantity(queryDTO);
if (CollectionUtils.isEmpty(statistics)) {
return sampleNameList.stream().map(t -> {
return new Statistics().setBrand(t).setTotal(0).setDoneNum(0);
}).collect(Collectors.toList());
return sampleNameList.stream().map(t -> new Statistics().setBrand(t).setTotal(0).setDoneNum(0)).collect(Collectors.toList());
}
List<Statistics> finalStatistics = statistics;
List<Statistics> statsList = new ArrayList<>();
for (String t : sampleNameList) {
AtomicReference<Statistics> statsAtomic = new AtomicReference<>();
// 是否存在对应的样品名称
if (finalStatistics.stream().anyMatch(s -> {
if (statistics.stream().anyMatch(s -> {
if (s.getBrand().equals(t)) {
statsAtomic.set(s);
return true;
......@@ -109,7 +122,7 @@ public class StatisticsServiceImpl extends BaseServiceImpl<StatisticsMapper, Sta
handleQueryTimeRange(queryDTO);
Map<String, Object> result = new HashMap<>();
List<Statistics> monthList = baseMapper.selectReportSendQuantityMonth(queryDTO);
handleMonthData(queryDTO, monthList);
monthList = handleMonthData(queryDTO, monthList);
result.put("monthList", monthList);
Statistics statistics = baseMapper.selectReportSendQuantity(queryDTO);
result.put("statsData", statistics);
......@@ -138,7 +151,7 @@ public class StatisticsServiceImpl extends BaseServiceImpl<StatisticsMapper, Sta
public List<Statistics> getOutTestItemQuantity(QueryDTO queryDTO) {
handleQueryTime(queryDTO);
List<Statistics> list = baseMapper.selectOutTestItemQuantity(queryDTO);
handleMonthData(queryDTO, list);
list = handleMonthData(queryDTO, list);
return list;
}
......@@ -157,4 +170,141 @@ public class StatisticsServiceImpl extends BaseServiceImpl<StatisticsMapper, Sta
public List<Statistics> getCurWeekCarbonBlocks(QueryDTO queryDTO) {
return baseMapper.selectCurWeekCarbonBlocks(queryDTO);
}
private void handleQuery(LedgerQueryDTO dto) {
RestAssert.fail(StringUtils.isBlank(dto.getYearMonth()), "请选择要查询的的月份");
}
private List<Map> dataByMonthHandler(String yearMonth, List<DailyStatsLedgerVO> list, Boolean isNumber) {
if (CollectionUtils.isEmpty(list)) {
return null;
}
isNumber = null != isNumber && isNumber;
// 查询出传递月份所有日期
List<String> dateList = DateKit.dateInMonth(yearMonth);
// 查询出所有label值
List<String> labels = list.stream().map(DailyStatsLedgerVO::getLabel).distinct().collect(Collectors.toList());
// 查询出主名称
List<String> names = list.stream().map(DailyStatsLedgerVO::getName).distinct().collect(Collectors.toList());
// 是否包含主类别
boolean isIncName = CollectionUtils.isNotEmpty(names);
// 循环label获取对应日期的value
Boolean finalIsNumber = isNumber;
return labels.stream().map(l -> {
// 此处过滤一边所有值中对应label的数据
List<DailyStatsLedgerVO> values = list.stream().filter(t -> t.getLabel().equals(l)).collect(Collectors.toList());
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("label", getDataLabel(l, names));
if (isIncName) {
dataMap.put("name", getDataName(l, names));
}
dataMap.put("data", dateList.stream().map(d -> {
String value = finalIsNumber ? "0" : "";
// 根据日期过滤对应的值
Optional<DailyStatsLedgerVO> optional = values.stream().filter(f -> f.getDay().equals(d)).findFirst();
if (optional.isPresent()) {
value = optional.get().getValue();
}
return value;
}).collect(Collectors.toList()));
return dataMap;
}).collect(Collectors.toList());
}
@Override
public List<Map> getAlGradeLedger(LedgerQueryDTO ledgerQueryDTO) {
handleQuery(ledgerQueryDTO);
List<DailyStatsLedgerVO> list = baseMapper.selectAlGradeLedger(ledgerQueryDTO);
return dataByMonthHandler(ledgerQueryDTO.getYearMonth(), list, null);
}
@Override
public List<Map> getAlGradeLedgerStats(LedgerQueryDTO ledgerQueryDTO) {
handleQuery(ledgerQueryDTO);
List<DailyStatsLedgerVO> list = baseMapper.selectAlGradeLedgerStats(ledgerQueryDTO);
List<Map> mapList = dataByMonthHandler(ledgerQueryDTO.getYearMonth(), list, true);
if (CollectionUtils.isEmpty(mapList)) {
return null;
}
Map<String, Object> total = new HashMap<>();
List<Integer> intList = DateKit.dateInMonth(ledgerQueryDTO.getYearMonth()).stream().map(t -> 0).collect(Collectors.toList());
total.put("label", "总和");
mapList.forEach(t -> {
List dataList = (List) t.get("data");
for (int i = 0; i < intList.size(); i++) {
intList.set(i, intList.get(i) + Integer.parseInt(dataList.get(i).toString()));
}
});
total.put("data", intList);
mapList.add(total);
return mapList;
}
@Override
public List<Map> getAlImpurityLedger(LedgerQueryDTO ledgerQueryDTO) {
handleQuery(ledgerQueryDTO);
List<DailyStatsLedgerVO> list = baseMapper.selectAlImpurityLedger(ledgerQueryDTO);
return dataByMonthHandler(ledgerQueryDTO.getYearMonth(), list, null);
}
@Override
public List<Map> getAlImpurityLedgerStats(LedgerQueryDTO ledgerQueryDTO) {
handleQuery(ledgerQueryDTO);
List<DailyStatsLedgerVO> list = baseMapper.selectAlImpurityLedgerStats(ledgerQueryDTO);
list.forEach(t -> t.setName(getDataName(t.getName())).setLabel(t.getName() + t.getLabel()));
return dataByMonthHandler(ledgerQueryDTO.getYearMonth(), list, null);
}
@Override
public List<Map> getAlFeLedgerStats(LedgerQueryDTO ledgerQueryDTO) {
handleQuery(ledgerQueryDTO);
List<DailyStatsLedgerVO> list = baseMapper.selectAlFeLedgerStats(ledgerQueryDTO);
return dataByMonthHandler(ledgerQueryDTO.getYearMonth(), list, null);
}
@Override
public List<Map> getSummaryLedgerStats(LedgerQueryDTO ledgerQueryDTO) {
return null;
}
private String getDataLabel(String label, List<String> names) {
if (StringUtils.isBlank(label) || CollectionUtils.isEmpty(names)) {
return label;
}
for (String t : names) {
if (label.contains(t)) {
return label.replace(t, "");
}
}
return label;
}
private String getDataName(String label, List<String> names) {
if (StringUtils.isBlank(label)) {
return "";
}
for (String t : names) {
if (label.contains(t)) {
return t;
}
}
return label;
}
private String getDataName(String name) {
if (StringUtils.isBlank(name)) {
return "";
}
return elementMap.get(name.replace("原铝", ""));
}
private enum StatsType {
AL_GRADE_LEDGER, // 原铝品位台账
AL_GRADE_LEDGER_STATS, // 原铝品位台账统计
AL_IMPURITY_LEDGER, // 原铝杂质台账
AL_IMPURITY_LEDGER_STATS, // 原铝杂质台账统计
AL_FE_LEDGER_STATS // 原铝含铁量统计
}
}
......@@ -180,7 +180,7 @@
</select>
<!--原铝品味统计查询-->
<select id="selectAlTasteStats" resultType="com.patzn.cloud.service.hmhj.vo.AlTasteStatsVO">
<select id="selectAlGradeStats" resultType="com.patzn.cloud.service.hmhj.vo.AlGradeStatsVO">
with ix as (
SELECT
s.id "sample_id",
......
......@@ -3,133 +3,133 @@
<mapper namespace="com.patzn.cloud.service.lims.hmhj.mapper.StatisticsMapper">
<!--当日原铝质量统计-->
<select id="selectAlBrandsRateStats" resultType="com.patzn.cloud.service.hmhj.entity.Statistics">
SELECT
s.sample_grading "brand",
A.total,
count (1) "brand_num",
round(count(1)::numeric / a.total_num,2) "ratio"
FROM
entrust_sample s,
(
SELECT COUNT (1) "total" FROM entrust_sample s WHERE s.deleted = 0
AND s.type = 0 AND s.sample_grading IS NOT NULL
AND to_char(s.judge_time, 'yyyy-MM-dd') = to_char( now(), 'yyyy-MM-dd')
) A
WHERE
s.deleted = 0 AND s.type = 0
AND s.sample_grading IS NOT NULL AND to_char( s.judge_time, 'yyyy-MM-dd' ) = to_char(now(), 'yyyy-MM-dd')
GROUP BY
A.total,
s.sample_grading
ORDER BY
s.sample_grading DESC
SELECT s.sample_grading "brand",
A.total,
count(1) "brand_num",
round(count(1)::numeric / a.total_num, 2) "ratio"
FROM entrust_sample s,
(
SELECT COUNT(1) "total"
FROM entrust_sample s
WHERE s.deleted = 0
AND s.type = 0
AND s.sample_grading IS NOT NULL
AND to_char(s.judge_time, 'yyyy-MM-dd') = to_char(now(), 'yyyy-MM-dd')
) A
WHERE s.deleted = 0
AND s.type = 0
AND s.sample_grading IS NOT NULL
AND to_char(s.judge_time, 'yyyy-MM-dd') = to_char(now(), 'yyyy-MM-dd')
GROUP BY A.total,
s.sample_grading
ORDER BY s.sample_grading DESC
</select>
<!--外委完成量统计-->
<select id="selectOutTestFinishQuantity" resultType="com.patzn.cloud.service.hmhj.entity.Statistics">
SELECT
count(distinct c.id) "total",
sum(case when s.status = 70 and s.judge_status = 2 then 1 else 0 end) "done_num"
FROM
contract_sample c, entrust_sample s
WHERE
c.deleted = 0 and s.deleted = 0 and c.id = s.contract_sample_id
and c.type = 1 AND s.type = 0
SELECT count(distinct c.id) "total",
sum(case when s.status = 70 and s.judge_status = 2 then 1 else 0 end) "done_num"
FROM contract_sample c,
entrust_sample s
WHERE c.deleted = 0
and s.deleted = 0
and c.id = s.contract_sample_id
and c.type = 1
AND s.type = 0
</select>
<!--本周自产炭块质量统计-->
<select id="selectCurWeekCarbonBlocks" resultType="com.patzn.cloud.service.hmhj.entity.Statistics">
SELECT
s.sample_grading "brand",
A.total,
sum(case when s.status = 70 and s.judge_status = 2 then 1 else 0 end) "brand_num",
round( sum(case when s.status = 70 and s.judge_status = 2 then 1 else 0 end) :: NUMERIC / A.total, 2 ) "ratio"
FROM
entrust_sample s,
(
SELECT COUNT( 1 ) "total"
FROM
entrust_sample s
WHERE
s.deleted = 0 AND s.type = 0
AND s.sample_grading IS NOT NULL
AND s.NAME = '自产阳极炭块'
AND EXTRACT ( YEAR FROM s.judge_time ) = EXTRACT ( YEAR FROM NOW() )
AND EXTRACT ( WEEK FROM s.judge_time ) = EXTRACT ( WEEK FROM NOW() )
) A
WHERE
s.deleted = 0 AND s.type = 0
SELECT s.sample_grading "brand",
A.total,
sum(case when s.status = 70 and s.judge_status = 2 then 1 else 0 end) "brand_num",
round(sum(case when s.status = 70 and s.judge_status = 2 then 1 else 0 end) :: NUMERIC / A.total,
2) "ratio"
FROM entrust_sample s,
(
SELECT COUNT(1) "total"
FROM entrust_sample s
WHERE s.deleted = 0
AND s.type = 0
AND s.sample_grading IS NOT NULL
AND s.NAME = '自产阳极炭块'
AND EXTRACT(YEAR FROM s.judge_time) = EXTRACT(YEAR FROM NOW())
AND EXTRACT(WEEK FROM s.judge_time) = EXTRACT(WEEK FROM NOW())
) A
WHERE s.deleted = 0
AND s.type = 0
AND s.sample_grading IS NOT NULL
AND s.NAME = '自产阳极炭块'
AND EXTRACT ( YEAR FROM s.judge_time ) = EXTRACT ( YEAR FROM NOW() )
AND EXTRACT ( WEEK FROM s.judge_time ) = EXTRACT ( WEEK FROM NOW() )
GROUP BY
A.total,
s.sample_grading
ORDER BY
s.sample_grading DESC
AND EXTRACT(YEAR FROM s.judge_time) = EXTRACT(YEAR FROM NOW())
AND EXTRACT(WEEK FROM s.judge_time) = EXTRACT(WEEK FROM NOW())
GROUP BY A.total,
s.sample_grading
ORDER BY s.sample_grading DESC
</select>
<!--本周验收合格情况-->
<select id="selectCurWeekAcceptanceQualified" resultType="com.patzn.cloud.service.hmhj.entity.Statistics">
SELECT
to_char(s.judge_time,'yyyy-MM-dd') "occur_date",
sum(case when s.ok_judge = '合格' then 1 else 0 end) "done_num",
sum(case when s.ok_judge = '不合格' then 1 else 0 end) "fail_num"
FROM
entrust_sample s
WHERE
s.deleted = 0 AND s.type = 0
SELECT to_char(s.judge_time, 'yyyy-MM-dd') "occur_date",
sum(case when s.ok_judge = '合格' then 1 else 0 end) "done_num",
sum(case when s.ok_judge = '不合格' then 1 else 0 end) "fail_num"
FROM entrust_sample s
WHERE s.deleted = 0
AND s.type = 0
AND s.sample_grading IS NOT NULL
AND s.status = 70 AND s.judge_status = 2
AND EXTRACT ( YEAR FROM s.judge_time ) = EXTRACT ( YEAR FROM NOW() )
AND EXTRACT ( WEEK FROM s.judge_time ) = EXTRACT ( WEEK FROM NOW() )
GROUP BY
to_char(s.judge_time,'yyyy-MM-dd')
ORDER BY
to_char(s.judge_time,'yyyy-MM-dd') ASC
AND s.status = 70
AND s.judge_status = 2
AND EXTRACT(YEAR FROM s.judge_time) = EXTRACT(YEAR FROM NOW())
AND EXTRACT(WEEK FROM s.judge_time) = EXTRACT(WEEK FROM NOW())
GROUP BY to_char(s.judge_time, 'yyyy-MM-dd')
ORDER BY to_char(s.judge_time, 'yyyy-MM-dd') ASC
</select>
<!--工作量统计-->
<select id="selectWorkloadQuantity" resultType="com.patzn.cloud.service.hmhj.entity.Statistics">
SELECT
a.*,
round((case when 0 = b.total then 0 else a.total - b.total end)::numeric / (case when 0 = b.total then 1 else b.total end),2) "chain_ratio",
round((case when 0 = c.total then 0 else a.total - c.total end)::numeric / (case when 0 = c.total then 1 else c.total end),2) "sames_ratio"
from (SELECT
count(r.id) "total",
sum(case when s.ok_judge = '合格' then 1 else 0 end) "done_num",
count(1) - sum(case when s.ok_judge = '合格' then 1 else 0 end) "fail_num",
round(sum(case when s.ok_judge = '合格' then 1 else 0 end):: NUMERIC / count(1),2) "done_ratio",
round((count(1) - sum(case when s.ok_judge = '合格' then 1 else 0 end)):: NUMERIC / count(1),2) "fail_ratio"
FROM
entrust_sample s
join entrust e on e.id = s.entrust_id
join entrust_report r on r.entrust_id = e.id
WHERE
s.deleted = 0 and e.deleted = 0 and r.deleted = 0
AND s.status = 70 AND s.judge_status = 2 AND s.type = 0
SELECT a.*,
round((case when 0 = b.total then 0 else a.total - b.total end)::numeric /
(case when 0 = b.total then 1 else b.total end), 2) "chain_ratio",
round((case when 0 = c.total then 0 else a.total - c.total end)::numeric /
(case when 0 = c.total then 1 else c.total end), 2) "sames_ratio"
from (SELECT count(r.id) "total",
sum(case when s.ok_judge = '合格' then 1 else 0 end) "done_num",
count(1) - sum(case when s.ok_judge = '合格' then 1 else 0 end) "fail_num",
round(sum(case when s.ok_judge = '合格' then 1 else 0 end):: NUMERIC / count(1), 2) "done_ratio",
round((count(1) - sum(case when s.ok_judge = '合格' then 1 else 0 end)):: NUMERIC / count(1),
2) "fail_ratio"
FROM entrust_sample s
join entrust e on e.id = s.entrust_id
join entrust_report r on r.entrust_id = e.id
WHERE s.deleted = 0
and e.deleted = 0
and r.deleted = 0
AND s.status = 70
AND s.judge_status = 2
AND s.type = 0
AND s.judge_time between #{vo.timeS} and #{vo.timeE}
) a , (SELECT
count(r.id) "total"
FROM
entrust_sample s
join entrust e on e.id = s.entrust_id
join entrust_report r on r.entrust_id = e.id
WHERE
s.deleted = 0 and e.deleted = 0 and r.deleted = 0
AND s.status = 70 AND s.judge_status = 2 AND s.type = 0
AND s.judge_time between #{vo.lastYearTimeS} and #{vo.lastYearTimeE}
) a,
(SELECT count(r.id) "total"
FROM entrust_sample s
join entrust e on e.id = s.entrust_id
join entrust_report r on r.entrust_id = e.id
WHERE s.deleted = 0
and e.deleted = 0
and r.deleted = 0
AND s.status = 70
AND s.judge_status = 2
AND s.type = 0
AND s.judge_time between #{vo.lastYearTimeS} and #{vo.lastYearTimeE}
) b,
(SELECT
count(r.id) "total"
FROM
entrust_sample s
join entrust e on e.id = s.entrust_id
join entrust_report r on r.entrust_id = e.id
WHERE
s.deleted = 0 and e.deleted = 0 and r.deleted = 0
AND s.status = 70 AND s.judge_status = 2 AND s.type = 0
(SELECT count(r.id) "total"
FROM entrust_sample s
join entrust e on e.id = s.entrust_id
join entrust_report r on r.entrust_id = e.id
WHERE s.deleted = 0
and e.deleted = 0
and r.deleted = 0
AND s.status = 70
AND s.judge_status = 2
AND s.type = 0
AND s.judge_time between #{vo.prevTimeS} and #{vo.prevTimeE}
) c
......@@ -138,56 +138,57 @@
<!--外委检测数量统计-->
<select id="selectOutTestItemQuantity" resultType="com.patzn.cloud.service.hmhj.entity.Statistics">
SELECT
to_char(i.ctime,'yyyy-MM') "occur_date",
count(i.id) "done_num"
to_char(i.ctime,'yyyy-MM') "occur_date",
count(i.id) "done_num"
FROM
entrust_sample_item i
join entrust_sample s on s.id = i.entrust_sample_id
join contract_sample c on c.id = s.contract_sample_id
entrust_sample_item i
join entrust_sample s on s.id = i.entrust_sample_id
join contract_sample c on c.id = s.contract_sample_id
WHERE
i.deleted = 0 and s.deleted = 0 and c.deleted = 0
and c.type = 1 AND s.type = 0
i.deleted = 0 and s.deleted = 0 and c.deleted = 0
and c.type = 1 AND s.type = 0
<if test="null != vo.timeS and null != vo.timeE">
AND i.ctime between #{vo.timeS} and #{vo.timeE}
</if>
GROUP BY
to_char(i.ctime,'yyyy-MM')
to_char(i.ctime,'yyyy-MM')
ORDER BY
to_char(i.ctime,'yyyy-MM') ASC
to_char(i.ctime,'yyyy-MM') ASC
</select>
<!--取样量统计-->
<select id="selectSamplingQuantity" resultType="com.patzn.cloud.service.hmhj.entity.Statistics">
SELECT
a.*,b.total "sames_num",c.total "chain_num",
round((case when 0 = b.total then 0 else a.total - b.total end)::numeric / (case when 0 = b.total then 1 else b.total end),2) "chain_ratio",
round((case when 0 = c.total then 0 else a.total - c.total end)::numeric / (case when 0 = c.total then 1 else c.total end),2) "sames_ratio"
from (SELECT
count(s.id) "total"
FROM
entrust_sample s
join entrust e on e.id = s.entrust_id
WHERE
s.deleted = 0 and e.deleted = 0 AND s.type = 0
SELECT a.*,
b.total "sames_num",
c.total "chain_num",
round((case when 0 = b.total then 0 else a.total - b.total end)::numeric /
(case when 0 = b.total then 1 else b.total end), 2) "chain_ratio",
round((case when 0 = c.total then 0 else a.total - c.total end)::numeric /
(case when 0 = c.total then 1 else c.total end), 2) "sames_ratio"
from (SELECT count(s.id) "total"
FROM entrust_sample s
join entrust e on e.id = s.entrust_id
WHERE s.deleted = 0
and e.deleted = 0
AND s.type = 0
AND e.entrust_time between #{vo.timeS} and #{vo.timeE}
) a ,
(SELECT
count(s.id) "total"
FROM
entrust_sample s
join entrust e on e.id = s.entrust_id
WHERE s.deleted = 0 and e.deleted = 0 AND s.type = 0
AND s.entrust_time between #{vo.lastYearTimeS} and #{vo.lastYearTimeE}
) b,
(SELECT
count(s.id) "total"
FROM
entrust_sample s
join entrust e on e.id = s.entrust_id
WHERE
s.deleted = 0 and e.deleted = 0 AND s.type = 0
AND s.entrust_time between #{vo.prevTimeS} and #{vo.prevTimeE}
) c
) a,
(SELECT count(s.id) "total"
FROM entrust_sample s
join entrust e on e.id = s.entrust_id
WHERE s.deleted = 0
and e.deleted = 0
AND s.type = 0
AND s.entrust_time between #{vo.lastYearTimeS} and #{vo.lastYearTimeE}
) b,
(SELECT count(s.id) "total"
FROM entrust_sample s
join entrust e on e.id = s.entrust_id
WHERE s.deleted = 0
and e.deleted = 0
AND s.type = 0
AND s.entrust_time between #{vo.prevTimeS} and #{vo.prevTimeE}
) c
</select>
<!--检测数量统计-->
......@@ -212,69 +213,317 @@
<!--报告发放量统计A-->
<select id="selectReportSendQuantityMonth" resultType="com.patzn.cloud.service.hmhj.entity.Statistics">
SELECT
to_char(r.report_check_time,'yyyy-MM') "occur_date",
count(r.id) "done_num"
to_char(r.report_check_time,'yyyy-MM') "occur_date",
count(r.id) "done_num"
FROM
entrust e
join entrust_report r on r.entrust_id = e.id
entrust e
join entrust_report r on r.entrust_id = e.id
WHERE
e.deleted = 0 and r.deleted = 0 AND s.type = 0 and r.status = 50
e.deleted = 0 and r.deleted = 0 AND s.type = 0 and r.status = 50
<if test="null != vo.timeS and null != vo.timeE">
AND r.report_check_time between #{vo.timeS} and #{vo.timeE}
</if>
GROUP BY
to_char(r.report_check_time,'yyyy-MM')
to_char(r.report_check_time,'yyyy-MM')
ORDER BY
to_char(r.report_check_time,'yyyy-MM') ASC
to_char(r.report_check_time,'yyyy-MM') ASC
</select>
<!--报告发放量统计B-->
<select id="selectReportSendQuantity" resultType="com.patzn.cloud.service.hmhj.entity.Statistics">
SELECT
a.*,b.total "sames_num",c.total "chain_num",
round((case when 0 = b.total then 0 else a.total - b.total end)::numeric / (case when 0 = b.total then 1 else b.total end),2) "chain_ratio",
round((case when 0 = c.total then 0 else a.total - c.total end)::numeric / (case when 0 = c.total then 1 else c.total end),2) "sames_ratio"
from (SELECT
count(r.id) "total"
FROM
entrust e
join entrust_report r on r.entrust_id = e.id
WHERE
e.deleted = 0 and r.deleted = 0
SELECT a.*,
b.total "sames_num",
c.total "chain_num",
round((case when 0 = b.total then 0 else a.total - b.total end)::numeric /
(case when 0 = b.total then 1 else b.total end), 2) "chain_ratio",
round((case when 0 = c.total then 0 else a.total - c.total end)::numeric /
(case when 0 = c.total then 1 else c.total end), 2) "sames_ratio"
from (SELECT count(r.id) "total"
FROM entrust e
join entrust_report r on r.entrust_id = e.id
WHERE e.deleted = 0
and r.deleted = 0
AND r.report_check_time between #{vo.timeS} and #{vo.timeE}
) a ,
(SELECT
count(r.id) "total"
FROM
entrust e
join entrust_report r on r.entrust_id = e.id
WHERE
e.deleted = 0 and r.deleted = 0
) a,
(SELECT count(r.id) "total"
FROM entrust e
join entrust_report r on r.entrust_id = e.id
WHERE e.deleted = 0
and r.deleted = 0
AND r.report_check_time between #{vo.lastYearTimeS} and #{vo.lastYearTimeE}
) b,
(SELECT
count(r.id) "total"
FROM
entrust e
join entrust_report r on r.entrust_id = e.id
WHERE
e.deleted = 0 and r.deleted = 0
(SELECT count(r.id) "total"
FROM entrust e
join entrust_report r on r.entrust_id = e.id
WHERE e.deleted = 0
and r.deleted = 0
AND r.report_check_time between #{vo.prevTimeS} and #{vo.prevTimeE}
) c
</select>
<!--化验委托量统计-->
<select id="selectEntrustedQuantity" resultType="com.patzn.cloud.service.hmhj.entity.Statistics">
SELECT S.NAME "brand",
COUNT(DISTINCT e.ID) "total",
COUNT(DISTINCT (CASE WHEN s.status = 70 THEN e.ID ELSE NULL END)) "done_num"
FROM ENTRUST E
JOIN ENTRUST_SAMPLE S ON S.entrust_id = E.ID
WHERE E.deleted = 0
AND S.deleted = 0
AND s.type = 0
AND S.NAME IN ('电解质', '硅铁', '磷铁', '锰铁', '水', '纯铝', '铝合金', '石灰石')
GROUP BY s.NAME
ORDER BY S.NAME
</select>
<sql id="query_date">
SELECT
to_char( tt.DAY, 'yyyy-mm-dd' ) AS DAY
FROM
(
SELECT
generate_series (
CAST ('${vo.yearMonth}-01' AS DATE ),
CAST ( CAST ('${vo.yearMonth}-01' AS TIMESTAMP ) + '1 MONTH' + '-1 d' AS DATE ),
'1 d'
) AS DAY
) AS tt
ORDER BY
DAY
</sql>
<!--原铝品味台账查询-->
<select id="selectAlGradeLedger" resultType="com.patzn.cloud.service.hmhj.vo.DailyStatsLedgerVO">
SELECT
s.slot_no "label",
i.test_time "day",
s.sample_grading "value"
FROM
entrust_sample s
JOIN electrolyzer e on e.id = s.electrolyzer_id
JOIN (
SELECT
i.entrust_sample_id,
to_char( MAX ( i.test_time ), 'yyyy-mm-dd' ) "test_time"
FROM
entrust_sample_item i
WHERE
i.deleted = 0
GROUP BY
i.entrust_sample_id
) i ON i.entrust_sample_id = s.ID
WHERE
s.deleted = 0 and e.deleted = 0
AND s.NAME = '原铝'
AND s.sample_grading IS NOT NULL
AND i.test_time LIKE '${vo.yearMonth}%'
<if test="null != vo.branch">
AND e.branch = #{vo.branch}
</if>
<if test="null != vo.partition">
and e.partition = #{vo.partition}
</if>
ORDER BY
s.slot_no, i.test_time
</select>
<!-- 原铝品味台账统计 -->
<select id="selectAlGradeLedgerStats" resultType="com.patzn.cloud.service.hmhj.vo.DailyStatsLedgerVO">
SELECT
s.sample_grading "label",
i.test_time "day",
count(1) "value"
FROM
entrust_sample s
JOIN electrolyzer e on e.id = s.electrolyzer_id
JOIN (
SELECT
i.entrust_sample_id,
to_char( MAX ( i.test_time ), 'yyyy-mm-dd' ) "test_time"
FROM
entrust_sample_item i
WHERE
i.deleted = 0
GROUP BY
i.entrust_sample_id
) i ON i.entrust_sample_id = s.ID
WHERE
s.deleted = 0 and e.deleted = 0
AND s.NAME = '原铝'
AND s.sample_grading IS NOT NULL
AND i.test_time LIKE '${vo.yearMonth}%'
<if test="null != vo.branch">
AND e.branch = #{vo.branch}
</if>
<if test="null != vo.partition">
and e.partition = #{vo.partition}
</if>
GROUP BY s.sample_grading,i.test_time
ORDER BY
s.sample_grading desc, i.test_time
</select>
<!-- 原铝杂质含量台账 -->
<select id="selectAlImpurityLedger" resultType="com.patzn.cloud.service.hmhj.vo.DailyStatsLedgerVO">
SELECT
s.slot_no "label",
i.test_time "day",
i.value
FROM
entrust_sample s
JOIN electrolyzer e on e.id = s.electrolyzer_id
JOIN (
SELECT
i.entrust_sample_id,
to_char( MAX ( i.test_time ), 'yyyy-mm-dd' ) "test_time",
sum(ii.zz_value) "value"
FROM
entrust_sample_item i
join (
select
ii.entrust_sample_item_id,
sum(cast(ii.test_value as numeric)) "zz_value"
from entrust_sample_item_index ii
where ii.deleted = 0 and is_numeric(ii.test_value)
<if test="null != vo.impurity">
and ii.name like concat('%',#{vo.impurity},'%')
</if>
group by ii.entrust_sample_item_id
) ii on ii.entrust_sample_item_id = i.id
WHERE
i.deleted = 0
GROUP BY
i.entrust_sample_id
) i ON i.entrust_sample_id = s.ID
WHERE
s.deleted = 0 and e.deleted = 0
AND s.NAME = '原铝'
AND s.sample_grading IS NOT NULL
AND i.test_time LIKE '${vo.yearMonth}%'
<if test="null != vo.branch">
AND e.branch = #{vo.branch}
</if>
<if test="null != vo.partition">
and e.partition = #{vo.partition}
</if>
ORDER BY
s.slot_no, i.test_time
</select>
<!--原铝含铁量台账统计 -->
<select id="selectAlFeLedgerStats" resultType="com.patzn.cloud.service.hmhj.vo.DailyStatsLedgerVO">
SELECT
S.NAME "brand",
COUNT ( DISTINCT e.ID ) "total",
COUNT ( DISTINCT ( CASE WHEN s.status = 70 THEN e.ID ELSE NULL END ) ) "done_num"
"unnest" ( Array[0,1,2,3,4,5,6] ) "sn",
"unnest" ( string_to_array( 'Fe≤0.100台次,Fe≤0.095台次,Fe≤0.090台次,Fe≤0.080台次,99.70以上槽台数,低铁铝台次,低镍铝台次', ',' ) ) "label",
T.test_time "day",
"unnest" (Array[t.fe_01,t.fe_0095,t.fe_0090,t.fe_0080,t.over_70,t.low_fe,t.low_ni]) "value"
FROM
ENTRUST E
JOIN ENTRUST_SAMPLE S ON S.entrust_id = E.ID
(
SELECT
I.test_time,
SUM ( i.fe_01 ) "fe_01",
SUM ( i.fe_0095 ) "fe_0095",
SUM ( i.fe_0090 ) "fe_0090",
SUM ( i.fe_0080 ) "fe_0080",
SUM ( CASE WHEN s.sample_grading IN ( 'Al99.85', 'Al99.70DT', 'Al99.80', 'Al99.70' ) THEN 1 ELSE 0 END ) "over_70",
SUM ( CASE WHEN s.sample_grading IN ( 'Al99.85', 'Al99.70DT', 'Al99.80', 'Al99.70' ) AND i.fe_01 > 0 THEN 1 ELSE 0 END ) "low_fe",
SUM ( CASE WHEN s.sample_grading IN ( 'Al99.85', 'Al99.70DT', 'Al99.80', 'Al99.70' ) AND i.ni_00042 > 0 THEN 1 ELSE 0 END ) "low_ni"
FROM
entrust_sample s
JOIN electrolyzer e ON e.ID = s.electrolyzer_id
JOIN (
SELECT
i.entrust_sample_id,
to_char( MAX ( i.test_time ), 'yyyy-mm-dd' ) "test_time",
SUM ( CASE WHEN ii.NAME = '原铝Fe' AND CAST ( ii.test_value AS NUMERIC ) &lt;= 0.1 THEN 1 ELSE 0 END ) "fe_01",
SUM ( CASE WHEN ii.NAME = '原铝Fe' AND CAST ( ii.test_value AS NUMERIC ) &lt;= 0.095 THEN 1 ELSE 0 END ) "fe_0095",
SUM ( CASE WHEN ii.NAME = '原铝Fe' AND CAST ( ii.test_value AS NUMERIC ) &lt;= 0.090 THEN 1 ELSE 0 END ) "fe_0090",
SUM ( CASE WHEN ii.NAME = '原铝Fe' AND CAST ( ii.test_value AS NUMERIC ) &lt;= 0.080 THEN 1 ELSE 0 END ) "fe_0080",
SUM ( CASE WHEN ii.NAME = '原铝Ni' AND CAST ( ii.test_value AS NUMERIC ) &lt;= 0.0042 THEN 1 ELSE 0 END) "ni_00042"
FROM
entrust_sample_item i
JOIN entrust_sample_item_index ii ON ii.entrust_sample_item_id = i.ID
WHERE
i.deleted = 0
AND ii.deleted = 0
AND i.NAME IN ( '原铝Fe', '原铝Ni')
AND ii.test_value is not null
AND is_numeric ( ii.test_value )
GROUP BY
i.entrust_sample_id
) i ON i.entrust_sample_id = s.ID
WHERE
E.deleted = 0 AND S.deleted = 0 AND s.type = 0
AND S.NAME IN ( '电解质', '硅铁', '磷铁', '锰铁', '水', '纯铝', '铝合金', '石灰石' )
s.deleted = 0
AND e.deleted = 0
AND s.NAME = '原铝'
AND s.sample_grading IS NOT NULL
AND i.test_time LIKE '${vo.yearMonth}%'
<if test="null != vo.branch">
AND e.branch = #{vo.branch}
</if>
<if test="null != vo.partition">
and e.partition = #{vo.partition}
</if>
GROUP BY
s.NAME ORDER BY S.NAME
I.test_time
) T order by sn , day
</select>
<!--原铝杂质含量台账统计 -->
<select id="selectAlImpurityLedgerStats" resultType="com.patzn.cloud.service.hmhj.vo.DailyStatsLedgerVO">
SELECT
t.name,
"unnest"(Array[ 0,1,2,3 ]) "sn",
"unnest"(Array[ '平均值','最大值', '最小值', '差值'] ) "label",
t.test_time "day",
"unnest"(Array[t.avg_val,t.max_val,t.min_val,t.dif_val]) "value"
FROM
(
SELECT
i."name",
to_char( i.test_time, 'yyyy-mm-dd' ) "test_time",
MAX ( CAST ( ii.test_value AS NUMERIC ) ) "max_val",
MIN ( CAST ( ii.test_value AS NUMERIC ) ) "min_val",
round( AVG ( CAST ( ii.test_value AS NUMERIC ) ), 5 ) "avg_val",
MAX ( CAST ( ii.test_value AS NUMERIC ) ) - MIN ( CAST ( ii.test_value AS NUMERIC ) ) "dif_val"
FROM
entrust_sample_item i
JOIN entrust_sample_item_index ii ON ii.entrust_sample_item_id = i.ID
AND ii.NAME = i.NAME
WHERE
i.deleted = 0
AND ii.deleted = 0
AND i.NAME = ii.NAME
AND I.NAME LIKE'%原铝%'
AND to_char( i.test_time, 'yyyy-mm-dd' ) like '${vo.yearMonth}%'
AND is_numeric ( ii.test_value )
<if test="null != vo.branch or null != vo.partition">
AND EXISTS (
SELECT
1
FROM entrust_sample s
join electrolyzer e ON e.ID = s.electrolyzer_id
WHERE s.deleted = 0 and e.deleted = 0 and s.id = i.entrust_sample_id
<if test="null != vo.branch">
AND e.branch = #{vo.branch}
</if>
<if test="null != vo.partition">
AND e.partition = #{vo.partition}
</if>
)
</if>
GROUP BY
i.NAME,
to_char( i.test_time, 'yyyy-mm-dd' )
ORDER BY
i.NAME,
to_char( i.test_time, 'yyyy-mm-dd' )
) T order by t.name, sn, label, day
</select>
</mapper>
package com.patzn.cloud.service.lims.test;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import com.patzn.cloud.service.lims.common.DateKit;
import java.io.File;
import java.io.IOException;
import java.util.List;
public class Test {
public static void main(String[] args) {
File file = new File("D:\\pxj\\生铁中硅.xlsx");
try {
XSSFWorkbook xssfWorkbook = new XSSFWorkbook(file);
XSSFSheet sheet= xssfWorkbook.getSheetAt(0);
String sheetName= sheet.getSheetName();
System.out.println(sheetName);
} catch (IOException e) {
e.printStackTrace();
} catch (InvalidFormatException e) {
e.printStackTrace();
}
List<String> dateList = DateKit.dateInMonth("2021-09");
dateList.stream().forEach(System.out::print);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment