查询配件数量记录(重点:报文中对象装换)

Controller:

	@RequestMapping("/getVehicleInfoAndPartNumByVin/{vin}")
	public @ResponseBody JsonResult getVehicleInfoAndPartNumByVin(@PathVariable("vin") String vin,HttpServletRequest request) throws Exception {
		String insCode = InsCodeUtil.get(request);
		JsonResult result = new JsonResult();
		LossResponse lossResponse = new LossResponse();
		lossResponse = scpVehicleIdentifyService.getVehicleInfoAndPartNumByVin(vin,insCode);
		result.setMessage(Constants.MS_SUCCESS);
		result.setCode(Constants.MC_SUCCESS);
		result.setResult(lossResponse);
		return result;
	}

Service:


	public LossResponse getVehicleInfoAndPartNumByVin(String vin,String insCode) throws Exception;

servieceImpl:

	public LossResponse getVehicleInfoAndPartNumByVin(String vin, String insCode) throws Exception {

		LossResponse lossResponse = new LossResponse();
		try {
			Map querys = new HashMap();
			querys.put("vin", vin);
			querys.put("maxPartNum", "1");
			JSONObject jsonObj = facadeUtils.doCompressGet(insCode, facadeProp.getVin(), querys);
			LOGGER.info("-----------" + jsonObj);
			if (StringUtils.notEmpty(jsonObj)) {
				if (!"200".equals(jsonObj.get("status"))) {
					String vinMsg = null;
					if ("204".equals(jsonObj.get("status"))) {
						vinMsg = "VIN码解析暂无车型,请用其他方式定型 ";
					} else {
						vinMsg = "VIN码服务异常 " + jsonObj.get("message");
					}
					throw new BaseException(vinMsg);
				}

				JSONArray obj = (JSONArray) jsonObj.get("result");

				String modelId = "";
				String familyId = "";
				String modelCode = "";
				String carType = "";
				Integer systemPartNum = 0;
				Integer standardPartNum = 0;
				Integer customizePartNum = 0;
				for (int i = 0; i < obj.size(); i++) {
					JSONObject jsonObject = obj.getJSONObject(i);
					JSONObject clVehFlagObject = (JSONObject) jsonObject.get("clVehFlag");
					ClVehFlag clVehFlag = JSON.toJavaObject(clVehFlagObject, ClVehFlag.class);
					//facade返回多个车型时,选择配件最多的车型
					if (clVehFlag.getPartNum() > systemPartNum) {
						familyId = jsonObject.getString("seriesId");
						modelId = clVehFlag.getClVehicleId();
						carType = jsonObject.getString("vehicleTypeCode");
						modelCode = jsonObject.getString("vehicleCode");
						systemPartNum = clVehFlag.getPartNum();
						standardPartNum = 0;
					}
				}

				// 获取自定义配件数量 乘用车车型维度(modelId) 商用车车系维度(familyId)
				if ("C".equals(carType)) {
					familyId = null;
					customizePartNum = evalPartLogicMapper.getCustomaizePartNum(modelId, familyId);
				} else if ("B".equals(carType)) {
					modelId = null;
					customizePartNum = evalPartLogicMapper.getCustomaizePartNum(modelId, familyId);
				}
				
				//自定义配件数量
				lossResponse.setCustomizePartNum(customizePartNum);
				//车型编码
				lossResponse.setModelCode(modelCode);
				//系统配件数量
				lossResponse.setSystemPartNum(systemPartNum);
				//标准配件数量
				lossResponse.setStandardPartNum(standardPartNum);
				//数据厂商编码
				lossResponse.setSupCode(" ");
				//返回类型 0-失败  1-成功
				lossResponse.setResponseCode("1");
				//响应信息
				lossResponse.setResponseMsg("成功");
			}

		} catch (BaseException e) {
			e.printStackTrace();
			lossResponse.setResponseCode("0");
			lossResponse.setResponseMsg(e.getMessage());
		}
		return lossResponse;
	}

mapper:

	public Integer getCustomaizePartNum(@Param("modelId") String modelId,@Param("familyId")String familyId);

mapper.xml

	

LossResponse:

public class LossResponse {
	/** 返回类型 */
	private String responseCode;
	/** 响应信息 */
	private String responseMsg;
	/** 车型编码 */
	private String modelCode;
	/** 系统件数量 */
	private Integer systemPartNum;
	/** 标准件数量 */
	private Integer standardPartNum;
	/** 系统自定义件数量 */
	private Integer customizePartNum;
	/** 数据商编码 */
	private String supCode;
	public String getResponseCode() {
		return responseCode;
	}
	public void setResponseCode(String responseCode) {
		this.responseCode = responseCode;
	}
	public String getResponseMsg() {
		return responseMsg;
	}
	public void setResponseMsg(String responseMsg) {
		this.responseMsg = responseMsg;
	}
	public String getModelCode() {
		return modelCode;
	}
	public void setModelCode(String modelCode) {
		this.modelCode = modelCode;
	}
	public Integer getSystemPartNum() {
		return systemPartNum;
	}
	public void setSystemPartNum(Integer systemPartNum) {
		this.systemPartNum = systemPartNum;
	}
	public Integer getStandardPartNum() {
		return standardPartNum;
	}
	public void setStandardPartNum(Integer standardPartNum) {
		this.standardPartNum = standardPartNum;
	}
	public Integer getCustomizePartNum() {
		return customizePartNum;
	}
	public void setCustomizePartNum(Integer customizePartNum) {
		this.customizePartNum = customizePartNum;
	}
	public String getSupCode() {
		return supCode;
	}
	public void setSupCode(String supCode) {
		this.supCode = supCode;
	}
	@Override
	public String toString() {
		return "LossResponse [responseCode=" + responseCode + ", responseMsg=" + responseMsg + ", modelCode="
				+ modelCode + ", systemPartNum=" + systemPartNum + ", standardPartNum=" + standardPartNum
				+ ", customizePartNum=" + customizePartNum + ", supCode=" + supCode + "]";
	}
	
	

}

ClVehFlag:

public class ClVehFlag {
	/** 车型ID */
	private String clVehicleId;
	/** 系统件数量 */
	private Integer systemPartNum;
	/** 标准件数量 */
	private Integer standardPartNum;
	/** 自定义件数量 */
	private Integer customizePartNUm;
	
	private Integer partNum;
	
	

	public String getClVehicleId() {
		return clVehicleId;
	}
	public void setClVehicleId(String clVehicleId) {
		this.clVehicleId = clVehicleId;
	}
	public Integer getPartNum() {
		return partNum;
	}
	public void setPartNum(Integer partNum) {
		this.partNum = partNum;
	}
	public Integer getSystemPartNum() {
		return systemPartNum;
	}
	public void setSystemPartNum(Integer systemPartNum) {
		this.systemPartNum = systemPartNum;
	}
	public Integer getStandardPartNum() {
		return standardPartNum;
	}
	public void setStandardPartNum(Integer standardPartNum) {
		this.standardPartNum = standardPartNum;
	}
	public Integer getCustomizePartNUm() {
		return customizePartNUm;
	}
	public void setCustomizePartNUm(Integer customizePartNUm) {
		this.customizePartNUm = customizePartNUm;
	}
	
}

你可能感兴趣的:(Java学习,java)