|
|
|
package org.jeecg.modules.erp.trade.controller;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import java.net.URLDecoder;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
import cn.hutool.core.date.DatePattern;
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
|
import org.jeecg.common.system.query.QueryGenerator;
|
|
|
|
import org.jeecg.common.util.oConvertUtils;
|
|
|
|
import org.jeecg.modules.erp.trade.entity.*;
|
|
|
|
import org.jeecg.modules.erp.trade.service.*;
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
|
import org.jeecg.common.aspect.annotation.AutoLog;
|
|
|
|
import org.jeecg.common.system.base.controller.JeecgController;
|
|
|
|
import org.jeecg.modules.erp.trade.entity.*;
|
|
|
|
import org.jeecg.modules.erp.trade.service.*;
|
|
|
|
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
|
|
|
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
|
|
|
import org.jeecgframework.poi.excel.entity.ExportParams;
|
|
|
|
import org.jeecgframework.poi.excel.entity.ImportParams;
|
|
|
|
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
|
|
|
import org.jeecg.common.system.base.controller.JeecgController;
|
|
|
|
import org.jeecgframework.poi.exception.excel.ExcelImportException;
|
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
...
|
...
|
@@ -41,10 +25,13 @@ import org.springframework.web.bind.annotation.*; |
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import org.jeecg.common.aspect.annotation.AutoLog;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Description: 贸易库存表
|
|
...
|
...
|
@@ -92,10 +79,10 @@ public class TblTradeInventoryController extends JeecgController<TblTradeInvento |
|
|
|
|
|
|
|
QueryWrapper<TblTradeMeterial> queryWrapper = new QueryWrapper<>();
|
|
|
|
if (StringUtils.isNotBlank( tblTradeInventory.getMaterialDescription())){
|
|
|
|
queryWrapper.like("meterial_review", tblTradeInventory.getMaterialDescription());
|
|
|
|
queryWrapper.like("material_review", tblTradeInventory.getMaterialDescription());
|
|
|
|
}
|
|
|
|
if (StringUtils.isNotBlank(tblTradeInventory.getMaterialCode())){
|
|
|
|
queryWrapper.eq("meterial_code", tblTradeInventory.getMaterialCode());
|
|
|
|
queryWrapper.eq("material_code", tblTradeInventory.getMaterialCode());
|
|
|
|
}
|
|
|
|
if (StringUtils.isNotBlank(tblTradeInventory.getBrand())){
|
|
|
|
queryWrapper.like("brand", tblTradeInventory.getBrand());
|
|
...
|
...
|
@@ -104,8 +91,8 @@ public class TblTradeInventoryController extends JeecgController<TblTradeInvento |
|
|
|
Page<TblTradeMeterial> page = new Page<TblTradeMeterial>(pageNo, pageSize);
|
|
|
|
IPage<TblTradeMeterial> pageList = tblTradeMeterialService.page(page, queryWrapper);
|
|
|
|
List<TblTradeMeterial> records = pageList.getRecords();
|
|
|
|
//meterialCode 物料编码list
|
|
|
|
List<String> collect = records.stream().map(TblTradeMeterial::getMeterialCode).collect(Collectors.toList());
|
|
|
|
//materialCode 物料编码list
|
|
|
|
List<String> collect = records.stream().map(TblTradeMeterial::getMaterialCode).collect(Collectors.toList());
|
|
|
|
|
|
|
|
//根据物料编码查询库存
|
|
|
|
QueryWrapper<TblTradeInventory> tblTradeInventoryQueryWrapper = new QueryWrapper<>();
|
|
...
|
...
|
@@ -115,12 +102,13 @@ public class TblTradeInventoryController extends JeecgController<TblTradeInvento |
|
|
|
Map<String, TblTradeInventory> inventoryMap = list.stream().collect(Collectors.toMap(TblTradeInventory::getMaterialCode, e -> e));
|
|
|
|
|
|
|
|
for (TblTradeMeterial record : records) {
|
|
|
|
record.setActualInventory(inventoryMap.get(record.getMeterialCode()) == null ? 0 : inventoryMap.get(record.getMeterialCode()).getActualInventory() == null ? 0 : inventoryMap.get(record.getMeterialCode()).getActualInventory());
|
|
|
|
record.setQuantityInTransit(inventoryMap.get(record.getMeterialCode()) == null ? 0 : inventoryMap.get(record.getMeterialCode()).getQuantityInTransit() == null ? 0 : inventoryMap.get(record.getMeterialCode()).getQuantityInTransit());
|
|
|
|
record.setTotalQuantity(inventoryMap.get(record.getMeterialCode()) == null ? 0 : inventoryMap.get(record.getMeterialCode()).getTotalQuantity() == null ? 0 : inventoryMap.get(record.getMeterialCode()).getTotalQuantity());
|
|
|
|
record.setFirstStorageTime(inventoryMap.get(record.getMeterialCode()) == null ? null : inventoryMap.get(record.getMeterialCode()).getFirstStorageTime());
|
|
|
|
record.setLastOutboundTime(inventoryMap.get(record.getMeterialCode()) == null ? null : inventoryMap.get(record.getMeterialCode()).getLastOutboundTime());
|
|
|
|
if (record.getLastOutboundTime() != null) {
|
|
|
|
record.setInventoryBoh(inventoryMap.get(record.getMaterialCode()) == null ? 0 : inventoryMap.get(record.getMaterialCode()).getInventoryBoh() == null ? 0 : inventoryMap.get(record.getMaterialCode()).getInventoryBoh());
|
|
|
|
record.setActualInventory(inventoryMap.get(record.getMaterialCode()) == null ? 0 : inventoryMap.get(record.getMaterialCode()).getActualInventory() == null ? 0 : inventoryMap.get(record.getMaterialCode()).getActualInventory());
|
|
|
|
record.setQuantityInTransit(inventoryMap.get(record.getMaterialCode()) == null ? 0 : inventoryMap.get(record.getMaterialCode()).getQuantityInTransit() == null ? 0 : inventoryMap.get(record.getMaterialCode()).getQuantityInTransit());
|
|
|
|
record.setTotalQuantity(inventoryMap.get(record.getMaterialCode()) == null ? 0 : inventoryMap.get(record.getMaterialCode()).getTotalQuantity() == null ? 0 : inventoryMap.get(record.getMaterialCode()).getTotalQuantity());
|
|
|
|
record.setFirstStorageTime(inventoryMap.get(record.getMaterialCode()) == null ? null : inventoryMap.get(record.getMaterialCode()).getFirstStorageTime());
|
|
|
|
record.setLastOutboundTime(inventoryMap.get(record.getMaterialCode()) == null ? null : inventoryMap.get(record.getMaterialCode()).getLastOutboundTime());
|
|
|
|
if ((null != record.getLastOutboundTime()) && (null != record.getFirstStorageTime())) {
|
|
|
|
long daysDifference = calculateDaysDifference(new Date(), record.getFirstStorageTime());
|
|
|
|
record.setDaysInStock((int) daysDifference + 1);
|
|
|
|
}
|
|
...
|
...
|
@@ -141,7 +129,7 @@ public class TblTradeInventoryController extends JeecgController<TblTradeInvento |
|
|
|
|
|
|
|
/**
|
|
|
|
* 添加
|
|
|
|
*
|
|
|
|
*备注:总数量的逻辑有问题
|
|
|
|
* @param tblTradeInventory
|
|
|
|
* @return
|
|
|
|
*/
|
|
...
|
...
|
@@ -149,26 +137,25 @@ public class TblTradeInventoryController extends JeecgController<TblTradeInvento |
|
|
|
@ApiOperation(value = "贸易库存表-添加", notes = "贸易库存表-添加")
|
|
|
|
@PostMapping(value = "/add")
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
public Result<String> add(@RequestBody TblTradeInventory tblTradeInventory) {
|
|
|
|
//订单验证
|
|
|
|
public Result<String> add(@RequestBody TblTradeInventory tblTradeInventory){
|
|
|
|
Result<String> error = orderVerification(tblTradeInventory);
|
|
|
|
if (error != null) return error;
|
|
|
|
|
|
|
|
TblTradeInventoryIn tblTradeInventoryIn = new TblTradeInventoryIn();
|
|
|
|
//入库单号
|
|
|
|
tblTradeInventoryIn.setWaybillNum("BZSIN" + DatePattern.PURE_DATETIME_FORMAT.format(new Date()));
|
|
|
|
tblTradeInventoryIn.setMaterialCode(tblTradeInventory.getMaterialCode());
|
|
|
|
tblTradeInventoryIn.setMaterialDescription(tblTradeInventory.getMaterialDescription());
|
|
|
|
tblTradeInventoryIn.setMeasurementUnit(tblTradeInventory.getMeasurementUnit());
|
|
|
|
tblTradeInventoryIn.setBrand(tblTradeInventory.getBrand());
|
|
|
|
tblTradeInventoryIn.setInventoryQuantity(tblTradeInventory.getRksl());
|
|
|
|
tblTradeInventoryIn.setOperator(tblTradeInventory.getOperator());
|
|
|
|
tblTradeInventoryIn.setWaybillNum("BZSIN" + DatePattern.PURE_DATETIME_FORMAT.format(new Date()));//单号
|
|
|
|
tblTradeInventoryIn.setMaterialCode(tblTradeInventory.getMaterialCode());//物料编码
|
|
|
|
tblTradeInventoryIn.setMaterialDescription(tblTradeInventory.getMaterialDescription());//物料长描述
|
|
|
|
tblTradeInventoryIn.setMeasurementUnit(tblTradeInventory.getMeasurementUnit());//计量单位
|
|
|
|
tblTradeInventoryIn.setBrand(tblTradeInventory.getBrand());//品牌
|
|
|
|
tblTradeInventoryIn.setInventoryQuantity(tblTradeInventory.getRksl());//入库数量
|
|
|
|
tblTradeInventoryIn.setOperator(tblTradeInventory.getOperator());//采购员
|
|
|
|
tblTradeInventoryIn.setCreateTime(new Date());
|
|
|
|
tblTradeInventoryIn.setUpdateTime(new Date());
|
|
|
|
tblTradeInventoryIn.setDeliveryContractNumber(tblTradeInventory.getHth());
|
|
|
|
tblTradeInventoryIn.setExpressDeliveryNumber(tblTradeInventory.getWldh());
|
|
|
|
tblTradeInventoryIn.setSupplierName(tblTradeInventory.getCs());
|
|
|
|
tblTradeInventoryIn.setWarehouse(tblTradeInventory.getWarehouse());
|
|
|
|
tblTradeInventoryIn.setDeliveryContractNumber(tblTradeInventory.getHth());//交货合同编号
|
|
|
|
tblTradeInventoryIn.setExpressDeliveryNumber(tblTradeInventory.getWldh());//合同单号/快递单号
|
|
|
|
tblTradeInventoryIn.setSupplierName(tblTradeInventory.getCs());//供货商名称
|
|
|
|
tblTradeInventoryIn.setWarehouse(tblTradeInventory.getWarehouse());//仓库
|
|
|
|
tblTradeInventoryIn.setType("入库");
|
|
|
|
//根据 物流编码 查询库存信息 如存在库存信息则进行修改库存信息,不存在则新增库存信息
|
|
|
|
String hth = tblTradeInventory.getHth();
|
|
...
|
...
|
@@ -181,12 +168,12 @@ public class TblTradeInventoryController extends JeecgController<TblTradeInvento |
|
|
|
//修改订单信息
|
|
|
|
String purchaseId = tblTradeInventory.getPurchaseId();
|
|
|
|
TblTradePurchaseInfo tblTradePurchaseInfo = tblTradePurchaseInfoService.getById(purchaseId);
|
|
|
|
Integer yrkNum = tblTradePurchaseInfo.getYrkNum() == null ? 0 : tblTradePurchaseInfo.getYrkNum();
|
|
|
|
Integer rksl = tblTradeInventory.getRksl() == null ? 0 : tblTradeInventory.getRksl();
|
|
|
|
Integer yrkNum = tblTradePurchaseInfo.getYrkNum() == null ? 0 : tblTradePurchaseInfo.getYrkNum();//已入库数量
|
|
|
|
Integer rksl = tblTradeInventory.getRksl() == null ? 0 : tblTradeInventory.getRksl();//入库数量
|
|
|
|
tblTradePurchaseInfo.setYrkNum(yrkNum + rksl);
|
|
|
|
Integer wrkNum = tblTradePurchaseInfo.getWrkNum() == null ? 0 : tblTradePurchaseInfo.getWrkNum();
|
|
|
|
tblTradePurchaseInfo.setWrkNum(wrkNum - rksl);
|
|
|
|
tblTradePurchaseInfoService.updateById(tblTradePurchaseInfo);
|
|
|
|
Integer wrkNum = tblTradePurchaseInfo.getWrkNum() == null ? 0 : tblTradePurchaseInfo.getWrkNum();//未入库数量
|
|
|
|
tblTradePurchaseInfo.setWrkNum( tblTradePurchaseInfo.getPurchaseQuantity()- rksl);
|
|
|
|
tblTradePurchaseInfoService.updateById(tblTradePurchaseInfo);//更新采购信息
|
|
|
|
|
|
|
|
if (tradeInventory == null) {
|
|
|
|
kcl = rksl;
|
|
...
|
...
|
@@ -216,12 +203,12 @@ public class TblTradeInventoryController extends JeecgController<TblTradeInvento |
|
|
|
//当前库存
|
|
|
|
Integer actualInventory = tradeInventory.getActualInventory();
|
|
|
|
|
|
|
|
kcl = rksl + actualInventory;
|
|
|
|
kcl = rksl + (null == actualInventory ? 0 : actualInventory);
|
|
|
|
|
|
|
|
//在途数量
|
|
|
|
Integer wrk =tblTradePurchaseInfoService.getWrkNum(tblTradeInventory.getMaterialCode());
|
|
|
|
wrk = wrk == null ? 0 : wrk;
|
|
|
|
tblTradeInventory.setQuantityInTransit(wrk);
|
|
|
|
tblTradeInventory.setQuantityInTransit(wrk);//在途数量
|
|
|
|
Integer yrk = tblTradePurchaseInfoService.getYrkNumByMaterialCode(tblTradeInventory.getMaterialCode());
|
|
|
|
yrk = yrk == null ? 0 : yrk;
|
|
|
|
Integer ck = tblTradeInventoryOutService.getOutboundQuantityByMaterialCode(tblTradeInventory.getMaterialCode());
|
|
...
|
...
|
@@ -344,6 +331,20 @@ public class TblTradeInventoryController extends JeecgController<TblTradeInvento |
|
|
|
return Result.OK("出库成功!");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 更新BOH
|
|
|
|
*
|
|
|
|
* @param tblTradeInventory
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@AutoLog(value = "贸易库存表-BOH更新")
|
|
|
|
@ApiOperation(value = "贸易库存表-BOH更新", notes = "贸易库存表-BOH更新")
|
|
|
|
@RequestMapping(value = "/updateBoh", method = {RequestMethod.PUT, RequestMethod.POST})
|
|
|
|
public Result<String> updateBoh(@RequestBody TblTradeInventoryUpdateBoh tblTradeInventory) {
|
|
|
|
tblTradeInventoryService.updateBohAndActual(tblTradeInventory);
|
|
|
|
return Result.OK("BOH更新成功!");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 编辑
|
|
...
|
...
|
@@ -427,4 +428,72 @@ public class TblTradeInventoryController extends JeecgController<TblTradeInvento |
|
|
|
return super.importExcel(request, response, TblTradeInventory.class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 批量更新BOH
|
|
|
|
*
|
|
|
|
* @param request
|
|
|
|
* @param response
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@RequestMapping(value = "/importExcelBoh", method = RequestMethod.POST)
|
|
|
|
public Result<?> importExcelBoh(HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
|
|
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
|
|
|
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
|
|
|
// 获取上传文件对象
|
|
|
|
MultipartFile file = entity.getValue();
|
|
|
|
ImportParams params = new ImportParams();
|
|
|
|
params.setTitleRows(2);
|
|
|
|
params.setHeadRows(1);
|
|
|
|
params.setNeedSave(true);
|
|
|
|
try {
|
|
|
|
List<TblTradeInventoryUpdateBoh> list = ExcelImportUtil.importExcel(file.getInputStream(), TblTradeInventoryUpdateBoh.class, params);
|
|
|
|
|
|
|
|
// List<TblTradeInventory> tblTradeMeterialArrayList = new ArrayList<>();
|
|
|
|
for (TblTradeInventoryUpdateBoh tblTradeInventoryUpdateBoh : list) {
|
|
|
|
if (tblTradeInventoryUpdateBoh != null) {
|
|
|
|
if(StrUtil.isBlank(tblTradeInventoryUpdateBoh.getMaterialCode()) || StrUtil.isBlank(tblTradeInventoryUpdateBoh.getMaterialDescription()) || (null == tblTradeInventoryUpdateBoh.getInventoryBoh())){
|
|
|
|
return Result.error("文件导入失败,编码、物料长描述、BOH有空白!");
|
|
|
|
}
|
|
|
|
// tblTradeMeterialArrayList.add(new TblTradeInventory(tblTradeMeterial));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// if(!tblTradeMeterialArrayList.isEmpty()){
|
|
|
|
// 如果有数据需要保存,则批量保存
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
tblTradeInventoryService.updateBohAndActualBatch(list);
|
|
|
|
log.info("批量保存消耗时间:" + (System.currentTimeMillis() - start) + "毫秒");
|
|
|
|
if(list.size()<=0){
|
|
|
|
return Result.error("没有有效的导入数据");
|
|
|
|
}
|
|
|
|
return Result.ok("文件导入成功!数据行数:" + list.size());
|
|
|
|
// } else {
|
|
|
|
// return Result.error("文件导入失败:没有有效的数据需要保存!");
|
|
|
|
// }
|
|
|
|
|
|
|
|
}catch (ExcelImportException e) {
|
|
|
|
return Result.error("文件导入失败,导入数据格式错误");
|
|
|
|
} catch (Exception e) {
|
|
|
|
log.error(e.getMessage());
|
|
|
|
//update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示
|
|
|
|
String msg = e.getMessage();
|
|
|
|
log.error(msg, e);
|
|
|
|
if(msg!=null && msg.indexOf("Duplicate entry")>=0){
|
|
|
|
return Result.error("文件导入失败:有重复数据!");
|
|
|
|
}else{
|
|
|
|
return Result.error("文件导入失败:" + e.getMessage());
|
|
|
|
}
|
|
|
|
//update-end-author:taoyan date:20211124 for: 导入数据重复增加提示
|
|
|
|
} finally {
|
|
|
|
try {
|
|
|
|
file.getInputStream().close();
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Result.error("文件导入失败!");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} |
...
|
...
|
|