Commit c27b9264 zshaohui

出货计算:增加机种,导出功能

出货料号维护: 增加机种(By机种设定优先级),出库数量,批量导入功能
库存信息抛送:增加机种(By机种抛送信息), 数量,模糊查询
1 个父辈 ea73bc4e
...@@ -101,5 +101,5 @@ public interface IStoragePosManager extends IBaseManager<StoragePos> { ...@@ -101,5 +101,5 @@ public interface IStoragePosManager extends IBaseManager<StoragePos> {
List<StoragePos> findPosByIdList(List<String> idList); List<StoragePos> findPosByIdList(List<String> idList);
List<StoragePos> findOdnCalculatePos(String pn, String warehouseCode,Collection<String> excludeOutPosIds); List<StoragePos> findOdnCalculatePos(String pn, String warehouseCode,Collection<String> excludeOutPosIds,String modelFamily);
} }
...@@ -913,7 +913,7 @@ public class StoragePosManagerImpl implements IStoragePosManager { ...@@ -913,7 +913,7 @@ public class StoragePosManagerImpl implements IStoragePosManager {
} }
@Override @Override
public List<StoragePos> findOdnCalculatePos(String pn, String warehouseCode,Collection<String> excludeOutPosIds) { public List<StoragePos> findOdnCalculatePos(String pn, String warehouseCode,Collection<String> excludeOutPosIds,String modelFamily) {
//排除hold的料箱 //排除hold的料箱
List<String> holdPalletIdList = new ArrayList<>(); List<String> holdPalletIdList = new ArrayList<>();
List<FetchHoldInfoResult> holdList = LuxsanApi.fetchHoldInfo(new FetchHoldInfoRequest(CommonUtil.plantCode, warehouseCode, pn)); List<FetchHoldInfoResult> holdList = LuxsanApi.fetchHoldInfo(new FetchHoldInfoRequest(CommonUtil.plantCode, warehouseCode, pn));
...@@ -931,8 +931,11 @@ public class StoragePosManagerImpl implements IStoragePosManager { ...@@ -931,8 +931,11 @@ public class StoragePosManagerImpl implements IStoragePosManager {
if (holdPalletIdList != null && !holdPalletIdList.isEmpty()){ if (holdPalletIdList != null && !holdPalletIdList.isEmpty()){
c.and("barcode.palletId").nin(holdPalletIdList); c.and("barcode.palletId").nin(holdPalletIdList);
} }
if (StringUtils.isNotEmpty(modelFamily)){
c.and("barcode.modelFamily").is(modelFamily);
}
Query q = new Query(c); Query q = new Query(c);
q.fields().include("barcode.amount","barcode.partNumber","barcode.warehouseCode","posName","barcode.barcode","barcode.palletId"); q.fields().include("barcode.amount","barcode.partNumber","barcode.warehouseCode","posName","barcode.barcode","barcode.palletId","barcode.modelFamily");
return storagePosDao.findByQuery(q); return storagePosDao.findByQuery(q);
} }
......
package com.neotel.smfcore.custom.luxsan.factory_c.wipstor.bean; package com.neotel.smfcore.custom.luxsan.factory_c.wipstor.bean;
import com.neotel.smfcore.common.base.BasePo; import com.neotel.smfcore.common.base.BasePo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
@Data @Data
public class PnPriorityMt extends BasePo { public class PnPriorityMt extends BasePo {
private String partNumber; private String partNumber;
private int priority; private int priority;
private String modelFamily;
private int checkOutNum;
//private int inventoryNum; //private int inventoryNum;
} }
...@@ -12,4 +12,6 @@ public class AutoDispatchDto { ...@@ -12,4 +12,6 @@ public class AutoDispatchDto {
private String partNumber; private String partNumber;
private String warehouseCode; private String warehouseCode;
private String posName; private String posName;
private String modelFamily;
private int amount;
} }
...@@ -18,5 +18,11 @@ public class PnPriorityMtDto implements Serializable { ...@@ -18,5 +18,11 @@ public class PnPriorityMtDto implements Serializable {
private int priority; private int priority;
//机种
private String modelFamily;
//要出库的数量
private int checkOutNum;
//private int inventoryNum; //private int inventoryNum;
} }
package com.neotel.smfcore.custom.luxsan.factory_c.wipstor.bean.query;
import com.neotel.smfcore.common.annotation.QueryCondition;
import com.neotel.smfcore.common.bean.BetweenData;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
@Data
public class AutoDispatchInventoryQueryCriteria {
@QueryCondition(blurry ="posName,barcode.barcode,barcode.amount,barcode.palletId,barcode.partNumber,barcode.warehouseCode,barcode.requestId,barcode.odn,barcode.modelFamily")
private String blurry;
@QueryCondition(propName = "barcode.modelFamily")
private String modelFamily;
}
...@@ -2,6 +2,7 @@ package com.neotel.smfcore.custom.luxsan.factory_c.wipstor.controller; ...@@ -2,6 +2,7 @@ package com.neotel.smfcore.custom.luxsan.factory_c.wipstor.controller;
import com.neotel.smfcore.common.bean.ResultBean; import com.neotel.smfcore.common.bean.ResultBean;
import com.neotel.smfcore.common.utils.Constants; import com.neotel.smfcore.common.utils.Constants;
import com.neotel.smfcore.common.utils.QueryHelp;
import com.neotel.smfcore.core.barcode.service.po.Barcode; import com.neotel.smfcore.core.barcode.service.po.Barcode;
import com.neotel.smfcore.core.device.util.DataCache; import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.core.storage.service.manager.IStoragePosManager; import com.neotel.smfcore.core.storage.service.manager.IStoragePosManager;
...@@ -11,6 +12,7 @@ import com.neotel.smfcore.custom.luxsan.api.bean.request.FetchHoldInfoRequest; ...@@ -11,6 +12,7 @@ import com.neotel.smfcore.custom.luxsan.api.bean.request.FetchHoldInfoRequest;
import com.neotel.smfcore.custom.luxsan.api.bean.result.FetchHoldInfoResult; import com.neotel.smfcore.custom.luxsan.api.bean.result.FetchHoldInfoResult;
import com.neotel.smfcore.custom.luxsan.factory_c.common.util.CommonUtil; import com.neotel.smfcore.custom.luxsan.factory_c.common.util.CommonUtil;
import com.neotel.smfcore.custom.luxsan.factory_c.wipstor.bean.dto.AutoDispatchDto; import com.neotel.smfcore.custom.luxsan.factory_c.wipstor.bean.dto.AutoDispatchDto;
import com.neotel.smfcore.custom.luxsan.factory_c.wipstor.bean.query.AutoDispatchInventoryQueryCriteria;
import com.neotel.smfcore.security.annotation.AnonymousAccess; import com.neotel.smfcore.security.annotation.AnonymousAccess;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
...@@ -65,13 +67,13 @@ public class AutoDispatchInventoryController { ...@@ -65,13 +67,13 @@ public class AutoDispatchInventoryController {
@ApiOperation("获取库存信息") @ApiOperation("获取库存信息")
@RequestMapping("/getAllInventory") @RequestMapping("/getAllInventory")
@AnonymousAccess @AnonymousAccess
public ResultBean getAllInventory() { public ResultBean getAllInventory(AutoDispatchInventoryQueryCriteria criteria) {
List<AutoDispatchDto> autoDispatchDtoList = new ArrayList<>(); List<AutoDispatchDto> autoDispatchDtoList = new ArrayList<>();
//获取所有的库存信息 //获取所有的库存信息
Query q = new Query(); Query q = QueryHelp.getQuery(criteria);
Criteria c = Criteria.where("barcode").exists(true) Criteria c = Criteria.where("barcode").exists(true)
.and("enabled").is(true); .and("enabled").is(true);
q.addCriteria(c).fields().include("id","posName","barcode.barcode", "barcode.palletId", "barcode.partNumber", "barcode.warehouseCode", "barcode.requestId", "barcode.odn"); q.addCriteria(c).fields().include("id","posName","barcode.barcode", "barcode.amount","barcode.palletId", "barcode.partNumber", "barcode.warehouseCode", "barcode.requestId", "barcode.odn","barcode.modelFamily");
//查询所有的,把hold的排除 //查询所有的,把hold的排除
Map<String, FetchHoldInfoRequest> fetchHoldInfoRequestMap = new HashMap<>(); Map<String, FetchHoldInfoRequest> fetchHoldInfoRequestMap = new HashMap<>();
...@@ -124,6 +126,8 @@ public class AutoDispatchInventoryController { ...@@ -124,6 +126,8 @@ public class AutoDispatchInventoryController {
dto.setPartNumber(barcode.getPartNumber()); dto.setPartNumber(barcode.getPartNumber());
dto.setWarehouseCode(barcode.getWarehouseCode()); dto.setWarehouseCode(barcode.getWarehouseCode());
dto.setPosName(pos.getPosName()); dto.setPosName(pos.getPosName());
dto.setModelFamily(barcode.getModelFamily());
dto.setAmount(barcode.getAmount());
autoDispatchDtoList.add(dto); autoDispatchDtoList.add(dto);
} }
} }
......
package com.neotel.smfcore.custom.luxsan.factory_c.wipstor.controller; package com.neotel.smfcore.custom.luxsan.factory_c.wipstor.controller;
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.utils.FileUtil;
import com.neotel.smfcore.common.utils.StringUtils; import com.neotel.smfcore.common.utils.StringUtils;
import com.neotel.smfcore.core.order.LiteOrderCache; import com.neotel.smfcore.core.order.LiteOrderCache;
import com.neotel.smfcore.core.storage.service.manager.IStoragePosManager; import com.neotel.smfcore.core.storage.service.manager.IStoragePosManager;
...@@ -18,6 +20,7 @@ import org.springframework.web.bind.annotation.RequestBody; ...@@ -18,6 +20,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.util.*; import java.util.*;
@Slf4j @Slf4j
...@@ -48,7 +51,8 @@ public class OdnCalculateQty { ...@@ -48,7 +51,8 @@ public class OdnCalculateQty {
String pn = paramMap.get("pn"); String pn = paramMap.get("pn");
String targetNumStr = paramMap.get("targetNum"); String targetNumStr = paramMap.get("targetNum");
String warehouseCode = paramMap.get("warehouseCode"); String warehouseCode = paramMap.get("warehouseCode");
log.info("收到odn出货计算数量,料号为:" + pn + ",目标数量为:" + targetNumStr + "库别为:" + warehouseCode); String modelFamily = paramMap.get("modelFamily");
log.info("收到odn出货计算数量,料号为:" + pn + ",目标数量为:" + targetNumStr + "库别为:" + warehouseCode+",机种为:"+modelFamily);
//检验参数 //检验参数
if (StringUtils.isEmpty(pn) || StringUtils.isEmpty(warehouseCode) || StringUtils.isEmpty(targetNumStr)) { if (StringUtils.isEmpty(pn) || StringUtils.isEmpty(warehouseCode) || StringUtils.isEmpty(targetNumStr)) {
...@@ -66,7 +70,7 @@ public class OdnCalculateQty { ...@@ -66,7 +70,7 @@ public class OdnCalculateQty {
//查找所有符合条件的库位 //查找所有符合条件的库位
Collection<String> excludeOutPosIds = liteOrderCache.excludeOutPosIds(); Collection<String> excludeOutPosIds = liteOrderCache.excludeOutPosIds();
List<StoragePos> storagePosList = storagePosManager.findOdnCalculatePos(pn,warehouseCode,excludeOutPosIds); List<StoragePos> storagePosList = storagePosManager.findOdnCalculatePos(pn,warehouseCode,excludeOutPosIds,modelFamily);
if (storagePosList == null || storagePosList.isEmpty()){ if (storagePosList == null || storagePosList.isEmpty()){
calculate = false; calculate = false;
return ResultBean.newErrorResult(-1,"","料号:" + pn +"库别:"+warehouseCode+"库存中未找到料箱"); return ResultBean.newErrorResult(-1,"","料号:" + pn +"库别:"+warehouseCode+"库存中未找到料箱");
...@@ -87,6 +91,7 @@ public class OdnCalculateQty { ...@@ -87,6 +91,7 @@ public class OdnCalculateQty {
resultMap.put("warehouseCode",pos.getBarcode().getWarehouseCode()); resultMap.put("warehouseCode",pos.getBarcode().getWarehouseCode());
resultMap.put("pn",pos.getBarcode().getPartNumber()); resultMap.put("pn",pos.getBarcode().getPartNumber());
resultMap.put("palletId",pos.getBarcode().getPalletId()); resultMap.put("palletId",pos.getBarcode().getPalletId());
resultMap.put("modelFamily",pos.getBarcode().getModelFamily());
resultList.add(resultMap); resultList.add(resultMap);
} }
...@@ -94,4 +99,66 @@ public class OdnCalculateQty { ...@@ -94,4 +99,66 @@ public class OdnCalculateQty {
return ResultBean.newOkResult(resultList); return ResultBean.newOkResult(resultList);
} }
@ApiOperation("计算数量")
@RequestMapping("/calculate/download")
@AnonymousAccess
public void calculate(String pn,String targetNum,String warehouseCode,String modelFamily,HttpServletResponse response) throws Exception {
calculate = true;
//检验参数
if (StringUtils.isEmpty(pn) || StringUtils.isEmpty(warehouseCode) || StringUtils.isEmpty(targetNum)) {
calculate = false;
throw new ValidateException("", "料号,库别,目标数量信息不能为空");
}
int target = 0;
try {
target = Integer.parseInt(targetNum);
} catch (NumberFormatException e) {
log.info("解析数量:" + targetNum + "报错:", e);
calculate = false;
throw new ValidateException("", targetNum + "格式不正确");
}
//查找所有符合条件的库位
Collection<String> excludeOutPosIds = liteOrderCache.excludeOutPosIds();
List<StoragePos> storagePosList = storagePosManager.findOdnCalculatePos(pn, warehouseCode, excludeOutPosIds, modelFamily);
if (storagePosList == null || storagePosList.isEmpty()) {
calculate = false;
throw new ValidateException("", "料号:" + pn + "库别:" + warehouseCode + "库存中未找到料箱");
}
List<StoragePos> combinationsPosList = CalculateUtil.findCombinationsByPos(storagePosList, target);
if (combinationsPosList == null || combinationsPosList.isEmpty()) {
calculate = false;
throw new ValidateException("", "料号:" + pn + "库别:" + warehouseCode + "库存中未找到对应的组合数据");
}
List<Map<String, Object>> dataList = new ArrayList<>();
for (StoragePos pos : combinationsPosList) {
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("料箱", pos.getBarcode().getBarcode());
resultMap.put("栈板ID", pos.getBarcode().getPalletId());
resultMap.put("料号", pos.getBarcode().getPartNumber());
resultMap.put("机种", pos.getBarcode().getModelFamily());
resultMap.put("数量", pos.getBarcode().getAmount());
resultMap.put("库别", pos.getBarcode().getWarehouseCode());
resultMap.put("库位", pos.getPosName());
dataList.add(resultMap);
}
calculate = false;
List<String> titles = new ArrayList<>();
titles.add("料箱");
titles.add("料号");
titles.add("栈板ID");
titles.add("数量");
titles.add("库别");
titles.add("库位");
titles.add("机种");
FileUtil.downloadCSV(dataList, titles, response);
}
} }
...@@ -172,7 +172,7 @@ public class OdnCheckOutNewController { ...@@ -172,7 +172,7 @@ public class OdnCheckOutNewController {
excludeOutPosIds.addAll(holdPosIdList); excludeOutPosIds.addAll(holdPosIdList);
} }
//获取符合条件的pn //获取符合条件的pn
List<StoragePos> dbStoragePosList = storagePosManager.findOdnCalculatePos(pn, warehouseCode, excludeOutPosIds); List<StoragePos> dbStoragePosList = storagePosManager.findOdnCalculatePos(pn, warehouseCode, excludeOutPosIds,"");
if (dbStoragePosList == null) { if (dbStoragePosList == null) {
dbStoragePosList = new ArrayList<>(); dbStoragePosList = new ArrayList<>();
} }
......
package com.neotel.smfcore.custom.luxsan.factory_c.wipstor.controller; package com.neotel.smfcore.custom.luxsan.factory_c.wipstor.controller;
import cn.hutool.core.util.ObjectUtil;
import com.google.common.collect.Lists;
import com.neotel.smfcore.common.base.IExcelDownLoad; import com.neotel.smfcore.common.base.IExcelDownLoad;
import com.neotel.smfcore.common.bean.PageData; 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.csv.CsvReader;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.common.utils.FileUtil; import com.neotel.smfcore.common.utils.FileUtil;
import com.neotel.smfcore.common.utils.StringUtils; import com.neotel.smfcore.common.utils.StringUtils;
import com.neotel.smfcore.core.order.service.po.LiteOrderItem;
import com.neotel.smfcore.core.storage.service.po.Storage;
import com.neotel.smfcore.core.storage.service.po.StoragePos;
import com.neotel.smfcore.core.system.bean.OrderSetting;
import com.neotel.smfcore.custom.luxsan.factory_c.wipstor.bean.PnPriorityMt; import com.neotel.smfcore.custom.luxsan.factory_c.wipstor.bean.PnPriorityMt;
import com.neotel.smfcore.custom.luxsan.factory_c.wipstor.bean.dto.PnPriorityMtDto; import com.neotel.smfcore.custom.luxsan.factory_c.wipstor.bean.dto.PnPriorityMtDto;
import com.neotel.smfcore.custom.luxsan.factory_c.wipstor.bean.mapstruct.PnPriorityMtMapper; import com.neotel.smfcore.custom.luxsan.factory_c.wipstor.bean.mapstruct.PnPriorityMtMapper;
import com.neotel.smfcore.custom.luxsan.factory_c.wipstor.service.manager.IPnPriorityMtManager; import com.neotel.smfcore.custom.luxsan.factory_c.wipstor.service.manager.IPnPriorityMtManager;
import com.neotel.smfcore.security.annotation.AnonymousAccess; import com.neotel.smfcore.security.annotation.AnonymousAccess;
import com.neotel.smfcore.security.bean.FileProperties;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Query;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.List;
/** /**
* partNumber优先级维护 * partNumber优先级维护
...@@ -42,14 +52,22 @@ public class PnPriorityMtController { ...@@ -42,14 +52,22 @@ public class PnPriorityMtController {
@Autowired @Autowired
private PnPriorityMtMapper pnPriorityMtMapper; private PnPriorityMtMapper pnPriorityMtMapper;
@Autowired
private FileProperties properties;
@ApiOperation("获取列表") @ApiOperation("获取列表")
@RequestMapping("/getPnPriorityList") @RequestMapping("/getPnPriorityList")
@AnonymousAccess @AnonymousAccess
public PageData getPnPriorityList(String partNumber, Pageable pageable) { public PageData getPnPriorityList(String partNumber, String modelFamily,Pageable pageable) {
Query query = new Query(); Query query = new Query();
Criteria criteria = new Criteria();
if (StringUtils.isNotEmpty(partNumber)) { if (StringUtils.isNotEmpty(partNumber)) {
query.addCriteria(Criteria.where("partNumber").is(partNumber)); criteria.and("partNumber").is(partNumber);
} }
if (StringUtils.isNotEmpty(modelFamily)) {
criteria.and("modelFamily").is(modelFamily);
}
query.addCriteria(criteria);
query.with(Sort.by(Sort.Direction.DESC,"priority")); query.with(Sort.by(Sort.Direction.DESC,"priority"));
PageData<PnPriorityMt> pageData = pnPriorityMtManager.findByPage(query, pageable); PageData<PnPriorityMt> pageData = pnPriorityMtManager.findByPage(query, pageable);
List<PnPriorityMt> content = pageData.getContent(); List<PnPriorityMt> content = pageData.getContent();
...@@ -96,6 +114,8 @@ public class PnPriorityMtController { ...@@ -96,6 +114,8 @@ public class PnPriorityMtController {
List<List<String>> headerList = new ArrayList<>(); List<List<String>> headerList = new ArrayList<>();
headerList.add(Arrays.asList("id")); headerList.add(Arrays.asList("id"));
headerList.add(Arrays.asList("料号")); headerList.add(Arrays.asList("料号"));
headerList.add(Arrays.asList("机种"));
headerList.add(Arrays.asList("出库数量"));
headerList.add(Arrays.asList("优先级")); headerList.add(Arrays.asList("优先级"));
headerList.add(Arrays.asList("创建时间")); headerList.add(Arrays.asList("创建时间"));
headerList.add(Arrays.asList("修改时间")); headerList.add(Arrays.asList("修改时间"));
...@@ -110,6 +130,8 @@ public class PnPriorityMtController { ...@@ -110,6 +130,8 @@ public class PnPriorityMtController {
List<Object> data = new ArrayList<>(); List<Object> data = new ArrayList<>();
data.add(pnPriorityMt.getId()); data.add(pnPriorityMt.getId());
data.add(pnPriorityMt.getPartNumber()); data.add(pnPriorityMt.getPartNumber());
data.add(pnPriorityMt.getModelFamily());
data.add(pnPriorityMt.getCheckOutNum());
data.add(pnPriorityMt.getPriority()); data.add(pnPriorityMt.getPriority());
data.add(pnPriorityMt.getCreateDate()); data.add(pnPriorityMt.getCreateDate());
data.add(pnPriorityMt.getUpdateDate()); data.add(pnPriorityMt.getUpdateDate());
...@@ -119,4 +141,117 @@ public class PnPriorityMtController { ...@@ -119,4 +141,117 @@ public class PnPriorityMtController {
} }
}); });
} }
@ApiOperation("下载工单模板")
@GetMapping(value = "/downloadModel")
@AnonymousAccess
public void download(HttpServletResponse response) throws IOException {
downloadModel(response);
}
@ApiOperation("上传表格")
@RequestMapping("/upload")
@AnonymousAccess
public ResultBean upload(@RequestParam MultipartFile uploadFile) {
//判断是不是csv文件
// 验证文件上传的格式
String image = "csv";
String fileType = FileUtil.getExtensionName(uploadFile.getOriginalFilename());
if (fileType != null && !image.contains(fileType)) {
throw new ValidateException("smfcore.feleFormatError", "文件格式错误!, 仅支持{0}格式", new String[]{image});
}
File folder = new File(properties.getPath(), "pnPriority");
File file = FileUtil.upload(uploadFile, folder.getAbsolutePath());
List<PnPriorityMt> pnPriorityMtList = readCsvFile(file.getAbsolutePath());
if (pnPriorityMtList == null || pnPriorityMtList.isEmpty()){
return ResultBean.newErrorResult(-1,"","请检查是否有空值或者出库数量和优先级不是数字");
}
for (PnPriorityMt pnPriorityMt : pnPriorityMtList) {
PnPriorityMt mt = pnPriorityMtManager.findOne(new Query(Criteria.where("partNumber").is(pnPriorityMt.getPartNumber()).and("modelFamily").is(pnPriorityMt.getModelFamily())));
if (mt != null){
pnPriorityMt.setId(mt.getId());
pnPriorityMt.setCreateDate(mt.getCreateDate());
}
pnPriorityMtManager.save(pnPriorityMt);
}
return ResultBean.newOkResult("");
}
public List<PnPriorityMt> readCsvFile(String fileURL) {
CsvReader csvRead = null;
List<PnPriorityMt> resultList = new ArrayList<>();
try {
csvRead = CsvReader.newReader(fileURL, "料号", "料号");
int partNumberIndex = csvRead.getIndex("料号", "料号");
int modelIndex = csvRead.getIndex("机种", "机种");
int checkOutIndex = csvRead.getIndex("出库数量", "出库数量");
int priorityIndex = csvRead.getIndex("优先级", "优先级");
int row = 1;
while (csvRead.readRecord()) {
row++;
String[] lineValues = csvRead.getValues();
String partNumber = lineValues[partNumberIndex];
if (StringUtils.isEmpty(partNumber)) {
continue;
}
String modelValue = lineValues[modelIndex];
if (StringUtils.isEmpty(modelValue)) {
continue;
}
String priorityValue = lineValues[priorityIndex];
if (StringUtils.isEmpty(priorityValue)){
continue;
}
int priority = Integer.parseInt(priorityValue);
String checkOutValue = lineValues[checkOutIndex];
if (StringUtils.isEmpty(checkOutValue)){
continue;
}
int checkOutNum = Integer.parseInt(checkOutValue);
PnPriorityMt mt = new PnPriorityMt();
mt.setPriority(priority);
mt.setPartNumber(partNumber);
mt.setCheckOutNum(checkOutNum);
mt.setModelFamily(modelValue);
mt.setCheckOutNum(checkOutNum);
resultList.add(mt);
}
} catch (Exception ex) {
log.error("解析上传的工单出错:",ex);
} finally {
if (csvRead != null) {
csvRead.close();
}
}
return resultList;
}
public void downloadModel(HttpServletResponse response) throws IOException {
try {
List<Map<String, Object>> maps = new ArrayList<>();
List<String> titles = new ArrayList<>();
titles.add("料号");
titles.add("机种");
titles.add("出库数量");
titles.add("优先级");
for (int i = 1; i <= 10; i++) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("料号", "料号" + i);
map.put("机种", "机种" + i);
map.put("出库数量", i);
map.put("优先级", i);
maps.add(map);
}
FileUtil.downloadCSV(maps, titles, response);
} catch (Exception e) {
log.error("导出失败" + e.getMessage(), e);
}
}
} }
...@@ -11,4 +11,6 @@ public interface IPnPriorityMtManager extends IBaseManager<PnPriorityMt> { ...@@ -11,4 +11,6 @@ public interface IPnPriorityMtManager extends IBaseManager<PnPriorityMt> {
void deleteById(String id); void deleteById(String id);
List<PnPriorityMt> findByQuery(Query query, Pageable pageable); List<PnPriorityMt> findByQuery(Query query, Pageable pageable);
PnPriorityMt findOne(Query query);
} }
...@@ -55,4 +55,9 @@ public class PnPriorityMtManagerImpl implements IPnPriorityMtManager { ...@@ -55,4 +55,9 @@ public class PnPriorityMtManagerImpl implements IPnPriorityMtManager {
public List<PnPriorityMt> findByQuery(Query query, Pageable pageable) { public List<PnPriorityMt> findByQuery(Query query, Pageable pageable) {
return pnPriorityMtDao.findByQuery(query,pageable); return pnPriorityMtDao.findByQuery(query,pageable);
} }
@Override
public PnPriorityMt findOne(Query query) {
return pnPriorityMtDao.findOne(query);
}
} }
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!