空货位盘点

nanjing-yancao-wuliuzhongxin
yiming 3 years ago
parent 023e836423
commit b1f871a74b

@ -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<CheckStreetSummary> excels = emptyCheckService.checkStreetSummaries(taskId);
EasyExcel.write(os, CheckStreetSummary.class).sheet().doWrite(excels);
}
@PostMapping("/statusByRowColumn")
@ApiOperation(value = "行列的空货位状态")
public Result<CheckStatus>checkStatus(@Validated @RequestBody RowColumnStatus rowColumnStatus){
return Result.success(emptyCheckService.emptyStatusByRowColumn(rowColumnStatus));
}
}

@ -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;
}

@ -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<Stock> stocks;
private List<EmptyCheck> emptyStatus;
private Integer columnStart;
private Integer columnEnd;

@ -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());
List<EmptyCheck>stockList = new ArrayList<>();
//默认全部盘点正确
Map<String,Integer> rowTabStatus = new LinkedHashMap<>();
int columns = 0;
int rows = 0;
for(String rowTab: rowColumnStatus.getRowTabs()){
rows = getMax(rowTab,rows);
rowTabStatus.put(rowTab,0);
}
Map<String,Integer> columnTabStatus = new LinkedHashMap<>();
for(String column:rowColumnStatus.getColumnTabs()){
columns = getMax(column,columns);
columnTabStatus.put(column,0);
}
Map<String,Integer> columnTabCorrectCount = new LinkedHashMap<>();
Map<String,Integer> rowTabCorrectCount = new LinkedHashMap<>();
List<EmptyCheck> stocks = emptyCheckMapper.selectList(new QueryWrapper<EmptyCheck>().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<String,Integer> 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<String,Integer> 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<EmptyCheck> stockInit(Integer rowStart, Integer rowEnd,Integer columnStart,Integer columnEnd,String shelveId,List<EmptyCheck> readyList){
Map<Integer,Map<Integer,Boolean>> map = new HashMap<>();
readyList.forEach(stock -> {
if(map.get(stock.getRow()) == null){
Map<Integer,Boolean> columnMap = new HashMap<>();
columnMap.put(stock.getColumn(),true);
map.put(stock.getRow(),columnMap);
}else {
Map<Integer,Boolean> 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<Integer,Boolean> 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<String,Integer> 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;
}
}

@ -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);

Loading…
Cancel
Save