| | |
| | | package com.vincent.rsf.server.manager.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.vincent.rsf.framework.common.R; |
| | | import com.vincent.rsf.framework.exception.CoolException; |
| | | import com.vincent.rsf.server.manager.controller.params.IsptOrderParam; |
| | | import com.vincent.rsf.server.manager.controller.params.QlyInspectAndItem; |
| | | import com.vincent.rsf.server.manager.entity.AsnOrder; |
| | | import com.vincent.rsf.server.manager.entity.AsnOrderItem; |
| | | import com.vincent.rsf.server.manager.entity.QlyIsptItem; |
| | | import com.vincent.rsf.server.manager.enums.QlyIsptStatus; |
| | | import com.vincent.rsf.server.manager.mapper.QlyInspectMapper; |
| | | import com.vincent.rsf.server.manager.entity.QlyInspect; |
| | | import com.vincent.rsf.server.manager.service.AsnOrderItemService; |
| | | import com.vincent.rsf.server.manager.service.AsnOrderService; |
| | | import com.vincent.rsf.server.manager.service.QlyInspectService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.vincent.rsf.server.manager.service.QlyIsptItemService; |
| | | import com.vincent.rsf.server.system.constant.SerialRuleCode; |
| | | import com.vincent.rsf.server.system.utils.SerialRuleUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service("qlyInspectService") |
| | | public class QlyInspectServiceImpl extends ServiceImpl<QlyInspectMapper, QlyInspect> implements QlyInspectService { |
| | | |
| | | @Autowired |
| | | private AsnOrderItemService asnOrderItemService; |
| | | |
| | | @Autowired |
| | | private AsnOrderService asnOrderService; |
| | | |
| | | @Autowired |
| | | private QlyIsptItemService qlyIsptItemService; |
| | | |
| | | @Override |
| | | public List<AsnOrderItem> listByAsn(Map<String, Object> map) { |
| | | if (Objects.isNull(map.get("asnCode"))) { |
| | | throw new CoolException("收货单据明细编码不能为空!!"); |
| | | } |
| | | AsnOrder asnOrder = asnOrderService.getOne(new LambdaQueryWrapper<AsnOrder>() |
| | | .eq(AsnOrder::getCode, map.get("asnCode")) |
| | | .ne(AsnOrder::getNtyStatus, 0)); |
| | | if (Objects.isNull(asnOrder)) { |
| | | throw new CoolException("单据不存在!!"); |
| | | } |
| | | List<AsnOrderItem> asnOrderItems = asnOrderItemService.list(new LambdaQueryWrapper<AsnOrderItem>() |
| | | .eq(AsnOrderItem::getAsnCode, map.get("asnCode")) |
| | | .eq(AsnOrderItem::getNtyStatus, 1)); |
| | | if (asnOrderItems.isEmpty()) { |
| | | return new ArrayList<>(); |
| | | } |
| | | return asnOrderItems; |
| | | } |
| | | |
| | | @Override |
| | | public R allSave(QlyInspectAndItem params) { |
| | | if (Objects.isNull(params.getQlyInspect())) { |
| | | throw new CoolException("质检单据不能为空!!"); |
| | | } |
| | | QlyInspect inspect = params.getQlyInspect(); |
| | | if (Objects.isNull(inspect.getWkType())) { |
| | | throw new CoolException("业务类型不能为空!!"); |
| | | } |
| | | String code = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_INSPECT_CODE, inspect); |
| | | inspect.setCode(code); |
| | | if (!this.saveOrUpdate(inspect)) { |
| | | throw new CoolException("质检单保存失败!!"); |
| | | } |
| | | List<QlyIsptItem> isptItems = params.getQlyIsptItems(); |
| | | if (isptItems.isEmpty()) { |
| | | return R.ok("保存成功!!"); |
| | | } |
| | | List<QlyIsptItem> items = new ArrayList<>(); |
| | | for (QlyIsptItem isptItem : isptItems) { |
| | | if (Objects.isNull(isptItem.getMatnrCode())) { |
| | | continue; |
| | | } |
| | | isptItem.setIspectId(inspect.getId()); |
| | | items.add(isptItem); |
| | | } |
| | | if (!qlyIsptItemService.saveOrUpdateBatch(items)) { |
| | | throw new CoolException("质检明细保存失败!!"); |
| | | } |
| | | return R.ok("保存成功!!"); |
| | | } |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @description 获取未质检单据 |
| | | * @param |
| | | * @return |
| | | * @time 2025/3/31 10:12 |
| | | */ |
| | | @Override |
| | | public List<AsnOrder> getUnInspect(Map<String, Object> params) { |
| | | List<AsnOrder> asnOrders = asnOrderService.list(new LambdaQueryWrapper<AsnOrder>() |
| | | .eq(AsnOrder::getStatus, 1) |
| | | .eq(!Objects.isNull(params.get("asnCode")) && StringUtils.isNotBlank(params.get("asnCode").toString()), AsnOrder::getCode, StringUtils.isNotBlank(params.get("asnCode").toString()) ? params.get("asnCode").toString() : null)); |
| | | return asnOrders; |
| | | } |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @description 保存 |
| | | * @param |
| | | * @return |
| | | * @time 2025/3/31 14:54 |
| | | */ |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R saveSelected(IsptOrderParam param, Long loginUserId) { |
| | | if (Objects.isNull(param.getIds()) || param.getIds().isEmpty()) { |
| | | throw new CoolException("单据ID不能为空!!"); |
| | | } |
| | | List<AsnOrder> asnOrders = asnOrderService.list(new LambdaQueryWrapper<AsnOrder>().in(AsnOrder::getId, param.getIds()).eq(AsnOrder::getNtyStatus, 0)); |
| | | if (asnOrders.isEmpty()) { |
| | | throw new CoolException("单据不存在!!"); |
| | | } |
| | | List<AsnOrderItem> orderItems = asnOrderItemService.list(new LambdaQueryWrapper<AsnOrderItem>().in(AsnOrderItem::getAsnId, param.getIds())); |
| | | if (orderItems.isEmpty()) { |
| | | throw new CoolException("单据明细不存在!!"); |
| | | } |
| | | Map<Long, List<AsnOrderItem>> listMap = orderItems.stream().collect(Collectors.groupingBy(AsnOrderItem::getAsnId)); |
| | | for (AsnOrder asnOrder : asnOrders) { |
| | | QlyInspect inspect = new QlyInspect(); |
| | | String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_INSPECT_CODE, null); |
| | | if (StringUtils.isBlank(ruleCode)) { |
| | | throw new CoolException("策略错误:请检查策略「" + SerialRuleCode.SYS_INSPECT_CODE + "」是否设置正确!!"); |
| | | } |
| | | inspect.setCode(ruleCode) |
| | | .setWkType(asnOrder.getWkType()) |
| | | .setIsptStatus(QlyIsptStatus.QLY_ISPT_STAS_ING.val) |
| | | .setCreateBy(loginUserId) |
| | | .setAsnId(asnOrder.getId()) |
| | | .setAsnCode(asnOrder.getCode()); |
| | | /**获取单据明细*/ |
| | | List<AsnOrderItem> asnOrderItems = listMap.get(asnOrder.getId()); |
| | | if (Objects.isNull(asnOrderItems) || asnOrderItems.isEmpty()) { |
| | | continue; |
| | | } |
| | | double rcptQty = asnOrderItems.stream().mapToDouble(AsnOrderItem::getQty).sum(); |
| | | double anfme = asnOrderItems.stream().mapToDouble(AsnOrderItem::getAnfme).sum(); |
| | | inspect.setRcptQty(rcptQty).setDlyQty(anfme); |
| | | if (!this.save(inspect)) { |
| | | throw new CoolException("单据" + asnOrder.getCode() + "保存失败!!"); |
| | | } |
| | | List<QlyIsptItem> items = new ArrayList<>(); |
| | | for (AsnOrderItem orderItem : asnOrderItems) { |
| | | QlyIsptItem isptItem = new QlyIsptItem(); |
| | | BeanUtils.copyProperties(orderItem, isptItem); |
| | | isptItem.setAsnItemId(orderItem.getId()) |
| | | .setIspectId(inspect.getId()) |
| | | .setRcptQty(orderItem.getQty()) |
| | | .setCreateBy(loginUserId) |
| | | .setDlyQty(orderItem.getAnfme()); |
| | | items.add(isptItem); |
| | | } |
| | | if (!qlyIsptItemService.saveBatch(items)) { |
| | | throw new CoolException("明细保存失败!!"); |
| | | } |
| | | } |
| | | if (!asnOrderService.update(new LambdaUpdateWrapper<AsnOrder>().in(AsnOrder::getId, param.getIds()).set(AsnOrder::getNtyStatus, 1))) { |
| | | throw new CoolException("报检状态修改失败!!"); |
| | | } |
| | | return R.ok("保存成功!!"); |
| | | } |
| | | } |