ReceiptContainerHeaderAGVService.java 26.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523
package com.huaheng.pc.receipt.receiptContainerHeader.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.Wrappers;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.service.ConfigService;
import com.huaheng.mobile.receipt.ReceiptBill;
import com.huaheng.pc.config.company.domain.CompanyU8;
import com.huaheng.pc.config.company.service.CompanyU8Service;
import com.huaheng.pc.config.configValue.domain.ConfigValue;
import com.huaheng.pc.config.configValue.mapper.ConfigValueMapper;
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.containerCapacity.domain.ContainerCapacity;
import com.huaheng.pc.config.containerCapacity.service.ContainerCapacityService;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.pc.config.receiptPreference.domain.ReceiptPreference;
import com.huaheng.pc.config.receiptPreference.mapper.ReceiptPreferenceMapper;
import com.huaheng.pc.config.zone.domain.Zone;
import com.huaheng.pc.config.zone.service.ZoneService;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
import com.huaheng.pc.receipt.receiptContainerDetail.domain.ReceiptContainerDetail;
import com.huaheng.pc.receipt.receiptContainerDetail.service.ReceiptContainerDetailService;
import com.huaheng.pc.receipt.receiptContainerHeader.domain.ReceiptContainerHeader;
import com.huaheng.pc.receipt.receiptContainerHeader.domain.ReceiptContainerView;
import com.huaheng.pc.receipt.receiptContainerHeader.mapper.ReceiptContainerHeaderMapper;
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptDetail.service.ReceiptDetailService;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
import com.huaheng.pc.shipment.shipmentContainerHeader.domain.ShipmentContainerHeader;
import com.huaheng.pc.shipment.shipmentContainerHeader.service.ShipmentContainerHeaderService;
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.MessageFormat;
import java.util.*;

/**
 * @author huaheng
 */
@Service
public class ReceiptContainerHeaderAGVService extends ServiceImpl<ReceiptContainerHeaderMapper, ReceiptContainerHeader>{
    @Resource
    private ReceiptContainerHeaderMapper receiptContainerHeaderMapper;
    @Resource
    private ReceiptContainerDetailService receiptContainerDetailService;
    @Resource
    private ReceiptDetailService receiptDetailService;
    @Resource
    private ContainerService containerService;
    @Resource
    private ZoneService zoneService;
    @Resource
    private TaskHeaderService taskHeaderService;
    @Resource
    private TaskDetailService taskDetailService;
    @Resource
    private ReceiptHeaderService receiptHeaderService;
    @Resource
    private CompanyU8Service companyU8Service;
    @Resource
    private MaterialService materialService;
    @Resource
    private InventoryDetailService inventoryDetailService;

    @Resource
    private ContainerCapacityService containerCapacityService;


    @Transactional
    public AjaxResult<List<Map<String, Object>>> scanAGVReceipt(String receiptCode)  {
        List<Map<String, Object>> detail = receiptContainerHeaderMapper.getAGVDetail(receiptCode, ShiroUtils.getWarehouseCode());
        return AjaxResult.success(detail);
    }

    @Transactional
    public AjaxResult<List<Map<String, Object>>> getAGVReceiptInfoByBill(String receiptCode)  {
        List<Map<String, Object>> detail = receiptContainerHeaderMapper.getAGVReceiptInfoByBill(receiptCode, ShiroUtils.getWarehouseCode());
        return AjaxResult.success(detail);
    }
    /**入库组盘保存收货信息*/
    @Transactional
    public AjaxResult<Map<String, String>> save(ReceiptContainerView record)  {
        //取出入库详单对应的物料编码和物料库区
        /*生成组盘明细前校验组盘明细里已有的组盘数量,已组盘数量加正在组盘的数量不能大于入库单明细条的数量 */
        record.setTaskType((short)200);
        ReceiptDetail rc=new ReceiptDetail();
        rc.setReceiptCode(record.getReceiptCode());
        rc.setWarehouseCode(ShiroUtils.getWarehouseCode());
        rc.setId(record.getReceiptDetailId());
        rc=receiptDetailService.selectFirstEntity(rc);
        record.setMaterialCode(rc.getMaterialCode());

        //找到库位的的库区
        Container container=containerService.getContainerByCode(record.getContainerCode());
        if(container ==null){
            throw new ServiceException("系统没有此容器");
        }
        if(!ShiroUtils.getCompanyCodeList().contains(container.getCompanyCode())){
            throw new ServiceException("该操作员没有此容器的操作权限");
        }

        if(StringUtils.isEmpty(record.getLocationCode())){
            record.setLocationCode(container.getLocationCode());
        }
        switch (container.getContainerType()){
            case "A":
                record.setZoneCode("AGV");
                break;
            case "D":
                record.setZoneCode("PK");
                break;
            case "C":
                record.setZoneCode("XC");
                break;
            case "L":
            case "M":
                record.setZoneCode("LK");
                break;
            case "Q":
                record.setZoneCode("QG");
                break;
            default:
                record.setZoneCode("XN");
                break;
        }
        if(record.getZoneCode()==null){
            throw new ServiceException("此单据没有分配库区,请分配库区");
        }

        if((record.getZoneCode().equals("LK") || record.getZoneCode().equals("XC") ) && StringUtils.isEmpty(record.getLocationCode())){
            record.setTaskType((short)100);
        }

        LambdaQueryWrapper<ReceiptContainerDetail> lambdaDetails = Wrappers.lambdaQuery();
        lambdaDetails.eq(ReceiptContainerDetail::getReceiptCode, record.getReceiptCode());
        lambdaDetails.eq(ReceiptContainerDetail::getReceiptDetailId, rc.getId());
        lambdaDetails.eq(ReceiptContainerDetail::getMaterialCode,record.getMaterialCode());
        List<ReceiptContainerDetail> rcdlist = receiptContainerDetailService.list(lambdaDetails);
        BigDecimal sum =BigDecimal.ZERO;
        for(ReceiptContainerDetail item:rcdlist){
            sum = sum.add(item.getQty());
        }
        //sum2不能大于qty
        BigDecimal sum2 = sum.add(record.getQty());
        int s = sum2.compareTo(rc.getQty());
        if(s == 1){
            throw new ServiceException("子单据组盘的总数量不能超过单据数量,请检查入库详单数量和已组盘的数量!");
        }
        checkContainer(record);//检查容器

        //autoLocationCode(record);//自动分配库位
        ReceiptContainerHeader receiptContainerHeader = receiptContainerHeaderAdd(record,container);
        ReceiptDetail receiptDetail = receiptDetailQtyAdd(record.getReceiptDetailId(), record.getQty());
        ReceiptContainerDetail receiptContainerDetail=receiptContainerDetailAdd(receiptContainerHeader.getId(), receiptDetail, record);
        receiptStatusUpdate(receiptDetail.getReceiptId(), 200);
        return AjaxResult.success(ReturnValue(record.getReceiptDetailId(), receiptDetail));
    }
    public void receiptStatusUpdate(Integer receiptId, Integer status){
        ReceiptHeader receiptHeader=receiptHeaderService.getById(receiptId);
        LambdaQueryWrapper<ReceiptDetail> lambdaDetails = Wrappers.lambdaQuery();
        lambdaDetails.eq(ReceiptDetail::getReceiptId, receiptId);
        lambdaDetails.last("limit 1");
        lambdaDetails.orderByDesc(ReceiptDetail::getProcessStamp);
        ReceiptDetail receiptDetail = receiptDetailService.getOne(lambdaDetails);
        if(receiptDetail!=null){
            receiptHeader.setFirstStatus(status);
            receiptHeader.setLastStatus(Integer.valueOf(receiptDetail.getProcessStamp()));
            receiptHeaderService.updateById(receiptHeader);
        }

    }
    public AjaxResult checkContainer(ReceiptContainerView record) {
        if (StringUtils.isEmpty(record.getContainerCode())) {
            throw new ServiceException("容器不能为空");
        }
        Container container = containerService.getContainerByCode(record.getContainerCode());

        if(container == null){
            return AjaxResult.error(record.getContainerCode()+"容器编码错误");
        }

        if(record.getTaskType().intValue() == 100){
            if (StringUtils.isNotEmpty(container.getLocationCode())) {
                throw new ServiceException("容器已经在货架" + container.getLocationCode() + "上!");
            }
        }
        if(record.getTaskType().intValue() == 200) {
            if (StringUtils.isEmpty(container.getLocationCode())) {
                throw new ServiceException("容器不在货架" + container.getLocationCode() + "上!");
            }
        }

        LambdaQueryWrapper<TaskHeader> lambda = Wrappers.lambdaQuery();
        lambda.eq(TaskHeader::getContainerCode,container.getCode());
        lambda.in(TaskHeader::getStatus,10,20,30);
        lambda.last("limit 1");
        TaskHeader taskHeader=taskHeaderService.getOne(lambda);
        if(taskHeader!=null){
            throw new ServiceException("该容器已有任务,且已下发");
        }

        LambdaQueryWrapper<TaskHeader> tasklambda = Wrappers.lambdaQuery();
        tasklambda.eq(TaskHeader::getContainerCode,container.getCode());
        tasklambda.eq(TaskHeader::getStatus,1);
        tasklambda.last("limit 1");
        TaskHeader condition=taskHeaderService.getOne(tasklambda);
        if(condition!=null && condition.getTaskType().intValue()>200){
            throw new ServiceException("该容器已有其他任务,无法组盘");
        }

        LambdaQueryWrapper<TaskHeader> tasklambda1 = Wrappers.lambdaQuery();
        tasklambda1.eq(TaskHeader::getContainerCode,container.getCode());
        tasklambda1.eq(TaskHeader::getStatus,100);
        tasklambda1.last("limit 1");
        TaskHeader task1=taskHeaderService.getOne(tasklambda1);
        if(task1!= null && !task1.getCreatedBy().equals(ShiroUtils.getLoginName())){
            throw new ServiceException("该容器已被其他操作员使用");
        }
        //容器和物料库位类型进行匹配
        LambdaQueryWrapper<Zone> zonelambda = Wrappers.lambdaQuery();
        zonelambda.eq(Zone::getCode,container.getCode());
        zonelambda.last("limit 1");
        Zone zo = zoneService.getOne(zonelambda);
        //地面库区可以放任意物料,不校验
        if(StringUtils.isNotEmpty(record.getZoneCode())){

            if(container.getContainerType().equals("D") && zo.getLocationType().equals("PK")){
                return AjaxResult.success("");
            }else if(container.getContainerType().equals("M") && zo.getLocationType().equals("LK")){
                return AjaxResult.success("");
            }else if(container.getContainerType().equals("L") && zo.getLocationType().equals("LK")){
                return AjaxResult.success("");
            }else if(container.getContainerType().equals("C") && zo.getLocationType().equals("XC")){
                return AjaxResult.success("");
            }
            else if(container.getContainerType().equals("A") && zo.getLocationType().equals("AGV")){
                return AjaxResult.success("");
            }else if(container.getContainerType().equals("Q") && zo.getLocationType().equals("QG")){
                return AjaxResult.success("");
            }else if(container.getContainerType().equals("X") && zo.getLocationType().equals("XN")){
                return AjaxResult.success("");
            }else{
                throw new ServiceException("物料不适用与该容器托盘!请更换容器托盘");
            }
        }
        return AjaxResult.success("");
    }
    /**
     *  增加组盘表头记录
     * @param record  组盘信息实体
     */
    private  ReceiptContainerHeader  receiptContainerHeaderAdd(ReceiptContainerView record,Container container)  {

        //从主单获取单号
        ReceiptHeader receiptHeader=new ReceiptHeader();
        receiptHeader.setCode(record.getReceiptCode());
        receiptHeader=receiptHeaderService.selectFirstEntity(receiptHeader);
        //根据托盘查询组盘表头记录
        LambdaQueryWrapper<ReceiptContainerHeader> lambda = Wrappers.lambdaQuery();
        lambda.eq(ReceiptContainerHeader::getCompanyCode,record.getContainerCode());
        lambda.lt(ReceiptContainerHeader::getStatus,20);
        List<ReceiptContainerHeader> list = this.list(lambda);
        ReceiptContainerHeader receiptContainerHeader=new ReceiptContainerHeader();
        if (list.size() < 1)
        {

            ReceiptDetail receiptDetail = receiptDetailService.getById(record.getReceiptDetailId());
            if(receiptDetail == null){
                throw new ServiceException("id为"+record.getReceiptDetailId()+"入库单明细不存在");
            }
            if(receiptHeader.getReceiptType().equals("SI") && StringUtils.isNotEmpty(receiptDetail.getReferLineNum())){
                CompanyU8 companyWu = new CompanyU8();
                companyWu.setCompanyCode(receiptHeader.getCompanyCode());
                companyWu = companyU8Service.getByCode(companyWu);
                if(companyWu == null){
                    throw new ServiceException("入库单对应的U8账套不存在");
                }
                Map detailMap = new HashMap();
                detailMap.put("MODID",receiptDetail.getReferLineNum());
                detailMap.put("iQuantity",receiptDetail.getQty());
                detailMap.put("itemcode",receiptDetail.getMaterialCode());

                List<Map> maps = new ArrayList<>();
                maps.add(detailMap);

                Map<String,Object> map = new HashMap();
                map.put("CompanyCode",companyWu.getUCompanyCode());
                map.put("details",maps);

//                AjaxResult ajaxResult = finishedProductService.checkMesReceipt(map);
//                if(ajaxResult.hasErr()){
//                    throw new ServiceException(ajaxResult.getMsg());
//                }
            }


            if (!container.getCompanyCode().equals(receiptDetail.getCompanyCode())) {
                throw new ServiceException("容器货主属性和单据不一致,请换容器");
            }
            /*if(StringUtils.isNotEmpty(receiptDetail.getUWarehouseCode()) && StringUtils.isNotEmpty(container.getuWarehouseCode())) {
                if (!container.getUWarehouseCode().equals(receiptDetail.getUWarehouseCode())) {
                    throw new ServiceException("容器仓库属性和单据不一致,请换容器");
                }
            }*/
            receiptContainerHeader.setContainerCode(record.getContainerCode());
            receiptContainerHeader.setStatus(0);
            receiptContainerHeader.setTaskType(record.getTaskType().intValue());
            receiptContainerHeader.setWarehouseCode(ShiroUtils.getWarehouseCode());
            //赋值u8仓库
            receiptContainerHeader.setCompanyCode(receiptDetail.getCompanyCode());
            receiptContainerHeader.setCreatedBy(ShiroUtils.getLoginName());
            receiptContainerHeader.setToLocation(record.getLocationCode());
//            receiptContainerHeader.setZoneCode(record.getZoneCode());
            this.save(receiptContainerHeader);
        }else {
            return list.get(0);
        }
        return  receiptContainerHeader;
    }
    /**
     * 增加入库明细的收货数量
     * @param receiptDetailId
     * @param Qty
     * @return
     */
    public ReceiptDetail receiptDetailQtyAdd(Integer receiptDetailId, BigDecimal Qty)  {
        ReceiptDetail receiptDetail = new ReceiptDetail();
        receiptDetail.setId(receiptDetailId);
        receiptDetail = receiptDetailService.selectFirstEntity(receiptDetail);

        // 将入库单明细的收货数量 + 保存的数量,然后在存入明细表
        receiptDetail.setTaskQty(receiptDetail.getTaskQty().add(Qty));
        receiptDetail.setStatus((short) 200);
        if (receiptDetail.getTaskQty().compareTo(receiptDetail.getQty()) > 0){
            throw new ServiceException("收货数大于待收数量!");
        }
        receiptDetailService.updateById(receiptDetail);

        return receiptDetail;
    }
    /**
     *  增加组盘明细记录
     * @param receiptContainerHeaderId
     * @param receiptDetail
     * @param record
     */
    private  ReceiptContainerDetail  receiptContainerDetailAdd(Integer receiptContainerHeaderId, ReceiptDetail receiptDetail, ReceiptContainerView record)  {
        int flag =1;
        // 根据表头ID和入库单明细ID找组盘明细
        ReceiptContainerDetail receiptContainerDetail = new ReceiptContainerDetail();
        receiptContainerDetail.setReceiptContainerId(receiptContainerHeaderId);
        receiptContainerDetail.setReceiptDetailId(record.getReceiptDetailId());
        receiptContainerDetail = receiptContainerDetailService.selectFirstEntity(receiptContainerDetail);

        ReceiptHeader receiptHeader =new ReceiptHeader();
        receiptHeader.setCode(record.getReceiptCode());
        receiptHeader =receiptHeaderService.selectFirstEntity(receiptHeader);

        //查看组盘头状态,如果状态在10到20,则生成任务明细或修改任务明细的数量
        ReceiptContainerHeader receiptContainerHeader = this.getById(receiptContainerHeaderId);
        TaskHeader task = new TaskHeader();
        if(receiptContainerHeader.getStatus()>=10 && receiptContainerHeader.getStatus()< 20) {
            LambdaQueryWrapper<TaskHeader> tasklambda1 = Wrappers.lambdaQuery();
            tasklambda1.eq(TaskHeader::getAllocationHeadId,receiptContainerHeaderId);
            tasklambda1.eq(TaskHeader::getWarehouseCode,receiptContainerHeader.getWarehouseCode());
            tasklambda1.in(TaskHeader::getTaskType,100,200);
            tasklambda1.last("limit 1");
            task=taskHeaderService.getOne(tasklambda1);

            if (task == null) {
                throw new ServiceException("任务主表不存在");
            }
        }
        if (receiptContainerDetail == null)
        {
            Material material = materialService.getMaterialByCode(receiptDetail.getMaterialCode());
            receiptContainerDetail = new ReceiptContainerDetail();
            receiptContainerDetail.setReceiptContainerId(receiptContainerHeaderId);
            receiptContainerDetail.setReceiptCode(receiptHeader.getReferCode());
            receiptContainerDetail.setReceiptCode(receiptDetail.getReceiptCode());
            receiptContainerDetail.setReceiptId(receiptDetail.getReceiptId());
            receiptContainerDetail.setReceiptDetailId(record.getReceiptDetailId());
            receiptContainerDetail.setMaterialCode(receiptDetail.getMaterialCode());
            receiptContainerDetail.setMaterialName(material.getName());
            receiptContainerDetail.setMaterialSpec(material.getSpec());
            BigDecimal num=new BigDecimal(0);
            num=record.getQty();
            //物料库区为AGV的需要考虑是否满盘
            if(StringUtils.isNotEmpty(receiptDetail.getZoneCode()) && receiptDetail.getZoneCode().equals("AGV")){
                //查出与容器和物料对应的库存
                InventoryDetail inventory=new InventoryDetail();

                LambdaQueryWrapper<InventoryDetail> invlambda= Wrappers.lambdaQuery();
                invlambda.eq(InventoryDetail::getMaterialCode,receiptDetail.getMaterialCode());
                invlambda.eq(InventoryDetail::getContainerCode,record.getContainerCode());
                invlambda.last("limit 1");
                inventory=inventoryDetailService.getOne(invlambda);
                //查看容器与物料对应的满盘度
                ContainerCapacity containerCapacity=new ContainerCapacity();
//                containerCapacity.setCode("AGV");
                containerCapacity.setMaterialCode(record.getMaterialCode());
                containerCapacity.setWarehouseCode(ShiroUtils.getWarehouseCode());

                LambdaQueryWrapper<ContainerCapacity> capacitylambda= Wrappers.lambdaQuery();
                capacitylambda.eq(ContainerCapacity::getWarehouseCode,ShiroUtils.getWarehouseCode());
                capacitylambda.eq(ContainerCapacity::getMaterialCode,record.getMaterialCode());
                capacitylambda.last("limit 1");
                containerCapacity=containerCapacityService.getOne(capacitylambda);
                num=containerCapacity.getUph();
                String qty=null;
                //如果没有库存
                if(inventory==null){
                    //物料满盘度大于单据数量时,组盘数量为单据数量,否则为满盘数量
                    if(num.intValue()-record.getQty().intValue()>=0){
                        num=record.getQty();
                    }
                }else {
                    //容器剩余数量大于单据数量时,组盘数量单据数量,否则为剩余数量
                    if(num.intValue()-inventory.getQty().intValue()-record.getQty().intValue()>0){
                        num=record.getQty();
                    }else {
                        throw new ServiceException("收货数量大于容器剩余数量,请调低收获数量!");
                    }

                }

            }
            receiptContainerDetail.setQty(num);
            receiptContainerDetail.setCreatedBy(ShiroUtils.getLoginName());
            receiptContainerDetail.setProjectNo(receiptDetail.getProjectNo());
            receiptContainerDetailService.save(receiptContainerDetail);

            //生成任务明细
            if(task !=null && StringUtils.isNotEmpty(task.getWarehouseCode())){
                TaskDetail taskDetail =new TaskDetail();
                taskDetail.setTaskId(task.getId());
                taskDetail.setWarehouseId(task.getWarehouseId());
                taskDetail.setWarehouseCode(task.getWarehouseCode());
                taskDetail.setCompanyId(task.getCompanyId());
                taskDetail.setCompanyCode(task.getCompanyCode());
//                taskDetail.setZoneCode(receiptContainerHeader.getZoneCode());
                taskDetail.setMaterialCode(receiptContainerDetail.getMaterialCode());
                taskDetail.setMaterialName(receiptContainerDetail.getMaterialName());
                taskDetail.setAllocationId(receiptContainerDetail.getId());
                taskDetail.setBillId(receiptContainerDetail.getReceiptId());
                taskDetail.setBillDetailId(receiptContainerDetail.getReceiptDetailId());
                taskDetail.setBillCode(receiptContainerDetail.getReceiptCode());
                taskDetail.setReferenceCode(receiptDetail.getReferCode());
                taskDetail.setGoodsShelfNo(task.getGoodsShelfNo());
//                taskDetail.setSourceCode(receiptContainerDetail.getSourceCode());
                taskDetail.setQty(receiptContainerDetail.getQty());
                taskDetail.setContainerCode(task.getContainerCode());
                taskDetail.setToLocation(task.getToLocation());
                taskDetail.setFromLocation(task.getFromLocation());
                taskDetail.setTaskType(QuantityConstant.TASK_TYPE_WHOLERECEIPT);
                taskDetail.setStatus(task.getStatus());
                taskDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
                taskDetail.setProjectNo(receiptContainerDetail.getProjectNo());

                if(!taskDetailService.save(taskDetail)){
                    throw new ServiceException("新建任务明细失败,sql错误");
                }
            }
        }
        else
        {
            receiptContainerDetail.setQty(receiptContainerDetail.getQty().add(record.getQty()));
            receiptContainerDetailService.updateById(receiptContainerDetail);

            //修改任务明细
            if(task !=null && StringUtils.isNotEmpty(task.getWarehouseCode())){
                TaskDetail taskDetail =new TaskDetail();
                taskDetail.setAllocationId(receiptContainerDetail.getId());
                taskDetail.setTaskId(task.getId());

                LambdaQueryWrapper<TaskDetail> tasklambda1 = Wrappers.lambdaQuery();
                tasklambda1.eq(TaskDetail::getAllocationId,receiptContainerDetail.getId());
                tasklambda1.eq(TaskDetail::getTaskId,task.getId());
                tasklambda1.last("limit 1");
                taskDetail =taskDetailService.getOne(tasklambda1);
                if(taskDetail == null){
                    throw new ServiceException("找不到对应的任务明细");
                }
                taskDetail.setQty(taskDetail.getQty().add(record.getQty()));
                if(!taskDetailService.updateById(taskDetail)){
                    throw new ServiceException("修改任务明细失败,sql错误");
                }
            }
        }
        return receiptContainerDetail;
    }
    /**
     *  返回客户端的键值对
     * @param receiptDetailId
     * @param receiptDetail
     * @return
     */
    public Map<String, String>  ReturnValue(Integer receiptDetailId, ReceiptDetail receiptDetail)    {
        Map<String, String> returnValue = new HashMap<>();
        returnValue.put("id", receiptDetailId.toString());
        returnValue.put("receiptId", receiptDetail.getReceiptId().toString());
        returnValue.put("materialCode", receiptDetail.getMaterialCode());
        returnValue.put("qtyCompleted", receiptDetail.getTaskQty().toString());
        return  returnValue;
    }
}