package com.ld.igds.protocol.inoutplug; import com.alibaba.fastjson.JSONObject; import com.bstek.bdf2.core.model.DefaultDept; import com.ld.igds.common.CoreCommonService; import com.ld.igds.inout.dto.InoutData; import com.ld.igds.inout.manager.InoutManager; import com.ld.igds.models.Depot; import com.ld.igds.protocol.inoutplug.data.InoutPlugRespData; import com.ld.igds.sys.service.SysDeptService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.HashMap; import java.util.Map; /** * 出入库数据解析 * * @author chen */ @Slf4j @Component(InoutPlugAnalysis.BEAN_ID) public class InoutPlugAnalysis { /** * 匹配仓库编码 */ public static final String BEAN_ID = "plug.inoutPlugAnalysis"; public static Map depotMap = new HashMap(); //仓库编码匹配 static { depotMap.put("1L0101", "1L0101"); depotMap.put("1L0102", "1L0102"); depotMap.put("1L0103", "1L0103"); depotMap.put("1L0201", "1L0201"); depotMap.put("1L0202", "1L0202"); depotMap.put("1L0203", "1L0203"); depotMap.put("2L0101", "2L0101"); depotMap.put("2L0102", "2L0102"); depotMap.put("2L0103", "2L0103"); depotMap.put("2L0201", "2L0201"); depotMap.put("2L0202", "2L0202"); depotMap.put("2L0203", "2L0203"); depotMap.put("3L0202", "3L0202"); depotMap.put("3L0203", "3L0203"); depotMap.put("3L0301", "3L0301"); depotMap.put("3L0302", "3L0302"); depotMap.put("3L0303", "3L0303"); } @Autowired private CoreCommonService commonService; @Autowired private SysDeptService deptService; @Autowired private InoutManager inoutManager; /** * 出入库信息解析 * * @param request */ public String analysisInout(JSONObject request) throws Exception { InoutPlugRespData inoutPlugRespData = JSONObject.parseObject(request.toString(), InoutPlugRespData.class); if (inoutPlugRespData == null) { log.warn("出入库数据插件------>>>平台:出入库数据为空,无法进行解析"); return null; } if (StringUtils.isEmpty(inoutPlugRespData.getDeptId()) || StringUtils.isEmpty(inoutPlugRespData.getDepotId())) { log.warn("出入库数据插件----->>>平台:库区编码={},仓库ID={},出入库数据信息不全,报文无法进行解析", inoutPlugRespData.getDeptId(), inoutPlugRespData.getDepotId()); return null; } //获取库区信息 DefaultDept dept = deptService.getDeptById(inoutPlugRespData.getDeptId()); if (dept == null) { log.warn("出入库数据插件----->>>平台:库区编码={},系统获取不到库区信息,报文无法进行解析", inoutPlugRespData.getDeptId()); return null; } String depotId = depotMap.get(inoutPlugRespData.getDepotId()); inoutPlugRespData.setDepotId(depotId); //获取仓库信息 Depot depot = commonService.getCacheDepot(dept.getCompanyId(), depotId); if (depot == null) { log.warn("出入库数据插件----->>>平台:仓库ID={},系统获取不到仓库信息,报文无法进行解析", inoutPlugRespData.getDepotId()); return null; } InoutData data = new InoutData(); //TODO 封装处理 inoutManager.addInoutData(data); return null; } }