| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328 |
- package com.dk.mdm.service.ivt.inbound;
- import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
- import com.dk.common.exception.BaseBusinessException;
- import com.dk.common.infrastructure.annotaiton.Pagination;
- import com.dk.common.infrastructure.constant.Constant;
- import com.dk.common.infrastructure.enums.ErrorCodeEnum;
- import com.dk.common.mapper.BaseMapper;
- import com.dk.common.model.pojo.PageList;
- import com.dk.common.model.vo.AnnexVO;
- import com.dk.common.response.ResponseCodeEnum;
- import com.dk.common.response.ResponseResultUtil;
- import com.dk.common.response.ResponseResultVO;
- import com.dk.common.service.BaseService;
- import com.dk.mdm.infrastructure.convert.ivt.InboundConvert;
- import com.dk.mdm.infrastructure.convert.ivt.InboundItemConvert;
- import com.dk.mdm.mapper.common.CommonMapper;
- import com.dk.mdm.mapper.ivt.InboundItemMapper;
- import com.dk.mdm.mapper.ivt.InboundMapper;
- import com.dk.mdm.mapper.pur.PurchaseItemMapper;
- import com.dk.mdm.mapper.pur.PurchaseMapper;
- import com.dk.mdm.model.pojo.ivt.Inbound;
- import com.dk.mdm.model.pojo.ivt.InboundItem;
- import com.dk.mdm.model.pojo.pur.Purchase;
- import com.dk.mdm.model.pojo.pur.PurchaseItem;
- import com.dk.mdm.model.query.ivt.InboundItemQuery;
- import com.dk.mdm.model.query.ivt.InboundQuery;
- import com.dk.mdm.model.response.ivt.InboundItemResponse;
- import com.dk.mdm.model.response.ivt.InboundResponse;
- import com.dk.mdm.model.response.pur.PurchaseItemResponse;
- import com.dk.mdm.model.response.pur.PurchaseResponse;
- import com.dk.mdm.model.vo.ivt.InboundItemVO;
- import com.dk.mdm.model.vo.ivt.InboundVO;
- import com.dk.mdm.service.common.CommonService;
- import com.dk.mdm.service.ivt.inventory.InventoryService;
- import com.dk.mdm.service.mac.AccountService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.math.BigDecimal;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.UUID;
- /**
- * @author : 寇珊珊
- * @desc : 采购入库业务层
- * @date : 2024/3/7 14:11
- */
- @Service
- public class InboundPurchaseService extends BaseService<Inbound> {
- @Override
- public BaseMapper<Inbound> getRepository() {
- return inboundMapper;
- }
- @Autowired
- private InboundMapper inboundMapper;
- @Autowired
- private InboundConvert inboundConvert;
- @Autowired
- private InboundItemMapper inboundItemMapper;
- @Autowired
- private InboundItemConvert inboundItemConvert;
- @Autowired
- private PurchaseMapper purchaseMapper;
- @Autowired
- private PurchaseItemMapper purchaseItemMapper;
- @Autowired
- private CommonService commonService;
- @Autowired
- private CommonMapper commonMapper;
- @Autowired
- private InventoryService inventoryService;
- @Autowired
- private AccountService accountService;
- /**
- * @desc : 条件查询
- * @date : 2024/3/7 14:12
- * @author : 寇珊珊
- */
- @Pagination
- public ResponseResultVO<PageList<InboundResponse>> selectByCond(InboundQuery inboundQuery) {
- return super.mergeListWithCount(inboundQuery, inboundMapper.selectByCond(inboundQuery),
- inboundMapper.countByCond(inboundQuery));
- }
- /**
- * @desc : 查询明细
- * @date : 2024/3/9 15:43
- * @author : 寇珊珊
- */
- @Pagination
- public ResponseResultVO<Map<String, Object>> selectPurchaseInboundItemInfoById(String id) {
- Map<String, Object> result = new HashMap<>();
- // 商品明细
- List<InboundItemResponse> inboundItemResponses = inboundItemMapper.selectByCond(new InboundItemQuery().setIntoId(id));
- result.put("itemList", inboundItemResponses);
- // 收款
- // 附件
- return ResponseResultUtil.success(result);
- }
- /**
- * @desc : 查询入库价
- * @date : 2024/7/1 11:29
- * @author : 寇珊珊
- */
- @Transactional(rollbackFor = {Exception.class})
- public InboundItemResponse selectPriceInto(InboundItemVO inboundItemVO) {
- List<InboundItemResponse> inboundItemResponses = inboundItemMapper.selectPriceInto(new InboundItemQuery().setSkuId(inboundItemVO.getSkuId())
- .setNonStdCode(inboundItemVO.getNonStdCode())
- .setWhId(inboundItemVO.getWhId()));
- if (inboundItemResponses != null && inboundItemResponses.size() > 0) {
- return inboundItemResponses.get(0);
- }
- return null;
- }
- /**
- * @desc : 采购入库新建
- * @date : 2024/3/7 14:13
- * 入库中数量/金额 已入库数量/金额 由调用方传入
- * @author : 寇珊珊
- */
- @Transactional(rollbackFor = {Exception.class})
- public ResponseResultVO<?> purchaseInboundInsert(InboundVO inboundVO) {
- //region 校验明细
- if (inboundVO.getItemList().size() == 0) {
- throw new BaseBusinessException(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(),
- ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
- }
- //endregion
- //region 查询当前入库明细中是否存在未空或者0的入库价,如果存在去库存流水差最近一条有价格的数据赋值到当前明细
- Boolean priceIntoFlag = false;
- for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
- if(inboundItemVO.getPriceInto() == null || inboundItemVO.getPriceInto().compareTo(BigDecimal.ZERO)==0){
- priceIntoFlag = true;
- //查询库存批次最近一条入库价
- InboundItemResponse inboundItemResponse = this.selectPriceInto(inboundItemVO);
- inboundItemVO.setPriceInto(inboundItemResponse != null ? inboundItemResponse.getPriceInto() : BigDecimal.ZERO);
- inboundItemVO.setIntoingAmt(inboundItemResponse != null ? inboundItemResponse.getPriceInto().multiply(inboundItemVO.getIntoingQty()).setScale(2, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO);
- inboundItemVO.setCostPrice(inboundItemResponse != null ? inboundItemResponse.getCostPrice() : BigDecimal.ZERO);
- inboundItemVO.setCostAmt(inboundItemResponse != null ? inboundItemResponse.getCostPrice().multiply(inboundItemVO.getIntoingQty()).setScale(2, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO);
- }
- }
- if(priceIntoFlag){
- BigDecimal intoingAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- inboundVO.setIntoingAmt(intoingAmt);
- }
- //endregion
- //region 查询当前公司的系统参数 自动办理信息 并赋值
- Map<String, Object> map = new HashMap<>();
- map.put("cpId", inboundVO.getCpId());
- map.put("code", Constant.SystemConstant.IVT_001.getValue());
- //自动办理标识
- String flgHandleSetting = commonMapper.getSettingValue(map);
- //自动办理标识为1 自动办理入库
- if (Constant.FlgAutoHandleStringType.ONE.getValue().equals(flgHandleSetting)) {
- inboundVO.setFlgHandleSetting(Constant.FlgHandleSetting.TRUE.getValue());
- inboundVO.setFlgAutoHandle(Constant.FlgAutoHandle.TRUE.getValue());
- }
- //endregion
- //region 总单
- //获取 id/单号
- Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.PURCASEINBOUND.getName(), false);
- inboundVO.setIntoId(codeMap.get("outId").toString()).
- setIntoNo(codeMap.get("outNote").toString());
- //入库类型
- inboundVO.setIntoType(Constant.IntoType.SALE.getName());
- //自动入库标识
- if (inboundVO.getFlgAutoHandle()) {
- //已入库
- inboundVO.setIntoStatus(Constant.IntoStatus.YIRUKU.getName());
- } else {
- //入库中
- inboundVO.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName());
- }
- //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
- if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
- inboundVO.setIntoQty(inboundVO.getIntoingQty())
- .setIntoAmt(inboundVO.getIntoingAmt())
- .setIntoingQty(BigDecimal.ZERO)
- .setIntoingAmt(BigDecimal.ZERO)
- ;
- } else {
- inboundVO.setIntoQty(BigDecimal.ZERO)
- .setIntoAmt(BigDecimal.ZERO)
- ;
- }
- //实体转换
- Inbound inbound = inboundConvert.convertToPo(inboundVO);
- inboundMapper.insert(inbound);
- //endregion
- //region 采购总单
- if (inboundVO.getFromId() != null) {
- //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
- Purchase purchaseUpdate = new Purchase();
- purchaseUpdate.setPurId(inboundVO.getFromId());
- //根据id查询
- PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId());
- //已入库
- if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
- purchaseUpdate.setIntoingQty(BigDecimal.ZERO);
- purchaseUpdate.setIntoingAmt(BigDecimal.ZERO);
- purchaseUpdate.setIntoQty(inboundVO.getIntoQty());
- purchaseUpdate.setIntoAmt(inboundVO.getIntoAmt());
- }
- //入库中
- else {
- purchaseUpdate.setIntoingQty(inboundVO.getIntoingQty());
- purchaseUpdate.setIntoingAmt(inboundVO.getIntoingAmt());
- purchaseUpdate.setIntoQty(BigDecimal.ZERO);
- purchaseUpdate.setIntoAmt(BigDecimal.ZERO);
- }
- //入库状态
- String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchaseUpdate.getIntoingQty()),
- purchaseResponse.getIntoQty().add(purchaseUpdate.getIntoQty()), purchaseResponse.getSumQuantity());
- purchaseUpdate.setIntoStatus(intoStatus);
- //修改
- int countRow = purchaseMapper.updateById(purchaseUpdate);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
- }
- }
- //endregion
- //region 明细
- for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
- //region 将库存需要的参数赋值
- inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
- inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
- inboundItemVO.setAddOrEditFlag(true);
- //endregion
- //总单id
- inboundItemVO.setIntoId(inboundVO.getIntoId());
- //入库类型
- inboundItemVO.setIntoType(inboundVO.getIntoType());
- //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
- if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
- inboundItemVO
- .setIntoQty(inboundItemVO.getIntoingQty())
- .setIntoAmt(inboundItemVO.getIntoingAmt())
- .setIntoingQty(BigDecimal.ZERO)
- .setIntoingAmt(BigDecimal.ZERO)
- .setCostPrice(inboundItemVO.getPriceInto())
- .setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
- ;
- } else {
- inboundItemVO
- .setIntoQty(BigDecimal.ZERO)
- .setIntoAmt(BigDecimal.ZERO);
- }
- //入库状态
- inboundItemVO.setIntoStatus(inboundVO.getIntoStatus());
- //实体转换
- InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
- inboundItemMapper.insert(inboundItem);
- inboundItemVO.setItemId(inboundItem.getItemId());
- //endregion
- //region 采购明细
- if (inboundItemVO.getFromItemId() != null) {
- //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
- PurchaseItem purchaseItem = new PurchaseItem();
- purchaseItem.setItemId(inboundItemVO.getFromItemId());
- //根据id查询
- PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
- //已入库
- if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
- purchaseItem.setIntoingQty(BigDecimal.ZERO);
- purchaseItem.setIntoingAmt(BigDecimal.ZERO);
- purchaseItem.setIntoQty(inboundItemVO.getIntoQty());
- purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt());
- }
- //入库中
- else {
- purchaseItem.setIntoingQty(inboundItemVO.getIntoingQty());
- purchaseItem.setIntoingAmt(inboundItemVO.getIntoingAmt());
- purchaseItem.setIntoQty(BigDecimal.ZERO);
- purchaseItem.setIntoAmt(BigDecimal.ZERO);
- }
- //入库状态
- String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
- purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()), purchaseItemResponse.getItemQty());
- purchaseItem.setIntoStatus(intoStatus);
- int countRow = purchaseItemMapper.updateById(purchaseItem);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
- }
- }
- //endregion
- }
- //endregion
- //region 入账
- if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
- accountService.accPayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
- }
- //endregion
- //region 库存
- if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
- Map<String, Object> invMap = new HashMap<>();
- invMap.put("intoDetail", inboundVO.getItemList());
- inventoryService.operatingInventoryInformation(invMap);
- }
- //endregion
- return ResponseResultUtil.success(inboundVO);
- }
- /**
- * @desc : 采购入库编辑
- * @date : 2024/3/25 16:25
- * @author : 寇珊珊
- */
- @Transactional(rollbackFor = {Exception.class})
- public ResponseResultVO<?> purchaseInboundUpdate(InboundVO inboundVO) {
- //region 小编辑
- if (!inboundVO.getLimitEdit()) {
- Inbound inbound = new Inbound();
- inbound.setIntoId(inboundVO.getIntoId());
- inbound.setRemarks(inboundVO.getRemarks());
- inbound.setAnnexPaths(inboundVO.getAnnexPaths());
- inboundMapper.update(inbound,
- new UpdateWrapper<Inbound>().lambda()
- .eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
- );
- for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
- InboundItem inboundItem = new InboundItem();
- inboundItem.setItemId(inboundItemVO.getItemId());
- if (inboundItemVO.getRemarks() != null && inboundItemVO.getRemarks() != "") {
- inboundItem.setRemarks(inboundItemVO.getRemarks());
- inboundItemMapper.update(inboundItem,
- new UpdateWrapper<InboundItem>().lambda()
- .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
- );
- }
- }
- }
- //endregion
- //region 大编辑
- else {
- //region 根据id查询 此条入库单的数据还未更改前的数据
- InboundResponse inboundResponse = inboundMapper.selectById(inboundVO.getIntoId());
- BigDecimal sumQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- BigDecimal sumAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- //endregion
- //region 自动办理参数为true 已入库编辑
- //自动办理参数为true
- if (Constant.FlgHandleSetting.TRUE.getValue().equals(inboundVO.getFlgHandleSetting())) {
- //region 退账
- if (inboundVO.getReceivableId() != null) {
- accountService.reversePayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
- }
- //endregion
- //region 修改明细
- List<InboundItemVO> itemList = inboundVO.getItemList();
- for (InboundItemVO inboundItemVO : itemList) {
- //根据id查询
- InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId());
- //region 编辑明细 赋值
- if (inboundItemVO.getItemId() != null) {
- //region 将库存需要的参数赋值
- inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
- inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
- //编辑之前的数
- inboundItemVO.setQtyBeforeUpdate(inboundItemResponse.getIntoQty());
- inboundItemVO.setAmtBeforeUpdate(inboundItemResponse.getIntoAmt());
- //编辑之后的数
- inboundItemVO.setIntoQty(inboundItemVO.getIntoingQty());
- inboundItemVO.setIntoAmt(inboundItemVO.getIntoingAmt());
- inboundItemVO.setAddOrEditFlag(false);
- //endregion
- InboundItem inboundItem = new InboundItem();
- inboundItem.setItemId(inboundItemVO.getItemId());
- inboundItem.setIntoQty(inboundItemVO.getIntoingQty());
- inboundItem.setIntoAmt(inboundItemVO.getIntoingAmt());
- inboundItem.setCostPrice(inboundItemVO.getPriceInto());
- inboundItem.setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(6, BigDecimal.ROUND_HALF_UP));
- //修改
- inboundItemMapper.update(inboundItem,
- new UpdateWrapper<InboundItem>().lambda()
- .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
- );
- }
- //endregion
- //region 新建明细
- else {
- inboundItemVO
- .setIntoQty(inboundItemVO.getIntoingQty())
- .setIntoAmt(inboundItemVO.getIntoingAmt())
- .setIntoingQty(BigDecimal.ZERO)
- .setIntoingAmt(BigDecimal.ZERO)
- .setCostPrice(inboundItemVO.getPriceInto())
- .setCostAmt(inboundItemVO.getOutQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
- ;
- inboundItemVO.setIntoId(inboundVO.getIntoId());
- //入库状态
- inboundItemVO.setIntoStatus(inboundVO.getIntoStatus());
- inboundItemVO.setIntoType(Constant.IntoType.SALE.getName());
- //实体转换
- InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
- inboundItemMapper.insert(inboundItem);
- inboundItemVO.setItemId(inboundItem.getItemId());
- //region 将库存需要的参数赋值
- inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
- inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
- inboundItemVO.setIntoQty(inboundItemVO.getIntoQty());
- inboundItemVO.setIntoAmt(inboundItemVO.getIntoAmt());
- inboundItemVO.setAddOrEditFlag(true);
- //endregion
- }
- //endregion
- //region 销售明细
- if (inboundItemVO.getFromItemId() != null) {
- //根据id查询
- PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
- PurchaseItem purchaseItem = new PurchaseItem();
- purchaseItem.setItemId(inboundItemVO.getFromItemId());
- purchaseItem.setIntoQty(inboundItemResponse.getIntoQty().negate().add(inboundItemVO.getIntoingQty()));
- purchaseItem.setIntoAmt(inboundItemResponse.getIntoAmt().negate().add(inboundItemVO.getIntoingAmt()));
- //入库状态
- String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty(),
- purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()), purchaseItemResponse.getItemQty());
- purchaseItem.setIntoStatus(intoStatus);
- int countRow = purchaseItemMapper.updateById(purchaseItem);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
- }
- }
- //endregion
- }
- //endregion
- //region 删除明细
- BigDecimal delIntoQty = BigDecimal.ZERO;
- BigDecimal delIntoAmt = BigDecimal.ZERO;
- if (inboundVO.getDeleteItemList() != null && inboundVO.getDeleteItemList().size() > 0) {
- delIntoQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- delIntoAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- for (InboundItemVO inboundItemVO : inboundVO.getDeleteItemList()) {
- if (inboundItemVO.getItemId() != null) {
- //region 将库存需要的参数赋值
- inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
- inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
- inboundItemVO.setIntoQty(inboundItemVO.getIntoQty());
- inboundItemVO.setIntoAmt(inboundItemVO.getIntoAmt());
- //endregion
- InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
- inboundItem.setFlgValid(false);
- //修改
- inboundItemMapper.update(inboundItem,
- new UpdateWrapper<InboundItem>().lambda()
- .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
- );
- }
- //region 销售明细
- if (inboundItemVO.getFromItemId() != null) {
- //根据id查询
- PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
- PurchaseItem purchaseItem = new PurchaseItem();
- purchaseItem.setItemId(inboundItemVO.getFromItemId());
- purchaseItem.setIntoQty(inboundItemVO.getIntoQty().negate());
- purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt().negate());
- purchaseItem.setIntoingQty(inboundItemVO.getIntoQty());
- purchaseItem.setIntoingAmt(inboundItemVO.getIntoAmt());
- //入库状态
- String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
- purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()), purchaseItemResponse.getItemQty());
- purchaseItem.setIntoStatus(intoStatus);
- int countRow = purchaseItemMapper.updateById(purchaseItem);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
- }
- }
- //endregion
- }
- }
- //endregion
- //region 修改入库总单
- Inbound inbound = new Inbound();
- inbound.setIntoId(inboundVO.getIntoId());
- inbound.setIntoQty(sumQty);
- inbound.setIntoAmt(sumAmt);
- //修改
- inboundMapper.update(inbound,
- new UpdateWrapper<Inbound>().lambda().eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
- );
- //endregion
- //region 修改销售总单
- if (inboundVO.getFromId() != null) {
- //根据id查询
- PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId());
- Purchase purchase = new Purchase();
- purchase.setPurId(inboundVO.getFromId());
- purchase.setIntoQty(inboundResponse.getIntoQty().negate().add(sumQty).subtract(delIntoQty));
- purchase.setIntoAmt(inboundResponse.getIntoAmt().negate().add(sumAmt).subtract(delIntoAmt));
- purchase.setIntoingQty(delIntoQty);
- purchase.setIntoingAmt(delIntoAmt);
- //入库状态
- String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchase.getIntoingQty()),
- purchaseResponse.getIntoQty().add(purchase.getIntoQty()), purchaseResponse.getSumQuantity());
- purchase.setIntoStatus(intoStatus);
- //修改
- int countRow = purchaseMapper.updateById(purchase);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
- }
- //endregion
- }
- //endregion
- //region 入账
- if (inboundVO.getReceivableId() != null) {
- accountService.accPayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
- }
- //endregion
- //region 调用库存
- Map<String, Object> map = new HashMap<>();
- map.put("intoDetail", inboundVO.getItemList());
- map.put("delIntoDetail", inboundVO.getDeleteItemList());
- inventoryService.operatingInventoryInformation(map);
- //endregion
- }
- else{
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.FLG_HANDLE_SETTING_NOT_ENABLED_INTO.getMessage());
- }
- //endregion
- //region 自动办理参数false 入库中编辑
- //自动办理标识为false 并且 自动办理参数为false 入库中
- if (!inboundVO.getFlgAutoHandle() && Constant.FlgHandleSetting.FALSE.getValue().equals(inboundVO.getFlgHandleSetting())) {
- //region 修改明细
- List<InboundItemVO> itemList = inboundVO.getItemList();
- for (InboundItemVO inboundItemVO : itemList) {
- //根据id查询 获取到还未进行修改的数据
- InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId());
- //region 编辑明细
- if (inboundItemVO.getItemId() != null) {
- InboundItem inboundItem = new InboundItem();
- inboundItem.setItemId(inboundItemVO.getItemId());
- inboundItem.setIntoingQty(inboundItemVO.getIntoingQty());
- inboundItem.setIntoingAmt(inboundItemVO.getIntoingAmt());
- //修改
- inboundItemMapper.update(inboundItem,
- new UpdateWrapper<InboundItem>().lambda()
- .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
- );
- }
- //endregion
- //region 新建明细
- else {
- inboundItemVO
- .setIntoQty(BigDecimal.ZERO)
- .setIntoAmt(BigDecimal.ZERO)
- .setCostPrice(inboundItemVO.getPriceInto())
- .setCostAmt(inboundItemVO.getIntoingQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
- ;
- inboundItemVO.setIntoId(inboundVO.getIntoId());
- //入库状态
- inboundItemVO.setIntoStatus(inboundVO.getIntoStatus());
- inboundItemVO.setIntoType(Constant.IntoType.SALE.getName());
- //实体转换
- InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
- inboundItemMapper.insert(inboundItem);
- inboundItemVO.setItemId(inboundItem.getItemId());
- }
- //endregion
- //region 销售明细
- if (inboundItemVO.getFromItemId() != null) {
- //根据id查询
- PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
- PurchaseItem purchaseItem = new PurchaseItem();
- purchaseItem.setItemId(inboundItemVO.getFromItemId());
- //本次修改几个传几个(负数) sql中是原数据+本次修改数据
- purchaseItem.setIntoingQty(inboundItemResponse.getIntoingQty().negate().add(inboundItemVO.getIntoingQty()));
- purchaseItem.setIntoingAmt(inboundItemResponse.getIntoingAmt().negate().add(inboundItemVO.getIntoingAmt()));
- //入库状态
- String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
- purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()), purchaseItemResponse.getItemQty());
- purchaseItem.setIntoStatus(intoStatus);
- int countRow = purchaseItemMapper.updateById(purchaseItem);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
- }
- }
- //endregion
- }
- //endregion
- //region 删除明细
- BigDecimal delIntoQty = BigDecimal.ZERO;
- BigDecimal delIntoAmt = BigDecimal.ZERO;
- if (inboundVO.getDeleteItemList() != null && inboundVO.getDeleteItemList().size() > 0) {
- delIntoQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- delIntoAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- for (InboundItemVO inboundItemVO : inboundVO.getDeleteItemList()) {
- //region 明细
- if (inboundItemVO.getItemId() != null) {
- InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
- inboundItem.setFlgValid(false);
- //修改
- inboundItemMapper.update(inboundItem,
- new UpdateWrapper<InboundItem>().lambda()
- .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
- );
- }
- //endregion
- //region 销售明细
- if (inboundItemVO.getFromItemId() != null) {
- //根据id查询
- PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
- PurchaseItem purchaseItem = new PurchaseItem();
- purchaseItem.setItemId(inboundItemVO.getFromItemId());
- purchaseItem.setIntoingQty(inboundItemVO.getIntoingQty().negate());
- purchaseItem.setIntoingAmt(inboundItemVO.getIntoingAmt().negate());
- //入库状态
- String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
- purchaseItemResponse.getIntoQty(), purchaseItemResponse.getItemQty());
- purchaseItem.setIntoStatus(intoStatus);
- int countRow = purchaseItemMapper.updateById(purchaseItem);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
- }
- }
- //endregion
- }
- }
- //endregion
- //region 修改入库总单
- Inbound inbound = new Inbound();
- inbound.setIntoId(inboundVO.getIntoId());
- inbound.setIntoingQty(sumQty);
- inbound.setIntoingAmt(sumAmt);
- //修改
- inboundMapper.update(inbound,
- new UpdateWrapper<Inbound>().lambda().eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
- );
- //endregion
- //region 修改采购总单
- if (inboundVO.getFromId() != null) {
- //根据id查询
- PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId());
- Purchase purchase = new Purchase();
- purchase.setPurId(inboundVO.getFromId());
- purchase.setIntoingQty(inboundResponse.getIntoingQty().negate().add(sumQty).subtract(delIntoQty));
- purchase.setIntoingAmt(inboundResponse.getIntoingAmt().negate().add(sumAmt).subtract(delIntoAmt));
- //入库状态
- String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchase.getIntoingQty()),
- purchaseResponse.getIntoQty(), purchaseResponse.getSumQuantity());
- purchase.setIntoStatus(intoStatus);
- //修改
- int countRow = purchaseMapper.updateById(purchase);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
- }
- }
- //endregion
- }
- else{
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.FLG_HANDLE_SETTING_NOT_ENABLED_INTO.getMessage());
- }
- //endregion
- }
- //endregion
- return ResponseResultUtil.success(inboundVO);
- }
- /**
- * @desc : 采购入库作废
- * @date : 2024/3/26 9:24
- * @author : 寇珊珊
- */
- @Transactional(rollbackFor = {Exception.class})
- public ResponseResultVO<?> purchaseInboundRepeal(String intoId) {
- //region 查询总单 查询明细
- //根据id查询 此条入库单的数据还未更改前的数据
- InboundResponse inboundResponse = inboundMapper.selectById(intoId);
- //根据总单id查询
- List<InboundItemResponse> inboundItemResponseList = inboundItemMapper.selectByCond(new InboundItemQuery().setIntoId(inboundResponse.getIntoId()));
- //endregion
- //region 已入库作废
- if (Constant.IntoStatus.YIRUKU.getName().equals(inboundResponse.getIntoStatus())) {
- //region 退账
- if (inboundResponse.getReceivableId() != null) {
- accountService.reversePayable(inboundResponse.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
- }
- //endregion
- //region 修改明细
- for (InboundItemResponse inboundItemResponse : inboundItemResponseList) {
- //region 将库存需要的参数赋值
- inboundItemResponse.setInventoryType(Constant.InventoryType.INBOUND.getName());
- inboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
- inboundItemResponse.setIntoQty(inboundItemResponse.getIntoQty().negate());
- inboundItemResponse.setIntoAmt(inboundItemResponse.getIntoAmt().negate());
- //endregion
- //region 编辑明细 赋值 赋值明细 防止作废的单据查不到明细 故注掉下面代码
- // InboundItem inboundItem = new InboundItem();
- // inboundItem.setItemId(inboundItemResponse.getItemId());
- // inboundItem.setFlgValid(false);
- // //修改
- // inboundItemMapper.update(inboundItem,
- // new UpdateWrapper<InboundItem>().lambda()
- // .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
- // );
- //endregion
- //region 销售明细
- if (inboundItemResponse.getFromItemId() != null) {
- //根据id查询
- PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemResponse.getFromItemId());
- PurchaseItem purchaseItem = new PurchaseItem();
- purchaseItem.setItemId(inboundItemResponse.getFromItemId());
- purchaseItem.setIntoQty(inboundItemResponse.getIntoQty().negate());
- purchaseItem.setIntoAmt(inboundItemResponse.getIntoAmt().negate());
- //入库状态
- String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty(),
- purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()), purchaseItemResponse.getItemQty());
- purchaseItem.setIntoStatus(intoStatus);
- int countRow = purchaseItemMapper.updateById(purchaseItem);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
- }
- }
- //endregion
- }
- //endregion
- //region 修改入库总单
- Inbound inbound = new Inbound();
- inbound.setIntoId(inboundResponse.getIntoId());
- inbound.setFlgValid(false);
- //修改
- inboundMapper.update(inbound,
- new UpdateWrapper<Inbound>().lambda().eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
- );
- //endregion
- //region 修改销售总单
- if (inboundResponse.getFromId() != null) {
- //根据id查询
- PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundResponse.getFromId());
- Purchase purchase = new Purchase();
- purchase.setPurId(inboundResponse.getFromId());
- purchase.setIntoQty(inboundResponse.getIntoQty().negate());
- purchase.setIntoAmt(inboundResponse.getIntoAmt().negate());
- //入库状态
- String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty(),
- purchaseResponse.getIntoQty().add(purchase.getIntoQty()), purchaseResponse.getSumQuantity());
- purchase.setIntoStatus(intoStatus);
- //修改
- int countRow = purchaseMapper.updateById(purchase);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
- }
- }
- //endregion
- //region 入账
- if (inboundResponse.getReceivableId() != null) {
- accountService.accPayable(inboundResponse.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
- }
- //endregion
- //region 调用库存
- Map<String, Object> map = new HashMap<>();
- map.put("delIntoDetail", inboundItemResponseList);
- inventoryService.operatingInventoryInformation(map);
- //endregion
- }
- //endregion
- //region 入库中、待入库作废
- if (Constant.IntoStatus.RUKUZHONG.getName().equals(inboundResponse.getIntoStatus()) ||
- Constant.IntoStatus.DAIRUKU.getName().equals(inboundResponse.getIntoStatus())) {
- //region 修改明细
- for (InboundItemResponse inboundItemResponse : inboundItemResponseList) {
- //region 编辑明细 赋值
- InboundItem inboundItem = new InboundItem();
- inboundItem.setItemId(inboundItemResponse.getItemId());
- inboundItem.setIntoingQty(BigDecimal.ZERO);
- inboundItem.setIntoingAmt(BigDecimal.ZERO);
- // inboundItem.setFlgValid(false);
- //修改
- inboundItemMapper.update(inboundItem,
- new UpdateWrapper<InboundItem>().lambda()
- .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
- );
- //endregion
- //region 销售明细
- if (inboundItemResponse.getFromItemId() != null) {
- //根据id查询
- PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemResponse.getFromItemId());
- PurchaseItem purchaseItem = new PurchaseItem();
- purchaseItem.setItemId(inboundItemResponse.getFromItemId());
- purchaseItem.setIntoingQty(inboundItemResponse.getIntoingQty().negate());
- purchaseItem.setIntoingAmt(inboundItemResponse.getIntoingAmt().negate());
- //入库状态
- String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
- purchaseItemResponse.getIntoQty(), purchaseItemResponse.getItemQty());
- purchaseItem.setIntoStatus(intoStatus);
- int countRow = purchaseItemMapper.updateById(purchaseItem);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
- }
- }
- //endregion
- }
- //endregion
- //region 修改入库总单
- Inbound inbound = new Inbound();
- inbound.setIntoId(inboundResponse.getIntoId());
- inbound.setIntoingQty(BigDecimal.ZERO);
- inbound.setIntoAmt(BigDecimal.ZERO);
- inbound.setFlgValid(false);
- //修改
- inboundMapper.update(inbound,
- new UpdateWrapper<Inbound>().lambda().eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
- );
- //endregion
- //region 修改销售总单
- if (inboundResponse.getFromId() != null) {
- //根据id查询
- PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundResponse.getFromId());
- Purchase purchase = new Purchase();
- purchase.setPurId(inboundResponse.getFromId());
- purchase.setIntoingQty(inboundResponse.getIntoingQty().negate());
- purchase.setIntoingAmt(inboundResponse.getIntoingAmt().negate());
- //入库状态
- String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchase.getIntoingQty()),
- purchaseResponse.getIntoQty(), purchaseResponse.getSumQuantity());
- purchase.setIntoStatus(intoStatus);
- //修改
- int countRow = purchaseMapper.updateById(purchase);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
- }
- }
- //endregion
- }
- //endregion
- return ResponseResultUtil.success();
- }
- /**
- * @desc : 采购入库办理
- * @date : 2024/3/7 15:47
- * @author : 寇珊珊
- */
- @Transactional(rollbackFor = {Exception.class})
- public ResponseResultVO<?> purchaseHandleInbound(InboundVO inboundVO) {
- //region 根据id查询 此条入库单的数据还未更改前的数据
- InboundResponse inboundResponse = inboundMapper.selectById(inboundVO.getIntoId());
- //endregion
- //region 退账
- if (inboundResponse.getReceivableId() != null) {
- accountService.reversePayable(inboundResponse.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
- }
- //endregion
- //region 编辑明细
- //校验明细
- if (inboundVO.getItemList().size() == 0) {
- throw new BaseBusinessException(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(),
- ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
- }
- for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
- //入库明细根据id查询
- InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId());
- //region 校验数量是否超出
- if (inboundItemVO.getIntoingQty().compareTo(inboundItemResponse.getIntoingQty()) > 0) {
- throw new BaseBusinessException(ErrorCodeEnum.CANNOT_EXCEED_THE_QUANTITY_IN_THE_OUTBOUND_SHIPMENT.getCode(),
- ErrorCodeEnum.CANNOT_EXCEED_THE_QUANTITY_IN_THE_OUTBOUND_SHIPMENT.getMessage());
- }
- //endregion
- //region 编辑明细
- if (inboundItemVO.getItemId() != null) {
- inboundItemVO
- .setIntoQty(inboundItemResponse.getIntoQty().add(inboundItemVO.getIntoingQty()))
- .setIntoAmt(inboundItemResponse.getIntoAmt().add(inboundItemVO.getIntoingAmt()))
- .setIntoingQty(BigDecimal.ZERO)
- .setIntoingAmt(BigDecimal.ZERO)
- .setCostPrice(inboundItemVO.getPriceInto())
- .setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
- ;
- //入库状态
- String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
- inboundItemVO.setIntoStatus(intoStatus);
- //实体转换
- InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
- //修改
- inboundItemMapper.update(inboundItem,
- new UpdateWrapper<InboundItem>().lambda()
- .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
- );
- //region 将库存需要的参数赋值
- inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
- inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
- //编辑之前的数
- if(inboundItemResponse.getIntoQty().compareTo(BigDecimal.ZERO)>0) {
- inboundItemVO.setQtyBeforeUpdate(inboundItemResponse.getIntoQty());
- inboundItemVO.setAmtBeforeUpdate(inboundItemResponse.getIntoAmt());
- }
- inboundItemVO.setAddOrEditFlag(true);
- //endregion
- }
- //endregion
- //region 新建明细
- else {
- inboundItemVO
- .setIntoQty(inboundItemVO.getIntoingQty())
- .setIntoAmt(inboundItemVO.getIntoingAmt())
- .setIntoId(inboundVO.getIntoId())
- .setCostPrice(inboundItemVO.getPriceInto())
- .setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
- .setIntoType(Constant.IntoType.SALE.getName())
- .setIntoingQty(BigDecimal.ZERO)
- .setIntoingAmt(BigDecimal.ZERO)
- ;
- //入库状态
- String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
- inboundItemVO.setIntoStatus(intoStatus);
- //实体转换
- InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
- //新建
- inboundItemMapper.insert(inboundItem);
- inboundItemVO.setItemId(inboundItem.getItemId());
- //region 将库存需要的参数赋值
- inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
- inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
- inboundItemVO.setAddOrEditFlag(true);
- //endregion
- }
- //endregion
- //region 采购明细
- if(inboundItemVO.getFromItemId()!=null){
- //根据id查询
- PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
- //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
- PurchaseItem purchaseItem = new PurchaseItem();
- purchaseItem.setItemId(inboundItemVO.getFromItemId());
- purchaseItem.setIntoingQty(inboundItemVO.getIntoQty().negate());
- purchaseItem.setIntoingAmt(inboundItemVO.getIntoAmt().negate());
- purchaseItem.setIntoQty(inboundItemVO.getIntoQty());
- purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt());
- //入库状态
- String purItemIntoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
- purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()), purchaseItemResponse.getItemQty());
- purchaseItem.setIntoStatus(purItemIntoStatus);
- int countRow = purchaseItemMapper.updateById(purchaseItem);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
- }
- }
- //endregion
- }
- //endregion
- //region 删除明细
- BigDecimal delIntoingQty = BigDecimal.ZERO;
- BigDecimal delIntoingAmt = BigDecimal.ZERO;
- BigDecimal delIntoQty = BigDecimal.ZERO;
- BigDecimal delIntoAmt = BigDecimal.ZERO;
- if (inboundVO.getDeleteItemList() != null && inboundVO.getDeleteItemList().size() > 0) {
- delIntoingQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- delIntoingAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- delIntoQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- delIntoAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- for (InboundItemVO inboundItemVO : inboundVO.getDeleteItemList()) {
- if (inboundItemVO.getItemId() != null) {
- //region 将库存需要的参数赋值
- inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
- inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
- //endregion
- InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
- inboundItem.setFlgValid(false);
- //修改
- inboundItemMapper.update(inboundItem,
- new UpdateWrapper<InboundItem>().lambda()
- .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
- );
- }
- //region 采购
- if (inboundItemVO.getFromItemId() != null) {
- //region 采购订单明细
- //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
- PurchaseItem purchaseItem = new PurchaseItem();
- purchaseItem.setItemId(inboundItemVO.getFromItemId());
- purchaseItem.setIntoingQty(inboundItemVO.getIntoingQty().negate());
- purchaseItem.setIntoingAmt(inboundItemVO.getIntoingAmt().negate());
- purchaseItem.setIntoQty(inboundItemVO.getIntoQty().negate());
- purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt().negate());
- //根据id查询
- PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
- //入库状态
- String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
- purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()), purchaseItemResponse.getItemQty());
- purchaseItem.setIntoStatus(intoStatus);
- int countRow = purchaseItemMapper.updateById(purchaseItem);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
- }
- //endregion
- }
- //endregion
- }
- }
- //endregion
- //region 编辑总单
- BigDecimal sumIntoQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- BigDecimal sumIntoAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- inboundVO.setIntoQty(sumIntoQty);
- inboundVO.setIntoAmt(sumIntoAmt);
- inboundVO.setIntoingQty(BigDecimal.ZERO);
- inboundVO.setIntoingAmt(BigDecimal.ZERO);
- //入库状态
- String intoStatus = this.setIntoStatus(inboundVO.getIntoingQty(), inboundVO.getIntoQty());
- inboundVO.setIntoStatus(intoStatus);
- //实体转换
- Inbound inbound = inboundConvert.convertToPo(inboundVO);
- //修改
- inboundMapper.update(inbound,
- new UpdateWrapper<Inbound>().lambda().eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
- );
- //endregion
- //region 修改采购订单
- if (inboundVO.getFromId() != null) {
- //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
- Purchase purchase = new Purchase();
- purchase.setPurId(inboundVO.getFromId());
- purchase.setIntoQty(sumIntoQty.subtract(delIntoQty));
- purchase.setIntoAmt(sumIntoAmt.subtract(delIntoAmt));
- purchase.setIntoingQty((inboundResponse.getIntoingQty().add(delIntoingQty)).negate());
- purchase.setIntoingAmt((inboundResponse.getIntoingAmt().add(delIntoingAmt)).negate());
- //根据id查询
- PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId());
- //入库状态
- String purIntoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchase.getIntoingQty()),
- purchaseResponse.getIntoQty().add(purchase.getIntoQty()), purchaseResponse.getSumQuantity());
- purchase.setIntoStatus(purIntoStatus);
- //修改
- int countRow = purchaseMapper.updateById(purchase);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
- }
- }
- //endregion
- //region 入账
- accountService.accPayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
- //endregion
- //region 调用库存
- Map<String, Object> map = new HashMap<>();
- map.put("intoDetail", inboundVO.getItemList());
- map.put("delIntoDetail", inboundVO.getDeleteItemList());
- inventoryService.operatingInventoryInformation(map);
- //endregion
- return ResponseResultUtil.success(inboundVO);
- }
- /**
- * @desc : 采购入库撤销
- * @date : 2024/3/7 17:06
- * @author : 寇珊珊
- */
- @Transactional(rollbackFor = {Exception.class})
- public ResponseResultVO<?> purchaseInboundCancel(InboundVO inboundVO) {
- //region 查询入库总单数据信息
- InboundResponse inboundResponse = inboundMapper.selectById(inboundVO.getIntoId());
- //endregion
- //region 退账
- if (inboundResponse.getReceivableId() != null) {
- accountService.reversePayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
- }
- //endregion
- //region 修改订单数据信息
- if (inboundResponse.getFromId() != null) {
- //根据id查询
- PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId());
- //赋值 (这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
- Purchase purchase = new Purchase();
- purchase.setPurId(inboundResponse.getFromId());
- purchase.setIntoQty(inboundResponse.getIntoQty().negate());
- purchase.setIntoAmt(inboundResponse.getIntoAmt().negate());
- purchase.setIntoingQty(inboundResponse.getIntoQty());
- purchase.setIntoingAmt(inboundResponse.getIntoAmt());
- //入库状态
- String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchase.getIntoingQty()),
- purchaseResponse.getIntoQty().add(purchase.getIntoQty()), purchaseResponse.getSumQuantity());
- purchase.setIntoStatus(intoStatus);
- int countRow = purchaseMapper.updateById(purchase);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
- }
- }
- //endregion
- //region 修改总单数据信息
- Inbound inbound = new Inbound();
- inbound.setIntoId(inboundVO.getIntoId());
- inbound.setIntoDate(null);
- inbound.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName());
- inbound.setIntoingQty(inboundResponse.getIntoingQty().add(inboundResponse.getIntoQty()));
- inbound.setIntoingAmt(inboundResponse.getIntoingAmt().add(inboundResponse.getIntoAmt()));
- inbound.setIntoQty(BigDecimal.ZERO);
- inbound.setIntoAmt(BigDecimal.ZERO);
- //修改
- inboundMapper.update(inbound,
- new UpdateWrapper<Inbound>().lambda()
- .eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
- );
- //endregion
- //region 明细数据
- //根据总单id查明细
- List<InboundItemResponse> inboundItemResponseList = inboundItemMapper.selectByCond(new InboundItemQuery().setIntoId(inbound.getIntoId()));
- for (InboundItemResponse inboundItemResponse : inboundItemResponseList) {
- //region 修改采购明细数据信息
- if (inboundItemResponse.getFromItemId() != null) {
- //根据id查询
- PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemResponse.getFromItemId());
- //赋值 (这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
- PurchaseItem purchaseItem = new PurchaseItem();
- purchaseItem.setItemId(inboundItemResponse.getFromItemId());
- purchaseItem.setIntoQty(inboundItemResponse.getIntoQty().negate());
- purchaseItem.setIntoAmt(inboundItemResponse.getIntoAmt().negate());
- purchaseItem.setIntoingQty(inboundItemResponse.getIntoQty());
- purchaseItem.setIntoingAmt(inboundItemResponse.getIntoAmt());
- //入库状态
- String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
- purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()), purchaseItemResponse.getItemQty());
- purchaseItem.setIntoStatus(intoStatus);
- //修改
- int countRow = purchaseItemMapper.updateById(purchaseItem);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
- }
- }
- //endregion
- //region修改入库明细信息
- InboundItem inboundItem = new InboundItem();
- //region 将库存需要的参数赋值
- inboundItemResponse.setInventoryType(Constant.InventoryType.INBOUND.getName());
- inboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
- inboundItemResponse.setIntoQty(inboundItemResponse.getIntoQty().negate());
- inboundItemResponse.setIntoAmt(inboundItemResponse.getIntoAmt().negate());
- //endregion
- inboundItem
- .setIntoId(inbound.getIntoId())
- .setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName())
- .setIntoingQty(inboundItemResponse.getIntoingQty().add(inboundItemResponse.getIntoQty()))
- .setIntoingAmt(inboundItemResponse.getIntoingAmt().add(inboundItemResponse.getIntoAmt()))
- .setIntoQty(BigDecimal.ZERO)
- .setIntoAmt(BigDecimal.ZERO)
- .setCostPrice(BigDecimal.ZERO)
- .setCostAmt(BigDecimal.ZERO)
- .setItemId(inboundItemResponse.getItemId());
- //入库状态
- String intoStatus = this.setIntoStatus(inboundItem.getIntoingQty(), inboundItem.getIntoQty());
- inboundItem.setIntoStatus(intoStatus);
- //修改
- inboundItemMapper.update(inboundItem,
- new UpdateWrapper<InboundItem>().lambda()
- .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
- );
- //endregion
- }
- //endregion
- //region 调用库存
- Map<String, Object> map = new HashMap<>();
- map.put("delIntoDetail", inboundItemResponseList);
- inventoryService.operatingInventoryInformation(map);
- //endregion
- return ResponseResultUtil.success();
- }
- /**
- * @desc : 入库状态通用(目前本页面)
- * @date : 2024/3/9 8:59
- * @author : 寇珊珊
- */
- @Transactional(rollbackFor = {Exception.class})
- public String setIntoStatus(BigDecimal intoingQty, BigDecimal intoQty) {
- //入库状态
- String intoStatus = null;
- //已入库数量>0 入库中数量>0
- if (intoQty.compareTo(BigDecimal.ZERO) >= 0 && intoingQty.compareTo(BigDecimal.ZERO) > 0) {
- //入库中
- intoStatus = Constant.IntoStatus.RUKUZHONG.getName();
- }
- //已入库数量=0 入库中数量=0
- else if (intoQty.compareTo(BigDecimal.ZERO) == 0 && intoingQty.compareTo(BigDecimal.ZERO) == 0) {
- //待入库
- intoStatus = Constant.IntoStatus.DAIRUKU.getName();
- }
- //已入库数量>0 入库中数量=0
- else if (intoQty.compareTo(BigDecimal.ZERO) > 0 && intoingQty.compareTo(BigDecimal.ZERO) == 0) {
- //已入库
- intoStatus = Constant.IntoStatus.YIRUKU.getName();
- }
- return intoStatus;
- }
- /**
- * @desc : 上游单据入库状态通用(目前本页面)
- * @date : 2024/4/1 17:14
- * @author : 寇珊珊
- */
- @Transactional(rollbackFor = {Exception.class})
- public String setIntoStatus(BigDecimal intoingQty, BigDecimal intoQty, BigDecimal sumQty) {
- //入库状态
- String intoStatus = null;
- //入库中+已入库 小于 总数 并且 入库中数量 等于订单总数量
- if (intoingQty.compareTo(sumQty) <= 0 && intoingQty.add(intoQty).compareTo(sumQty) <= 0) {
- //入库中
- intoStatus = Constant.IntoStatus.RUKUZHONG.getName();
- }
- //已入库数量=0 入库中数量=0
- else if (intoQty.compareTo(BigDecimal.ZERO) == 0 && intoingQty.compareTo(BigDecimal.ZERO) == 0) {
- //待入库
- intoStatus = Constant.IntoStatus.DAIRUKU.getName();
- }
- //入库中+已入库 等于 总数 并且 入库中数量 小于等于订单总数量
- else if (intoingQty.compareTo(sumQty) < 0 && intoingQty.add(intoQty).compareTo(sumQty) == 0) {
- //已入库
- intoStatus = Constant.IntoStatus.YIRUKU.getName();
- }
- return intoStatus;
- }
- }
|