Java tutorial
package com.ihandy.rbquote.controller; import java.io.UnsupportedEncodingException; import java.util.HashMap; import java.util.Map; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.alibaba.fastjson.JSONObject; import com.ihandy.qoute_common.springutils.SpringMVCUtils; import com.ihandy.quote_core.bean.other.CarInfoResponse; import com.ihandy.quote_core.bean.other.HebaoResponse; import com.ihandy.quote_core.bean.other.PostPrecisePricerResponse; import com.ihandy.quote_core.service.IQuoteService; import com.ihandy.quote_core.service.IService; /** * Created by fengwen on 2016/4/28. */ @Controller @RequestMapping("/Rb") public class RbController { private static Logger logger = LoggerFactory.getLogger(RbController.class); @Autowired private IService rbService; @Resource(name = "quoteServiceImpl") private IQuoteService quoteServiceImpl; /** * ?? * * @param LicenseNo * @param CityCode * @param CustKey * @param SecCode * @return */ @RequestMapping("/getRenewalInfo") @Transactional public void getRenewalInfo(HttpServletRequest request, HttpServletResponse response, String LicenseNo, int CityCode, String CustKey, String SecCode, String IsPublic) { if (request.getMethod().equals("GET")) { try { if (StringUtils.isNotBlank(LicenseNo)) { LicenseNo = new String(LicenseNo.getBytes("iso8859-1"), "GBK"); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } JSONObject renewalInfoJson = new JSONObject(); try { renewalInfoJson = rbService.getRenewalInfo(LicenseNo, CityCode, CustKey, IsPublic); logger.info("? API?????LicenseNo" + LicenseNo); } catch (Exception e) { logger.info("? API????LicenseNo" + LicenseNo + "" + e.getMessage()); } SpringMVCUtils.renderJson(response, renewalInfoJson); } /** * ??????????? * * @param LicenseNo * @return */ @RequestMapping("/getCarInfoByLicenseNo") @Transactional @ResponseBody public Map<String, Object> getCarInfoByLicenseNo(String LicenseNo) { Map map = new HashMap(); try { // CarInfoResponse response = // rbService.getCarInfoByLicenseNo(LicenseNo, "02"); } catch (Exception e) { } return map; } /** * ?? * * @param LicenseNo * ? * @param CarOwnersName * ?? ? * @param IdCard * ?? ? * @param IsSingleSubmit * ?????1=0=? * @param IntentionCompany * ????(-1:????0:?1:?2:?) * @param InsuredName * ???(??) ? * @param InsuredIdCard * ???(??) ? * @param InsuredIdType * ???? ? * @param InsuredMobile * ??? * @param IsNewCar * ?0?1 * @param CarType * 0: 1: * @param CarUsedType * 0????1?? * @param CityCode * Id(1?2 3?45) * @param EngineNo * ?? * @param CarVin * ? * @param RegisterDate * (2014-08-07) * @param MoldName * ?? * @param ForceTax * +(1:+0??) * @param BizStartDate * ?? ??, * @param BoLi * ?0-??12? * @param BuJiMianCheSun * ??(?) 0-??1? * @param BuJiMianDaoQiang * ??() 0-??1? * @param BuJiMianFuJia * ??() 0-??1? * @param BuJiMianRenYuan * ??() 0-??1? * @param BuJiMianSanZhe * ??() 0-??1? * @param CheDeng * ??????0-??1-2-? * @param SheShui * ?0-??1? * @param HuaHen * ?0-??>0?(?)200050001000020000 * @param SiJi * (?) * 0-??>0?(?)1000020000300004000050000100000 * 200000 (?????) * @param ChengKe * () * 0-??>0?(?)1000020000300004000050000100000 * 200000 (?????) * @param CheSun * ??0-??1-? * @param DaoQiang * ?0-??1-? * @param SanZhe * ?0-??>0?(?)50000100000150000200000300 * 00050000010000001500000 * @param ZiRan * ?0-??1? * @param SeatCount * ? ? * @param TonCount * ? ? * @param HcSheBeiSunshi * ?0:?1 ? * @param HcHuoWuZeRen * 0:?>0?? ? * @param HcFeiYongBuChang * ??0:?>0?? ? * @param HcJingShenSunShi * ?0:?>0?? ? * @param HcSanFangTeYue * ??0:?>0?? ? * @param HcXiuLiChang * ?0:?>0?? ? * @param DName * ?? ? * @param DQuantity * ? ? * @param DAmount * ? ? * @param PDate * ? * @param DName1 * ?? ? * @param DQuantity1 * ? ? * @param DAmount1 * ? ? * @param PDate1 * ? * @param DName2 * ?? ? * @param DQuantity2 * ? ? * @param DAmount2 * ? ? * @param PDate2 * ? * @param DName3 * ?? ? * @param DQuantity3 * ? ? * @param DAmount3 * ? ? * @param PDate3 * ? * @param CustKey * ?10-32? * @param Agent * ? * @param SecCode * secCode?????MD532????? * @param RunMiles * ? 10000 30000 * @return */ @RequestMapping("/postPrecisePrice") @Transactional @ResponseBody public void postPrecisePrice(HttpServletRequest request, HttpServletResponse response, String LicenseNo, String CarOwnersName, String IdCard, String IsSingleSubmit, String IntentionCompany, String InsuredName, String InsuredIdCard, String InsuredIdType, String InsuredMobile, String IsNewCar, String CarType, String CarUsedType, String CityCode, String EngineNo, String CarVin, String RegisterDate, String MoldName, String ForceTax, String BizStartDate, String BoLi, String BuJiMianCheSun, String BuJiMianDaoQiang, String BuJiMianFuJia, String BuJiMianRenYuan, String BuJiMianSanZhe, String CheDeng, String SheShui, String HuaHen, String SiJi, String ChengKe, String CheSun, String DaoQiang, String SanZhe, String ZiRan, String SeatCount, String TonCount, String HcSheBeiSunshi, String HcHuoWuZeRen, String HcFeiYongBuChang, String HcJingShenSunShi, String HcSanFangTeYue, String HcXiuLiChang, String DName, String DQuantity, String DAmount, String PDate, String DName1, String DQuantity1, String DAmount1, String PDate1, String DName2, String DQuantity2, String DAmount2, String PDate2, String DName3, String DQuantity3, String DAmount3, String PDate3, String CustKey, String Agent, String SecCode, String RunMiles) { // ?get,chakan if (request.getMethod().equals("GET")) { try { if (StringUtils.isNotBlank(LicenseNo)) { LicenseNo = new String(LicenseNo.getBytes("iso8859-1"), "GBK"); } if (StringUtils.isNotBlank(CarOwnersName)) { CarOwnersName = new String(CarOwnersName.getBytes("iso8859-1"), "GBK"); } if (StringUtils.isNotBlank(InsuredName)) { InsuredName = new String(InsuredName.getBytes("iso8859-1"), "GBK"); } if (StringUtils.isNotBlank(MoldName)) { MoldName = new String(MoldName.getBytes("iso8859-1"), "GBK"); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } PostPrecisePricerResponse postPrecisePricerResponse = new PostPrecisePricerResponse(); try { postPrecisePricerResponse = quoteServiceImpl.postPrecisePrice(LicenseNo, CarOwnersName, IdCard, IsSingleSubmit, IntentionCompany, InsuredName, InsuredIdCard, InsuredIdType, InsuredMobile, IsNewCar, CarType, CarUsedType, CityCode, EngineNo, CarVin, RegisterDate, MoldName, ForceTax, BizStartDate, BoLi, BuJiMianCheSun, BuJiMianDaoQiang, BuJiMianFuJia, BuJiMianRenYuan, BuJiMianSanZhe, CheDeng, SheShui, HuaHen, SiJi, ChengKe, CheSun, DaoQiang, SanZhe, ZiRan, SeatCount, TonCount, HcSheBeiSunshi, HcHuoWuZeRen, HcFeiYongBuChang, HcJingShenSunShi, HcSanFangTeYue, HcXiuLiChang, DName, DQuantity, DAmount, PDate, DName1, DQuantity1, DAmount1, PDate1, DName2, DQuantity2, DAmount2, PDate2, DName3, DQuantity3, DAmount3, PDate3, CustKey, Agent, SecCode, RunMiles); logger.info("PICC API ?????LicenseNo" + LicenseNo); } catch (Exception e) { postPrecisePricerResponse.setBusinessStatus("-1"); postPrecisePricerResponse.setStatusMessage("?" + e.getMessage()); logger.error("PICC API ???" + e.getMessage()); } JSONObject postPrecisePricerResponseJson = (JSONObject) JSONObject.toJSON(postPrecisePricerResponse); JSONObject resultPostPrecisePricerResponseJson = new JSONObject(); for (Map.Entry<String, Object> entry : postPrecisePricerResponseJson.entrySet()) { String key = entry.getKey(); key = key.substring(0, 1).toUpperCase() + key.substring(1); Object value = entry.getValue(); resultPostPrecisePricerResponseJson.put(key, value); } SpringMVCUtils.renderJson(response, resultPostPrecisePricerResponseJson); } /** * * * @param request * @param response * @param LicenseNo * @param IntentionCompany * @param Agent * @param CustKey * @param SecCode */ @RequestMapping("/getPrecisePrice") @ResponseBody public void postPrecisePrice(HttpServletRequest request, HttpServletResponse response, String LicenseNo, String IntentionCompany, String Agent, String CustKey, String SecCode) { // ?get if (request.getMethod().equals("GET")) { try { if (StringUtils.isNotBlank(LicenseNo)) { LicenseNo = new String(LicenseNo.getBytes("iso8859-1"), "GBK"); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } JSONObject result = null; try { result = quoteServiceImpl.getPrecisePrice(LicenseNo, IntentionCompany, Agent, CustKey, SecCode); logger.info("PICC API ???LicenseNo" + LicenseNo); } catch (Exception e) { logger.error("PICC API ??" + e.getMessage()); } if (result == null) { PostPrecisePricerResponse postPrecisePricerResponse = new PostPrecisePricerResponse(); postPrecisePricerResponse.setBusinessStatus("-1"); postPrecisePricerResponse.setStatusMessage("??"); JSONObject postPrecisePricerResponseJson = (JSONObject) JSONObject.toJSON(postPrecisePricerResponse); JSONObject resultPostPrecisePricerResponseJson = new JSONObject(); for (Map.Entry<String, Object> entry : postPrecisePricerResponseJson.entrySet()) { String key = entry.getKey(); key = key.substring(0, 1).toUpperCase() + key.substring(1); Object value = entry.getValue(); resultPostPrecisePricerResponseJson.put(key, value); } SpringMVCUtils.renderJson(response, resultPostPrecisePricerResponseJson); return; } SpringMVCUtils.renderJson(response, result); } @RequestMapping("/getSubmitInfo") @ResponseBody public void getSubmitInfo(HttpServletRequest request, HttpServletResponse response, String LicenseNo, String IntentionCompany, String Agent, String CustKey, String SecCode) { // ?get if (request.getMethod().equals("GET")) { try { if (StringUtils.isNotBlank(LicenseNo)) { LicenseNo = new String(LicenseNo.getBytes("iso8859-1"), "GBK"); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } HebaoResponse hebaoResponse = new HebaoResponse(); JSONObject result = new JSONObject(); try { hebaoResponse = rbService.getHebaoResponse(LicenseNo); JSONObject hebaoResponseJson = (JSONObject) JSONObject.toJSON(hebaoResponse); JSONObject resultHebaoResponseJson = new JSONObject(); for (Map.Entry<String, Object> entry : hebaoResponseJson.entrySet()) { String key = entry.getKey(); key = key.substring(0, 1).toUpperCase() + key.substring(1); Object value = entry.getValue(); resultHebaoResponseJson.put(key, value); } result.put("Item", resultHebaoResponseJson); result.put("BusinessStatus", 1); result.put("StatusMessage", "???"); logger.info("? API?????LicenseNo" + LicenseNo); } catch (Exception e) { result.put("BusinessStatus", 1); result.put("StatusMessage", "??" + e.getMessage()); logger.info("? API????LicenseNo" + LicenseNo + "" + e.getMessage()); } SpringMVCUtils.renderJson(response, result); } }