From b1f871a74b80bfaec6991d8e6854408c1c9164e9 Mon Sep 17 00:00:00 2001 From: yiming Date: Fri, 4 Nov 2022 16:40:00 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A9=BA=E8=B4=A7=E4=BD=8D=E7=9B=98=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/EmptyCheckController.java | 31 +++ .../web/entity/CheckStreetSummary.java | 14 ++ .../zhehekeji/web/pojo/stock/CheckStatus.java | 3 + .../web/service/EmptyCheckService.java | 178 +++++++++++++++++- .../zhehekeji/web/service/TestService.java | 3 - 5 files changed, 221 insertions(+), 8 deletions(-) diff --git a/web/src/main/java/com/zhehekeji/web/controller/EmptyCheckController.java b/web/src/main/java/com/zhehekeji/web/controller/EmptyCheckController.java index 15e4182..6f2a1cb 100644 --- a/web/src/main/java/com/zhehekeji/web/controller/EmptyCheckController.java +++ b/web/src/main/java/com/zhehekeji/web/controller/EmptyCheckController.java @@ -1,16 +1,29 @@ package com.zhehekeji.web.controller; +import com.alibaba.excel.EasyExcel; import com.github.pagehelper.PageInfo; import com.zhehekeji.core.pojo.Result; import com.zhehekeji.web.entity.CheckStreetSummary; import com.zhehekeji.web.entity.CheckSummary; import com.zhehekeji.web.pojo.empty.EmptyCheckSearch; +import com.zhehekeji.web.pojo.stock.CheckStatus; +import com.zhehekeji.web.pojo.stock.RowColumnStatus; +import com.zhehekeji.web.pojo.stock.StockExportExcel; import com.zhehekeji.web.service.EmptyCheckService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.springframework.core.io.ClassPathResource; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URLEncoder; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.List; @Api(tags = "盘点统计") @@ -33,4 +46,22 @@ public class EmptyCheckController { return Result.success(emptyCheckService.checkStreetSummaries(taskId)); } + @ApiOperation(value = "导出巷道excel") + @RequestMapping(value = "/export", method = RequestMethod.GET) + public void export(@RequestParam String taskId, HttpServletResponse response) throws IOException { + OutputStream os = response.getOutputStream(); + response.setContentType("application/vnd.ms-excel"); + response.setCharacterEncoding("utf-8"); + String fileName = URLEncoder.encode("盘点统计-"+taskId, "UTF-8"); + response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); + List excels = emptyCheckService.checkStreetSummaries(taskId); + EasyExcel.write(os, CheckStreetSummary.class).sheet().doWrite(excels); + } + + @PostMapping("/statusByRowColumn") + @ApiOperation(value = "行列的空货位状态") + public ResultcheckStatus(@Validated @RequestBody RowColumnStatus rowColumnStatus){ + return Result.success(emptyCheckService.emptyStatusByRowColumn(rowColumnStatus)); + } + } diff --git a/web/src/main/java/com/zhehekeji/web/entity/CheckStreetSummary.java b/web/src/main/java/com/zhehekeji/web/entity/CheckStreetSummary.java index 8354c5b..429e7cb 100644 --- a/web/src/main/java/com/zhehekeji/web/entity/CheckStreetSummary.java +++ b/web/src/main/java/com/zhehekeji/web/entity/CheckStreetSummary.java @@ -1,14 +1,19 @@ package com.zhehekeji.web.entity; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ColumnWidth; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.fasterxml.jackson.annotation.JsonFormat; +import com.zhehekeji.web.pojo.stock.LocalDateTimeConvert; import lombok.Data; import java.time.LocalDateTime; @Data +@ExcelIgnoreUnannotated public class CheckStreetSummary { @TableId(type = IdType.AUTO) @@ -17,8 +22,10 @@ public class CheckStreetSummary { private Integer streetId; @TableField(exist = false) + @ExcelProperty(index = 0, value = "巷道名称") private String streetName; + @ExcelProperty(index = 1, value = "盘点任务号") private String taskId; private Integer type; @@ -26,21 +33,28 @@ public class CheckStreetSummary { /** * 空货位的数量 */ + @ExcelProperty(index = 2, value = "无托盘数量") private Integer emptyCount; /** * 空托盘的数量(只有托盘没有货物) */ + @ExcelProperty(index = 3, value = "空托盘数量") private Integer emptyGoodsCount; /** * 有货物的数量 */ + @ExcelProperty(index = 4, value = "有货物数量") private Integer goodsCount; @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ColumnWidth(20) + @ExcelProperty(index = 5, value = "开始时间",converter = LocalDateTimeConvert.class) private LocalDateTime startTime; @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ColumnWidth(20) + @ExcelProperty(index = 6,value = "结束时间",converter = LocalDateTimeConvert.class) private LocalDateTime endTime; } diff --git a/web/src/main/java/com/zhehekeji/web/pojo/stock/CheckStatus.java b/web/src/main/java/com/zhehekeji/web/pojo/stock/CheckStatus.java index c5f1266..323baba 100644 --- a/web/src/main/java/com/zhehekeji/web/pojo/stock/CheckStatus.java +++ b/web/src/main/java/com/zhehekeji/web/pojo/stock/CheckStatus.java @@ -1,5 +1,6 @@ package com.zhehekeji.web.pojo.stock; +import com.zhehekeji.web.entity.EmptyCheck; import com.zhehekeji.web.entity.Stock; import lombok.Data; @@ -11,6 +12,8 @@ public class CheckStatus { private List stocks; + private List emptyStatus; + private Integer columnStart; private Integer columnEnd; diff --git a/web/src/main/java/com/zhehekeji/web/service/EmptyCheckService.java b/web/src/main/java/com/zhehekeji/web/service/EmptyCheckService.java index 402733f..846f87a 100644 --- a/web/src/main/java/com/zhehekeji/web/service/EmptyCheckService.java +++ b/web/src/main/java/com/zhehekeji/web/service/EmptyCheckService.java @@ -10,16 +10,17 @@ import com.zhehekeji.web.mapper.CheckSummaryMapper; import com.zhehekeji.web.mapper.EmptyCheckMapper; import com.zhehekeji.web.mapper.StockMapper; import com.zhehekeji.web.pojo.empty.EmptyCheckSearch; +import com.zhehekeji.web.pojo.stock.CheckStatus; +import com.zhehekeji.web.pojo.stock.RowColumnStatus; import com.zhehekeji.web.service.client.ECTransmission; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import javax.annotation.Resource; import java.time.LocalDateTime; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; @Service @@ -173,15 +174,182 @@ public class EmptyCheckService { emptyCheck.setStreetId(street.getId()); emptyCheck.setSide(ecTransmission.getSide()); emptyCheck.setDirection(ecTransmission.getDirection()); + //0:未知 1:空 2:非空 if(ecTransmission.getIsEmpty().equals("N")){ - emptyCheck.setEmptyStatus(3); - }else { emptyCheck.setEmptyStatus(1); + }else { + emptyCheck.setEmptyStatus(2); } emptyCheck.setRow(ecTransmission.getRow()); emptyCheck.setColumn(ecTransmission.getColumn()); emptyCheckMapper.insert(emptyCheck); } + public CheckStatus emptyStatusByRowColumn(RowColumnStatus rowColumnStatus){ + CheckStatus checkStatus = new CheckStatus(); + checkStatus.setColumnStart(rowColumnStatus.getColumnStart()); + checkStatus.setColumnEnd(rowColumnStatus.getColumnEnd()); + checkStatus.setRowStart(rowColumnStatus.getRowStart()); + checkStatus.setRowEnd(rowColumnStatus.getRowEnd()); + //checkStatus.setShelveId(rowColumnStatus.getShelveId()); + + + ListstockList = new ArrayList<>(); + //默认全部盘点正确 + Map rowTabStatus = new LinkedHashMap<>(); + int columns = 0; + int rows = 0; + for(String rowTab: rowColumnStatus.getRowTabs()){ + rows = getMax(rowTab,rows); + rowTabStatus.put(rowTab,0); + } + Map columnTabStatus = new LinkedHashMap<>(); + for(String column:rowColumnStatus.getColumnTabs()){ + columns = getMax(column,columns); + columnTabStatus.put(column,0); + } + Map columnTabCorrectCount = new LinkedHashMap<>(); + Map rowTabCorrectCount = new LinkedHashMap<>(); + List stocks = emptyCheckMapper.selectList(new QueryWrapper().select("empty_status","`row`","`column`").eq("`street_id`",rowColumnStatus.getStreetId()).eq("direction",rowColumnStatus.getDirection()).eq("side",rowColumnStatus.getSide())); + if(CollectionUtils.isEmpty(stocks)){ + stockInit(rowColumnStatus.getRowStart(), rowColumnStatus.getRowEnd(), rowColumnStatus.getColumnStart(), rowColumnStatus.getColumnEnd(), null,stocks); + checkStatus.setEmptyStatus(stocks); + checkStatus.setRowTabStatus(rowTabStatus); + checkStatus.setColumnTabStatus(columnTabStatus); + return checkStatus; + } + for(EmptyCheck emptyCheck: stocks){ + if(emptyCheck.getEmptyStatus() == null){ + continue; + } + if(emptyCheck.getColumn()>= rowColumnStatus.getColumnStart() && emptyCheck.getColumn()<= rowColumnStatus.getColumnEnd() && emptyCheck.getRow() >= rowColumnStatus.getRowStart() && emptyCheck.getRow()<= rowColumnStatus.getRowEnd()){ + stockList.add(emptyCheck); + } + if(!CollectionUtils.isEmpty(rowColumnStatus.getRowTabs())){ + for(String rowTab: rowColumnStatus.getRowTabs()){ + if(isRowColumnInTab(emptyCheck,rowTab,true)){ + tabStatus(emptyCheck,rowTabStatus,rowTab); + +// if(emptyCheck.getEmptyStatus() != 0 && emptyCheck.getEmptyStatus() != 1){ +// if(rowTabCorrectCount.get(rowTab) == null){ +// rowTabCorrectCount.put(rowTab,1); +// }else { +// int c = rowTabCorrectCount.get(rowTab); +// rowTabCorrectCount.put(rowTab,c+1); +// } +// } + } + } + } + if(!CollectionUtils.isEmpty(rowColumnStatus.getColumnTabs())){ + for(String columnTab: rowColumnStatus.getColumnTabs()){ + if(isRowColumnInTab(emptyCheck,columnTab,false)){ + tabStatus(emptyCheck,columnTabStatus,columnTab); +// if(emptyCheck.getEmptyStatus() != 0 && emptyCheck.getEmptyStatus() != 1){ +// if(columnTabCorrectCount.get(columnTab) == null){ +// columnTabCorrectCount.put(columnTab,1); +// }else { +// int c = columnTabCorrectCount.get(columnTab); +// columnTabCorrectCount.put(columnTab,c+1); +// } +// } + } + } + } + } + +// for(Map.Entry entry: rowTabCorrectCount.entrySet()){ +// String [] strings = entry.getKey().split(" - "); +// Integer tabStart = Integer.valueOf(strings[0]); +// Integer tabEnd = Integer.valueOf(strings[1]); +// int counts = (tabEnd- tabStart + 1) * rows; +// if(counts == entry.getValue()){ +// rowTabStatus.put(entry.getKey(),2); +// } +// } +// for(Map.Entry entry: columnTabCorrectCount.entrySet()){ +// String [] strings = entry.getKey().split(" - "); +// Integer tabStart = Integer.valueOf(strings[0]); +// Integer tabEnd = Integer.valueOf(strings[1]); +// int counts = (tabEnd- tabStart + 1) * rows; +// if(counts == entry.getValue()){ +// columnTabStatus.put(entry.getKey(),2); +// } +// } + + checkStatus.setColumnTabStatus(columnTabStatus); + checkStatus.setRowTabStatus(rowTabStatus); + checkStatus.setEmptyStatus(stockInit(rowColumnStatus.getRowStart(), rowColumnStatus.getRowEnd(), rowColumnStatus.getColumnStart(), rowColumnStatus.getColumnEnd(), null,stockList)); + return checkStatus; + } + + private List stockInit(Integer rowStart, Integer rowEnd,Integer columnStart,Integer columnEnd,String shelveId,List readyList){ + Map> map = new HashMap<>(); + readyList.forEach(stock -> { + if(map.get(stock.getRow()) == null){ + Map columnMap = new HashMap<>(); + columnMap.put(stock.getColumn(),true); + map.put(stock.getRow(),columnMap); + }else { + Map columnMap = map.get(stock.getRow()); + if(columnMap.get(stock.getColumn()) == null){ + columnMap.put(stock.getColumn(),true); + } + map.put(stock.getRow(),columnMap); + } + + }); + for(int i = rowStart;i<=rowEnd;i++){ + Map columnMap = map.get(i); + for(int j = columnStart;j<=columnEnd;j++){ + if(columnMap == null || columnMap.get(j) == null){ + EmptyCheck emptyCheck = new EmptyCheck(); + emptyCheck.setColumn(j); + emptyCheck.setRow(i); + emptyCheck.setEmptyStatus(0); + //stock.setShelveId(shelveId); + readyList.add(emptyCheck); + } + } + } + return readyList; + + } + + //0:未知 1:空 2:非空 + //未知 > 空 > 非空 + private void tabStatus(EmptyCheck stock,Map tabStatus,String tab){ + if(tabStatus.get(tab) == null){ + tabStatus.put(tab,stock.getEmptyStatus()); + }else { + Integer status = tabStatus.get(tab); + if(stock.getEmptyStatus() == 0){ + //未知为最优先状态 + tabStatus.put(tab,0); + }else if(stock.getEmptyStatus() == 1 && status != 0) { + tabStatus.put(tab, 1); + } + } + } + + private Boolean isRowColumnInTab(EmptyCheck stock,String tab,Boolean isRow){ + String [] strings = tab.split(" - "); + Integer tabStart = Integer.valueOf(strings[0]); + Integer tabEnd = Integer.valueOf(strings[1]); + if(isRow){ + return stock.getRow() >= tabStart && stock.getRow() <= tabEnd; + }else { + return stock.getColumn() >= tabStart && stock.getColumn() <= tabEnd; + } + } + + public Integer getMax(String tab,Integer max){ + String [] strings = tab.split(" - "); + Integer tabStart = Integer.valueOf(strings[0]); + Integer tabEnd = Integer.valueOf(strings[1]); + int a = tabStart > tabEnd ? tabStart : tabEnd; + a = max > a ? max : a; + return a; + } } diff --git a/web/src/main/java/com/zhehekeji/web/service/TestService.java b/web/src/main/java/com/zhehekeji/web/service/TestService.java index b6cadc3..ca9ad33 100644 --- a/web/src/main/java/com/zhehekeji/web/service/TestService.java +++ b/web/src/main/java/com/zhehekeji/web/service/TestService.java @@ -19,9 +19,6 @@ public class TestService { private static Boolean isRunning = Boolean.FALSE; - - - public void CheckTest(String plcId,Integer leftRight){ Street street = streetService.getStreetByPlcId(plcId);