Commit f6495699 张少辉

1.料号基础数据 优化

1 个父辈 87984628
package com.neotel.smfcore.custom.lizhen.innerBox.bean; package com.neotel.smfcore.custom.lizhen.innerBox.bean;
import com.neotel.smfcore.common.base.BasePo;
import lombok.Data; import lombok.Data;
import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@Data @Data
public class ReelConsumption { public class ReelConsumption extends BasePo implements Serializable {
private String req;
private String partNumber; private String partNumber;
private String replacementPartNumber;
private String warehouseCode;
private Map<String,ReelConsumptionInventory> inventoryMap = new HashMap<>(); private Map<String,ReelConsumptionInventory> inventoryMap = new HashMap<>();
} }
package com.neotel.smfcore.custom.lizhen.innerBox.bean; package com.neotel.smfcore.custom.lizhen.innerBox.bean;
import com.neotel.smfcore.common.base.BasePo;
import lombok.Data; import lombok.Data;
import java.io.Serializable;
@Data @Data
public class ReelConsumptionInventory { public class ReelConsumptionInventory extends BasePo implements Serializable {
private int min; private int min;
private int max; private int max;
......
package com.neotel.smfcore.custom.lizhen.innerBox.bean.dto;
import com.neotel.smfcore.common.base.BasePo;
import lombok.Getter;
import lombok.Setter;
import java.util.HashMap;
import java.util.Map;
@Getter
@Setter
public class ReelConsumptionDto extends BasePo {
private String partNumber;
private Map<String, ReelConsumptionInventoryDto> inventoryMap = new HashMap<>();
}
package com.neotel.smfcore.custom.lizhen.innerBox.bean.dto;
import com.neotel.smfcore.common.base.BasePo;
import lombok.Data;
import java.io.Serializable;
@Data
public class ReelConsumptionInventoryDto extends BasePo implements Serializable {
private int min;
private int max;
}
package com.neotel.smfcore.custom.lizhen.innerBox.rest; package com.neotel.smfcore.custom.lizhen.innerBox.rest;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.neotel.smfcore.common.bean.PageData;
import com.neotel.smfcore.common.bean.ResultBean; import com.neotel.smfcore.common.bean.ResultBean;
import com.neotel.smfcore.common.exception.ValidateException; import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.common.utils.Constants; import com.neotel.smfcore.common.utils.Constants;
...@@ -9,6 +10,9 @@ import com.neotel.smfcore.common.utils.StringUtils; ...@@ -9,6 +10,9 @@ import com.neotel.smfcore.common.utils.StringUtils;
import com.neotel.smfcore.core.device.util.DataCache; import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.custom.lizhen.innerBox.bean.ReelConsumption; import com.neotel.smfcore.custom.lizhen.innerBox.bean.ReelConsumption;
import com.neotel.smfcore.custom.lizhen.innerBox.bean.ReelConsumptionInventory; import com.neotel.smfcore.custom.lizhen.innerBox.bean.ReelConsumptionInventory;
import com.neotel.smfcore.custom.lizhen.innerBox.bean.dto.ReelConsumptionDto;
import com.neotel.smfcore.custom.lizhen.innerBox.bean.dto.ReelConsumptionInventoryDto;
import com.neotel.smfcore.custom.lizhen.innerBox.service.manager.IReelConsumptionManager;
import com.neotel.smfcore.security.annotation.AnonymousAccess; import com.neotel.smfcore.security.annotation.AnonymousAccess;
import com.neotel.smfcore.security.bean.FileProperties; import com.neotel.smfcore.security.bean.FileProperties;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -21,12 +25,11 @@ import org.apache.poi.ss.usermodel.Sheet; ...@@ -21,12 +25,11 @@ import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.data.mongodb.core.query.Query;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.yaml.snakeyaml.scanner.Constant;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.File; import java.io.File;
...@@ -48,43 +51,38 @@ public class ReelConsumptionController { ...@@ -48,43 +51,38 @@ public class ReelConsumptionController {
@Autowired @Autowired
private DataCache dataCache; private DataCache dataCache;
@Autowired
private IReelConsumptionManager reelConsumptionManager;
//下载模板 //下载模板
@ApiOperation("下载模板") @ApiOperation("下载模板")
@RequestMapping("/download") @RequestMapping("/download")
//@AnonymousAccess //@AnonymousAccess
public void download(HttpServletResponse response) throws IOException { public void download(HttpServletResponse response) throws IOException {
//判断线体是否存在
Map<String, Integer> cacheMap = dataCache.getCache(Constants.CACHE_wireQtyMaint);
if (cacheMap == null) {
cacheMap = new HashMap<>();
}
if (cacheMap.isEmpty()) {
throw new ValidateException("", "开线数量维护页面,线体信息为空,请先配置后再进行下载模板");
}
//根据开线数量维护,构造模板信息
List<List<String>> headerList = new ArrayList<>(); List<List<String>> headerList = new ArrayList<>();
headerList.add(Arrays.asList("序号"));
headerList.add(Arrays.asList("料号")); headerList.add(Arrays.asList("料号"));
headerList.add(Arrays.asList("替代料")); List<String> lineList = cacheMap.keySet().stream().sorted().collect(Collectors.toList());
headerList.add(Arrays.asList("库别")); for (String line : lineList) {
headerList.add(Arrays.asList("Everst1340最小库存")); headerList.add(Arrays.asList(line + "最小库存"));
headerList.add(Arrays.asList("Everst1340最大库存")); headerList.add(Arrays.asList(line + "最大库存"));
headerList.add(Arrays.asList("Everst770最小库存")); }
headerList.add(Arrays.asList("Everst770最大库存"));
headerList.add(Arrays.asList("X81340最小库存"));
headerList.add(Arrays.asList("X81340最大库存"));
headerList.add(Arrays.asList("X8770最小库存"));
headerList.add(Arrays.asList("X8770最大库存"));
headerList.add(Arrays.asList("OPAL最小库存"));
headerList.add(Arrays.asList("OPAL最大库存"));
List<List<Object>> datas = new ArrayList<>(); List<List<Object>> datas = new ArrayList<>();
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
List<Object> dataList = new ArrayList<>(); List<Object> dataList = new ArrayList<>();
dataList.add(i); dataList.add("料号" + i);
dataList.add("料号"+i); for (String line : lineList) {
dataList.add("替代料"+i); dataList.add(i);
dataList.add("库别"+i); dataList.add(i+10);
dataList.add(i); }
dataList.add(i+10);
dataList.add(i);
dataList.add(i+10);
dataList.add(i);
dataList.add(i+10);
dataList.add(i);
dataList.add(i+10);
dataList.add(i);
dataList.add(i+10);
datas.add(dataList); datas.add(dataList);
} }
FileUtil.downloadExcel(headerList, datas, response); FileUtil.downloadExcel(headerList, datas, response);
...@@ -135,60 +133,33 @@ public class ReelConsumptionController { ...@@ -135,60 +133,33 @@ public class ReelConsumptionController {
ReelConsumption reelConsumption = new ReelConsumption(); ReelConsumption reelConsumption = new ReelConsumption();
for (String header : headerList) { for (String header : headerList) {
if ("序号".equals(header)) {
Integer index = headerMap.get(header);
if (index == null || index == -1) {
throw new ValidateException("smfcore.valueNotExist", "{0}[{1}]不存在", new String[]{"序号"});
}
Cell cell = dataRaw.getCell(index);
String value = String.valueOf((int)cell.getNumericCellValue());
if (StringUtils.isEmpty(value)) {
throw new ValidateException("smfcore.valueCanotNull", "{0}不能为空", new String[]{"序号"});
}
reelConsumption.setReq(value);
} else
if ("料号".equals(header)) { if ("料号".equals(header)) {
Integer index = headerMap.get(header); Integer index = headerMap.get(header);
if (index == null || index == -1) { if (index == null || index == -1) {
throw new ValidateException("smfcore.valueNotExist", "{0}[{1}]不存在", new String[]{"料号"}); throw new ValidateException("smfcore.valueNotExist", "{0}[{1}]不存在", new String[]{"料号"});
} }
Cell cell = dataRaw.getCell(index); Cell cell = dataRaw.getCell(index);
String value = cell.getStringCellValue(); if (cell == null){
if (StringUtils.isEmpty(value)) {
throw new ValidateException("smfcore.valueCanotNull", "{0}不能为空", new String[]{"料号"}); throw new ValidateException("smfcore.valueCanotNull", "{0}不能为空", new String[]{"料号"});
} }
reelConsumption.setPartNumber(value);
} else if ("替代料".equals(header)) {
Integer index = headerMap.get(header);
if (index == null || index == -1) {
throw new ValidateException("smfcore.valueNotExist", "{0}[{1}]不存在", new String[]{"替代料"});
}
Cell cell = dataRaw.getCell(index);
String value = cell.getStringCellValue(); String value = cell.getStringCellValue();
if (StringUtils.isEmpty(value)) { if (StringUtils.isEmpty(value)) {
throw new ValidateException("smfcore.valueCanotNull", "{0}不能为空", new String[]{"替代料"}); throw new ValidateException("smfcore.valueCanotNull", "{0}不能为空", new String[]{"料号"});
}
reelConsumption.setReplacementPartNumber(value);
} else if ("库别".equals(header)) {
Integer index = headerMap.get(header);
if (index == null || index == -1) {
throw new ValidateException("smfcore.valueNotExist", "{0}[{1}]不存在", new String[]{"库别"});
}
Cell cell = dataRaw.getCell(index);
String value = cell.getStringCellValue();
if (StringUtils.isEmpty(value)) {
throw new ValidateException("smfcore.valueCanotNull", "{0}不能为空", new String[]{"库别"});
} }
reelConsumption.setWarehouseCode(value); reelConsumption.setPartNumber(value);
} else { } else {
String maxInventory = header + "最大库存"; String maxInventory = header + "最大库存";
Integer maxIndex = headerMap.get(maxInventory); Integer maxIndex = headerMap.get(maxInventory);
if (maxIndex == null || maxIndex == -1) { if (maxIndex == null || maxIndex == -1) {
throw new ValidateException("smfcore.valueNotExist", "{0}[{1}]不存在", new String[]{maxInventory}); throw new ValidateException("smfcore.valueNotExist", "{0}[{1}]不存在", new String[]{maxInventory});
} }
Cell maxCell = dataRaw.getCell(maxIndex); Cell maxCell = dataRaw.getCell(maxIndex);
double maxValue = maxCell.getNumericCellValue();
if (maxCell == null){
throw new ValidateException("smfcore.valueNotExist", "{0}[{1}]不存在", new String[]{maxInventory});
}
double maxValue = maxCell.getNumericCellValue();
String minInventory = header + "最小库存"; String minInventory = header + "最小库存";
Integer minIndex = headerMap.get(minInventory); Integer minIndex = headerMap.get(minInventory);
...@@ -196,6 +167,11 @@ public class ReelConsumptionController { ...@@ -196,6 +167,11 @@ public class ReelConsumptionController {
throw new ValidateException("smfcore.valueNotExist", "{0}[{1}]不存在", new String[]{minInventory}); throw new ValidateException("smfcore.valueNotExist", "{0}[{1}]不存在", new String[]{minInventory});
} }
Cell cell = dataRaw.getCell(minIndex); Cell cell = dataRaw.getCell(minIndex);
if (cell == null){
throw new ValidateException("smfcore.valueNotExist", "{0}[{1}]不存在", new String[]{minInventory});
}
double minValue = cell.getNumericCellValue(); double minValue = cell.getNumericCellValue();
ReelConsumptionInventory inventory = new ReelConsumptionInventory(); ReelConsumptionInventory inventory = new ReelConsumptionInventory();
...@@ -210,26 +186,294 @@ public class ReelConsumptionController { ...@@ -210,26 +186,294 @@ public class ReelConsumptionController {
} }
log.info(JSON.toJSONString(resultList)); log.info(JSON.toJSONString(resultList));
Map<String,ReelConsumption> cacheMap = dataCache.getCache(Constants.Cache_reelConsumption); reelConsumptionManager.batchSaveAndUpdate(resultList);
if (cacheMap == null){
return ResultBean.newOkResult("");
}
@ApiOperation("获取列表信息")
@RequestMapping(value = "/list")
@AnonymousAccess
public PageData list(String partNumber, Pageable pageable) {
Query query = new Query();
if (StringUtils.isNotEmpty(partNumber)) {
query.addCriteria(Criteria.where("partNumber").is(partNumber));
}
PageData<ReelConsumption> pageData = reelConsumptionManager.findByPage(query, pageable);
int totalElements = pageData.getTotalElements();
if (totalElements == 0) {
return pageData;
}
//判断线体是否存在
Map<String, Integer> cacheMap = dataCache.getCache(Constants.CACHE_wireQtyMaint);
if (cacheMap == null) {
cacheMap = new HashMap<>(); cacheMap = new HashMap<>();
} }
List<ReelConsumptionDto> resultList = new ArrayList<>();
List<ReelConsumption> contentList = pageData.getContent();
for (ReelConsumption reelConsumption : contentList) {
ReelConsumptionDto dto = new ReelConsumptionDto();
dto.setPartNumber(reelConsumption.getPartNumber());
dto.setId(reelConsumption.getId());
Map<String, ReelConsumptionInventoryDto> inventoryMap = new HashMap<>();
Map<String, ReelConsumptionInventory> oldInventoryMap = reelConsumption.getInventoryMap();
if (oldInventoryMap != null && !oldInventoryMap.isEmpty()) {
for (String key : oldInventoryMap.keySet()) {
if (cacheMap.containsKey(key)){
ReelConsumptionInventory inventory = oldInventoryMap.get(key);
ReelConsumptionInventoryDto reelConsumptionInventoryDto = new ReelConsumptionInventoryDto();
reelConsumptionInventoryDto.setMax(inventory.getMax());
reelConsumptionInventoryDto.setMin(inventory.getMin());
inventoryMap.put(key,reelConsumptionInventoryDto);
}
}
}
dto.setInventoryMap(inventoryMap);
resultList.add(dto);
}
return new PageData(resultList,totalElements);
}
for (ReelConsumption consumption : resultList) { @ApiOperation("删除")
cacheMap.put(consumption.getPartNumber(),consumption); @RequestMapping("/delete")
@AnonymousAccess
public ResultBean delete(@RequestBody Set<String> ids) {
log.info("开始删除基础数据,待删除ID: {}", ids);
for (String id : ids) {
if (StringUtils.isNotEmpty(id)) {
reelConsumptionManager.deleteById(id);
} else {
log.warn("删除操作中存在空ID,跳过");
}
} }
dataCache.updateCache(Constants.Cache_reelConsumption, cacheMap);
return ResultBean.newOkResult(""); return ResultBean.newOkResult("");
} }
@ApiOperation("获取列表信息") @ApiOperation("修改或者新增调用,需要构造数据")
@RequestMapping(value = "/list") @RequestMapping("beforeSaveOrUpdate")
//@AnonymousAccess @AnonymousAccess
public ResultBean list() { public ResultBean beforeSaveOrUpdate(String id) {
Map<String,ReelConsumption> cacheMap = dataCache.getCache(Constants.Cache_reelConsumption); //判断线体是否存在
if (cacheMap == null){ Map<String, Integer> cacheMap = dataCache.getCache(Constants.CACHE_wireQtyMaint);
if (cacheMap == null) {
cacheMap = new HashMap<>();
}
if (cacheMap.isEmpty()) {
return ResultBean.newErrorResult(-1, "", "开线数量维护页面,线体信息为空,请先配置后再进行新增或者修改");
}
ReelConsumptionDto dto = new ReelConsumptionDto();
Map<String, ReelConsumptionInventoryDto> inventoryMap = new HashMap<>();
if (StringUtils.isEmpty(id)) {
dto.setPartNumber("");
dto.setId("");
for (String key : cacheMap.keySet()) {
ReelConsumptionInventoryDto inventoryDto = new ReelConsumptionInventoryDto();
inventoryDto.setMax(0);
inventoryDto.setMin(0);
inventoryMap.put(key, inventoryDto);
}
} else {
ReelConsumption reelConsumption = reelConsumptionManager.get(id);
if (reelConsumption != null) {
dto.setPartNumber(reelConsumption.getId());
dto.setId(reelConsumption.getId());
Map<String, ReelConsumptionInventory> oldInventoryMap = reelConsumption.getInventoryMap();
if (oldInventoryMap == null) {
oldInventoryMap = new HashMap<>();
}
for (String key : cacheMap.keySet()) {
ReelConsumptionInventoryDto inventoryDto = new ReelConsumptionInventoryDto();
inventoryDto.setMax(0);
inventoryDto.setMin(0);
ReelConsumptionInventory inventory = oldInventoryMap.get(key);
if (inventory != null) {
inventoryDto.setMin(inventory.getMin());
inventoryDto.setMax(inventory.getMax());
}
inventoryMap.put(key, inventoryDto);
}
}
}
dto.setInventoryMap(inventoryMap);
return ResultBean.newOkResult(dto);
}
@ApiOperation("新增")
@RequestMapping("save")
@AnonymousAccess
public ResultBean save(@RequestBody ReelConsumptionDto dto) {
String partNumber = dto.getPartNumber();
if (StringUtils.isEmpty(partNumber)) {
return ResultBean.newErrorResult(-1, "smfcore.valueCanotNull", "{0}不能为空", new String[]{"料号"});
}
partNumber = partNumber.trim();
dto.setPartNumber(partNumber);
ReelConsumption oldConsumption = reelConsumptionManager.getByPartNumber(partNumber);
if (oldConsumption != null) {
return ResultBean.newErrorResult(-1, "smfcore.dataExist", "料号[{0}]已存在,不能重复新增", new String[]{partNumber});
}
Map<String, Integer> cacheMap = dataCache.getCache(Constants.CACHE_wireQtyMaint);
if (cacheMap == null) {
cacheMap = new HashMap<>(); cacheMap = new HashMap<>();
} }
return ResultBean.newOkResult(cacheMap.values());
//开始构造数据
ReelConsumption reelConsumption = new ReelConsumption();
reelConsumption.setPartNumber(partNumber);
Map<String, ReelConsumptionInventory> inventoryMap = new HashMap<>();
Map<String, ReelConsumptionInventoryDto> dtoInventoryMap = dto.getInventoryMap() == null ? new HashMap<>() : dto.getInventoryMap();
for (String lineKey : cacheMap.keySet()) {
ReelConsumptionInventory inventory = new ReelConsumptionInventory();
ReelConsumptionInventoryDto dtoInventory = dtoInventoryMap.get(lineKey);
int min = 0;
int max = 0;
if (dtoInventory != null) {
min = dtoInventory.getMin();
max = dtoInventory.getMax();
}
inventory.setMin(min);
inventory.setMax(max);
inventoryMap.put(lineKey, inventory);
}
reelConsumption.setInventoryMap(inventoryMap);
reelConsumptionManager.save(reelConsumption);
log.info("新增物料基础数据成功,料号:{},线体配置数量:{}", partNumber, inventoryMap.size());
return ResultBean.newOkResult("新增成功");
}
@ApiOperation("修改")
@RequestMapping("update")
@AnonymousAccess
public ResultBean update(@RequestBody ReelConsumptionDto dto) {
String id = dto.getId();
if (StringUtils.isEmpty(id)) {
return ResultBean.newErrorResult(-1, "smfcore.valueCanotNull", "{0}不能为空", new String[]{"数据ID"});
}
String partNumber = dto.getPartNumber();
if (StringUtils.isEmpty(partNumber)) {
return ResultBean.newErrorResult(-1, "smfcore.valueCanotNull", "{0}不能为空", new String[]{"料号"});
}
partNumber = partNumber.trim();
dto.setPartNumber(partNumber);
ReelConsumption oldConsumption = reelConsumptionManager.get(id);
if (oldConsumption == null) {
return ResultBean.newErrorResult(-1, "smfcore.dataNotExist", "料号[{0}]对应的记录不存在,无法修改", new String[]{partNumber});
}
if (!partNumber.equals(oldConsumption.getPartNumber())) {
ReelConsumption otherConsumption = reelConsumptionManager.getByPartNumber(partNumber);
if (otherConsumption != null) {
return ResultBean.newErrorResult(-1, "smfcore.dataExist", "料号[{0}]已被其他记录占用,无法修改", new String[]{partNumber});
}
}
Map<String, Integer> cacheMap = dataCache.getCache(Constants.CACHE_wireQtyMaint);
if (cacheMap == null) {
cacheMap = new HashMap<>();
}
ReelConsumption reelConsumption = new ReelConsumption();
reelConsumption.setId(id); // 保留原ID
reelConsumption.setPartNumber(partNumber); // 更新料号
Map<String, ReelConsumptionInventory> inventoryMap = oldConsumption.getInventoryMap();
Map<String, ReelConsumptionInventoryDto> dtoInventoryMap = dto.getInventoryMap() == null ? new HashMap<>() : dto.getInventoryMap();
for (String lineKey : cacheMap.keySet()) {
ReelConsumptionInventory inventory = new ReelConsumptionInventory();
ReelConsumptionInventoryDto dtoInventory = dtoInventoryMap.get(lineKey);
int min = 0;
int max = 0;
if (dtoInventory != null) {
min = dtoInventory.getMin();
max = dtoInventory.getMax();
}
inventory.setMin(min);
inventory.setMax(max);
inventoryMap.put(lineKey, inventory);
}
reelConsumption.setInventoryMap(inventoryMap);
reelConsumptionManager.save(reelConsumption);
return ResultBean.newOkResult("修改成功");
}
@ApiOperation("导出数据")
@RequestMapping("/list/download")
@AnonymousAccess
public void listDownload(String partNumber,HttpServletResponse response) throws IOException {
// 1. 获取线体配置缓存(和list接口逻辑一致)
Map<String, Integer> cacheMap = dataCache.getCache(Constants.CACHE_wireQtyMaint);
if (cacheMap == null) {
cacheMap = new HashMap<>();
}
if (cacheMap.isEmpty()) {
throw new ValidateException("", "开线数量维护页面,线体信息为空,暂无数据可导出");
}
// 2. 构建Excel表头(和模板下载格式一致:料号 + 各线体最小/最大库存)
List<List<String>> headerList = new ArrayList<>();
headerList.add(Arrays.asList("料号"));
// 线体按排序后处理,保证表头顺序统一
List<String> lineList = cacheMap.keySet().stream().sorted().collect(Collectors.toList());
for (String line : lineList) {
headerList.add(Arrays.asList(line + "最小库存"));
headerList.add(Arrays.asList(line + "最大库存"));
}
// 3. 查询全部物料基础数据(不分页)
Query query = new Query(); // 空查询表示查询所有数据
if (StringUtils.isNotEmpty(partNumber)){
query.addCriteria(Criteria.where("partNumber").is(partNumber));
}
List<ReelConsumption> allDataList = reelConsumptionManager.findByQuery(query);
// 4. 构造Excel数据行(复用list接口的DTO转换逻辑)
List<List<Object>> datas = new ArrayList<>();
if (allDataList != null && !allDataList.isEmpty()) {
for (ReelConsumption reelConsumption : allDataList) {
List<Object> dataRow = new ArrayList<>();
// 第一列:料号
dataRow.add(reelConsumption.getPartNumber());
// 按线体顺序填充各线体的最小/最大库存
Map<String, ReelConsumptionInventory> oldInventoryMap = reelConsumption.getInventoryMap();
if (oldInventoryMap == null) {
oldInventoryMap = new HashMap<>();
}
for (String line : lineList) {
// 只处理缓存中存在的线体(和list接口逻辑一致)
if (cacheMap.containsKey(line)) {
ReelConsumptionInventory inventory = oldInventoryMap.get(line);
// 无配置时填充0(和新增/修改接口默认值一致)
int min = inventory != null ? inventory.getMin() : 0;
int max = inventory != null ? inventory.getMax() : 0;
dataRow.add(min);
dataRow.add(max);
}
}
datas.add(dataRow);
}
log.info("导出物料基础数据,共{}条记录", datas.size());
} else {
List<Object> emptyRow = new ArrayList<>();
emptyRow.add("暂无物料基础数据");
// 补全列数,保证Excel格式正常
for (int i = 1; i < headerList.size(); i++) {
emptyRow.add("");
}
datas.add(emptyRow);
log.info("导出物料基础数据:暂无数据");
}
FileUtil.downloadExcel(headerList, datas, response);
} }
} }
package com.neotel.smfcore.custom.lizhen.innerBox.service.dao;
import com.neotel.smfcore.common.base.IBaseDao;
public interface IReelConsumptionDao extends IBaseDao {
}
package com.neotel.smfcore.custom.lizhen.innerBox.service.dao.impl;
import com.neotel.smfcore.common.base.AbstractBaseDao;
import com.neotel.smfcore.custom.lizhen.innerBox.bean.ReelConsumption;
import com.neotel.smfcore.custom.lizhen.innerBox.service.dao.IReelConsumptionDao;
import org.springframework.stereotype.Service;
@Service
public class ReelConsumptionDaoImpl extends AbstractBaseDao implements IReelConsumptionDao {
@Override
public Class getEntityClass() {
return ReelConsumption.class;
}
}
package com.neotel.smfcore.custom.lizhen.innerBox.service.manager;
import com.neotel.smfcore.common.base.IBaseManager;
import com.neotel.smfcore.custom.lizhen.innerBox.bean.ReelConsumption;
import java.util.List;
public interface IReelConsumptionManager extends IBaseManager<ReelConsumption> {
void batchSaveAndUpdate(List<ReelConsumption> resultList);
ReelConsumption getByPartNumber(String partNumber);
void deleteById(String id);
}
package com.neotel.smfcore.custom.lizhen.innerBox.service.manager.impl;
import com.neotel.smfcore.common.bean.PageData;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.custom.lizhen.innerBox.bean.ReelConsumption;
import com.neotel.smfcore.custom.lizhen.innerBox.bean.ReelConsumptionInventory;
import com.neotel.smfcore.custom.lizhen.innerBox.service.dao.IReelConsumptionDao;
import com.neotel.smfcore.custom.lizhen.innerBox.service.manager.IReelConsumptionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
@Service
public class ReelConsumptionManagerImpl implements IReelConsumptionManager {
@Autowired
private IReelConsumptionDao reelConsumptionDao;
@Override
public ReelConsumption get(String id) {
return reelConsumptionDao.findOneById(id);
}
@Override
public ReelConsumption save(ReelConsumption object) throws ValidateException {
return reelConsumptionDao.save(object);
}
@Override
public void delete(ReelConsumption object) throws ValidateException {
reelConsumptionDao.removeOneById(object.getId());
}
@Override
public PageData<ReelConsumption> findByPage(Query query, Pageable pageable) {
int count = reelConsumptionDao.countByQuery(query);
List list = reelConsumptionDao.findByQuery(query, pageable);
return new PageData<>(list,count);
}
@Override
public List<ReelConsumption> findByQuery(Query query) {
return reelConsumptionDao.findByQuery(query);
}
@Override
public void batchSaveAndUpdate(List<ReelConsumption> resultList) {
for (ReelConsumption reelConsumption : resultList) {
ReelConsumption old = getByPartNumber(reelConsumption.getPartNumber());
if (old != null) {
reelConsumption.setId(old.getId());
Map<String, ReelConsumptionInventory> inventoryMap = reelConsumption.getInventoryMap();
Map<String, ReelConsumptionInventory> oldInventoryMap = old.getInventoryMap();
if (oldInventoryMap != null) {
for (String key : oldInventoryMap.keySet()) {
if (!inventoryMap.containsKey(key)) {
inventoryMap.put(key, oldInventoryMap.get(key));
}
}
}
}
reelConsumptionDao.save(reelConsumption);
}
}
@Override
public ReelConsumption getByPartNumber(String partNumber) {
return reelConsumptionDao.findOne(new Query(Criteria.where("partNumber").is(partNumber)));
}
@Override
public void deleteById(String id) {
reelConsumptionDao.removeOneById(id);
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!