| | |
| | | package com.yuanchu.mom.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.yuanchu.mom.mapper.ConsignmentMapper; |
| | | import com.yuanchu.mom.mapper.ReceiptMapper; |
| | | import com.yuanchu.mom.mapper.RepertoryMapper; |
| | | import com.yuanchu.mom.pojo.Consignment; |
| | | import com.yuanchu.mom.pojo.Receipt; |
| | | import com.yuanchu.mom.pojo.Repertory; |
| | | import com.yuanchu.mom.pojo.dto.ConsignmentDto; |
| | | import com.yuanchu.mom.pojo.dto.ConsignmentDto2; |
| | | import com.yuanchu.mom.service.ConsignmentService; |
| | | import com.yuanchu.mom.utils.MyUtil; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 成品发货表(Consignment)表服务实现类 |
| | |
| | | @Resource |
| | | RepertoryMapper repertoryMapper; |
| | | |
| | | @Resource |
| | | ReceiptMapper receiptMapper; |
| | | |
| | | //新增成品发货 |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public String addCon(String name, ConsignmentDto consignmentDto) { |
| | | //如果该订单已经发过货了不能再发货 |
| | | //生成一个押运单编号 |
| | | String escortCode = MyUtil.getTimeSixNumberCode("YY", "num"); |
| | | List<Consignment> consignments = consignmentMapper.selectAll(); |
| | | for (Consignment consignment : consignments) { |
| | | if (consignment.getCustomerCode().equals(consignmentDto.getCustomerCode())) { |
| | | return "该合同订单已发过货,无法再次发货!"; |
| | | } else { |
| | | /*新增成品发货*/ |
| | | List<ConsignmentDto2> messages = consignmentDto.getMessages(); |
| | | for (ConsignmentDto2 message : messages) { |
| | | //查询产品编码(通过在成品库存表中的产品名称,规格型号以及单位进行查找) |
| | | LambdaQueryWrapper<Repertory> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(Repertory::getName, message.getName()) |
| | | .eq(Repertory::getSpecifications, message.getSpecifications()) |
| | | .eq(Repertory::getUnit, message.getUnit()) |
| | | .eq(Repertory::getType, 0); |
| | | Repertory repertory = repertoryMapper.selectOne(queryWrapper); |
| | | //该成品的检验状态是已检验1才能进行发货 |
| | | if (repertory.getCheckState() == 1) { |
| | | //该成品库存的数量大于等于发货的数量才能进行发货 |
| | | if (repertory.getNumber() >= message.getNumber()) { |
| | | //构造成品发货实体类 |
| | | Consignment consig = Consignment.builder() |
| | | .customerCode(consignmentDto.getCustomerCode()) |
| | | .escortCode(MyUtil.getTimeSixNumberCode("YY")) |
| | | .orderCode(consignmentDto.getOrderCode()) |
| | | .userName(name) |
| | | .checkName(consignmentDto.getCheckName()) |
| | | .fitName(consignmentDto.getFitName()) |
| | | .name(message.getName()) |
| | | .specifications(message.getSpecifications()) |
| | | .unit(message.getUnit()) |
| | | .number(message.getNumber()) |
| | | .code(repertory.getCode()) |
| | | .build(); |
| | | consignmentMapper.insert(consig); |
| | | /*减少对应的库存*/ |
| | | repertory.setNumber(repertory.getNumber() - consig.getNumber()); |
| | | repertoryMapper.updateById(repertory); |
| | | } else return "库存不足,无法发货!"; |
| | | } else return "该产品还未检验,不能发货!"; |
| | | } |
| | | } |
| | | //如果发货表中没有数据也可以发货 |
| | | if (consignments.size() == 0) { |
| | | /*新增成品发货*/ |
| | | return addConsign(name, consignmentDto, escortCode); |
| | | } |
| | | //获取发货表中的合同编号集合 |
| | | List<String> customerCodeList = consignments.stream().map(consignment -> { |
| | | String customerCode = consignment.getCustomerCode(); |
| | | return customerCode; |
| | | }).distinct().collect(Collectors.toList()); |
| | | if (customerCodeList.contains(consignmentDto.getCustomerCode())) { |
| | | return "该合同订单已发过货,无法再次发货!"; |
| | | } |
| | | /*新增成品发货*/ |
| | | return addConsign(name, consignmentDto, escortCode); |
| | | } |
| | | |
| | | //查询发货记录列表 |
| | | @Override |
| | | public IPage<Map<String, Object>> selectAllCon(Page<Object> page, String name, String specifications, String time) { |
| | | return consignmentMapper.selectAllCon(page, name, specifications, time); |
| | | } |
| | | |
| | | //新增发货一系列操作 |
| | | private String addConsign(String name, ConsignmentDto consignmentDto, String escortCode) { |
| | | /*新增成品发货*/ |
| | | List<ConsignmentDto2> messages = consignmentDto.getMessages(); |
| | | for (ConsignmentDto2 message : messages) { |
| | | //查询产品库存数量 |
| | | LambdaQueryWrapper<Repertory> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(Repertory::getName, message.getName()) |
| | | .eq(Repertory::getSpecifications, message.getSpecifications()) |
| | | .eq(Repertory::getUnit, message.getUnit()) |
| | | .eq(Repertory::getType, 0) |
| | | .eq(Repertory::getOrderCode, consignmentDto.getOrderCode()); |
| | | Repertory repertory = repertoryMapper.selectOne(queryWrapper); |
| | | //该成品库存不为空且数量大于等于发货的数量才能进行发货 |
| | | if (ObjectUtils.isNotEmpty(repertory) && repertory.getNumber() < message.getNumber()) { |
| | | return "库存不足,无法发货!"; |
| | | } |
| | | //构造成品发货实体类 |
| | | Consignment consig = Consignment.builder() |
| | | .customerCode(consignmentDto.getCustomerCode()) |
| | | .escortCode(escortCode) |
| | | .orderCode(consignmentDto.getOrderCode()) |
| | | .userName(name) |
| | | .checkName(consignmentDto.getCheckName()) |
| | | .fitName(consignmentDto.getFitName()) |
| | | .name(message.getName()) |
| | | .specifications(message.getSpecifications()) |
| | | .unit(message.getUnit()) |
| | | .number(message.getNumber()) |
| | | .qualityTraceability(repertory.getQualityTraceability()) |
| | | .build(); |
| | | consignmentMapper.insert(consig); |
| | | /*减少对应的库存*/ |
| | | repertory.setNumber(repertory.getNumber() - consig.getNumber()); |
| | | repertoryMapper.updateById(repertory); |
| | | } |
| | | /*发货成功之后需要新增一张回单*/ |
| | | Receipt receipt = new Receipt(); |
| | | BeanUtils.copyProperties(consignmentDto, receipt); |
| | | receipt.setName(consignmentDto.getUsername());//收货联系人 |
| | | receipt.setUserName(name);//发货人 |
| | | receipt.setEscortCode(escortCode);//押运单编号 |
| | | receipt.setDeliverTime(new Date());//发货日期 |
| | | receiptMapper.insert(receipt); |
| | | return "发货成功!"; |
| | | } |
| | | } |
| | | |
| | | |