|
|
|
@ -1,27 +1,29 @@
|
|
|
|
package com.zhehekeji.web.service;
|
|
|
|
package com.zhehekeji.web.service;
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
import com.zhehekeji.core.util.Assert;
|
|
|
|
import com.zhehekeji.core.util.Assert;
|
|
|
|
import com.zhehekeji.web.entity.Stock;
|
|
|
|
import com.zhehekeji.web.entity.Stock;
|
|
|
|
import com.zhehekeji.web.entity.StockLog;
|
|
|
|
import com.zhehekeji.web.entity.StockLog;
|
|
|
|
import com.zhehekeji.web.entity.Street;
|
|
|
|
import com.zhehekeji.web.entity.Street;
|
|
|
|
import com.zhehekeji.web.mapper.StockLogMapper;
|
|
|
|
import com.zhehekeji.web.mapper.StockLogMapper;
|
|
|
|
import com.zhehekeji.web.mapper.StockMapper;
|
|
|
|
import com.zhehekeji.web.mapper.StockMapper;
|
|
|
|
import com.zhehekeji.web.pojo.stock.StockCheck;
|
|
|
|
import com.zhehekeji.web.pojo.category.PageSearch;
|
|
|
|
import com.zhehekeji.web.pojo.stock.StockExcel;
|
|
|
|
import com.zhehekeji.web.pojo.stock.*;
|
|
|
|
import com.zhehekeji.web.pojo.stock.StockExportExcel;
|
|
|
|
|
|
|
|
import com.zhehekeji.web.pojo.stock.StockStatus;
|
|
|
|
|
|
|
|
import com.zhehekeji.web.pojo.street.StreetType;
|
|
|
|
import com.zhehekeji.web.pojo.street.StreetType;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
@ -36,7 +38,7 @@ public class StockService {
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private StockLogMapper logMapper;
|
|
|
|
private StockLogMapper logMapper;
|
|
|
|
|
|
|
|
|
|
|
|
public void importExcel(MultipartFile file){
|
|
|
|
public void importExcel(MultipartFile file) {
|
|
|
|
log.info("import excel stock");
|
|
|
|
log.info("import excel stock");
|
|
|
|
Thread thread = new Thread(
|
|
|
|
Thread thread = new Thread(
|
|
|
|
new Runnable() {
|
|
|
|
new Runnable() {
|
|
|
|
@ -45,7 +47,7 @@ public class StockService {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
EasyExcel.read(file.getInputStream(), StockExcel.class, new StockImport(stockMapper)).sheet().doRead();
|
|
|
|
EasyExcel.read(file.getInputStream(), StockExcel.class, new StockImport(stockMapper)).sheet().doRead();
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
log.error("库存导入error:{}",e);
|
|
|
|
log.error("库存导入error:{}", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -55,28 +57,36 @@ public class StockService {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 根据巷道获取所有的格子
|
|
|
|
* 根据巷道获取所有的格子
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param streetId
|
|
|
|
* @param streetId
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public Map<String,List<Stock>> stocksByStreetId(Integer streetId){
|
|
|
|
public Map<String, List<Stock>> stocksByStreetId(Integer streetId) {
|
|
|
|
List<Stock> stocks = list(streetId);
|
|
|
|
List<Stock> stocks = list(streetId);
|
|
|
|
Map<String,List<Stock>> shelveMap = stocks.stream().collect(Collectors.groupingBy(Stock::getShelveId));
|
|
|
|
Map<String, List<Stock>> shelveMap = stocks.stream().collect(Collectors.groupingBy(Stock::getShelveId));
|
|
|
|
return shelveMap;
|
|
|
|
return shelveMap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<Stock> list(Integer streetId){
|
|
|
|
public List<Stock> list(Integer streetId) {
|
|
|
|
Street street = streetService.streetById(streetId);
|
|
|
|
Street street = streetService.streetById(streetId);
|
|
|
|
List<String> shelves = streetService.check(street);
|
|
|
|
List<String> shelves = streetService.check(street);
|
|
|
|
List<Stock> stocks = stockMapper.selectList(new QueryWrapper<Stock>().in("shelve_id",shelves).orderByAsc("shelve_id","`row`","`column`"));
|
|
|
|
List<Stock> stocks = stockMapper.selectList(new QueryWrapper<Stock>().in("shelve_id", shelves).orderByAsc("shelve_id", "`row`", "`column`"));
|
|
|
|
|
|
|
|
return stocks;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<Stock> page(PageSearch pageSearch) {
|
|
|
|
|
|
|
|
PageHelper.startPage(pageSearch.getPageNum(), pageSearch.getPageSize());
|
|
|
|
|
|
|
|
List<Stock> stocks = stockMapper.selectList(new QueryWrapper<Stock>().orderByAsc("shelve_id", "`row`", "`column`"));
|
|
|
|
return stocks;
|
|
|
|
return stocks;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 导出巷道格子信息
|
|
|
|
* 导出巷道格子信息
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param streetId
|
|
|
|
* @param streetId
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public List<StockExportExcel> exportExcels(Integer streetId){
|
|
|
|
public List<StockExportExcel> exportExcels(Integer streetId) {
|
|
|
|
List<Stock> stocks = list(streetId);
|
|
|
|
List<Stock> stocks = list(streetId);
|
|
|
|
Street street = streetService.streetById(streetId);
|
|
|
|
Street street = streetService.streetById(streetId);
|
|
|
|
List<StockExportExcel> stockExportExcels = new ArrayList<>(stocks.size());
|
|
|
|
List<StockExportExcel> stockExportExcels = new ArrayList<>(stocks.size());
|
|
|
|
@ -97,34 +107,83 @@ public class StockService {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 获取行列号,货架号对应的格子信息
|
|
|
|
* 获取行列号,货架号对应的格子信息
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param stockCheck
|
|
|
|
* @param stockCheck
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public Stock stockInfo(StockCheck stockCheck){
|
|
|
|
public Stock stockInfo(StockCheck stockCheck) {
|
|
|
|
Stock stock = stockMapper.getByShelveIdAndRowColumn(stockCheck.getShelveId(),stockCheck.getRow(),stockCheck.getColumn());
|
|
|
|
Stock stock = stockMapper.getByShelveIdAndRowColumn(stockCheck.getShelveId(), stockCheck.getRow(), stockCheck.getColumn());
|
|
|
|
return stock;
|
|
|
|
return stock;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 核对单子
|
|
|
|
* 核对单子
|
|
|
|
* 核对正确、核对错误
|
|
|
|
* 核对正确
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param stockCheck
|
|
|
|
* @param stockCheck
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void check(StockCheck stockCheck){
|
|
|
|
public Stock checkCorrect(StockCheck stockCheck) {
|
|
|
|
log.debug("check stock shelveID:{},row:{},column:{},status:{}",stockCheck.getShelveId(),stockCheck.getRow(),stockCheck.getColumn(),stockCheck.getStatus());
|
|
|
|
log.debug("check stock correct, shelveID:{},row:{},column:{}", stockCheck.getShelveId(), stockCheck.getRow(), stockCheck.getColumn());
|
|
|
|
Stock stock = stockInfo(stockCheck);
|
|
|
|
Stock stock = stockInfo(stockCheck);
|
|
|
|
Assert.notNull(stock,"库存不存在");
|
|
|
|
Assert.notNull(stock, "该货位暂时没有记录");
|
|
|
|
Integer oldStatus = stock.getStatus();
|
|
|
|
Integer oldStatus = stock.getStatus();
|
|
|
|
stock.setStatus(stockCheck.getStatus());
|
|
|
|
stock.setStatus(StockStatus.SUCCESS.getStatus());
|
|
|
|
stockMapper.updateById(stock);
|
|
|
|
stockMapper.updateById(stock);
|
|
|
|
checkLog(stock,oldStatus);
|
|
|
|
checkLog(stock, oldStatus, null, null);
|
|
|
|
|
|
|
|
return stock;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void checkLog(Stock stock,Integer oldStatus){
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 人工核对
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param checkByMan
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public Stock checkByMan(CheckByMan checkByMan) {
|
|
|
|
|
|
|
|
Stock stock = stockMapper.getByShelveIdAndRowColumn(checkByMan.getShelveId(), checkByMan.getRow(), checkByMan.getColumn());
|
|
|
|
|
|
|
|
Assert.notNull(stock, "该货位暂时没有记录");
|
|
|
|
|
|
|
|
Boolean same = checkByMan.getCategory().equals(stock.getCategory()) && checkByMan.getCount().equals(stock.getCount());
|
|
|
|
|
|
|
|
Assert.isTrue(!same, "品规和数量与原有记录相同");
|
|
|
|
|
|
|
|
Integer oldStatus = stock.getStatus();
|
|
|
|
|
|
|
|
String oldCategory = stock.getCategory();
|
|
|
|
|
|
|
|
Integer count = stock.getCount();
|
|
|
|
|
|
|
|
stock.setStatus(StockStatus.ERROR.getStatus());
|
|
|
|
|
|
|
|
stock.setCategory(checkByMan.getCategory());
|
|
|
|
|
|
|
|
stock.setCount(checkByMan.getCount());
|
|
|
|
|
|
|
|
stockMapper.updateById(stock);
|
|
|
|
|
|
|
|
checkLog(stock, oldStatus, oldCategory, count);
|
|
|
|
|
|
|
|
return stock;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 核对历史记录
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param stock
|
|
|
|
|
|
|
|
* @param oldStatus
|
|
|
|
|
|
|
|
* @param oldCategory
|
|
|
|
|
|
|
|
* @param oldCount
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void checkLog(Stock stock, Integer oldStatus, String oldCategory, Integer oldCount) {
|
|
|
|
StockLog stockLog = new StockLog();
|
|
|
|
StockLog stockLog = new StockLog();
|
|
|
|
BeanUtils.copyProperties(stock,stockLog);
|
|
|
|
BeanUtils.copyProperties(stock, stockLog);
|
|
|
|
stockLog.setOldStatus(oldStatus);
|
|
|
|
Map<String, Object> map = new HashMap<>(8);
|
|
|
|
stockLog.setNewStatus(stock.getStatus());
|
|
|
|
if (oldStatus != null) {
|
|
|
|
|
|
|
|
map.put("old_status", oldStatus);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!StringUtils.isEmpty(oldCategory)) {
|
|
|
|
|
|
|
|
map.put("old_category", oldCategory);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oldCount != null) {
|
|
|
|
|
|
|
|
map.put("old_count", oldCount);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
map.put("new_status", stock.getStatus());
|
|
|
|
|
|
|
|
map.put("new_category", stock.getCategory());
|
|
|
|
|
|
|
|
map.put("new_count", stock.getCount());
|
|
|
|
|
|
|
|
stockLog.setContent(JSONObject.toJSONString(map));
|
|
|
|
|
|
|
|
stockLog.setCreateTime(LocalDateTime.now());
|
|
|
|
|
|
|
|
stockLog.setUserId(1);
|
|
|
|
|
|
|
|
stockLog.setUsername("wong");
|
|
|
|
// todo username
|
|
|
|
// todo username
|
|
|
|
logMapper.insert(stockLog);
|
|
|
|
logMapper.insert(stockLog);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|