KuaidiDetailService.java 1.89 KB
package com.huaheng.pc.shipment.kuaidiDetail.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.pc.shipment.kuaidiDetail.domain.KuaidiDetail;
import com.huaheng.pc.shipment.kuaidiDetail.mapper.KuaidiDetailMapper;
import com.huaheng.pc.shipment.kuaidiHeader.domain.KuaidiHeader;
import com.huaheng.pc.shipment.kuaidiHeader.service.KuaidiHeaderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * 【请填写功能名称】 服务层实现
 * 
 * @author huaheng
 * @date 2022-09-07
 */
@Service
public class KuaidiDetailService extends ServiceImpl<KuaidiDetailMapper, KuaidiDetail> {
    @Resource
    private KuaidiHeaderService kuaidiHeaderService;
    @Resource
    private MaterialService materialService;

    public AjaxResult insertDetail(KuaidiDetail kuaidiDetail) {
        KuaidiHeader kuaidiHeader = kuaidiHeaderService.getById(kuaidiDetail.getShipmentId());
        if(kuaidiHeader==null){
            return AjaxResult.error("快递主单查找不到");
        }
        kuaidiDetail.setWarehouseId(kuaidiHeader.getWarehouseId());
        kuaidiDetail.setWarehouseCode(kuaidiHeader.getWarehouseCode());
        kuaidiDetail.setUWarehouseCode(kuaidiHeader.getUWarehouseCode());

        Material material = materialService.getMaterialByCode(kuaidiDetail.getMaterialCode());
        if(material==null){
            return AjaxResult.error("物料编码错误,系统无此物料编码");
        }
        kuaidiDetail.setMaterialName(material.getName());
        kuaidiDetail.setSpecification(material.getSpec());
        kuaidiDetail.setUnit(material.getUnit());
        this.save(kuaidiDetail);
        return AjaxResult.success("添加物料成功");
    }
}