|
|
|
package org.jeecg.modules.erp.trade.controller;
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
import cn.hutool.core.date.DatePattern;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
|
import org.jeecg.common.system.query.QueryGenerator;
|
|
|
|
import org.jeecg.modules.erp.trade.entity.*;
|
|
|
|
import org.jeecg.modules.erp.trade.service.*;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
import org.jeecg.common.system.base.controller.JeecgController;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import org.jeecg.common.aspect.annotation.AutoLog;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Description: tbl_trade_purchase_info
|
|
|
|
* @Author: jeecg-boot
|
|
|
|
* @Date: 2025-03-19
|
|
|
|
* @Version: V1.0
|
|
|
|
*/
|
|
|
|
@Api(tags="tbl_trade_purchase_info")
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("/trade/tblTradePurchaseInfo")
|
|
|
|
@Slf4j
|
|
|
|
public class TblTradePurchaseInfoController extends JeecgController<TblTradePurchaseInfo, ITblTradePurchaseInfoService> {
|
|
|
|
@Autowired
|
|
|
|
private ITblTradePurchaseInfoService tblTradePurchaseInfoService;
|
|
|
|
@Autowired
|
|
|
|
private ITblTradeBidMaterialDetailsService tblTradeBidMaterialDetailsService;
|
|
|
|
@Autowired
|
|
|
|
private ITblTradeInventoryService tblTradeInventoryService;
|
|
|
|
@Value(value = "${jeecg.path.upload}")
|
|
|
|
private String uploadpath;
|
|
|
|
@Autowired
|
|
|
|
private ITblTradeTenderInfoService tblTradeTenderInfoService;
|
|
|
|
@Autowired
|
|
|
|
private ITblTradeInquiryInfoService tblTradeInquiryInfoService;
|
|
|
|
@Autowired
|
|
|
|
private ITblTradeMeterialService tblTradeMeterialService;
|
|
|
|
@Autowired
|
|
|
|
private ITblTradeInventoryInService tblTradeInventoryInService;
|
|
|
|
@Autowired
|
|
|
|
private ITblTradeInventoryOutService tblTradeInventoryOutService;
|
|
|
|
@Autowired
|
|
|
|
private ITblTradeInventoryDefectiveProductService tblTradeInventoryDefectiveProductService;
|
|
|
|
/**
|
|
|
|
* 分页列表查询
|
|
|
|
*
|
|
|
|
* @param tblTradePurchaseInfo
|
|
|
|
* @param pageNo
|
|
|
|
* @param pageSize
|
|
|
|
* @param req
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
//@AutoLog(value = "tbl_trade_purchase_info-分页列表查询")
|
|
|
|
@ApiOperation(value="tbl_trade_purchase_info-分页列表查询", notes="tbl_trade_purchase_info-分页列表查询")
|
|
|
|
@GetMapping(value = "/list")
|
|
|
|
public Result<IPage<TblTradePurchaseInfo>> queryPageList(TblTradePurchaseInfo tblTradePurchaseInfo,
|
|
|
|
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
|
|
|
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
|
|
|
HttpServletRequest req) {
|
|
|
|
QueryWrapper<TblTradePurchaseInfo> queryWrapper = QueryGenerator.initQueryWrapper(tblTradePurchaseInfo, req.getParameterMap());
|
|
|
|
Page<TblTradePurchaseInfo> page = new Page<TblTradePurchaseInfo>(pageNo, pageSize);
|
|
|
|
IPage<TblTradePurchaseInfo> pageList = tblTradePurchaseInfoService.page(page, queryWrapper);
|
|
|
|
return Result.OK(pageList);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value="采买列表", notes="采买列表查询")
|
|
|
|
@GetMapping(value = "/purchaseList")
|
|
|
|
public Result<IPage<TblTradeBidMaterialDetails>> purchaseList(TblTradeBidMaterialDetails tblTradeBidMaterialDetails,
|
|
|
|
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
|
|
|
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
|
|
|
HttpServletRequest req) {
|
|
|
|
QueryWrapper<TblTradeBidMaterialDetails> queryWrapper = QueryGenerator.initQueryWrapper(tblTradeBidMaterialDetails, req.getParameterMap());
|
|
|
|
Page<TblTradeBidMaterialDetails> page = new Page<>(pageNo, pageSize);
|
|
|
|
Page<TblTradeBidMaterialDetails> pageList = tblTradeBidMaterialDetailsService.page(page, queryWrapper);
|
|
|
|
//获取库存数量
|
|
|
|
pageList.getRecords().forEach(item->{
|
|
|
|
//获取库存数量
|
|
|
|
Integer inventoryNum = tblTradeInventoryService.getInventoryNum(item.getMaterialCode());
|
|
|
|
item.setInventoryNum(inventoryNum);
|
|
|
|
Integer purchaseQuantityNum = tblTradePurchaseInfoService.getPurchaseQuantityNumByMaterialCode(item.getMaterialCode());
|
|
|
|
item.setOrderQuantity(purchaseQuantityNum);
|
|
|
|
});
|
|
|
|
|
|
|
|
return Result.OK(pageList);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "获取历史询价信息", notes = "获取历史询价信息")
|
|
|
|
@GetMapping(value = "/getHistoryInquiryInfo")
|
|
|
|
public Result<List<TblTradeInquiryInfo>> getHistoryInquiryInfo(TblTradePurchaseInfo tblTradePurchaseInfo) {
|
|
|
|
|
|
|
|
String bidNum = tblTradePurchaseInfo.getBidNum();
|
|
|
|
String materialCode = tblTradePurchaseInfo.getWlbh();
|
|
|
|
QueryWrapper<TblTradeTenderInfo> queryWrapper = new QueryWrapper<>();
|
|
|
|
queryWrapper.eq("xjbswjh", bidNum);
|
|
|
|
queryWrapper.eq("code", materialCode);
|
|
|
|
List<TblTradeTenderInfo> tblTradeTenderInfoList = tblTradeTenderInfoService.list(queryWrapper);
|
|
|
|
TblTradeTenderInfo tblTradeTenderInfo;
|
|
|
|
if (!CollectionUtil.isEmpty(tblTradeTenderInfoList)) {
|
|
|
|
tblTradeTenderInfo = tblTradeTenderInfoList.get(0);
|
|
|
|
String id = tblTradeTenderInfo.getId();
|
|
|
|
QueryWrapper<TblTradeInquiryInfo> queryWrapper1 = new QueryWrapper<>();
|
|
|
|
queryWrapper1.eq("trade_id", id);
|
|
|
|
List<TblTradeInquiryInfo> tblTradeInquiryInfoList = tblTradeInquiryInfoService.list(queryWrapper1);
|
|
|
|
return Result.OK(tblTradeInquiryInfoList);
|
|
|
|
}
|
|
|
|
return Result.OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value="获取采购信息", notes="获取采购信息")
|
|
|
|
@GetMapping(value = "/getCgInfo")
|
|
|
|
public Result<Map<String, List<TblTradePurchaseInfo>>> getCgInfo(TblTradePurchaseInfo tblTradePurchaseInfo) {
|
|
|
|
String materialCode = tblTradePurchaseInfo.getWlbh();
|
|
|
|
QueryWrapper<TblTradePurchaseInfo> queryWrapper = new QueryWrapper<>();
|
|
|
|
if (StringUtils.isNotBlank(materialCode)) {
|
|
|
|
queryWrapper.eq("wlbh", materialCode);
|
|
|
|
}
|
|
|
|
List<TblTradePurchaseInfo> list = tblTradePurchaseInfoService.list(queryWrapper);
|
|
|
|
list.forEach(item->{
|
|
|
|
String wlbh = item.getWlbh();
|
|
|
|
String hth = item.getHth();
|
|
|
|
QueryWrapper<TblTradeInventoryDefectiveProduct> queryWrapper1 = new QueryWrapper<>();
|
|
|
|
queryWrapper1.eq("material_code", wlbh);
|
|
|
|
queryWrapper1.eq("express_delivery_number", hth);
|
|
|
|
List<TblTradeInventoryDefectiveProduct> list1 = tblTradeInventoryDefectiveProductService.list(queryWrapper1);
|
|
|
|
if (!CollectionUtil.isEmpty(list1)) {
|
|
|
|
item.setBlpNum(list1.stream().map(TblTradeInventoryDefectiveProduct::getBlpsl).reduce(Integer::sum).get());
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
//已采购
|
|
|
|
List<TblTradePurchaseInfo> collect = list.stream().filter(e -> e.getStatus() == 3).collect(Collectors.toList());
|
|
|
|
//待采购
|
|
|
|
List<TblTradePurchaseInfo> collect2 = list.stream().filter(e -> e.getStatus() != 3).collect(Collectors.toList());
|
|
|
|
|
|
|
|
Map<String, List<TblTradePurchaseInfo>> map = new HashMap<>();
|
|
|
|
map.put("dcgList", collect2);
|
|
|
|
map.put("ycgList", collect);
|
|
|
|
return Result.OK(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 添加
|
|
|
|
*
|
|
|
|
* @param tblTradePurchaseInfo
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@AutoLog(value = "tbl_trade_purchase_info-添加")
|
|
|
|
@ApiOperation(value="tbl_trade_purchase_info-添加", notes="tbl_trade_purchase_info-添加")
|
|
|
|
@PostMapping(value = "/add")
|
|
|
|
public Result<String> add(@RequestBody TblTradePurchaseInfo tblTradePurchaseInfo) {
|
|
|
|
if (tblTradePurchaseInfo.getPurchaseQuantity() != null && tblTradePurchaseInfo.getPurchaseQuantity() > 0) {
|
|
|
|
tblTradePurchaseInfo.setWrkNum(tblTradePurchaseInfo.getPurchaseQuantity());
|
|
|
|
}
|
|
|
|
tblTradePurchaseInfo.setStatus(0);
|
|
|
|
tblTradePurchaseInfoService.save(tblTradePurchaseInfo);
|
|
|
|
return Result.OK("添加成功!");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 编辑
|
|
|
|
*
|
|
|
|
* @param tblTradePurchaseInfo
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@AutoLog(value = "tbl_trade_purchase_info-编辑")
|
|
|
|
@ApiOperation(value="tbl_trade_purchase_info-编辑", notes="tbl_trade_purchase_info-编辑")
|
|
|
|
@RequestMapping(value = "/audit", method = {RequestMethod.PUT,RequestMethod.POST})
|
|
|
|
public Result<String> audit(@RequestBody TblTradePurchaseInfo tblTradePurchaseInfo) {
|
|
|
|
//验证
|
|
|
|
String hth = tblTradePurchaseInfo.getHth();
|
|
|
|
if (StringUtils.isNotBlank(hth) &&
|
|
|
|
(tblTradePurchaseInfo.getThhPj() == null || tblTradePurchaseInfo.getGysPj() == null )
|
|
|
|
) {
|
|
|
|
QueryWrapper<TblTradePurchaseInfo> queryWrapper = new QueryWrapper<>();
|
|
|
|
queryWrapper.eq("hth", hth);
|
|
|
|
List<TblTradePurchaseInfo> list = tblTradePurchaseInfoService.list(queryWrapper);
|
|
|
|
if (!CollectionUtil.isEmpty(list)) {
|
|
|
|
return Result.error("合同号已存在");
|
|
|
|
}
|
|
|
|
//修改库存信息
|
|
|
|
QueryWrapper<TblTradeInventory> wrapper = new QueryWrapper<>();
|
|
|
|
wrapper.eq("material_code", tblTradePurchaseInfo.getWlbh());
|
|
|
|
List<TblTradeInventory> list1 = tblTradeInventoryService.list(wrapper);
|
|
|
|
|
|
|
|
QueryWrapper<TblTradeMeterial> queryWrapper1 = new QueryWrapper<>();
|
|
|
|
queryWrapper1.eq("meterial_code", tblTradePurchaseInfo.getWlbh());
|
|
|
|
List<TblTradeMeterial> tradeMeterials = tblTradeMeterialService.list(queryWrapper1);
|
|
|
|
|
|
|
|
if (!CollectionUtil.isEmpty(tradeMeterials)) {
|
|
|
|
TblTradeMeterial tblTradeMeterial = tradeMeterials.get(0);
|
|
|
|
TblTradeInventory tblTradeInventory = new TblTradeInventory();
|
|
|
|
tblTradeInventory.setMaterialCode(tblTradePurchaseInfo.getWlbh());
|
|
|
|
tblTradeInventory.setHth(hth);
|
|
|
|
tblTradeInventory.setMaterialDescription(tblTradeMeterial.getMeterialReview());
|
|
|
|
tblTradeInventory.setMeasurementUnit(tblTradeMeterial.getUnit());
|
|
|
|
tblTradeInventory.setBrand(tblTradeMeterial.getBrand());
|
|
|
|
tblTradeInventory.setActualInventory(0);
|
|
|
|
tblTradeInventory.setQuantityInTransit(0);
|
|
|
|
tblTradeInventory.setTotalQuantity(tblTradePurchaseInfo.getPurchaseQuantity());
|
|
|
|
//单价
|
|
|
|
tblTradeInventory.setUnitPrice(tblTradePurchaseInfo.getUnitPrice());
|
|
|
|
tblTradeInventory.setFirstStorageTime(new Date());
|
|
|
|
tblTradeInventory.setCs(tblTradePurchaseInfo.getSupplier());
|
|
|
|
tblTradeInventory.setTaxRate(tblTradePurchaseInfo.getTaxRate());
|
|
|
|
//仓库、采购员
|
|
|
|
if (CollectionUtil.isEmpty(list1)) {
|
|
|
|
tblTradeInventoryService.save(tblTradeInventory);
|
|
|
|
}else {
|
|
|
|
TblTradeInventory tblTradeInventory1 = list1.get(0);
|
|
|
|
tblTradeInventory1.setTotalQuantity(tblTradeInventory1.getTotalQuantity() + tblTradePurchaseInfo.getPurchaseQuantity());
|
|
|
|
tblTradeInventory1.setQuantityInTransit(tblTradeInventory1.getQuantityInTransit() + tblTradePurchaseInfo.getPurchaseQuantity());
|
|
|
|
tblTradeInventoryService.updateById(tblTradeInventory1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
tblTradePurchaseInfoService.updateById(tblTradePurchaseInfo);
|
|
|
|
return Result.OK("编辑成功!");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 编辑
|
|
|
|
*
|
|
|
|
* @param tblTradePurchaseInfo
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@AutoLog(value = "tbl_trade_purchase_info-编辑")
|
|
|
|
@ApiOperation(value="tbl_trade_purchase_info-编辑", notes="tbl_trade_purchase_info-编辑")
|
|
|
|
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
public Result<String> edit(@RequestBody TblTradePurchaseInfo tblTradePurchaseInfo) {
|
|
|
|
//获取本条数据所有信息
|
|
|
|
TblTradePurchaseInfo purchaseInfo = tblTradePurchaseInfoService.getById(tblTradePurchaseInfo.getId());
|
|
|
|
if (purchaseInfo == null) {
|
|
|
|
return Result.error("未找到对应数据");
|
|
|
|
}
|
|
|
|
//订单数量
|
|
|
|
Integer purchaseQuantity = purchaseInfo.getPurchaseQuantity();
|
|
|
|
//本次入库数量
|
|
|
|
Integer rkNum = tblTradePurchaseInfo.getRkNum();
|
|
|
|
if (purchaseQuantity < rkNum) {
|
|
|
|
return Result.error("入库数量不能大于订单数量");
|
|
|
|
}
|
|
|
|
//未入库数量
|
|
|
|
Integer wrkNum = purchaseInfo.getWrkNum();
|
|
|
|
wrkNum = wrkNum == null ? 0 : wrkNum;
|
|
|
|
Integer yrkNum = purchaseInfo.getYrkNum();
|
|
|
|
yrkNum = yrkNum == null ? 0 : yrkNum;
|
|
|
|
if (rkNum > wrkNum) {
|
|
|
|
return Result.error("入库数量不能大于未入库数量");
|
|
|
|
}
|
|
|
|
// if (tblTradePurchaseInfo.getBlpNum() != null && tblTradePurchaseInfo.getBlpNum() >0){
|
|
|
|
// //不良品入库
|
|
|
|
// blpStore(tblTradePurchaseInfo);
|
|
|
|
// }
|
|
|
|
|
|
|
|
tblTradePurchaseInfo.setYrkNum(yrkNum + rkNum);
|
|
|
|
tblTradePurchaseInfo.setWrkNum(wrkNum - rkNum);
|
|
|
|
tblTradePurchaseInfoService.updateById(tblTradePurchaseInfo);
|
|
|
|
//入库
|
|
|
|
store(rkNum,tblTradePurchaseInfo,purchaseQuantity);
|
|
|
|
|
|
|
|
|
|
|
|
return Result.OK("编辑成功!");
|
|
|
|
}
|
|
|
|
// //不良品入库
|
|
|
|
// private void blpStore(TblTradePurchaseInfo tblTradePurchaseInfo){
|
|
|
|
// TblTradeInventoryDefectiveProduct defectiveProduct = new TblTradeInventoryDefectiveProduct();
|
|
|
|
// defectiveProduct.setWaybillNum("BZSOUT"+ DatePattern.PURE_DATETIME_FORMAT.format(new Date()));
|
|
|
|
// defectiveProduct.setMaterialCode(tblTradePurchaseInfo.getWlbh());
|
|
|
|
// QueryWrapper<TblTradeMeterial> queryWrapper1 = new QueryWrapper<>();
|
|
|
|
// queryWrapper1.eq("meterial_code", tblTradePurchaseInfo.getWlbh());
|
|
|
|
// //物料信息
|
|
|
|
// List<TblTradeMeterial> tradeMeterials = tblTradeMeterialService.list(queryWrapper1);
|
|
|
|
// if (!CollectionUtil.isEmpty(tradeMeterials)) {
|
|
|
|
// TblTradeMeterial tblTradeMeterial = tradeMeterials.get(0);
|
|
|
|
// defectiveProduct.setBrand(tblTradeMeterial.getBrand());
|
|
|
|
// defectiveProduct.setMaterialDescription(tblTradeMeterial.getMeterialReview());
|
|
|
|
// defectiveProduct.setMeasurementUnit()
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
//入库
|
|
|
|
private void store(Integer rkNum, TblTradePurchaseInfo tblTradePurchaseInfo, Integer purchaseQuantity){
|
|
|
|
//合同号
|
|
|
|
String hth = tblTradePurchaseInfo.getHth();
|
|
|
|
//物料编号
|
|
|
|
String wlbh = tblTradePurchaseInfo.getWlbh();
|
|
|
|
//根据物料编号查询库存信息,如果有则更新,没有则新增
|
|
|
|
QueryWrapper<TblTradeInventory> queryWrapper = new QueryWrapper<>();
|
|
|
|
queryWrapper.eq("material_code", wlbh);
|
|
|
|
//库存信息
|
|
|
|
List<TblTradeInventory> list = tblTradeInventoryService.list(queryWrapper);
|
|
|
|
QueryWrapper<TblTradeMeterial> queryWrapper1 = new QueryWrapper<>();
|
|
|
|
queryWrapper1.eq("meterial_code", wlbh);
|
|
|
|
List<TblTradeMeterial> tradeMeterials = tblTradeMeterialService.list(queryWrapper1);
|
|
|
|
if (CollectionUtil.isEmpty(list)) {
|
|
|
|
//为空,新增库存记录
|
|
|
|
//根据物料编码查询物料信息
|
|
|
|
|
|
|
|
if (CollectionUtil.isEmpty(tradeMeterials)) {
|
|
|
|
return;
|
|
|
|
}else {
|
|
|
|
TblTradeMeterial tblTradeMeterial = tradeMeterials.get(0);
|
|
|
|
TblTradeInventory tblTradeInventory = new TblTradeInventory();
|
|
|
|
tblTradeInventory.setMaterialCode(wlbh);
|
|
|
|
tblTradeInventory.setHth(hth);
|
|
|
|
tblTradeInventory.setMaterialDescription(tblTradeMeterial.getMeterialReview());
|
|
|
|
tblTradeInventory.setMeasurementUnit(tblTradeMeterial.getUnit());
|
|
|
|
tblTradeInventory.setBrand(tblTradeMeterial.getBrand());
|
|
|
|
|
|
|
|
String meterialCode = tblTradeMeterial.getMeterialCode();
|
|
|
|
Integer yrk = tblTradePurchaseInfoService.getYrkNumByMaterialCode(meterialCode);
|
|
|
|
yrk = yrk == null ? 0 : yrk;
|
|
|
|
Integer ck = tblTradeInventoryOutService.getOutboundQuantityByMaterialCode(meterialCode);
|
|
|
|
ck = ck == null ? 0 : ck;
|
|
|
|
Integer wrk =tblTradePurchaseInfoService.getWrkNum(meterialCode);
|
|
|
|
wrk = wrk == null ? 0 : wrk;
|
|
|
|
tblTradeInventory.setActualInventory(yrk-ck);
|
|
|
|
tblTradeInventory.setQuantityInTransit(wrk);
|
|
|
|
Integer purchaseQuantityNum = tblTradePurchaseInfoService.getPurchaseQuantityNumByMaterialCode(meterialCode);
|
|
|
|
purchaseQuantityNum = purchaseQuantityNum == null ? 0 : purchaseQuantityNum;
|
|
|
|
tblTradeInventory.setTotalQuantity(purchaseQuantityNum);
|
|
|
|
//单价
|
|
|
|
tblTradeInventory.setUnitPrice(tblTradePurchaseInfo.getUnitPrice());
|
|
|
|
tblTradeInventory.setFirstStorageTime(new Date());
|
|
|
|
tblTradeInventory.setCs(tblTradePurchaseInfo.getSupplier());
|
|
|
|
tblTradeInventory.setTaxRate(tblTradePurchaseInfo.getTaxRate());
|
|
|
|
tblTradeInventory.setTotalPrice(BigDecimal.valueOf(rkNum * tblTradePurchaseInfo.getUnitPrice().doubleValue()));
|
|
|
|
//仓库、采购员
|
|
|
|
tblTradeInventoryService.save(tblTradeInventory);
|
|
|
|
//新增入库记录
|
|
|
|
TblTradeInventoryIn tblTradeInventoryIn = new TblTradeInventoryIn();
|
|
|
|
//入库单号
|
|
|
|
tblTradeInventoryIn.setWaybillNum("BZSIN" + DatePattern.PURE_DATETIME_FORMAT.format(new Date()));
|
|
|
|
tblTradeInventoryIn.setMaterialCode(wlbh);
|
|
|
|
tblTradeInventoryIn.setMaterialDescription(tblTradeMeterial.getMeterialReview());
|
|
|
|
tblTradeInventoryIn.setMeasurementUnit(tblTradeMeterial.getUnit());
|
|
|
|
tblTradeInventoryIn.setBrand(tblTradeMeterial.getBrand());
|
|
|
|
tblTradeInventoryIn.setActualInventory(rkNum);
|
|
|
|
tblTradeInventoryIn.setInventoryQuantity(rkNum);
|
|
|
|
tblTradeInventoryIn.setExpressDeliveryNumber(tblTradePurchaseInfo.getWlbh());
|
|
|
|
tblTradeInventoryIn.setSupplierName(tblTradePurchaseInfo.getSupplier());
|
|
|
|
tblTradeInventoryIn.setDeliveryContractNumber(hth);
|
|
|
|
tblTradeInventoryIn.setType("入库");
|
|
|
|
tblTradeInventoryInService.save(tblTradeInventoryIn);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
TblTradeMeterial tblTradeMeterial = tradeMeterials.get(0);
|
|
|
|
//不为空,更新库存记录
|
|
|
|
//历史库存
|
|
|
|
TblTradeInventory tblTradeInventory = list.get(0);
|
|
|
|
//更新实际库存量
|
|
|
|
// 获取该物料的所有订单的已入库数量 减去 该物料所有的出库记录中出库数量
|
|
|
|
// 获取该物料的所有订单的已入库数量
|
|
|
|
String meterialCode = tblTradeMeterial.getMeterialCode();
|
|
|
|
Integer yrk = tblTradePurchaseInfoService.getYrkNumByMaterialCode(meterialCode);
|
|
|
|
yrk = yrk == null ? 0 : yrk;
|
|
|
|
Integer ck = tblTradeInventoryOutService.getOutboundQuantityByMaterialCode(meterialCode);
|
|
|
|
ck = ck == null ? 0 : ck;
|
|
|
|
Integer wrk =tblTradePurchaseInfoService.getWrkNum(meterialCode);
|
|
|
|
wrk = wrk == null ? 0 : wrk;
|
|
|
|
Integer purchaseQuantityNum = tblTradePurchaseInfoService.getPurchaseQuantityNumByMaterialCode(meterialCode);
|
|
|
|
tblTradeInventory.setTotalQuantity(purchaseQuantityNum - ck);
|
|
|
|
|
|
|
|
tblTradeInventory.setActualInventory(yrk-ck);
|
|
|
|
tblTradeInventory.setQuantityInTransit(wrk);
|
|
|
|
|
|
|
|
tblTradeInventoryService.updateById(tblTradeInventory);
|
|
|
|
//入库单号
|
|
|
|
TblTradeInventoryIn tblTradeInventoryIn = new TblTradeInventoryIn();
|
|
|
|
tblTradeInventoryIn.setWaybillNum("BZSIN" + DatePattern.PURE_DATETIME_FORMAT.format(new Date()));
|
|
|
|
tblTradeInventoryIn.setMaterialCode(wlbh);
|
|
|
|
tblTradeInventoryIn.setMaterialDescription(tblTradeMeterial.getMeterialReview());
|
|
|
|
tblTradeInventoryIn.setMeasurementUnit(tblTradeMeterial.getUnit());
|
|
|
|
tblTradeInventoryIn.setBrand(tblTradeMeterial.getBrand());
|
|
|
|
tblTradeInventoryIn.setActualInventory(rkNum);
|
|
|
|
tblTradeInventoryIn.setInventoryQuantity(rkNum);
|
|
|
|
tblTradeInventoryIn.setExpressDeliveryNumber(tblTradePurchaseInfo.getWlbh());
|
|
|
|
tblTradeInventoryIn.setSupplierName(tblTradePurchaseInfo.getSupplier());
|
|
|
|
tblTradeInventoryIn.setDeliveryContractNumber(hth);
|
|
|
|
tblTradeInventoryIn.setType("入库");
|
|
|
|
tblTradeInventoryInService.save(tblTradeInventoryIn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 通过id删除
|
|
|
|
*
|
|
|
|
* @param id
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@AutoLog(value = "tbl_trade_purchase_info-通过id删除")
|
|
|
|
@ApiOperation(value="tbl_trade_purchase_info-通过id删除", notes="tbl_trade_purchase_info-通过id删除")
|
|
|
|
@DeleteMapping(value = "/delete")
|
|
|
|
public Result<String> delete(@RequestParam(name="id",required=true) String id) {
|
|
|
|
tblTradePurchaseInfoService.removeById(id);
|
|
|
|
return Result.OK("删除成功!");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 批量删除
|
|
|
|
*
|
|
|
|
* @param ids
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@AutoLog(value = "tbl_trade_purchase_info-批量删除")
|
|
|
|
@ApiOperation(value="tbl_trade_purchase_info-批量删除", notes="tbl_trade_purchase_info-批量删除")
|
|
|
|
@DeleteMapping(value = "/deleteBatch")
|
|
|
|
public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
|
|
|
this.tblTradePurchaseInfoService.removeByIds(Arrays.asList(ids.split(",")));
|
|
|
|
return Result.OK("批量删除成功!");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 通过id查询
|
|
|
|
*
|
|
|
|
* @param id
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
//@AutoLog(value = "tbl_trade_purchase_info-通过id查询")
|
|
|
|
@ApiOperation(value="tbl_trade_purchase_info-通过id查询", notes="tbl_trade_purchase_info-通过id查询")
|
|
|
|
@GetMapping(value = "/queryById")
|
|
|
|
public Result<TblTradePurchaseInfo> queryById(@RequestParam(name="id",required=true) String id) {
|
|
|
|
TblTradePurchaseInfo tblTradePurchaseInfo = tblTradePurchaseInfoService.getById(id);
|
|
|
|
// tblTradePurchaseInfo.setBlpNum(tblTradePurchaseInfo.getBlpNum() == null ? 0 : tblTradePurchaseInfo.getBlpNum());
|
|
|
|
//根据合同订单号和物料编码 从入库记录获取已入库数量和剩余订单未入库数量
|
|
|
|
// QueryWrapper<TblTradeInventoryIn> queryWrapper = new QueryWrapper<>();
|
|
|
|
// queryWrapper.eq("delivery_contract_number", tblTradePurchaseInfo.getHth());
|
|
|
|
// queryWrapper.eq("material_code", tblTradePurchaseInfo.getWlbh());
|
|
|
|
// queryWrapper.eq("type", "入库");
|
|
|
|
// List<TblTradeInventoryIn> list = tblTradeInventoryInService.list(queryWrapper);
|
|
|
|
// if (!CollectionUtil.isEmpty(list)){
|
|
|
|
//已入库数量
|
|
|
|
// Integer rkNum = list.stream().map(TblTradeInventoryIn::getActualInventory).reduce(Integer::sum).get();
|
|
|
|
// tblTradePurchaseInfo.setYrkNum(tblTradePurchaseInfo.getYrkNum() == null ? 0 : tblTradePurchaseInfo.getYrkNum());
|
|
|
|
// tblTradePurchaseInfo.setWrkNum(tblTradePurchaseInfo.getWrkNum() == null ? 0 : tblTradePurchaseInfo.getWrkNum());
|
|
|
|
// }else {
|
|
|
|
// tblTradePurchaseInfo.setYrkNum(0);
|
|
|
|
// tblTradePurchaseInfo.setWrkNum(tblTradePurchaseInfo.getPurchaseQuantity());
|
|
|
|
// }
|
|
|
|
|
|
|
|
return Result.OK(tblTradePurchaseInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 导出excel
|
|
|
|
*
|
|
|
|
* @param request
|
|
|
|
* @param tblTradePurchaseInfo
|
|
|
|
*/
|
|
|
|
@RequestMapping(value = "/exportXls")
|
|
|
|
public ModelAndView exportXls(HttpServletRequest request, TblTradePurchaseInfo tblTradePurchaseInfo) {
|
|
|
|
return super.exportXls(request, tblTradePurchaseInfo, TblTradePurchaseInfo.class, "tbl_trade_purchase_info");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 通过excel导入数据
|
|
|
|
*
|
|
|
|
* @param request
|
|
|
|
* @param response
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
|
|
|
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
return super.importExcel(request, response, TblTradePurchaseInfo.class);
|
|
|
|
}
|
|
|
|
|
|
|
|
@GetMapping("/pdf/base64")
|
|
|
|
public Result<String> getPdfBase64(@RequestParam String filePath) throws IOException {
|
|
|
|
// 读取PDF文件
|
|
|
|
byte[] pdfBytes = Files.readAllBytes(Paths.get(uploadpath + "\\" + filePath));
|
|
|
|
|
|
|
|
// 将PDF文件转换为Base64编码
|
|
|
|
String base64Pdf = Base64.getEncoder().encodeToString(pdfBytes);
|
|
|
|
|
|
|
|
return Result.ok(base64Pdf);
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|