ICSCyclecountAPIService.java 6.16 KB
package com.huaheng.api.U8.Service;

import com.alibaba.fastjson.JSON;
import com.huaheng.api.U8.domain.ICSCyclecountAdjustDetail;
import com.huaheng.api.U8.domain.ICSCyclecountAdjustHeader;
import com.huaheng.api.U8.domain.ICSCyclecountModel;
import com.huaheng.common.utils.http.HttpUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.general.material.domain.Material;
import com.huaheng.pc.general.material.service.IMaterialService;
import com.huaheng.pc.general.warehouse.domain.Warehouse;
import com.huaheng.pc.general.warehouse.service.IWarehouseService;
import com.huaheng.pc.inventory.cyclecountAdjust.domain.CyclecountAdjust;
import com.huaheng.pc.inventory.cyclecountAdjust.mapper.CyclecountAdjustMapperAuto;
import com.huaheng.pc.inventory.cyclecountAdjust.service.ICycleconutAdjustService;
import com.huaheng.pc.inventory.cyclecountAdjustDetail.domain.CyclecountAdjustDetail;
import com.huaheng.pc.inventory.cyclecountAdjustDetail.service.ICyclecountAdjustDetailService;
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 CyclecountAdjustMapperAuto cyclecountAdjustMapperAuto;
    @Resource
    private ICycleconutAdjustService cycleconutAdjustService;
    @Resource
    private ICyclecountAdjustDetailService cyclecountAdjustDetailService;
    @Resource
    private IWarehouseService warehouseService;
    @Resource
    private IMaterialService materialService;

    public AjaxResult confirm(String code , String sourceCode) {

        //查找状态为10的盘点差异主单
        CyclecountAdjust cyclecountAdjust=new CyclecountAdjust();
        cyclecountAdjust.setStatus(10);
        cyclecountAdjust.setCode(code);
        cyclecountAdjust.setSourceCode(sourceCode);
        cyclecountAdjust=cyclecountAdjustMapperAuto.selectFirstEntity(cyclecountAdjust);
        if(cyclecountAdjust==null){
            return AjaxResult.error("没有盘点差异上传");
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
        //替换成icsCyclecountAdjustHeader
        ICSCyclecountAdjustHeader icsCyclecountAdjustHeader=new ICSCyclecountAdjustHeader();
        icsCyclecountAdjustHeader.setcCode(cyclecountAdjust.getCode());
        icsCyclecountAdjustHeader.setcId(cyclecountAdjust.getId());
        icsCyclecountAdjustHeader.setdDate(simpleDateFormat.format(cyclecountAdjust.getCreated()));
        icsCyclecountAdjustHeader.setdDate2(simpleDateFormat.format(cyclecountAdjust.getLastUpdated()));
        icsCyclecountAdjustHeader.setdOperator(cyclecountAdjust.getCreatedBy());
        icsCyclecountAdjustHeader.setdVerifyer(cyclecountAdjust.getLastUpdatedBy());
        icsCyclecountAdjustHeader.setCompanyCode(cyclecountAdjust.getCompanyCode());

        //通过主单id找到子单
        CyclecountAdjustDetail cyclecountAdjustDetail=new CyclecountAdjustDetail();
        cyclecountAdjustDetail.setCyclecountAdjustCode(cyclecountAdjust.getCode());
        List<CyclecountAdjustDetail> cyclecountAdjustDetails=cyclecountAdjustDetailService.selectListEntityByEqual(cyclecountAdjustDetail);

        Material material=new Material();
        Warehouse warehouse=new Warehouse();
        warehouse.setCode(cyclecountAdjust.getWarehouseCode());
        String warehouseName=warehouseService.selectFirstEntity(warehouse).getName();
        List<ICSCyclecountAdjustDetail> icsCyclecountAdjustDetails=new ArrayList<>();

        //替换成icsCyclecountAdjustDetail
        for (CyclecountAdjustDetail item :cyclecountAdjustDetails){
            ICSCyclecountAdjustDetail icsCyclecountAdjustDetail = new ICSCyclecountAdjustDetail();
            icsCyclecountAdjustDetail.setcDID(item.getId());
            icsCyclecountAdjustDetail.setcCode(cyclecountAdjust.getCode());
            icsCyclecountAdjustDetail.setcId(cyclecountAdjust.getId());
            icsCyclecountAdjustDetail.setcWhCode(cyclecountAdjust.getWarehouseCode());
            icsCyclecountAdjustDetail.setcWhName(warehouseName);
            icsCyclecountAdjustDetail.setcWarecell(item.getLocationCode());
            icsCyclecountAdjustDetail.setcContainer(item.getContainerCode());
            icsCyclecountAdjustDetail.setcItemName(item.getProject());
            icsCyclecountAdjustDetail.setcInvCode(item.getMaterialCode());
            material.setCode(item.getMaterialCode());
            String materialName=materialService.selectFirstEntity(material).getName();
            String ComUnitName=materialService.selectFirstEntity(material).getMasterUnit();
            icsCyclecountAdjustDetail.setcInvName(materialName);
            icsCyclecountAdjustDetail.setcInvStd(item.getMaterialSpecification());
            icsCyclecountAdjustDetail.setiQuantity(item.getSystemQty());
            icsCyclecountAdjustDetail.setcComUnitName(ComUnitName);
            icsCyclecountAdjustDetail.setdQuantity(item.getCountedQty());
            icsCyclecountAdjustDetail.setcAttribute(item.getInventoryStatus());
            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);
        AjaxResult ajaxResult = JSON.parseObject(result, AjaxResult.class);
        if(!ajaxResult.hasErr()) {
            cyclecountAdjust.setStatus(20);
            cycleconutAdjustService.updateByModel(cyclecountAdjust);
        }
        return ajaxResult;
    }
}