|
...
|
...
|
@@ -5,6 +5,7 @@ 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;
|
|
...
|
...
|
@@ -12,26 +13,27 @@ 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.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.TblTradeInventory;
|
|
|
|
import org.jeecg.modules.erp.trade.entity.TblTradeMeterial;
|
|
|
|
import org.jeecg.modules.erp.trade.service.ITblTradeInventoryService;
|
|
|
|
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.modules.erp.trade.service.ITblTradeMeterialService;
|
|
|
|
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.jetbrains.annotations.Nullable;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
...
|
...
|
@@ -42,163 +44,338 @@ import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import org.jeecg.common.aspect.annotation.AutoLog;
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @Description: 贸易库存表
|
|
|
|
* @Author: jeecg-boot
|
|
|
|
* @Date: 2024-12-24
|
|
|
|
* @Date: 2024-12-24
|
|
|
|
* @Version: V1.0
|
|
|
|
*/
|
|
|
|
@Api(tags="贸易库存表")
|
|
|
|
@Api(tags = "贸易库存表")
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("/trade/tblTradeInventory")
|
|
|
|
@Slf4j
|
|
|
|
public class TblTradeInventoryController extends JeecgController<TblTradeInventory, ITblTradeInventoryService> {
|
|
|
|
@Autowired
|
|
|
|
private ITblTradeInventoryService tblTradeInventoryService;
|
|
|
|
@Autowired
|
|
|
|
private ITblTradeMeterialService tblTradeMeterialService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 分页列表查询
|
|
|
|
*
|
|
|
|
* @param tblTradeInventory
|
|
|
|
* @param pageNo
|
|
|
|
* @param pageSize
|
|
|
|
* @param req
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
//@AutoLog(value = "贸易库存表-分页列表查询")
|
|
|
|
@ApiOperation(value="贸易库存表-分页列表查询", notes="贸易库存表-分页列表查询")
|
|
|
|
@GetMapping(value = "/list")
|
|
|
|
public Result<IPage<TblTradeInventory>> queryPageList(TblTradeInventory tblTradeInventory,
|
|
|
|
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
|
|
|
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
|
|
|
HttpServletRequest req) {
|
|
|
|
QueryWrapper<TblTradeInventory> queryWrapper = QueryGenerator.initQueryWrapper(tblTradeInventory, req.getParameterMap());
|
|
|
|
Page<TblTradeInventory> page = new Page<TblTradeInventory>(pageNo, pageSize);
|
|
|
|
IPage<TblTradeInventory> pageList = tblTradeInventoryService.page(page, queryWrapper);
|
|
|
|
pageList.getRecords().forEach(e->{
|
|
|
|
// 在库天数
|
|
|
|
e.setDaysInStock(DateUtil.betweenDay(e.getFirstStorageTime(),new Date(),true));
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
// System.out.println(tblTradeInventory.getMaterialDescription());
|
|
|
|
// IPage<TblTradeInventory> pageList = new Page<>();
|
|
|
|
// TblTradeMeterial tblTradeMeterial = new TblTradeMeterial();
|
|
|
|
// tblTradeMeterial.setMeterialReview(tblTradeInventory.getMaterialDescription());
|
|
|
|
// QueryWrapper<TblTradeMeterial> queryWrapper = QueryGenerator.initQueryWrapper(tblTradeMeterial, req.getParameterMap());
|
|
|
|
// Page<TblTradeMeterial> page = new Page<TblTradeMeterial>(pageNo, pageSize);
|
|
|
|
// IPage<TblTradeMeterial> pageList1 = tblTradeMeterialService.page(page, queryWrapper);
|
|
|
|
//
|
|
|
|
// pageList.setCurrent(pageList1.getCurrent());
|
|
|
|
// pageList.setPages(pageList1.getPages());
|
|
|
|
// pageList.setSize(pageList1.getSize());
|
|
|
|
// pageList.setTotal(pageList1.getTotal());
|
|
|
|
//
|
|
|
|
// List<TblTradeInventory> records = new ArrayList<>();
|
|
|
|
// pageList1.getRecords().forEach(e->{
|
|
|
|
// TblTradeInventory record = new TblTradeInventory(e);
|
|
|
|
// records.add(record);
|
|
|
|
// });
|
|
|
|
//
|
|
|
|
// pageList.setRecords(records);
|
|
|
|
|
|
|
|
return Result.OK(pageList);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 添加
|
|
|
|
*
|
|
|
|
* @param tblTradeInventory
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@AutoLog(value = "贸易库存表-添加")
|
|
|
|
@ApiOperation(value="贸易库存表-添加", notes="贸易库存表-添加")
|
|
|
|
@PostMapping(value = "/add")
|
|
|
|
public Result<String> add(@RequestBody TblTradeInventory tblTradeInventory) {
|
|
|
|
tblTradeInventoryService.save(tblTradeInventory);
|
|
|
|
return Result.OK("添加成功!");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 编辑
|
|
|
|
*
|
|
|
|
* @param tblTradeInventory
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@AutoLog(value = "贸易库存表-编辑")
|
|
|
|
@ApiOperation(value="贸易库存表-编辑", notes="贸易库存表-编辑")
|
|
|
|
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
|
|
|
|
public Result<String> edit(@RequestBody TblTradeInventory tblTradeInventory) {
|
|
|
|
tblTradeInventoryService.updateById(tblTradeInventory);
|
|
|
|
return Result.OK("编辑成功!");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 通过id删除
|
|
|
|
*
|
|
|
|
* @param id
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@AutoLog(value = "贸易库存表-通过id删除")
|
|
|
|
@ApiOperation(value="贸易库存表-通过id删除", notes="贸易库存表-通过id删除")
|
|
|
|
@DeleteMapping(value = "/delete")
|
|
|
|
public Result<String> delete(@RequestParam(name="id",required=true) String id) {
|
|
|
|
tblTradeInventoryService.removeById(id);
|
|
|
|
return Result.OK("删除成功!");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 批量删除
|
|
|
|
*
|
|
|
|
* @param ids
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@AutoLog(value = "贸易库存表-批量删除")
|
|
|
|
@ApiOperation(value="贸易库存表-批量删除", notes="贸易库存表-批量删除")
|
|
|
|
@DeleteMapping(value = "/deleteBatch")
|
|
|
|
public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
|
|
|
this.tblTradeInventoryService.removeByIds(Arrays.asList(ids.split(",")));
|
|
|
|
return Result.OK("批量删除成功!");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 通过id查询
|
|
|
|
*
|
|
|
|
* @param id
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
//@AutoLog(value = "贸易库存表-通过id查询")
|
|
|
|
@ApiOperation(value="贸易库存表-通过id查询", notes="贸易库存表-通过id查询")
|
|
|
|
@GetMapping(value = "/queryById")
|
|
|
|
public Result<TblTradeInventory> queryById(@RequestParam(name="id",required=true) String id) {
|
|
|
|
TblTradeInventory tblTradeInventory = tblTradeInventoryService.getById(id);
|
|
|
|
if(tblTradeInventory==null) {
|
|
|
|
return Result.error("未找到对应数据");
|
|
|
|
}
|
|
|
|
return Result.OK(tblTradeInventory);
|
|
|
|
}
|
|
|
|
@Autowired
|
|
|
|
private ITblTradeInventoryService tblTradeInventoryService;
|
|
|
|
@Autowired
|
|
|
|
private ITblTradeMeterialService tblTradeMeterialService;
|
|
|
|
@Autowired
|
|
|
|
private ITblTradeInventoryInService tblTradeInventoryInService;
|
|
|
|
@Autowired
|
|
|
|
private ITblTradeInventoryOutService tblTradeInventoryOutService;
|
|
|
|
@Autowired
|
|
|
|
private ITblTradeBidSubService tblTradeBidSubService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 导出excel
|
|
|
|
*
|
|
|
|
* @param request
|
|
|
|
* @param tblTradeInventory
|
|
|
|
*/
|
|
|
|
* 分页列表查询
|
|
|
|
*
|
|
|
|
* @param tblTradeInventory
|
|
|
|
* @param pageNo
|
|
|
|
* @param pageSize
|
|
|
|
* @param req
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
//@AutoLog(value = "贸易库存表-分页列表查询")
|
|
|
|
@ApiOperation(value = "贸易库存表-分页列表查询", notes = "贸易库存表-分页列表查询")
|
|
|
|
@GetMapping(value = "/list")
|
|
|
|
public Result<IPage<TblTradeMeterial>> queryPageList(TblTradeInventory tblTradeInventory,
|
|
|
|
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
|
|
|
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
|
|
|
HttpServletRequest req) {
|
|
|
|
TblTradeMeterial tblTradeMeterial = new TblTradeMeterial();
|
|
|
|
tblTradeMeterial.setMeterialReview(tblTradeInventory.getMaterialDescription());
|
|
|
|
QueryWrapper<TblTradeMeterial> queryWrapper = QueryGenerator.initQueryWrapper(tblTradeMeterial, req.getParameterMap());
|
|
|
|
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());
|
|
|
|
|
|
|
|
//根据物料编码查询库存
|
|
|
|
QueryWrapper<TblTradeInventory> tblTradeInventoryQueryWrapper = new QueryWrapper<>();
|
|
|
|
if (!CollectionUtil.isEmpty(collect)) {
|
|
|
|
tblTradeInventoryQueryWrapper.in("material_code", collect);
|
|
|
|
List<TblTradeInventory> list = tblTradeInventoryService.list(tblTradeInventoryQueryWrapper);
|
|
|
|
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) {
|
|
|
|
long daysDifference = calculateDaysDifference(new Date(), record.getFirstStorageTime());
|
|
|
|
record.setDaysInStock((int) daysDifference);
|
|
|
|
}
|
|
|
|
if (inventoryMap.get(record.getMeterialCode()) != null) {
|
|
|
|
TblTradeInventory inventory = inventoryMap.get(record.getMeterialCode());
|
|
|
|
Integer actualInventory = inventory.getActualInventory();
|
|
|
|
Integer quantityInTransit = inventory.getQuantityInTransit();
|
|
|
|
if (actualInventory == null) {
|
|
|
|
actualInventory = 0;
|
|
|
|
}
|
|
|
|
if (quantityInTransit == null) {
|
|
|
|
quantityInTransit = 0;
|
|
|
|
}
|
|
|
|
record.setTotalQuantity(actualInventory + quantityInTransit);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Result.OK(pageList);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static long calculateDaysDifference(Date startDate, Date endDate) {
|
|
|
|
long diffInMillies = Math.abs(endDate.getTime() - startDate.getTime());
|
|
|
|
return TimeUnit.DAYS.convert(diffInMillies, TimeUnit.MILLISECONDS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 添加
|
|
|
|
*
|
|
|
|
* @param tblTradeInventory
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@AutoLog(value = "贸易库存表-添加")
|
|
|
|
@ApiOperation(value = "贸易库存表-添加", notes = "贸易库存表-添加")
|
|
|
|
@PostMapping(value = "/add")
|
|
|
|
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.setCreateTime(new Date());
|
|
|
|
tblTradeInventoryIn.setUpdateTime(new Date());
|
|
|
|
tblTradeInventoryIn.setDeliveryContractNumber(tblTradeInventory.getHth());
|
|
|
|
tblTradeInventoryIn.setExpressDeliveryNumber(tblTradeInventory.getWldh());
|
|
|
|
tblTradeInventoryIn.setSupplierName(tblTradeInventory.getCs());
|
|
|
|
tblTradeInventoryIn.setWarehouse(tblTradeInventory.getWarehouse());
|
|
|
|
tblTradeInventoryIn.setType("入库");
|
|
|
|
//根据 物流编码 查询库存信息 如存在库存信息则进行修改库存信息,不存在则新增库存信息
|
|
|
|
String hth = tblTradeInventory.getHth();
|
|
|
|
String materialCode = tblTradeInventory.getMaterialCode();
|
|
|
|
QueryWrapper<TblTradeInventory> queryWrapper = new QueryWrapper<>();
|
|
|
|
queryWrapper.eq("material_code", materialCode);
|
|
|
|
//库存信息
|
|
|
|
TblTradeInventory tradeInventory = tblTradeInventoryService.getOne(queryWrapper);
|
|
|
|
Integer kcl = 0;
|
|
|
|
if (tradeInventory == null) {
|
|
|
|
kcl = tblTradeInventory.getRksl();
|
|
|
|
//新增库存信息
|
|
|
|
tblTradeInventory.setCreateTime(new Date());
|
|
|
|
tblTradeInventory.setUpdateTime(new Date());
|
|
|
|
tblTradeInventory.setFirstStorageTime(new Date());
|
|
|
|
tblTradeInventory.setActualInventory(tblTradeInventory.getRksl());
|
|
|
|
tblTradeInventoryService.save(tblTradeInventory);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
//修改库存信息
|
|
|
|
tblTradeInventory.setId(tradeInventory.getId());
|
|
|
|
tblTradeInventory.setUpdateTime(new Date());
|
|
|
|
//当前库存
|
|
|
|
Integer actualInventory = tradeInventory.getActualInventory();
|
|
|
|
|
|
|
|
kcl = tblTradeInventory.getRksl() + actualInventory;
|
|
|
|
|
|
|
|
tblTradeInventory.setActualInventory(kcl);
|
|
|
|
tblTradeInventoryService.updateById(tblTradeInventory);
|
|
|
|
|
|
|
|
}
|
|
|
|
//当前库存量
|
|
|
|
tblTradeInventoryIn.setActualInventory(kcl);
|
|
|
|
|
|
|
|
//新增入库记录
|
|
|
|
tblTradeInventoryInService.save(tblTradeInventoryIn);
|
|
|
|
|
|
|
|
|
|
|
|
return Result.OK("添加成功!");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
private Result<String> orderVerification(TblTradeInventory tblTradeInventory) {
|
|
|
|
QueryWrapper<TblTradeBidSub> queryWrapper = new QueryWrapper<>();
|
|
|
|
queryWrapper.eq("hth",tblTradeInventory.getHth());
|
|
|
|
queryWrapper.eq("wlbm",tblTradeInventory.getMaterialCode());
|
|
|
|
List<TblTradeBidSub> list = tblTradeBidSubService.list(queryWrapper);
|
|
|
|
if (CollectionUtil.isEmpty(list)) {
|
|
|
|
return Result.error("该订单不存在!");
|
|
|
|
}
|
|
|
|
if (list.size() > 1) {
|
|
|
|
return Result.error("存在多个相同订单!");
|
|
|
|
}
|
|
|
|
//订单信息
|
|
|
|
TblTradeBidSub tblTradeBidSub = list.get(0);
|
|
|
|
//订单数量
|
|
|
|
String sl = tblTradeBidSub.getSl();
|
|
|
|
//本次入库数量
|
|
|
|
Integer rksl = tblTradeInventory.getRksl();
|
|
|
|
if (rksl > Integer.parseInt(sl)){
|
|
|
|
return Result.error("添加失败,入库数量大于订单数量!");
|
|
|
|
}
|
|
|
|
|
|
|
|
//获取历史入库记录
|
|
|
|
|
|
|
|
String code = tblTradeInventory.getMaterialCode();
|
|
|
|
QueryWrapper<TblTradeInventoryIn> wrapper = new QueryWrapper<>();
|
|
|
|
wrapper.eq("material_code", code);
|
|
|
|
wrapper.eq("delivery_contract_number", tblTradeInventory.getHth());
|
|
|
|
//该物料的入库记录
|
|
|
|
List<TblTradeInventoryIn> rklog = tblTradeInventoryInService.list(wrapper);
|
|
|
|
//已入库数量
|
|
|
|
Integer yrksl = rklog.stream().map(TblTradeInventoryIn::getInventoryQuantity).reduce(Integer::sum).orElse(0);
|
|
|
|
|
|
|
|
//预计本次入库数量
|
|
|
|
int yjsl = yrksl + rksl;
|
|
|
|
if (yjsl > Integer.parseInt(sl)) {
|
|
|
|
return Result.error("添加失败,入库数量大于订单数量!");
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 出库
|
|
|
|
*
|
|
|
|
* @param tblTradeInventory
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@AutoLog(value = "出库")
|
|
|
|
@ApiOperation(value = "出库", notes = "出库")
|
|
|
|
@PostMapping(value = "/out")
|
|
|
|
public Result<String> out(@RequestBody TblTradeInventory tblTradeInventory) {
|
|
|
|
//根据物料编码获取库存信息
|
|
|
|
String materialCode = tblTradeInventory.getMaterialCode();
|
|
|
|
QueryWrapper<TblTradeInventory> queryWrapper = new QueryWrapper<>();
|
|
|
|
queryWrapper.eq("material_code", materialCode);
|
|
|
|
//库存信息
|
|
|
|
TblTradeInventory tradeInventory = tblTradeInventoryService.getOne(queryWrapper);
|
|
|
|
if (tradeInventory == null) {
|
|
|
|
return Result.error("出库失败,该物料库存信息不存在!");
|
|
|
|
}
|
|
|
|
//比对库存剩余数量和出库数量,做校验
|
|
|
|
Integer outboundQuantity = tblTradeInventory.getOutboundQuantity();
|
|
|
|
if (outboundQuantity > tradeInventory.getActualInventory()) {
|
|
|
|
return Result.error("出库失败,出库数量大于库存数量!");
|
|
|
|
}
|
|
|
|
//出库
|
|
|
|
tradeInventory.setActualInventory(tradeInventory.getActualInventory() - outboundQuantity);
|
|
|
|
tradeInventory.setLastOutboundTime(new Date());
|
|
|
|
tblTradeInventoryService.updateById(tradeInventory);
|
|
|
|
|
|
|
|
|
|
|
|
//记录出库记录
|
|
|
|
TblTradeInventoryOut tblTradeInventoryOut = new TblTradeInventoryOut();
|
|
|
|
tblTradeInventoryOut.setWaybillNumOut("BZSIN" + DatePattern.PURE_DATETIME_FORMAT.format(new Date()));
|
|
|
|
tblTradeInventoryOut.setMaterialCode(tblTradeInventory.getMaterialCode());
|
|
|
|
tblTradeInventoryOut.setMaterialDescription(tblTradeInventory.getMaterialDescription());
|
|
|
|
tblTradeInventoryOut.setMeasurementUnit(tblTradeInventory.getMeasurementUnit());
|
|
|
|
tblTradeInventoryOut.setBrand(tblTradeInventory.getBrand());
|
|
|
|
tblTradeInventoryOut.setSalesman(tblTradeInventory.getSalesman());
|
|
|
|
tblTradeInventoryOut.setCreateTime(new Date());
|
|
|
|
tblTradeInventoryOut.setUpdateTime(new Date());
|
|
|
|
tblTradeInventoryOut.setExpressDeliveryNumber(tblTradeInventory.getExpressDeliveryNumber());
|
|
|
|
tblTradeInventoryOut.setDeliveryContractNumber(tblTradeInventory.getDeliveryContractNumber());
|
|
|
|
tblTradeInventoryOut.setWarehouse(tblTradeInventory.getWarehouse());
|
|
|
|
tblTradeInventoryOut.setOutboundQuantity(outboundQuantity);
|
|
|
|
tblTradeInventoryOut.setDemandUnit(tblTradeInventory.getDemandUnit());
|
|
|
|
tblTradeInventoryOut.setActualInventory(tradeInventory.getActualInventory());
|
|
|
|
tblTradeInventoryOutService.save(tblTradeInventoryOut);
|
|
|
|
|
|
|
|
return Result.OK("出库成功!");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 编辑
|
|
|
|
*
|
|
|
|
* @param tblTradeInventory
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@AutoLog(value = "贸易库存表-编辑")
|
|
|
|
@ApiOperation(value = "贸易库存表-编辑", notes = "贸易库存表-编辑")
|
|
|
|
@RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
|
|
|
|
public Result<String> edit(@RequestBody TblTradeInventory tblTradeInventory) {
|
|
|
|
tblTradeInventoryService.updateById(tblTradeInventory);
|
|
|
|
return Result.OK("编辑成功!");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 通过id删除
|
|
|
|
*
|
|
|
|
* @param id
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@AutoLog(value = "贸易库存表-通过id删除")
|
|
|
|
@ApiOperation(value = "贸易库存表-通过id删除", notes = "贸易库存表-通过id删除")
|
|
|
|
@DeleteMapping(value = "/delete")
|
|
|
|
public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
|
|
|
|
tblTradeInventoryService.removeById(id);
|
|
|
|
return Result.OK("删除成功!");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 批量删除
|
|
|
|
*
|
|
|
|
* @param ids
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@AutoLog(value = "贸易库存表-批量删除")
|
|
|
|
@ApiOperation(value = "贸易库存表-批量删除", notes = "贸易库存表-批量删除")
|
|
|
|
@DeleteMapping(value = "/deleteBatch")
|
|
|
|
public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
|
|
|
|
this.tblTradeInventoryService.removeByIds(Arrays.asList(ids.split(",")));
|
|
|
|
return Result.OK("批量删除成功!");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 通过id查询
|
|
|
|
*
|
|
|
|
* @param id
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
//@AutoLog(value = "贸易库存表-通过id查询")
|
|
|
|
@ApiOperation(value = "贸易库存表-通过id查询", notes = "贸易库存表-通过id查询")
|
|
|
|
@GetMapping(value = "/queryById")
|
|
|
|
public Result<TblTradeInventory> queryById(@RequestParam(name = "id", required = true) String id) {
|
|
|
|
TblTradeInventory tblTradeInventory = tblTradeInventoryService.getById(id);
|
|
|
|
if (tblTradeInventory == null) {
|
|
|
|
return Result.error("未找到对应数据");
|
|
|
|
}
|
|
|
|
return Result.OK(tblTradeInventory);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 导出excel
|
|
|
|
*
|
|
|
|
* @param request
|
|
|
|
* @param tblTradeInventory
|
|
|
|
*/
|
|
|
|
@RequestMapping(value = "/exportXls")
|
|
|
|
public ModelAndView exportXls(HttpServletRequest request, TblTradeInventory tblTradeInventory) {
|
|
|
|
return super.exportXls(request, tblTradeInventory, TblTradeInventory.class, "贸易库存表");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 通过excel导入数据
|
|
|
|
*
|
|
|
|
* @param request
|
|
|
|
* @param response
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
* 通过excel导入数据
|
|
|
|
*
|
|
|
|
* @param request
|
|
|
|
* @param response
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
|
|
|
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
return super.importExcel(request, response, TblTradeInventory.class);
|
...
|
...
|
|