ICSCyclecountAPIService.java 5.83 KB
package com.huaheng.pc.u8.service;

import com.alibaba.fastjson.JSON;

import com.huaheng.common.utils.http.HttpUtils;
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.config.warehouse.domain.Warehouse;
import com.huaheng.pc.config.warehouse.service.WarehouseService;
import com.huaheng.pc.inventory.adjustDetail.domain.AdjustDetail;
import com.huaheng.pc.inventory.adjustDetail.service.AdjustDetailService;
import com.huaheng.pc.inventory.adjustHeader.domain.AdjustHeader;
import com.huaheng.pc.inventory.adjustHeader.service.AdjustHeaderService;
import com.huaheng.pc.inventory.cycleCountHeader.service.CycleCountHeaderService;
import com.huaheng.pc.u8.domain.ICSCyclecountAdjustDetail;
import com.huaheng.pc.u8.domain.ICSCyclecountAdjustHeader;
import com.huaheng.pc.u8.domain.ICSCyclecountModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

@Service
public class ICSCyclecountAPIService {
    @Resource
    private AdjustHeaderService adjustHeaderService;
    @Resource
    private AdjustDetailService adjustDetailService;
    @Resource
    private WarehouseService warehouseService;
    @Resource
    private MaterialService materialService;

    public AjaxResult confirm(String code , String sourceCode,String warehouseCode) {

        //查找状态为10的盘点差异主单
        AdjustHeader adjustHeader=new AdjustHeader();
        adjustHeader.setProcessStamp(String.valueOf(10));
        adjustHeader.setCode(code);
        adjustHeader.setReferCode(sourceCode);
        adjustHeader.setWarehouseCode(warehouseCode);
        List<AdjustHeader> adjustlist=adjustHeaderService.getByDoamin(adjustHeader);
        if(adjustlist==null||adjustlist.size()==0){
            return AjaxResult.error("没有盘点差异上传");
        }
        adjustHeader=adjustlist.get(0);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
        //替换成icsCyclecountAdjustHeader
        ICSCyclecountAdjustHeader icsCyclecountAdjustHeader=new ICSCyclecountAdjustHeader();
        icsCyclecountAdjustHeader.setCCode(adjustHeader.getCode());
        icsCyclecountAdjustHeader.setCId(adjustHeader.getId());
        icsCyclecountAdjustHeader.setDDate(simpleDateFormat.format(adjustHeader.getCreated()));
        icsCyclecountAdjustHeader.setDDate2(simpleDateFormat.format(adjustHeader.getLastUpdated()));
        icsCyclecountAdjustHeader.setDOperator(adjustHeader.getCreatedBy());
        icsCyclecountAdjustHeader.setDVerifyer(adjustHeader.getLastUpdatedBy());
        icsCyclecountAdjustHeader.setCompanyCode(adjustHeader.getCompanyCode());

        //通过主单id找到子单
        AdjustDetail adjustDetail=new AdjustDetail();
        adjustDetail.setAdjustCode(adjustHeader.getCode());
        List<AdjustDetail> adjustDetails=adjustDetailService.getByDoamin(adjustDetail);

//        Material material=new Material();
        // 查询仓库名
        String warehouseName=warehouseService.getWarehouseNameByCode(adjustHeader.getWarehouseCode());
        List<ICSCyclecountAdjustDetail> icsCyclecountAdjustDetails=new ArrayList<>();

        //替换成icsCyclecountAdjustDetail
        for (AdjustDetail item :adjustDetails){
            ICSCyclecountAdjustDetail icsCyclecountAdjustDetail = new ICSCyclecountAdjustDetail();
            icsCyclecountAdjustDetail.setCDID(item.getId());
            icsCyclecountAdjustDetail.setCCode(adjustHeader.getCode());
            icsCyclecountAdjustDetail.setCId(adjustHeader.getId());
            icsCyclecountAdjustDetail.setCWhCode(adjustHeader.getWarehouseCode());
            icsCyclecountAdjustDetail.setCWhName(warehouseName);
            icsCyclecountAdjustDetail.setCWarecell(item.getLocationCode());
            icsCyclecountAdjustDetail.setCContainer(item.getContainerCode());
            icsCyclecountAdjustDetail.setCItemName(item.getProjectNo());
            icsCyclecountAdjustDetail.setCInvCode(item.getMaterialCode());
            Material material=materialService.getMaterialByCode(item.getMaterialCode());
            if(material!=null){
                icsCyclecountAdjustDetail.setCInvName(material.getName());
                icsCyclecountAdjustDetail.setCComUnitName(material.getUnit());
            }
            icsCyclecountAdjustDetail.setCInvStd(item.getMaterialSpec());
            icsCyclecountAdjustDetail.setIQuantity(item.getFromQty());

            icsCyclecountAdjustDetail.setDQuantity(item.getToQty());
            icsCyclecountAdjustDetail.setCAttribute(item.getFromInventorySts());
            icsCyclecountAdjustDetail.setAQuantiy(item.getGapQty());
            icsCyclecountAdjustDetail.setCRegister(item.getCreatedBy());
            icsCyclecountAdjustDetail.setCRegisterDate(simpleDateFormat.format(item.getCreated()));
            icsCyclecountAdjustDetail.setCompanyCode(item.getCompanyCode());
            icsCyclecountAdjustDetails.add(icsCyclecountAdjustDetail);
        }

        //把主单和子单整合到一起
        ICSCyclecountModel icsCyclecountModel=new ICSCyclecountModel();
        icsCyclecountModel.setIcsCyclecountAdjustHeader(icsCyclecountAdjustHeader);
        icsCyclecountModel.setIcsCyclecountAdjustDetails(icsCyclecountAdjustDetails);
        String JsonParam = JSON.toJSONString(icsCyclecountModel);
        String url="http://58.240.189.134:8099/api/";  //对端地址
        String result = HttpUtils.bodypost(url, JsonParam,adjustHeader.getWarehouseCode());
        AjaxResult ajaxResult = JSON.parseObject(result, AjaxResult.class);
        if(!ajaxResult.hasErr()) {
            adjustHeader.setProcessStamp(String.valueOf(20));
            adjustHeaderService.updateById(adjustHeader);
        }
        return ajaxResult;
    }
}