java收货_商贸型企业 Java 收货 + 入库 + 生成付款单

本文档展示了如何使用Java实现商贸型企业收货、入库操作,并自动生成付款单。通过GrnOrderServiceImpl类的各个方法,包括添加、删除、更新收货单,创建和获取入库单详情,更新库存和库存事务,以及生成付款单等功能。
摘要由CSDN通过智能技术生成

package cn.hybn.erp.modular.system.service.impl;

import cn.hybn.erp.core.common.page.LayuiPageFactory;

import cn.hybn.erp.core.common.page.LayuiPageInfo;

import cn.hybn.erp.modular.system.base.BaseStatus;

import cn.hybn.erp.modular.system.base.Order;

import cn.hybn.erp.modular.system.base.Status;

import cn.hybn.erp.modular.system.entity.*;

import cn.hybn.erp.modular.system.mapper.GrnOrderMapper;

import cn.hybn.erp.modular.system.model.params.GrnOrderParam;

import cn.hybn.erp.modular.system.model.params.PurchaseOrderParam;

import cn.hybn.erp.modular.system.model.result.GrnOrderResult;

import cn.hybn.erp.modular.system.service.*;

import cn.hybn.erp.modular.system.utility.Katrina_CJ_Utils;

import cn.stylefeng.roses.core.util.ToolUtil;

import com.alibaba.fastjson.JSONObject;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.core.metadata.IPage;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.sun.xml.internal.bind.v2.TODO;

import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;

import java.math.BigDecimal;

import java.util.*;

/**

*

* 服务实现类

*

*

* @author Katrina_CJ

* @since 2019-03-16

*/

@Service

public class GrnOrderServiceImpl extends ServiceImpl implements GrnOrderService {

@Autowired

private PurchaseDetailService purchaseDetailService;

@Autowired

private GrnOrderDetailService grnOrderDetailService;

@Autowired

private InventoryService inventoryService;

@Autowired

private InventoryTransactionService inventoryTransactionService;

@Autowired

private PurchaseOrderService purchaseOrderService;

@Autowired

private PaymentOrderService paymentOrderService;

@Override

public void add(GrnOrderParam param) {

GrnOrder entity = getEntity(param);

this.save(entity);

}

@Override

public void delete(GrnOrderParam param) {

this.removeById(getKey(param));

}

@Override

public void update(GrnOrderParam param) {

GrnOrder oldEntity = getOldEntity(param);

GrnOrder newEntity = getEntity(param);

ToolUtil.copyProperties(newEntity, oldEntity);

this.updateById(newEntity);

}

@Override

public GrnOrderResult findBySpec(GrnOrderParam param) {

return null;

}

@Override

public List findListBySpec(GrnOrderParam param) {

return null;

}

@Override

public LayuiPageInfo findPageBySpec(GrnOrderParam param) {

Page pageContext = getPageContext();

QueryWrapper objectQueryWrapper = new QueryWrapper<>();

IPage page = this.page(pageContext, objectQueryWrapper);

return LayuiPageFactory.createPageInfo(page);

}

@Override

@Transactional(rollbackFor = {Exception.class})

public void createGrnOrder(PurchaseOrderParam param) {

GrnOrder grnOrder = new GrnOrder();

grnOrder.setGrnOrderStatus(Status.CREATE.getStatus());

grnOrder.setOrderId(param.getPoId());

grnOrder.setGrnOrderCreateTime(new Date());

QueryWrapper wrapper = new QueryWrapper<>();

wrapper.orderByDesc("grn_order_id").last("limit 1");

GrnOrder grnId = this.getOne(wrapper);

//如果当前数据库没有订单,手动赋值

if (Objects.isNull(grnId)) {

grnId = new GrnOrder();

grnId.setOrderId((long) 0);

}

//创建订单编号

LoggerFactory.getLogger(GrnOrderServiceImpl.class).info("DEBUG:->" + String.valueOf(grnId.getOrderId()));

String serial = Katrina_CJ_Utils.createOrderSerial(Order.RKD_, grnId.getOrderId());

grnOrder.setGrnOrderSerial(serial);

//填充入库单明细

// QueryWrapper queryWrapper = new QueryWrapper<>();

// queryWrapper.eq("order_po_id", param.getPoId());

//当前采购单明细

// List details = purchaseDetailService.list(queryWrapper);

this.getBaseMapper().insert(grnOrder);

// details.forEach(pd -> {

// GrnOrderDetail grnOrderDetail = new GrnOrderDetail();

// grnOrderDetail.setGrnOrderId(grnOrder.getGrnOrderId());

// grnOrderDetail.setGrnDetailIsGift(pd.getOrderIsGifts());

// grnOrderDetail.setGrnDetailProductId(pd.getOrderProductId());

// grnOrderDetail.setGrnDetailUnit(pd.getOrderUnit());

// grnOrderDetail.setGrnDetailGoods(new BigDecimal(0));

// grnOrderDetailService.getBaseMapper().insert(grnOrderDetail);

// });

}

@Override

@Transactional(rollbackFor = {Exception.class})

public void getGoods(GrnOrderParam grnOrderParam) {

GrnOrder grnOrder = new GrnOrder();

grnOrder.setGrnOrderId(grnOrderParam.getGrnOrderId());

grnOrder.setGrnOrderAgent(grnOrderParam.getGrnOrderAgent());

grnOrder.setGrnOrderAgentDept(grnOrderParam.getGrnOrderAgentDept());

grnOrder.setGrnOrderGetGoodsTime(new Date());

grnOrder.setGrnOrderRemark(grnOrderParam.getGrnOrderRemark());

grnOrder.setGrnOrderStatus(Status.FINISH.getStatus());

List grnOrderDetails = JSONObject.parseArray(grnOrderParam.getGrnOrderDetail(), GrnOrderDetail.class);

//更新入库单

this.getBaseMapper().updateById(grnOrder);

//更新入库单详情

grnOrderDetails.forEach(g -> {

// grnOrderDetail.setGrnDetailIsGift(pd.getOrderIsGifts());

// grnOrderDetail.setGrnDetailProductId(pd.getOrderProductId());

// grnOrderDetail.setGrnDetailUnit(pd.getOrderUnit());

// grnOrderDetail.setGrnDetailGoods(new BigDecimal(0));

g.setGrnDetailProductId(g.getGrnDetailProductId());

g.setGrnDetailIsGift(g.getGrnDetailIsGift());

g.setGrnOrderId(grnOrder.getGrnOrderId());

grnOrderDetailService.getBaseMapper().insert(g);

});

//查询入库单详情

QueryWrapper queryWrapper = new QueryWrapper<>();

queryWrapper.eq("grn_order_id", grnOrder.getGrnOrderId());

//更新库存和库存事务

List details = grnOrderDetailService.list(queryWrapper);

//获取采购单数据

GrnOrder grn = this.getById(grnOrder.getGrnOrderId());

PurchaseOrder purchaseOrder = purchaseOrderService.getById(grn.getOrderId());

//更新采购单数据

QueryWrapper purchaseDetailQueryWrapper = new QueryWrapper<>();

purchaseDetailQueryWrapper.eq("order_po_id", purchaseOrder.getPoId());

List purchaseDetails = purchaseDetailService.list(purchaseDetailQueryWrapper);

//移除无入库的明细

details.removeIf(d -> Objects.isNull(d.getGrnDetailWarehouse()));

details.forEach(d -> {

QueryWrapper inventoryQueryWrapper = new QueryWrapper<>();

inventoryQueryWrapper.eq("inventory_product_id", d.getGrnDetailProductId());

List inventories = inventoryService.list(inventoryQueryWrapper);

//如果无当前产品,新增库存

if (inventories.size() == 0) {

//新库存

Inventory inventory = new Inventory();

inventory.setInventoryAmount(d.getGrnDetailGoods());

inventory.setInventoryAvailableLocation(d.getGrnDetailGoods());

inventory.setInventoryIn(d.getGrnDetailGoods());

inventory.setInventoryLow(new BigDecimal(0));

inventory.setInventoryProductId(d.getGrnDetailProductId());

inventory.setInventoryMax(new BigDecimal(0));

inventory.setInventoryWarehouseId(d.getGrnDetailWarehouse());

inventory.setInventoryUnit(d.getGrnDetailUnit());

inventory.setInventoryCreateTime(new Date());

inventory.setInventoryOnWay(new BigDecimal(0));

inventory.setInventoryBatch(d.getGrnDetailBatch());

inventory.setInventoryProductTime(d.getGrnDetailProductTime());

inventoryService.getBaseMapper().insert(inventory);

//新库存事务

InventoryTransaction transaction = new InventoryTransaction();

transaction.setGrnTransactionInventoryId(inventory.getInventoryId());

transaction.setGrnTransactionIsGift(d.getGrnDetailIsGift());

transaction.setGrnTransactionOrderSerial(grnOrderParam.getGrnOrderSerial());

transaction.setGrnTransactionBatch(d.getGrnDetailBatch());

transaction.setGrnTransactionType(BaseStatus.RK.getDesc());

transaction.setGrnTransactionProductId(d.getGrnDetailProductId());

transaction.setGrnTransactionGrnOrderId(grnOrder.getGrnOrderId());

transaction.setGrnTransactionHappenNumber(d.getGrnDetailGoods());

transaction.setGrnTransactionProductionOfDate(d.getGrnDetailProductTime());

transaction.setGrnTransactionProductBarcode(d.getGrnDetailBarcode());

inventoryTransactionService.getBaseMapper().insert(transaction);

} else {

inventories.forEach(inventory -> {

//库位一致

if (inventory.getInventoryWarehouseId().equals(d.getGrnDetailWarehouse())) {

//单位一致

if (inventory.getInventoryUnit().equals(d.getGrnDetailUnit())) {

//更新库存数量

inventory.setInventoryAmount(inventory.getInventoryAmount().add(d.getGrnDetailGoods()));

inventoryService.getBaseMapper().updateById(inventory);

} else {

//新库存

Inventory newInventory = new Inventory();

newInventory.setInventoryAmount(d.getGrnDetailGoods());

newInventory.setInventoryAvailableLocation(d.getGrnDetailGoods());

newInventory.setInventoryIn(d.getGrnDetailGoods());

newInventory.setInventoryLow(new BigDecimal(0));

newInventory.setInventoryProductId(d.getGrnDetailProductId());

newInventory.setInventoryMax(new BigDecimal(0));

newInventory.setInventoryWarehouseId(d.getGrnDetailWarehouse());

newInventory.setInventoryUnit(d.getGrnDetailUnit());

newInventory.setInventoryCreateTime(new Date());

newInventory.setInventoryOnWay(new BigDecimal(0));

newInventory.setInventoryBatch(d.getGrnDetailBatch());

newInventory.setInventoryProductTime(d.getGrnDetailProductTime());

inventoryService.getBaseMapper().insert(newInventory);

//新库存事务

InventoryTransaction transaction = new InventoryTransaction();

transaction.setGrnTransactionInventoryId(newInventory.getInventoryId());

transaction.setGrnTransactionIsGift(d.getGrnDetailIsGift());

transaction.setGrnTransactionOrderSerial(grnOrderParam.getGrnOrderSerial());

transaction.setGrnTransactionBatch(d.getGrnDetailBatch());

transaction.setGrnTransactionType(BaseStatus.RK.getDesc());

transaction.setGrnTransactionProductId(d.getGrnDetailProductId());

transaction.setGrnTransactionGrnOrderId(grnOrder.getGrnOrderId());

transaction.setGrnTransactionHappenNumber(d.getGrnDetailGoods());

transaction.setGrnTransactionProductionOfDate(d.getGrnDetailProductTime());

transaction.setGrnTransactionProductBarcode(d.getGrnDetailBarcode());

inventoryTransactionService.getBaseMapper().insert(transaction);

}

} else {

//新库存

Inventory newInventory = new Inventory();

newInventory.setInventoryAmount(d.getGrnDetailGoods());

newInventory.setInventoryAvailableLocation(d.getGrnDetailGoods());

newInventory.setInventoryIn(d.getGrnDetailGoods());

newInventory.setInventoryLow(new BigDecimal(0));

newInventory.setInventoryProductId(d.getGrnDetailProductId());

newInventory.setInventoryMax(new BigDecimal(0));

newInventory.setInventoryWarehouseId(d.getGrnDetailWarehouse());

newInventory.setInventoryUnit(d.getGrnDetailUnit());

newInventory.setInventoryCreateTime(new Date());

newInventory.setInventoryOnWay(new BigDecimal(0));

newInventory.setInventoryBatch(d.getGrnDetailBatch());

newInventory.setInventoryProductTime(d.getGrnDetailProductTime());

inventoryService.getBaseMapper().insert(newInventory);

//新库存事务

InventoryTransaction transaction = new InventoryTransaction();

transaction.setGrnTransactionInventoryId(newInventory.getInventoryId());

transaction.setGrnTransactionIsGift(d.getGrnDetailIsGift());

transaction.setGrnTransactionOrderSerial(grnOrderParam.getGrnOrderSerial());

transaction.setGrnTransactionBatch(d.getGrnDetailBatch().longValue());

transaction.setGrnTransactionType(BaseStatus.RK.getDesc());

transaction.setGrnTransactionProductId(d.getGrnDetailProductId());

transaction.setGrnTransactionGrnOrderId(grnOrder.getGrnOrderId());

transaction.setGrnTransactionHappenNumber(d.getGrnDetailGoods());

transaction.setGrnTransactionProductionOfDate(d.getGrnDetailProductTime());

transaction.setGrnTransactionProductBarcode(d.getGrnDetailBarcode());

inventoryTransactionService.getBaseMapper().insert(transaction);

}

});

}

});

//TODO

//生成付款单

QueryWrapper wrapper = new QueryWrapper<>();

wrapper.orderByDesc("payment_order_id").last("limit 1");

PaymentOrder serial = paymentOrderService.getOne(wrapper);

if (Objects.isNull(serial)) {

serial = new PaymentOrder();

serial.setPaymentOrderId((long) 0);

}

String paySerial = Katrina_CJ_Utils.createOrderSerial(Order.FKD_, serial.getPaymentOrderId());

PaymentOrder paymentOrder = new PaymentOrder();

paymentOrder.setPaymentOrderSerial(paySerial);

paymentOrder.setPaymentOrderCreateTime(new Date());

paymentOrder.setPaymentOrderStatus(Status.EXECUTION.getStatus());

//更新采购单

//当前采购单总数

purchaseOrder.setPoSumNumbers(new BigDecimal(0));

details.forEach(d -> {

if (purchaseOrder.getPoStatus().equals(Status.EXECUTION.getStatus()) || purchaseOrder.getPoStatus().equals(Status.TERMINATION.getStatus())) {

purchaseDetails.forEach(pd -> {

if (pd.getOrderProductId().equals(d.getGrnDetailProductId())) {

//更新已完成数量

pd.setOrderFinishNumber(pd.getOrderFinishNumber().add(d.getGrnDetailGoods()));

int flag = pd.getOrderNumbers().compareTo(pd.getOrderFinishNumber());

if (flag == 0) {

//已完成

pd.setOrderPendingNumber(new BigDecimal(0));

} else if (flag < 0) {

//超收

pd.setOrderPendingNumber(new BigDecimal(0));

} else {

//更新未完成数量

pd.setOrderPendingNumber(pd.getOrderNumbers().subtract(pd.getOrderFinishNumber()));

}

paymentOrder.setPaymentAmountsPayable(pd.getOrderPrice().multiply(d.getGrnDetailGoods()));

purchaseOrder.setPoSumNumbers(purchaseOrder.getPoSumNumbers().add(pd.getOrderFinishNumber()));

purchaseDetailService.getBaseMapper().updateById(pd);

}

});

} else {

throw new RuntimeException("订单状态异常!");

}

});

PurchaseOrder purchaseOrder_old = purchaseOrderService.getById(purchaseOrder.getPoId());

int flag = purchaseOrder.getPoSumNumbers().compareTo(purchaseOrder_old.getPoSumNumbers());

//订单完成

if (flag == 0 || flag > 0) {

//订单完成

purchaseOrder_old.setPoStatus(Status.FINISH.getStatus());

purchaseOrderService.getBaseMapper().updateById(purchaseOrder_old);

}

paymentOrder.setPaymentGrnOrder(grnOrder.getGrnOrderId());

//新增付款单

paymentOrderService.getBaseMapper().insert(paymentOrder);

}

private Serializable getKey(GrnOrderParam param) {

return param.getGrnOrderId();

}

private Page getPageContext() {

return LayuiPageFactory.defaultPage();

}

private GrnOrder getOldEntity(GrnOrderParam param) {

return this.getById(getKey(param));

}

private GrnOrder getEntity(GrnOrderParam param) {

GrnOrder entity = new GrnOrder();

ToolUtil.copyProperties(param, entity);

return entity;

}

@Override

public Page> list(String condition, String date_1, String date_2, String status) {

Page productPage = LayuiPageFactory.defaultPage();

return baseMapper.order_list(productPage, condition, date_1, date_2, status);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值