package com.yh.saas.plugin.yiliangyiyun.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.yh.saas.plugin.yiliangyiyun.entity.ContractManagementInfo;
import com.yh.saas.plugin.yiliangyiyun.entity.InOutWarehouseTask;
import com.yh.saas.plugin.yiliangyiyun.mapper.ContractGoodsInfoMapper;
import com.yh.saas.plugin.yiliangyiyun.service.IContractGoodsInfoService;
import com.yh.saas.plugin.yiliangyiyun.entity.ContractGoodsInfo;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yh.saas.plugin.yiliangyiyun.service.IContractManagementInfoService;
import com.yh.saas.plugin.yiliangyiyun.service.IInOutWarehouseTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 合同货物信息 服务实现类
 * </p>
 *
 * @author Gongdc
 * @since 2021-05-17
 */
@Service
public class ContractGoodsInfoServiceImpl extends ServiceImpl<ContractGoodsInfoMapper, ContractGoodsInfo> implements IContractGoodsInfoService {

    @Autowired
    private IContractManagementInfoService contractManagementInfoService;
    @Autowired
    private IInOutWarehouseTaskService inOutWarehouseTaskService;
    /**
     * 查看货物信息
     * @param contractId
     * @return
     */
    @Override
    public ContractGoodsInfo getGoodsName(String contractId ,String contractNo){
        //货物信息
        ContractGoodsInfo contractGoodsInfo = this.selectOne(new EntityWrapper<ContractGoodsInfo>().eq(ContractGoodsInfo.QueryFiles.CONTRACT_ID, contractId));
        //合同信息
        ContractManagementInfo contractManagementInfo = contractManagementInfoService.selectOne(new EntityWrapper<ContractManagementInfo>().eq(ContractManagementInfo.QueryFiles.CONTRACT_NO, contractNo));
        if(contractManagementInfo!=null) {
            contractGoodsInfo.setWeight(contractManagementInfo.getWeight());
            contractGoodsInfo.setUnitContractPrice(contractManagementInfo.getUnitContractPrice());
        }
        //移库编号信息
        InOutWarehouseTask inOutWarehouseTask = inOutWarehouseTaskService.selectOne(new EntityWrapper<InOutWarehouseTask>().eq("move_task_no", contractNo));
        if(inOutWarehouseTask!=null) {
            ContractGoodsInfo contractGoodsInfo1=new ContractGoodsInfo();
            contractGoodsInfo1.setWeight(inOutWarehouseTask.getWeight());
            contractGoodsInfo1.setUnitContractPrice(Double.valueOf(String.valueOf(inOutWarehouseTask.getUnitPrice())));
            contractGoodsInfo1.setGoodsName(inOutWarehouseTask.getGoodsName());
            contractGoodsInfo1.setBulkDensity(inOutWarehouseTask.getBulkDensity());
            contractGoodsInfo1.setWaterContent(inOutWarehouseTask.getWaterContent());
            contractGoodsInfo1.setGrade(inOutWarehouseTask.getGrade());
            contractGoodsInfo=contractGoodsInfo1;
        }
        return contractGoodsInfo;
    }
}
