ItemDownloadApiService.java 2.29 KB
package com.huaheng.api.SSP.service;

import com.alibaba.fastjson.JSON;
import com.huaheng.api.SSP.domain.SSPmaterialModel;
import com.huaheng.common.exception.service.ServiceException;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.text.SimpleDateFormat;

//物料信息上传
@Service
@Transactional
public class ItemDownloadApiService {

    @Autowired
    IMaterialService iMaterialService;


    public AjaxResult Idls(String url){
        Material material = new Material();
        material.setZoneCode("QG");
        material.setUserDef2("0");
        Material materials = iMaterialService.selectFirstEntity(material);
        if (materials==null){
            return AjaxResult.success("系统中没有钱柜的物料!!或钱柜的物流已全部发完!!");
        }

        try {
            SSPmaterialModel smm = new SSPmaterialModel();
            smm.setSpecification(materials.getSpecification());
            smm.setCubeCode(materials.getZoneCode());
            smm.setCompanyCode(materials.getCompanyCode());
            smm.setItemCode(materials.getCode());
            smm.setItemName(materials.getName());
            smm.setItemBarcode(materials.getBarcode());
            smm.setWarehouseCode(materials.getWarehouseCode());
            smm.setItemUnit(materials.getMasterUnit());
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:sss");
            smm.setcDatetime(df.format(new Date()));

            String JsonParam = JSON.toJSONString(smm);
            String result = HttpUtils.bodypost(url, JsonParam);
            AjaxResult ajaxResult = JSON.parseObject(result, AjaxResult.class);

            Material upm = new Material();
            upm.setId(materials.getId());
            upm.setUserDef2("1");
            iMaterialService.updateByModel(upm);
            return ajaxResult;
        }catch (Exception e){
            throw new ServiceException("物料信息同步上传失败");
        }
    }


}