Java tutorial
package com.alipay.vbizplatform.web.controller; import java.net.URLDecoder; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Resource; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.ObjectUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.alibaba.common.lang.ObjectUtil; import com.alibaba.fastjson.JSONObject; import com.alipay.common.log.util.LogUtil; import com.alipay.common.log.util.MethodCallResultEnum; import com.alipay.fuellingPlatform.common.service.facade.model.CityMapModel; import com.alipay.vbizplatform.common.util.CommonCodeEnum; import com.alipay.vbizplatform.common.util.Constant; import com.alipay.vbizplatform.common.util.CookieTool; import com.alipay.vbizplatform.common.util.DateUtil; import com.alipay.vbizplatform.common.util.RandomUtil; import com.alipay.vbizplatform.common.util.SpyMemcachedClient; import com.alipay.vbizplatform.common.util.StringUtils; import com.alipay.vbizplatform.core.model.UserModel; import com.alipay.vbizplatform.vehicle.service.IMyCarManageService; import com.alipay.vbizplatform.vehicle.service.IOwnerMessage; import com.alipay.vbizplatform.vehicle.service.VehicleDrivingLicenseDistinguishBizService; import com.alipay.vehicleownercore.common.service.facade.model.ResponseData; /** * MyCarManageController.java * * @desc ?? * @author yuanfeng * @datetime 2016-4-5 ?8:31:34 */ @RequestMapping("/car") @Controller @SuppressWarnings({ "unchecked" }) public class MyCarManageController extends BaseController { private static final Logger logger = LoggerFactory.getLogger("vbizplatform"); // ? private static final String VEHICLE_MODEL_KEY_PREFIX = "vehicleM"; @Resource(name = "myCarManageService") private IMyCarManageService myCarManageService; @Resource(name = "spyMemcachedClient") private SpyMemcachedClient spyMemcachedClient; @Resource(name = "ownerMessage") private IOwnerMessage ownerMessage; @Resource(name = "vehicleDrivingLicenseDistinguishBizService") private VehicleDrivingLicenseDistinguishBizService vehicleDrivingLicenseDistinguishBizService; @Autowired private LogUtil logUtil; /** * ?? * @param request * @param response * @return */ @RequestMapping(value = "/portal") public String portal(HttpServletRequest request, HttpServletResponse response) { UserModel userModel = super.getUserInfo(request); /** PrintWriter out = null; try { response.setCharacterEncoding("UTF-8"); out = response.getWriter(); StringBuilder loading = new StringBuilder(); loading.append("<script type=\"text/javascript\" src=\"../js/portal.js\"></script>"); loading.append("<script type=\"text/javascript\">"); loading.append("document.write(_LoadingHtml);"); loading.append("</script>"); out.println(loading.toString()); out.flush(); } catch (Exception e) { logger.error("loading", e); } **/ // ??banner long startTime = System.currentTimeMillis(); String banner = super.invokeVelocityDynamicCreateHtml("banner/sample/topbars.utf8.vm"); request.setAttribute("banner", banner); // 1????? try { logger.info("userModel={}", userModel != null ? userModel.getUid() : ""); /**** test_begin ****/ if (userModel == null) { userModel = new UserModel(); userModel.setUid("2015052100077120770" + RandomUtil.getFixLenthString(3)); // userModel.setUid("2015052100077000000000120774"); userModel.setPhoneNumber("13810331329"); userModel.setRealName(""); userModel.setCertNo("2301012345678905678"); request.getSession().setAttribute(Constant.ALIPAY_USER_SESSION_KEY, userModel); } request.setAttribute("userMap", userModel); logger.info("userModel={}", JSONObject.toJSON(userModel)); /***** test_end *******/ // 2???? List<Map<String, Object>> vehicleList = myCarManageService.queryVehicleListByUid(userModel.getUid()); Map<String, Object> myCar = null; String viNumber = null; // 3?? if (vehicleList != null && vehicleList.size() > 1) { // ??24? spyMemcachedClient.set(userModel.getUid() + "_myCarList", Constant.MEMCACHED_SAVETIME_24, vehicleList); for (Map<String, Object> car : vehicleList) { if (car.get("defaultStatus") instanceof Integer && Integer.parseInt(car.get("defaultStatus").toString()) == 1) { myCar = car; viNumber = String.valueOf(myCar.get("viNumber")); } } if (myCar == null) { // myCar = vehicleList.get(0); viNumber = String.valueOf(myCar.get("viNumber")); } } else if (vehicleList != null && vehicleList.size() == 1) { myCar = vehicleList.get(0); viNumber = String.valueOf(myCar.get("viNumber")); } // 4??? request.setAttribute("myCar", myCar); // 5? Map<String, String> cityMap = null; try { cityMap = ownerMessage.queryResidentcity(userModel.getUid()); } catch (Exception e) { if (logger.isErrorEnabled()) logger.error("sofa?", e); } if (cityMap == null) { // cookie? Cookie cityName = CookieTool.getCookieByName(request, "aliPay_residentCityName"); Cookie cityCode = CookieTool.getCookieByName(request, "aliPay_residentCityCode"); if (cityName != null) { cityMap = new HashMap<String, String>(); cityMap.put("resident_city_name", URLDecoder.decode(cityName.getValue(), "UTF-8")); cityMap.put("resident_city_code", URLDecoder.decode(cityCode.getValue(), "UTF-8")); } } request.setAttribute("cityMap", cityMap); // 6? String cityCode = "330100"; //? if (cityMap != null && !cityMap.isEmpty()) { cityCode = cityMap.get("resident_city_code"); //?session start Object userLocaObject = request.getSession() .getAttribute(Constant.ALIPAY_USER_LOCATION_SESSION_KEY); Map<String, String> userLoca = null; if (null != userLocaObject) { userLoca = (Map<String, String>) userLocaObject; } else { userLoca = new HashMap<String, String>(); } userLoca.put("residentCityCode", cityCode); userLoca.put("residentCityName", cityMap.get("resident_city_name")); request.getSession().setAttribute(Constant.ALIPAY_USER_LOCATION_SESSION_KEY, userLoca); //end } Map<String, String> userMap = new HashMap<String, String>(); userMap.put("userId", userModel.getUid()); List<Map<String, Object>> categoryAppList = ownerMessage.queryCategoryApp(userMap, cityCode, viNumber); request.setAttribute("categoryAppList", categoryAppList); // 7??? int unReadMessage = 0; try { unReadMessage = ownerMessage.messageGetUnreadcount(userModel.getUid()); } catch (Exception e) { logger.error("??sofa?", e); } if (unReadMessage > 0) { // ? try { List<Map<String, Object>> messageList = ownerMessage.messageBatchquery(userModel.getUid(), false, 1, 1); if (messageList != null && !messageList.isEmpty()) { request.setAttribute("message", messageList.get(0)); } } catch (Exception e) { logger.error("?sofa?", e); } } else if (cityMap != null && cityMap.get("resident_city_code") != null) { try { String limitedContent = ownerMessage.queryLimitedLineContent(cityMap.get("resident_city_code"), new Date()); request.setAttribute("limitedContent", limitedContent); } catch (Exception e) { logger.error("??sofa?", e); } } //8??? String userLastTimeGPS = spyMemcachedClient.get(userModel.getUid() + "_LastTimeGPS"); request.setAttribute("lastTimeGPS", userLastTimeGPS); } catch (Exception e) { if (logger.isErrorEnabled()) { logger.error("??", e); } super.redirectErrorPage("BUSY-ERR", "??", null, null, response); logUtil.log(new Throwable(), "PORTAL", userModel.getUid(), MethodCallResultEnum.EXCEPTION, null, "??", startTime); return null; } logUtil.log(new Throwable(), "PORTAL", userModel.getUid(), MethodCallResultEnum.SUCCESS, null, "??", startTime); return "/page/portal"; } /** * ?(?) * @param request * @param response * @return */ @RequestMapping(value = "/queryBrand") public String queryBrand(HttpServletRequest request, HttpServletResponse response) { logger.info("uid={},class={},method=queryBrand,desc=?", super.getUserInfo(request).getUid(), this.getClass().getName()); Map<String, String> pageParam = super.getParametersFromPage(request); long startTime = System.currentTimeMillis(); String uId = ""; try { // 1???? Map<String, List<Map<String, Object>>> brandsMap = myCarManageService.getBrands(); uId = super.getUserInfo(request).getUid(); //1?session?? //? Map<String, Object> vo = null; // Object obj = request.getSession().getAttribute("newVehicleModel"); String vehicleModelKey = uId + VEHICLE_MODEL_KEY_PREFIX; Object obj = spyMemcachedClient.get(vehicleModelKey); if (obj != null) { vo = (HashMap<String, Object>) obj; /*****???vo******/ if (StringUtils.isNotEmpty(pageParam.get("viNumber"))) { vo.put("viNumber", URLDecoder.decode(pageParam.get("viNumber"), "UTF-8").toUpperCase()); } if (StringUtils.isNotEmpty(pageParam.get("viStartTime"))) {// vo.put("viStartTime", DateUtil.parserDateFromString(pageParam.get("viStartTime"), DateUtil.DATEFORMAT5)); } if (StringUtils.isNotEmpty(pageParam.get("vlCityId"))) {// vo.put("vlCityId", pageParam.get("vlCityId")); } if (StringUtils.isNotEmpty(pageParam.get("vlCityName"))) {// ?? vo.put("vlCityName", URLDecoder.decode(pageParam.get("vlCityName"), "UTF-8")); } if (null != (pageParam.get("viMileage"))) {// vo.put("viMileage", pageParam.get("viMileage")); } if (null != (pageParam.get("viVin"))) {// ? vo.put("viVin", pageParam.get("viVin").toUpperCase()); } if (null != (pageParam.get("engineNo"))) {// ? vo.put("engineNo", pageParam.get("engineNo").toUpperCase()); } // request.getSession().setAttribute("newVehicleModel", vo); this.spyMemcachedClient.set(vehicleModelKey, Constant.MEMCACHED_SAVETIME_24, vo); } //2???? request.setAttribute("brandsMap", brandsMap); request.setAttribute("brandSize", brandsMap.size()); request.setAttribute("upst", pageParam.get("upst")); request.setAttribute("viId", ObjectUtil.toString(pageParam.get("viId"))); request.setAttribute("newCarFlag", pageParam.get("newCarFlag")); request.setAttribute("fromPage", pageParam.get("fromPage")); //3??session request.getSession().setAttribute("backUrl", Constant.BACKURLMAP.get(pageParam.get("backUrl"))); } catch (Exception e) { if (logger.isErrorEnabled()) { logger.error("??", e); } logUtil.log(new Throwable(), "BRAND", uId, MethodCallResultEnum.EXCEPTION, null, "??", startTime); super.redirectErrorPage("BUSY-ERR", "??", null, null, response); return null; } if (logger.isInfoEnabled()) { logger.info("???,uid={},toPage->page/cars/selectBrand.jsp", super.getUserInfo(request).getUid()); } logUtil.log(new Throwable(), "BRAND", uId, MethodCallResultEnum.SUCCESS, null, "??", startTime); return "page/cars/selectBrand"; } /** * ? * @param request * @param response * @return */ @RequestMapping("/queryCarSeries") public String queryCarSeries(HttpServletRequest request, HttpServletResponse response) { logger.info("uid={},class={},method=queryCarSeries,desc=", super.getUserInfo(request).getUid(), this.getClass().getName()); Map<String, String> pageParam = super.getParametersFromPage(request); long startTime = System.currentTimeMillis(); String brandName = null; // ? String picUrl = null; // String bgUrl = null; String uId = null; //? Map<String, List<Map<String, Object>>> vehicleSeciesMap = null; try { uId = super.getUserInfo(request).getUid(); if (StringUtils.isNotEmpty(pageParam.get("brandName"))) { // ? brandName = URLDecoder.decode(pageParam.get("brandName"), "UTF-8"); } if (StringUtils.isNotEmpty(pageParam.get("picUrl"))) { // ?id picUrl = URLDecoder.decode(pageParam.get("picUrl"), "UTF-8"); } if (StringUtils.isNotEmpty(pageParam.get("bgUrl"))) { // ? bgUrl = URLDecoder.decode(pageParam.get("bgUrl"), "UTF-8"); } // ?session //request.getSession().setAttribute("newVehicleModel", vo); // 1??? vehicleSeciesMap = myCarManageService.getVehicleSecies(brandName); request.setAttribute("viId", ObjectUtil.toString(pageParam.get("viId"))); request.setAttribute("carSeriesMap", vehicleSeciesMap); request.setAttribute("brandName", brandName); request.setAttribute("picUrl", picUrl); request.setAttribute("bgUrl", bgUrl); request.setAttribute("upst", pageParam.get("upst")); request.setAttribute("newCarFlag", pageParam.get("newCarFlag")); } catch (Exception e) { if (logger.isErrorEnabled()) { logger.error("?", e); } logUtil.log(new Throwable(), "CARSERIES", uId, MethodCallResultEnum.EXCEPTION, null, "?", startTime); super.redirectErrorPage("BUSY-ERR", "??", null, null, response); return null; } if (logger.isInfoEnabled()) { logger.info("??,uid={},toPage->page/cars/selectCarSeries.jsp", super.getUserInfo(request).getUid()); } logUtil.log(new Throwable(), "CARSERIES", uId, MethodCallResultEnum.SUCCESS, null, "??", startTime); return "page/cars/selectCarSeries"; } /** * ?? * @param request * @param response * @return */ @RequestMapping("/queryCarCC") public String queryCarCC(HttpServletRequest request, HttpServletResponse response) { logger.info("uid={},class={},method=queryCarCC,desc=?", super.getUserInfo(request).getUid(), this.getClass().getName()); Map<String, String> pageParam = super.getParametersFromPage(request); long startTime = System.currentTimeMillis(); String uId = null; //? Map<String, Object> vo = null; // Map<String, Map> vehicleTypeListMap = null; try { //1?session?? // Object obj = request.getSession().getAttribute("newVehicleModel"); uId = super.getUserInfo(request).getUid(); String vehicleModelKey = uId + VEHICLE_MODEL_KEY_PREFIX; Object obj = spyMemcachedClient.get(vehicleModelKey); if (obj != null) { vo = (HashMap<String, Object>) obj; /*****???vo******/ if (StringUtils.isNotEmpty(pageParam.get("viNumber"))) { vo.put("viNumber", URLDecoder.decode(pageParam.get("viNumber"), "UTF-8").toUpperCase()); } if (StringUtils.isNotEmpty(pageParam.get("viStartTime"))) {// vo.put("viStartTime", DateUtil.parserDateFromString(pageParam.get("viStartTime"), DateUtil.DATEFORMAT5)); } if (StringUtils.isNotEmpty(pageParam.get("vlCityId"))) {// vo.put("vlCityId", pageParam.get("vlCityId")); } if (StringUtils.isNotEmpty(pageParam.get("vlCityName"))) {// ?? vo.put("vlCityName", URLDecoder.decode(pageParam.get("vlCityName"), "UTF-8")); } // vo.put("viMileage", pageParam.get("viMileage")); // ? vo.put("viVin", pageParam.get("viVin").toUpperCase()); // ?? vo.put("engineNo", pageParam.get("engineNo").toUpperCase()); this.spyMemcachedClient.set(vehicleModelKey, Constant.MEMCACHED_SAVETIME_24, vo); // ?? request.setAttribute("brandName", vo.get("viBrandName")); request.setAttribute("carSeriesName", vo.get("viSeriesName")); if (StringUtils.isNotEmpty(ObjectUtil.toString(vo.get("viLogoUrl")))) { request.setAttribute("modPicUrl", vo.get("viLogoUrl")); } else { request.setAttribute("modPicUrl", vo.get("viBrandLogo")); } request.setAttribute("viId", vo.get("viId")); request.setAttribute("upst", pageParam.get("upst")); request.setAttribute("url_res", ObjectUtil.toString(pageParam.get("url_res"))); } else { // ? if (logger.isErrorEnabled()) { logger.error("session??,toPage->/page/cars/carsList.jsp"); } logUtil.log(new Throwable(), "CARCC", uId, MethodCallResultEnum.EXCEPTION, null, "??session??", startTime); return "redirect:/car/myCarList"; } // // 1???? vehicleTypeListMap = myCarManageService.getVehiclesNow(String.valueOf(vo.get("manufacturer")), String.valueOf(vo.get("viSeriesName"))); //mapset List<String> carCCList = null; if (vehicleTypeListMap != null && !vehicleTypeListMap.isEmpty()) { carCCList = new ArrayList<String>(); for (Map.Entry<String, Map> entry : vehicleTypeListMap.entrySet()) { carCCList.add(entry.getKey()); } request.setAttribute("carCCList", carCCList); request.setAttribute("collapseFlag", pageParam.get("collapseFlag")); } } catch (Exception e) { if (logger.isErrorEnabled()) { logger.error("???", e); } logUtil.log(new Throwable(), "CARCC", uId, MethodCallResultEnum.EXCEPTION, null, "???", startTime); super.redirectErrorPage("BUSY-ERR", "??", null, null, response); return null; } logUtil.log(new Throwable(), "CARCC", uId, MethodCallResultEnum.SUCCESS, null, "????", startTime); return "page/cars/selectCarCc"; } /** * ? * @param request * @param response * @return */ @RequestMapping("/queryCarYear") public String queryCarYear(HttpServletRequest request, HttpServletResponse response) { logger.info("uid={},class={},method=queryCarYear,desc=", super.getUserInfo(request).getUid(), this.getClass().getName()); Map<String, String> pageParam = super.getParametersFromPage(request); //? Map<String, Object> vo = null; // Map<String, Map> vehicleTypeListMap = null; long startTime = System.currentTimeMillis(); String uId = null; try { //1?session?? // Object obj = request.getSession().getAttribute("newVehicleModel"); uId = super.getUserInfo(request).getUid(); String vehicleModelKey = uId + VEHICLE_MODEL_KEY_PREFIX; Object obj = spyMemcachedClient.get(vehicleModelKey); if (obj != null) { vo = (HashMap<String, Object>) obj; /*****???vo******/ if (StringUtils.isNotEmpty(pageParam.get("viStartTime"))) {// vo.put("viStartTime", DateUtil.parserDateFromString(pageParam.get("viStartTime"), DateUtil.DATEFORMAT5)); } if (StringUtils.isNotEmpty(pageParam.get("vlCityId"))) {// vo.put("vlCityId", pageParam.get("vlCityId")); } if (StringUtils.isNotEmpty(pageParam.get("vlCityName"))) {// ?? vo.put("vlCityName", URLDecoder.decode(pageParam.get("vlCityName"), "UTF-8")); } if (StringUtils.isNotEmpty(pageParam.get("viMileage"))) {// vo.put("viMileage", pageParam.get("viMileage")); } if (StringUtils.isNotEmpty(pageParam.get("viVin"))) {// ? vo.put("viVin", pageParam.get("viVin").toUpperCase()); } // request.getSession().setAttribute("newVehicleModel", vo); this.spyMemcachedClient.set(vehicleModelKey, Constant.MEMCACHED_SAVETIME_24, vo); // ?? request.setAttribute("brandName", vo.get("viBrandName")); request.setAttribute("carSeriesName", vo.get("viSeriesName")); if (StringUtils.isNotEmpty(ObjectUtil.toString(vo.get("viLogoUrl")))) { request.setAttribute("modPicUrl", vo.get("viLogoUrl")); } else { request.setAttribute("modPicUrl", vo.get("viBrandLogo")); } request.setAttribute("sweptVolume", pageParam.get("sweptVolume")); request.setAttribute("viId", vo.get("viId")); request.setAttribute("upst", pageParam.get("upst")); } else { // ? if (logger.isErrorEnabled()) { logger.error("session??,toPage->/page/cars/carsList.jsp"); } logUtil.log(new Throwable(), "CARYEAR", uId, MethodCallResultEnum.EXCEPTION, null, "session??,", startTime); return "redirect:/car/myCarList"; } // // 1???? vehicleTypeListMap = myCarManageService.getVehiclesNow(String.valueOf(vo.get("manufacturer")), String.valueOf(vo.get("viSeriesName"))); //mapset List<String> carYearList = null; if (vehicleTypeListMap != null && !vehicleTypeListMap.isEmpty()) { Map<String, Object> YearNode = vehicleTypeListMap .get(URLDecoder.decode(pageParam.get("sweptVolume"), "UTF-8")); carYearList = new ArrayList<String>(); if (null != YearNode) { for (Map.Entry<String, Object> entry : YearNode.entrySet()) { carYearList.add(entry.getKey()); } } request.setAttribute("carYearList", carYearList); request.setAttribute("collapseFlag", pageParam.get("collapseFlag")); } } catch (Exception e) { if (logger.isErrorEnabled()) { logger.error("??", e); } logUtil.log(new Throwable(), "CARYEAR", uId, MethodCallResultEnum.EXCEPTION, null, "??", startTime); super.redirectErrorPage("BUSY-ERR", "??", null, null, response); return null; } logUtil.log(new Throwable(), "CARYEAR", uId, MethodCallResultEnum.SUCCESS, null, "???", startTime); return "page/cars/selectCarvProductionDate"; } /** * ? * @param request * @param response * @return */ @RequestMapping("/queryCarModels") public String queryCarModels(HttpServletRequest request, HttpServletResponse response) { Map<String, String> pageParam = super.getParametersFromPage(request); // ?? String carYearName = null; Map<String, Object> vo = null; String uId = null; long startTime = System.currentTimeMillis(); // Map<String, Map> vehicleTypeListMap = null; try { // Object obj = request.getSession().getAttribute("newVehicleModel"); uId = super.getUserInfo(request).getUid(); String vehicleModelKey = uId + VEHICLE_MODEL_KEY_PREFIX; Object obj = spyMemcachedClient.get(vehicleModelKey); if (obj != null) { vo = (HashMap<String, Object>) obj; if (StringUtils.isNotEmpty(pageParam.get("viNumber"))) { vo.put("viNumber", URLDecoder.decode(pageParam.get("viNumber"), "UTF-8").toUpperCase()); } if (StringUtils.isNotEmpty(pageParam.get("viStartTime"))) {// vo.put("viStartTime", DateUtil.parserDateFromString(pageParam.get("viStartTime"), DateUtil.DATEFORMAT5)); } if (StringUtils.isNotEmpty(pageParam.get("vlCityId"))) {// vo.put("vlCityId", pageParam.get("vlCityId")); } if (StringUtils.isNotEmpty(pageParam.get("vlCityName"))) {// ?? vo.put("vlCityName", URLDecoder.decode(pageParam.get("vlCityName"), "UTF-8")); } if (StringUtils.isNotEmpty(pageParam.get("viMileage"))) {// vo.put("viMileage", pageParam.get("viMileage")); } if (StringUtils.isNotEmpty(pageParam.get("viVin"))) {// ? vo.put("viVin", pageParam.get("viVin").toUpperCase()); } if (StringUtils.isNotEmpty(pageParam.get("engineType"))) { // ?? vo.put("engineType", pageParam.get("engineType").toUpperCase()); } // request.getSession().setAttribute("newVehicleModel", vo); this.spyMemcachedClient.set(vehicleModelKey, Constant.MEMCACHED_SAVETIME_24, vo); request.setAttribute("brandName", vo.get("viBrandName")); request.setAttribute("seriesName", vo.get("viSeriesName")); request.setAttribute("sweptVolume", pageParam.get("sweptVolume")); request.setAttribute("carYearName", URLDecoder.decode(pageParam.get("carYearName"), "UTF-8")); request.setAttribute("viId", vo.get("viId")); request.setAttribute("upst", pageParam.get("upst")); } else { // ? logUtil.log(new Throwable(), "CARMODELS", uId, MethodCallResultEnum.EXCEPTION, null, "??", startTime); return "redirect:/car/myCarList"; } // 1???? vehicleTypeListMap = myCarManageService.getVehiclesNow(String.valueOf(vo.get("manufacturer")), String.valueOf(vo.get("viSeriesName"))); List<String> carModelsList = new ArrayList<String>(); if (null != vehicleTypeListMap) { Map<String, Object> vehicleYearMap = vehicleTypeListMap .get(URLDecoder.decode(pageParam.get("sweptVolume"), "UTF-8")); carModelsList = new ArrayList<String>(); if (null != vehicleYearMap) { Map<String, Object> vehicleTypeMap = (Map<String, Object>) vehicleYearMap .get(String.valueOf(URLDecoder.decode(pageParam.get("carYearName"), "UTF-8"))); if (null != vehicleTypeMap) { for (Map.Entry<String, Object> entry : vehicleTypeMap.entrySet()) { carModelsList.add(entry.getKey()); } } } } request.setAttribute("carModelList", carModelsList); request.setAttribute("collapseFlag", pageParam.get("collapseFlag")); } catch (Exception e) { if (logger.isErrorEnabled()) { logger.error("???", e); } logUtil.log(new Throwable(), "CARMODELS", uId, MethodCallResultEnum.EXCEPTION, null, "??", startTime); super.redirectErrorPage("BUSY-ERR", "??", null, null, response); return null; } logUtil.log(new Throwable(), "CARMODELS", uId, MethodCallResultEnum.SUCCESS, null, "???", startTime); return "page/cars/selectCarType"; } /** * ? * @param request * @param response * @return */ @RequestMapping("/queryCarEngine") public String queryCarEngine(HttpServletRequest request, HttpServletResponse response) { Map<String, String> pageParam = super.getParametersFromPage(request); // ?? Map<String, Object> vo = null; List<String> carEngineList = new ArrayList<String>(); // Map<String, Map> vehicleTypeListMap = null; try { // Object obj = request.getSession().getAttribute("newVehicleModel"); String uId = super.getUserInfo(request).getUid(); String vehicleModelKey = uId + VEHICLE_MODEL_KEY_PREFIX; Object obj = spyMemcachedClient.get(vehicleModelKey); if (obj != null) { vo = (HashMap<String, Object>) obj; vehicleTypeListMap = myCarManageService.getVehiclesNow(String.valueOf(vo.get("manufacturer")), String.valueOf(vo.get("viSeriesName"))); Map<String, Object> vehicleYearMap = vehicleTypeListMap .get(URLDecoder.decode(pageParam.get("sweptVolume"), "UTF-8")); if (null != vehicleYearMap) { Map<String, Object> vehicleTypeMap = (Map<String, Object>) vehicleYearMap .get(URLDecoder.decode(pageParam.get("carYearName"), "UTF-8")); if (null != vehicleTypeMap) { //??? Map<String, Object> vehicleEngineMap = (Map<String, Object>) vehicleTypeMap .get(URLDecoder.decode(pageParam.get("carModelName"), "UTF-8")); if (null != vehicleEngineMap && !vehicleEngineMap.isEmpty()) { for (Map.Entry<String, Object> entry : vehicleEngineMap.entrySet()) { if (!"?".equals(entry.getKey()) && !("null".equals(entry.getKey()))) { carEngineList.add(entry.getKey()); } } } } } if (carEngineList.isEmpty() || carEngineList.size() == 1) { request.setAttribute("carEngineList", carEngineList); if (pageParam.get("upst").equals("1")) { return toCarInfo(request, response); } else { return newCarInfo(request, response); } } if (StringUtils.isNotEmpty(pageParam.get("viNumber"))) { vo.put("viNumber", URLDecoder.decode(pageParam.get("viNumber"), "UTF-8").toUpperCase()); } if (StringUtils.isNotEmpty(pageParam.get("viStartTime"))) {// vo.put("viStartTime", DateUtil.parserDateFromString(pageParam.get("viStartTime"), DateUtil.DATEFORMAT5)); } if (StringUtils.isNotEmpty(pageParam.get("vlCityId"))) {// vo.put("vlCityId", pageParam.get("vlCityId")); } if (StringUtils.isNotEmpty(pageParam.get("vlCityName"))) {// ?? vo.put("vlCityName", URLDecoder.decode(pageParam.get("vlCityName"), "UTF-8")); } if (StringUtils.isNotEmpty(pageParam.get("viMileage"))) {// vo.put("viMileage", pageParam.get("viMileage")); } if (StringUtils.isNotEmpty(pageParam.get("viVin"))) {// ? vo.put("viVin", pageParam.get("viVin").toUpperCase()); } // if (StringUtils.isNotEmpty(pageParam.get("engineType"))) { // ?? // vo.put("engineType", pageParam.get("engineType").toUpperCase()); // } // if (StringUtils.isNotEmpty(pageParam.get("sweptVolume"))) { //? // vo.put("sweptVolume", pageParam.get("sweptVolume")); // } // request.getSession().setAttribute("newVehicleModel", vo); this.spyMemcachedClient.set(vehicleModelKey, Constant.MEMCACHED_SAVETIME_24, vo); request.setAttribute("brandName", vo.get("viBrandName")); request.setAttribute("seriesName", vo.get("viSeriesName")); request.setAttribute("viId", vo.get("viId")); request.setAttribute("upst", pageParam.get("upst")); request.setAttribute("carEngineFlag", carEngineList.isEmpty()); request.setAttribute("sweptVolume", pageParam.get("sweptVolume")); request.setAttribute("carYearName", URLDecoder.decode(pageParam.get("carYearName"), "UTF-8")); request.setAttribute("carModelName", URLDecoder.decode(pageParam.get("carModelName"), "UTF-8")); } else { // ? return "redirect:/car/myCarList"; } // 1???? request.setAttribute("carEngineList", carEngineList); request.setAttribute("collapseFlag", pageParam.get("collapseFlag")); } catch (Exception e) { if (logger.isErrorEnabled()) { logger.error("???", e); } super.redirectErrorPage("BUSY-ERR", "??", null, null, response); return null; } return "page/cars/selectCarEngine"; } /** * ?? * @param request * @param response * @return */ @RequestMapping("/newCarInfo") public String newCarInfo(HttpServletRequest request, HttpServletResponse response) { Map<String, String> pageParam = super.getParametersFromPage(request); // ??? Map<String, Object> vo = null; //?? String manufacturer = null; // ?? String carSeriesName = null; String uId = null; long startTime = System.currentTimeMillis(); try { // Object obj = request.getSession().getAttribute("newVehicleModel"); uId = super.getUserInfo(request).getUid(); String vehicleModelKey = uId + VEHICLE_MODEL_KEY_PREFIX; Object obj = spyMemcachedClient.get(vehicleModelKey); if (obj == null || (pageParam.get("newCarFlag") != null && pageParam.get("newCarFlag").equals("1"))) { vo = new HashMap<String, Object>(); // request.getSession().setAttribute("newVehicleModel", vo); this.spyMemcachedClient.set(vehicleModelKey, Constant.MEMCACHED_SAVETIME_24, vo); } else { vo = (HashMap<String, Object>) obj; } /*****???vo******/ if (StringUtils.isNotEmpty(pageParam.get("carSeriesName"))) { // ?? carSeriesName = URLDecoder.decode(pageParam.get("carSeriesName"), "UTF-8"); if (null != carSeriesName && !(ObjectUtil.toString(vo.get("viSeriesName")).equals(carSeriesName))) { vo.put("viSeriesName", carSeriesName); //? vo.put("viBrandName", URLDecoder.decode(pageParam.get("brandName"), "UTF-8")); //??? vo.put("viBrandLogo", URLDecoder.decode(pageParam.get("picUrl"), "UTF-8")); // vo.put("viLogoUrl", URLDecoder.decode(pageParam.get("modPicUrl"), "UTF-8")); //? vo.put("bgUrl", URLDecoder.decode(pageParam.get("bgUrl"), "UTF-8")); //?? manufacturer = URLDecoder.decode(pageParam.get("manufacturer"), "UTF-8"); vo.put("manufacturer", manufacturer); // vo.put("sweptVolume", ""); vo.put("viStyleName", ""); vo.put("viModelName", ""); vo.put("viModelId", ""); vo.put("engineType", ""); } } //??? List<String> carEngineList = request.getAttribute("carEngineList") == null ? new ArrayList<String>() : (List<String>) request.getAttribute("carEngineList"); String carEngineFlag = pageParam.get("carEngineFlag"); if (!carEngineList.isEmpty() || "false".equals(carEngineFlag)) { String engineType = ""; if (StringUtils.isNotEmpty(pageParam.get("engineType"))) { // ?? engineType = URLDecoder.decode(pageParam.get("engineType"), "UTF-8"); } else { engineType = carEngineList.get(0); } if (null != engineType && !(ObjectUtil.toString(vo.get("engineType")).equals(engineType))) { String sweptVolume = URLDecoder.decode(ObjectUtil.toString(pageParam.get("sweptVolume")), "UTF-8"); String productionYear = URLDecoder.decode(ObjectUtil.toString(pageParam.get("carYearName")), "UTF-8"); String carModelName = URLDecoder.decode(ObjectUtil.toString(pageParam.get("carModelName")), "UTF-8"); //? vo.put("sweptVolume", sweptVolume); // // vo.put("viStyleName", ); // vo.put("productionYear", productionYear); // vo.put("viModelName", carModelName); //?? vo.put("engineType", engineType); Map<String, Object> map = getVihcleInfo(ObjectUtil.toString(vo.get("manufacturer")), ObjectUtil.toString(vo.get("viSeriesName")), sweptVolume, productionYear, carModelName, engineType); // vo.put("viStyleName", ObjectUtil.toString(map.get("style"))); } } else { if (StringUtils.isNotEmpty(pageParam.get("carModelName"))) { // ?? String carModelName = URLDecoder.decode(pageParam.get("carModelName"), "UTF-8"); if (null != carModelName && !(ObjectUtil.toString(vo.get("viModelName")).equals(carModelName))) { String sweptVolume = URLDecoder.decode(ObjectUtil.toString(pageParam.get("sweptVolume")), "UTF-8"); String productionYear = URLDecoder.decode(ObjectUtil.toString(pageParam.get("carYearName")), "UTF-8"); //? vo.put("sweptVolume", sweptVolume); // // vo.put("productionYear", productionYear); // vo.put("viModelName", carModelName); Map<String, Object> map = getVihcleInfo(ObjectUtil.toString(vo.get("manufacturer")), ObjectUtil.toString(vo.get("viSeriesName")), sweptVolume, productionYear, carModelName, "?"); // vo.put("viStyleName", ObjectUtil.toString(map.get("style"))); } } } // cookie? if (StringUtils.isEmpty(ObjectUtils.toString(vo.get("vlCityName")))) { Map<String, String> cityInfo = getCityInfo(request); if (!cityInfo.isEmpty()) { vo.put("vlCityId", cityInfo.get("resident_city_code")); vo.put("vlCityName", cityInfo.get("resident_city_name")); } } // request.getSession().setAttribute("newVehicleModel", vo); this.spyMemcachedClient.set(vehicleModelKey, Constant.MEMCACHED_SAVETIME_24, vo); request.setAttribute("vehicleModel", vo); String viNumber = String.valueOf(vo.get("viNumber")); // if (StringUtils.isNotEmpty(viNumber) && viNumber.length() >= 1) { request.setAttribute("cityAB", viNumber.substring(0, 1)); // request.setAttribute("carNumber", viNumber.substring(1, viNumber.length())); // } else { if (!StringUtils.isEmpty(ObjectUtil.toString(vo.get("vlCityId"))) && (StringUtils.isEmpty(viNumber))) { CityMapModel cityCode = ownerMessage.queryCityMapInfo(vo.get("vlCityId").toString()); if (null != cityCode) request.setAttribute("cityAB", cityCode.getCarNoPrefix()); // } } if (vo.get("viStartTime") != null) { // request.setAttribute("viStartTime", DateUtil.parserDateToString((Date) vo.get("viStartTime"), DateUtil.DATEFORMAT5)); } String backUrl = "/car/myCarList"; Object backObj = request.getSession().getAttribute("backUrl"); if (backObj != null) { backUrl = backObj.toString(); } request.setAttribute("backUrl", backUrl); //ocs?? List<Map<String, Object>> vehicleList = spyMemcachedClient .get(super.getUserInfo(request).getUid() + "_myCarList"); request.setAttribute("carList", JSONObject.toJSON(vehicleList)); //collapse request.setAttribute("collapseFlag", pageParam.get("collapseFlag")); } catch (Exception e) { if (logger.isErrorEnabled()) { logger.error("???", e); } logUtil.log(new Throwable(), "CARINFO", uId, MethodCallResultEnum.EXCEPTION, null, "???", startTime); super.redirectErrorPage("BUSY-ERR", "??", null, null, response); return null; } logUtil.log(new Throwable(), "CARINFO", uId, MethodCallResultEnum.SUCCESS, null, "????", startTime); return "page/cars/completion"; } /** * ? * @param request * @param response * @return */ @RequestMapping("/addNewCarInfo") public String addNewCarInfo(HttpServletRequest request, HttpServletResponse response) { Map<String, String> pageParam = super.getParametersFromPage(request); Map<String, Object> vo = null; long startTime = System.currentTimeMillis(); String uId = null; try { // Object obj = request.getSession().getAttribute("newVehicleModel"); uId = super.getUserInfo(request).getUid(); String vehicleModelKey = uId + VEHICLE_MODEL_KEY_PREFIX; Object obj = spyMemcachedClient.get(vehicleModelKey); if (obj != null) { vo = (HashMap<String, Object>) obj; UserModel userModel = (UserModel) request.getSession() .getAttribute(Constant.ALIPAY_USER_SESSION_KEY); vo.put("uid", userModel.getUid()); if (pageParam.get("viNumber") != null) { vo.put("viNumber", URLDecoder.decode(pageParam.get("viNumber"), "UTF-8").toUpperCase()); } if (StringUtils.isNotEmpty(pageParam.get("viStartTime"))) {// vo.put("viStartTime", DateUtil.parserDateFromString(pageParam.get("viStartTime"), DateUtil.DATEFORMAT5)); } if (StringUtils.isNotEmpty(pageParam.get("vlCityId"))) {// vo.put("vlCityId", pageParam.get("vlCityId")); } if (StringUtils.isNotEmpty(pageParam.get("vlCityName"))) {// ?? vo.put("vlCityName", URLDecoder.decode(pageParam.get("vlCityName"), "UTF-8")); } // vo.put("viMileage", pageParam.get("viMileage")); // ? vo.put("viVin", pageParam.get("viVin").toUpperCase()); // ?? vo.put("engineNo", pageParam.get("engineNo").toUpperCase()); // request.getSession().setAttribute("newVehicleModel", vo); this.spyMemcachedClient.set(vehicleModelKey, Constant.MEMCACHED_SAVETIME_24, vo); // 1?sofa? Map<String, String> resMap = myCarManageService.addVehicle(vo); if (resMap == null) {// ??? if (logger.isErrorEnabled()) { logger.error("????sofa?null"); } super.redirectErrorPage("BUSY-ERR", "???", null, null, response); return null; } else if (!Constant.SOFA_RETURN_CODE_SUCCESS.equals(resMap.get("returnCode"))) { String errorMsg = "?"; if ("11006".equals(resMap.get("returnCode"))) { errorMsg = ""; } if (logger.isErrorEnabled()) { logger.error( "????sofa??{} |??{}", resMap.get("returnCode"), resMap.get("returnDesc")); } logUtil.log(new Throwable(), "NEWCARINFO", uId, MethodCallResultEnum.EXCEPTION, null, "????", startTime); super.redirectErrorPage("BUSY-ERR", errorMsg, null, null, response); return null; } else { String backUrl = "/car/myCarList"; Object backObj = request.getSession().getAttribute("backUrl"); if (backObj != null) { backUrl = backObj.toString(); } request.setAttribute("backUrl", backUrl); logUtil.log(new Throwable(), "NEWCARINFO", uId, MethodCallResultEnum.SUCCESS, null, "?????", startTime); return new StringBuilder("redirect:").append(backUrl).toString(); } } else { // ? logUtil.log(new Throwable(), "NEWCARINFO", uId, MethodCallResultEnum.EXCEPTION, null, "????", startTime); super.redirectErrorPage("BUSY-ERR", ",?", null, null, response); return null; } } catch (Exception e) { if (logger.isErrorEnabled()) { logger.error("????", e); } logUtil.log(new Throwable(), "NEWCARINFO", uId, MethodCallResultEnum.EXCEPTION, null, "????", startTime); super.redirectErrorPage("BUSY-ERR", "???", null, null, response); return null; } } /** * ? * @param request * @param response * @return */ @RequestMapping("/addNewCarInfoAjax") public @ResponseBody Object addNewCarInfoAjax(HttpServletRequest request, HttpServletResponse response) { Map<String, String> pageParam = super.getParametersFromPage(request); Map<String, Object> vo = null; long startTime = System.currentTimeMillis(); String uId = null; Map<String, Object> map = new HashMap<String, Object>(); map.put("success", "false"); try { // Object obj = request.getSession().getAttribute("newVehicleModel"); uId = super.getUserInfo(request).getUid(); String vehicleModelKey = uId + VEHICLE_MODEL_KEY_PREFIX; Object obj = spyMemcachedClient.get(vehicleModelKey); if (obj != null) { vo = (HashMap<String, Object>) obj; UserModel userModel = (UserModel) request.getSession() .getAttribute(Constant.ALIPAY_USER_SESSION_KEY); vo.put("uid", userModel.getUid()); if (pageParam.get("viNumber") != null) { vo.put("viNumber", URLDecoder.decode(pageParam.get("viNumber"), "UTF-8").toUpperCase()); } if (StringUtils.isNotEmpty(pageParam.get("viStartTime"))) {// vo.put("viStartTime", DateUtil.parserDateFromString(pageParam.get("viStartTime"), DateUtil.DATEFORMAT5)); } if (StringUtils.isNotEmpty(pageParam.get("vlCityId"))) {// vo.put("vlCityId", pageParam.get("vlCityId")); } if (StringUtils.isNotEmpty(pageParam.get("vlCityName"))) {// ?? vo.put("vlCityName", URLDecoder.decode(pageParam.get("vlCityName"), "UTF-8")); } // vo.put("viMileage", pageParam.get("viMileage")); // ? vo.put("viVin", pageParam.get("viVin").toUpperCase()); // ?? vo.put("engineNo", pageParam.get("engineNo").toUpperCase()); if (StringUtils.isNotEmpty(pageParam.get("sweptVolume"))) { //? vo.put("sweptVolume", URLDecoder.decode(pageParam.get("sweptVolume"), "UTF-8")); } // request.getSession().setAttribute("newVehicleModel", vo); this.spyMemcachedClient.set(vehicleModelKey, Constant.MEMCACHED_SAVETIME_24, vo); // 1?sofa? Map<String, String> resMap = myCarManageService.addVehicle(vo); if (resMap == null) {// ??? if (logger.isErrorEnabled()) { logger.error("????sofa?null"); } map.put("errorUrl", super.errorPageUrl("BUSY-ERR", "???", null, null)); return map; } else if (!Constant.SOFA_RETURN_CODE_SUCCESS.equals(resMap.get("returnCode"))) { String errorMsg = "?"; if ("11006".equals(resMap.get("returnCode"))) { errorMsg = ""; } if (logger.isErrorEnabled()) { logger.error( "????sofa??{} |??{}", resMap.get("returnCode"), resMap.get("returnDesc")); } logUtil.log(new Throwable(), "NEWCARINFO", uId, MethodCallResultEnum.EXCEPTION, null, "????", startTime); map.put("errorUrl", super.errorPageUrl("BUSY-ERR", errorMsg, null, null)); return map; } else { String backUrl = "/car/myCarList"; Object backObj = request.getSession().getAttribute("backUrl"); if (backObj != null) { backUrl = backObj.toString(); } request.setAttribute("backUrl", backUrl); logUtil.log(new Throwable(), "NEWCARINFO", uId, MethodCallResultEnum.SUCCESS, null, "?????", startTime); map.put("success", "true"); return map; } } else { // ? logUtil.log(new Throwable(), "NEWCARINFO", uId, MethodCallResultEnum.EXCEPTION, null, "????", startTime); map.put("errorUrl", super.errorPageUrl("BUSY-ERR", ",?", null, null)); return map; } } catch (Exception e) { if (logger.isErrorEnabled()) { logger.error("????", e); } logUtil.log(new Throwable(), "NEWCARINFO", uId, MethodCallResultEnum.EXCEPTION, null, "????", startTime); map.put("errorUrl", super.errorPageUrl("BUSY-ERR", "???", null, null)); return map; } } /** * ? * * @param request * @param response * @return */ @RequestMapping(value = "/myCarList") public String myCarList(HttpServletRequest request, HttpServletResponse response) { long startTime = System.currentTimeMillis(); String uId = null; try { // 1?session?? UserModel userModel = (UserModel) request.getSession().getAttribute(Constant.ALIPAY_USER_SESSION_KEY); uId = userModel.getUid(); // 2?? List<Map<String, Object>> vehicleList = myCarManageService.queryVehicleListByUid(uId); if (vehicleList == null || vehicleList.size() == 0) { return "page/cars/carsListNull"; } // ??24? spyMemcachedClient.set(uId + "_myCarList", Constant.MEMCACHED_SAVETIME_24, vehicleList); request.setAttribute("myCarList", vehicleList); } catch (Exception e) { if (logger.isErrorEnabled()) { logger.error("??", e); } logUtil.log(new Throwable(), "PORTAL", uId, MethodCallResultEnum.EXCEPTION, null, "??", startTime); super.redirectErrorPage("BUSY-ERR", "???", null, null, response); return null; } logUtil.log(new Throwable(), "PORTAL", uId, MethodCallResultEnum.SUCCESS, null, "???", startTime); return "page/cars/carsList"; } /** * ? * * @param request * @param response */ @RequestMapping(value = "/delMyCar") public @ResponseBody String delMyCar(HttpServletRequest request, HttpServletResponse response) { Map<String, String> pageParam = super.getParametersFromPage(request); Map<String, String> resMap = null; try { // id UserModel userModel = (UserModel) request.getSession().getAttribute(Constant.ALIPAY_USER_SESSION_KEY); if (StringUtils.isNotEmpty(pageParam.get("viId")) //id? && pageParam.get("viId").matches("^\\d+$")) {//id //? resMap = myCarManageService.deleteVehicleInfo(userModel.getUid(), pageParam.get("viId")); if (resMap != null && Constant.SOFA_RETURN_CODE_SUCCESS.equals(resMap.get("returnCode"))) { try { //? List<Map<String, Object>> vehicleList = spyMemcachedClient .get(userModel.getUid() + "_myCarList"); if (!vehicleList.isEmpty()) { for (Map<String, Object> vMap : vehicleList) { if (vMap.get("viId").equals(pageParam.get("viId"))) { vehicleList.remove(vMap); // break; } } //? spyMemcachedClient.set(userModel.getUid() + "_myCarList", Constant.MEMCACHED_SAVETIME_24, vehicleList); } } catch (Exception e) { if (logger.isErrorEnabled()) { logger.error("?ocs?", e); } } return "ok"; } } } catch (Exception e) { if (logger.isErrorEnabled()) { logger.error("?", e); } } return null; } /** * * * @param request * @param response */ @RequestMapping(value = "/setDefaultCar") public @ResponseBody String setDefaultCar(HttpServletRequest request, HttpServletResponse response) { Map<String, String> pageParam = super.getParametersFromPage(request); Map<String, String> resMap = null; try { // id UserModel userModel = (UserModel) request.getSession().getAttribute(Constant.ALIPAY_USER_SESSION_KEY); if (StringUtils.isNotEmpty(pageParam.get("viId")) //id? && pageParam.get("viId").matches("^\\d+$")) {//id // resMap = myCarManageService.updateDefaultVehicleSetting(userModel.getUid(), pageParam.get("viId")); if (resMap != null && Constant.SOFA_RETURN_CODE_SUCCESS.equals(resMap.get("returnCode"))) { return "ok"; } } } catch (Exception e) { if (logger.isErrorEnabled()) logger.error("?", e); } return null; } /** * ?? * @param request * @param response * @return */ @RequestMapping(value = "/toCarInfo") public String toCarInfo(HttpServletRequest request, HttpServletResponse response) { Map<String, String> pageParam = super.getParametersFromPage(request); try { // 1?session?? UserModel userModel = super.getUserInfo(request); String viId = pageParam.get("viId"); String carSeriesName = null; String manufacturer = null; Map<String, Object> updateVo = null; String uId = super.getUserInfo(request).getUid(); String vehicleModelKey = uId + VEHICLE_MODEL_KEY_PREFIX; boolean tf = false; //session?,?? if (StringUtils.isEmpty(pageParam.get("backUrl"))) { // Object obj = request.getSession().getAttribute("newVehicleModel"); Object obj = spyMemcachedClient.get(vehicleModelKey); if (obj != null) { updateVo = (HashMap<String, Object>) obj; if (viId.equals(String.valueOf(updateVo.get("viId")))) { tf = true; //?? } else { updateVo = null; } } } if (!tf) { //session? //memcached? List<Map<String, Object>> myCarList = spyMemcachedClient.get(userModel.getUid() + "_myCarList"); if (myCarList != null && myCarList.size() > 0) { for (Map<String, Object> vo : myCarList) { if (viId.equals(String.valueOf(vo.get("viId")))) { updateVo = vo; } } } if (updateVo == null) { //?idid? updateVo = myCarManageService.getVehicleInfo(userModel.getUid(), viId); } } if (updateVo == null) { super.redirectErrorPage("BUSY-ERR", "???", null, null, response); return null; } if (StringUtils.isNotEmpty(pageParam.get("carSeriesName"))) { // ?? carSeriesName = URLDecoder.decode(pageParam.get("carSeriesName"), "UTF-8"); if (null != carSeriesName && !(ObjectUtil.toString(updateVo.get("viSeriesName")).equals(carSeriesName))) { updateVo.put("viSeriesName", carSeriesName); //? updateVo.put("viBrandName", URLDecoder.decode(pageParam.get("brandName"), "UTF-8")); //??? updateVo.put("viBrandLogo", URLDecoder.decode(pageParam.get("picUrl"), "UTF-8")); // updateVo.put("viLogoUrl", URLDecoder.decode(pageParam.get("modPicUrl"), "UTF-8")); //? updateVo.put("bgUrl", URLDecoder.decode(pageParam.get("bgUrl"), "UTF-8")); //?? manufacturer = URLDecoder.decode(pageParam.get("manufacturer"), "UTF-8"); updateVo.put("manufacturer", manufacturer); // updateVo.put("sweptVolume", ""); updateVo.put("viStyleName", ""); updateVo.put("viModelName", ""); updateVo.put("viModelId", ""); updateVo.put("engineType", ""); updateVo.put("productionYear", ""); } } //??? List<String> carEngineList = request.getAttribute("carEngineList") == null ? new ArrayList<String>() : (List<String>) request.getAttribute("carEngineList"); String carEngineFlag = pageParam.get("carEngineFlag"); if (!carEngineList.isEmpty() || "false".equals(carEngineFlag)) { String engineType = ""; if (StringUtils.isNotEmpty(pageParam.get("engineType"))) { // ?? engineType = URLDecoder.decode(pageParam.get("engineType"), "UTF-8"); } else { engineType = carEngineList.get(0); } if (null != engineType && !(ObjectUtil.toString(updateVo.get("engineType")).equals(engineType))) { String sweptVolume = ObjectUtil.toString(pageParam.get("sweptVolume")); String productionYear = URLDecoder.decode(ObjectUtil.toString(pageParam.get("carYearName")), "UTF-8"); String carModelName = URLDecoder.decode(ObjectUtil.toString(pageParam.get("carModelName")), "UTF-8"); //? updateVo.put("sweptVolume", sweptVolume); // // vo.put("viStyleName", ); // updateVo.put("productionYear", productionYear); // updateVo.put("viModelName", carModelName); //?? updateVo.put("engineType", engineType); Map<String, Object> map = getVihcleInfo(ObjectUtil.toString(updateVo.get("manufacturer")), ObjectUtil.toString(updateVo.get("viSeriesName")), sweptVolume, productionYear, carModelName, engineType); // updateVo.put("viStyleName", ObjectUtil.toString(map.get("style"))); } } else { if (StringUtils.isNotEmpty(pageParam.get("carModelName"))) { // ?? String carModelName = URLDecoder.decode(pageParam.get("carModelName"), "UTF-8"); if (null != carModelName && !(ObjectUtil.toString(updateVo.get("viModelName")).equals(carModelName))) { String sweptVolume = ObjectUtil.toString(pageParam.get("sweptVolume")); String productionYear = URLDecoder.decode(ObjectUtil.toString(pageParam.get("carYearName")), "UTF-8"); //? updateVo.put("sweptVolume", sweptVolume); // // updateVo.put("productionYear", productionYear); // updateVo.put("viModelName", carModelName); Map<String, Object> map = getVihcleInfo(ObjectUtil.toString(updateVo.get("manufacturer")), ObjectUtil.toString(updateVo.get("viSeriesName")), sweptVolume, productionYear, carModelName, "?"); // updateVo.put("viStyleName", ObjectUtil.toString(map.get("style"))); } } } // ??url if (StringUtils.isNotEmpty(pageParam.get("backUrl"))) { request.getSession().setAttribute("backUrl", Constant.BACKURLMAP.get(pageParam.get("backUrl"))); } // request.getSession().setAttribute("newVehicleModel", updateVo); this.spyMemcachedClient.set(vehicleModelKey, Constant.MEMCACHED_SAVETIME_24, updateVo); request.setAttribute("vehicleModel", updateVo); String viNumber = String.valueOf(updateVo.get("viNumber"));// if (StringUtils.isNotEmpty(viNumber) && viNumber.length() > 1) { request.setAttribute("cityAB", viNumber.substring(0, 1)); // request.setAttribute("carNumber", viNumber.substring(1, viNumber.length())); // } if (updateVo.get("viStartTime") != null) { // ,??yyyy-mm? request.setAttribute("viStartTime", DateUtil.parserDateToString((Date) updateVo.get("viStartTime"), DateUtil.DATEFORMAT5)); } String backUrl = "/car/myCarList"; Object backObj = request.getSession().getAttribute("backUrl"); if (backObj != null) { backUrl = backObj.toString(); } request.setAttribute("backUrl", backUrl); //ocs?? List<Map<String, Object>> vehicleList = spyMemcachedClient .get(super.getUserInfo(request).getUid() + "_myCarList"); request.setAttribute("carList", JSONObject.toJSON(vehicleList)); } catch (Exception e) { if (logger.isErrorEnabled()) { logger.error("??", e); } super.redirectErrorPage("BUSY-ERR", "???", null, null, response); return null; } return "page/cars/carsDetail"; } /** * ? * @param request * @param response * @return */ @RequestMapping("/updateCarInfo") public String updateCarInfo(HttpServletRequest request, HttpServletResponse response) { Map<String, String> pageParam = super.getParametersFromPage(request); Map<String, Object> vo = null; try { // Object obj = request.getSession().getAttribute("newVehicleModel"); String uId = super.getUserInfo(request).getUid(); String vehicleModelKey = uId + VEHICLE_MODEL_KEY_PREFIX; Object obj = spyMemcachedClient.get(vehicleModelKey); if (obj != null) { vo = (HashMap<String, Object>) obj; UserModel userModel = super.getUserInfo(request); vo.put("uid", userModel.getUid()); if (pageParam.get("viNumber") != null) { vo.put("viNumber", URLDecoder.decode(pageParam.get("viNumber"), "UTF-8").toUpperCase()); } if (StringUtils.isNotEmpty(pageParam.get("viStartTime"))) {// vo.put("viStartTime", DateUtil.parserDateFromString(pageParam.get("viStartTime"), DateUtil.DATEFORMAT5)); } if (StringUtils.isNotEmpty(pageParam.get("vlCityId"))) {// vo.put("vlCityId", pageParam.get("vlCityId")); } if (StringUtils.isNotEmpty(pageParam.get("vlCityName"))) {// ?? vo.put("vlCityName", URLDecoder.decode(pageParam.get("vlCityName"), "UTF-8")); } // vo.put("viMileage", pageParam.get("viMileage")); // ? vo.put("viVin", pageParam.get("viVin").toUpperCase()); // ?? vo.put("engineNo", pageParam.get("engineNo").toUpperCase()); if (StringUtils.isNotEmpty(pageParam.get("sweptVolume"))) { //? vo.put("sweptVolume", URLDecoder.decode(pageParam.get("sweptVolume"), "UTF-8")); } // request.getSession().setAttribute("newVehicleModel", vo); this.spyMemcachedClient.set(vehicleModelKey, Constant.MEMCACHED_SAVETIME_24, vo); // 1?sofa? Map<String, String> resMap = myCarManageService.modifyVehicle(vo); if (resMap == null) {// ?? if (logger.isErrorEnabled()) { logger.error("????sofa?null"); } super.redirectErrorPage("BUSY-ERR", "???", null, null, response); return null; } else if (!Constant.SOFA_RETURN_CODE_SUCCESS.equals(resMap.get("returnCode"))) { String errorMsg = "?"; if (Constant.SOFA_RETURN_CODE_REPEAT.equals(resMap.get("returnCode"))) { errorMsg = ""; } if (logger.isErrorEnabled()) { logger.error( "????sofa??{} |??{}", resMap.get("returnCode"), resMap.get("returnDesc")); } super.redirectErrorPage("BUSY-ERR", errorMsg, null, null, response); return null; } else { //? List<Map<String, Object>> vehicleList = spyMemcachedClient .get(userModel.getUid() + "_myCarList"); if (null != vehicleList && !vehicleList.isEmpty()) { for (int i = 0; i < vehicleList.size(); i++) { Map<String, Object> vMap = vehicleList.get(i); if (vMap.get("viId").equals(vo.get("viId"))) { vehicleList.set(i, vo); // break; } } //? spyMemcachedClient.set(userModel.getUid() + "_myCarList", Constant.MEMCACHED_SAVETIME_24, vehicleList); } ////////////////// String backUrl = "/car/myCarList"; Object backObj = request.getSession().getAttribute("backUrl"); if (backObj != null) { backUrl = backObj.toString(); } request.setAttribute("backUrl", backUrl); return new StringBuilder("redirect:").append(backUrl).toString(); } } else { // ? logger.error("????,session?"); super.redirectErrorPage("BUSY-ERR", ",?", null, null, response); return null; } } catch (Exception e) { logger.error("????", e); super.redirectErrorPage("BUSY-ERR", "???", null, null, response); return null; } } /** * ? * @param request * @param response * @return */ @RequestMapping("/updateCarInfoAjax") public @ResponseBody Object updateCarInfoAjax(HttpServletRequest request, HttpServletResponse response) { Map<String, String> pageParam = super.getParametersFromPage(request); Map<String, Object> vo = null; Map<String, Object> map = new HashMap<String, Object>(); map.put("success", "false"); try { // Object obj = request.getSession().getAttribute("newVehicleModel"); String uId = super.getUserInfo(request).getUid(); String vehicleModelKey = uId + VEHICLE_MODEL_KEY_PREFIX; Object obj = spyMemcachedClient.get(vehicleModelKey); if (obj != null) { vo = (HashMap<String, Object>) obj; UserModel userModel = super.getUserInfo(request); vo.put("uid", userModel.getUid()); if (pageParam.get("viNumber") != null) { vo.put("viNumber", URLDecoder.decode(pageParam.get("viNumber"), "UTF-8").toUpperCase()); } if (StringUtils.isNotEmpty(pageParam.get("viStartTime"))) {// vo.put("viStartTime", DateUtil.parserDateFromString(pageParam.get("viStartTime"), DateUtil.DATEFORMAT5)); } if (StringUtils.isNotEmpty(pageParam.get("vlCityId"))) {// vo.put("vlCityId", pageParam.get("vlCityId")); } if (StringUtils.isNotEmpty(pageParam.get("vlCityName"))) {// ?? vo.put("vlCityName", URLDecoder.decode(pageParam.get("vlCityName"), "UTF-8")); } // vo.put("viMileage", pageParam.get("viMileage")); // ? vo.put("viVin", pageParam.get("viVin").toUpperCase()); // ?? vo.put("engineNo", pageParam.get("engineNo").toUpperCase()); if (StringUtils.isNotEmpty(pageParam.get("sweptVolume"))) { //? vo.put("sweptVolume", URLDecoder.decode(pageParam.get("sweptVolume"), "UTF-8")); } // request.getSession().setAttribute("newVehicleModel", vo); this.spyMemcachedClient.set(vehicleModelKey, Constant.MEMCACHED_SAVETIME_24, vo); // 1?sofa? Map<String, String> resMap = myCarManageService.modifyVehicle(vo); if (resMap == null) {// ?? if (logger.isErrorEnabled()) { logger.error("????sofa?null"); } map.put("errorUrl", super.errorPageUrl("BUSY-ERR", "???", null, null)); return map; } else if (!Constant.SOFA_RETURN_CODE_SUCCESS.equals(resMap.get("returnCode"))) { String errorMsg = "?"; if (Constant.SOFA_RETURN_CODE_REPEAT.equals(resMap.get("returnCode"))) { errorMsg = ""; } if (logger.isErrorEnabled()) { logger.error( "????sofa??{} |??{}", resMap.get("returnCode"), resMap.get("returnDesc")); } map.put("errorUrl", super.errorPageUrl("BUSY-ERR", errorMsg, null, null)); return map; } else { //? List<Map<String, Object>> vehicleList = spyMemcachedClient .get(userModel.getUid() + "_myCarList"); if (null != vehicleList && !vehicleList.isEmpty()) { for (int i = 0; i < vehicleList.size(); i++) { Map<String, Object> vMap = vehicleList.get(i); if (vMap.get("viId").equals(vo.get("viId"))) { vehicleList.set(i, vo); // break; } } //? spyMemcachedClient.set(userModel.getUid() + "_myCarList", Constant.MEMCACHED_SAVETIME_24, vehicleList); } ////////////////// String backUrl = "/car/myCarList"; Object backObj = request.getSession().getAttribute("backUrl"); if (backObj != null) { backUrl = backObj.toString(); } request.setAttribute("backUrl", backUrl); map.put("success", "true"); return map; } } else { // ? logger.error("????,session?"); map.put("errorUrl", super.errorPageUrl("BUSY-ERR", ",?", null, null)); return map; } } catch (Exception e) { logger.error("????", e); map.put("errorUrl", super.errorPageUrl("BUSY-ERR", ",?", null, null)); return map; } } @RequestMapping("/distinguish") public @ResponseBody Map distinguish(HttpServletRequest request, HttpServletResponse response) { String base64Content = request.getParameter("base64Content"); UserModel userModel = super.getUserInfo(request); //session?? ResponseData<Map<String, String>> responseData = vehicleDrivingLicenseDistinguishBizService .distinguish(userModel.getUid(), base64Content); Map responseMap = new HashMap(); response.setCharacterEncoding("utf-8"); response.setContentType("application/json"); if (!CommonCodeEnum.SUCCESS_ENUM.getErrorCode().equals(responseData.getReturnCode())) { responseMap.put("code", responseData.getReturnCode()); responseMap.put("errorMsg", ",?"); logger.info("getUid={},responseMap={}", userModel.getUid(), JSONObject.toJSON(responseMap).toString()); return responseMap; } responseMap.put("code", CommonCodeEnum.SUCCESS_ENUM.getErrorCode()); responseMap.put("errorMsg", "?"); responseMap.put("res", JSONObject.toJSON(responseData.getObj()).toString()); logger.info("?getUid={},responseMap={}", userModel.getUid(), JSONObject.toJSON(responseMap).toString()); return responseMap; } /** * ajax?? * @param request * @param response * @return */ @RequestMapping("/getDefaultCarInfo") public @ResponseBody Object getDefaultCarInfo(HttpServletRequest request, HttpServletResponse response) { Map<String, Object> result = new HashMap<String, Object>(); result.put("success", false); // 2???? // 1????? UserModel userModel = super.getUserInfo(request); try { logger.info("userModel={}", userModel != null ? userModel.getUid() : ""); List<Map<String, Object>> vehicleList = myCarManageService.queryVehicleListByUid(userModel.getUid()); Map<String, Object> myCar = null; String limitedContent = null; List<Map<String, Object>> messageList = null; // 3?? if (vehicleList != null && vehicleList.size() > 1) { for (Map<String, Object> car : vehicleList) { if (car.get("defaultStatus") instanceof Integer && Integer.parseInt(car.get("defaultStatus").toString()) == 1) { myCar = car; } } if (myCar == null) { // myCar = vehicleList.get(0); } } else if (vehicleList != null && vehicleList.size() == 1) { myCar = vehicleList.get(0); } // 5? Map<String, String> cityMap = null; try { cityMap = ownerMessage.queryResidentcity(userModel.getUid()); } catch (Exception e) { if (logger.isErrorEnabled()) logger.error("sofa?", e); } if (cityMap == null) { // cookie? Cookie cityName = CookieTool.getCookieByName(request, "aliPay_residentCityName"); Cookie cityCode = CookieTool.getCookieByName(request, "aliPay_residentCityCode"); if (cityName != null) { cityMap = new HashMap<String, String>(); cityMap.put("resident_city_name", URLDecoder.decode(cityName.getValue(), "UTF-8")); cityMap.put("resident_city_code", URLDecoder.decode(cityCode.getValue(), "UTF-8")); } } // 7??? int unReadMessage = 0; try { unReadMessage = ownerMessage.messageGetUnreadcount(userModel.getUid()); } catch (Exception e) { logger.error("??sofa?", e); } if (unReadMessage > 0) { // ? try { messageList = ownerMessage.messageBatchquery(userModel.getUid(), false, 1, 1); } catch (Exception e) { logger.error("?sofa?", e); } } else if (cityMap != null && cityMap.get("resident_city_code") != null) { try { limitedContent = ownerMessage.queryLimitedLineContent(cityMap.get("resident_city_code"), new Date()); } catch (Exception e) { logger.error("??sofa?", e); } } result.put("success", true); result.put("defaultCar", myCar); if (messageList != null && !messageList.isEmpty()) { // request.setAttribute("message", messageList.get(0)); result.put("messageList", messageList.get(0)); } else { result.put("messageList", null); } result.put("limitedContent", ObjectUtil.toString(limitedContent)); } catch (Exception e) { if (logger.isErrorEnabled()) logger.error("ajax?", e); } return result; } /** * ?? * @param manufacturer * @param viSeriesName * @param sweptVolume ? * @param prodYear * @param viModelName * @param engineType ? * @return ? */ private Map<String, Object> getVihcleInfo(String manufacturer, String viSeriesName, String sweptVolume, String prodYear, String viModelName, String engineType) { Map<String, Object> vehicleInfoMap = new HashMap<String, Object>(); try { Map<String, Map> vehicleTypeListMap = myCarManageService.getVehiclesNow(manufacturer, viSeriesName); Map<String, Object> vehicleYearMap = vehicleTypeListMap.get(sweptVolume); if (null != vehicleYearMap) { Map<String, Object> vehicleTypeMap = (Map<String, Object>) vehicleYearMap.get(prodYear); if (null != vehicleTypeMap) { //??? Map<String, Object> vehicleEngineMap = (Map<String, Object>) vehicleTypeMap.get(viModelName); if (null != vehicleEngineMap && !vehicleEngineMap.isEmpty()) { vehicleInfoMap = (Map<String, Object>) vehicleEngineMap.get(engineType); } } } } catch (Exception e) { logger.error("??:", e); } return vehicleInfoMap; } private Map<String, String> getCityInfo(HttpServletRequest request) throws Exception { Map<String, String> cityMap = null; try { UserModel userModel = super.getUserInfo(request); cityMap = ownerMessage.queryResidentcity(userModel.getUid()); } catch (Exception e) { logger.error("sofa?", e); } if (cityMap == null) { cityMap = new HashMap<String, String>(); // cookie? Cookie cityName = CookieTool.getCookieByName(request, "aliPay_residentCityName"); Cookie cityCode = CookieTool.getCookieByName(request, "aliPay_residentCityCode"); if (cityName != null && null != cityCode) { cityMap.put("vlCityId", URLDecoder.decode(cityCode.getValue(), "UTF-8")); cityMap.put("vlCityName", URLDecoder.decode(cityName.getValue(), "UTF-8")); } } else { cityMap.put("vlCityId", cityMap.get("resident_city_code")); cityMap.put("vlCityName", cityMap.get("resident_city_name")); } return cityMap; } /** * ?ajax * @param request * @param response * @return */ @RequestMapping(value = "/queryCategoryAppList") public @ResponseBody Object queryCategoryAppList(HttpServletRequest request, HttpServletResponse response) { Map<String, String> pageParam = super.getParametersFromPage(request); List<Map<String, Object>> result = null; try { Map<String, String> userMap = new HashMap<String, String>(); UserModel userModel = super.getUserInfo(request); userMap.put("userId", userModel.getUid()); String viNumber = null; if (StringUtils.isNotEmpty(pageParam.get("viNumber"))) { viNumber = URLDecoder.decode(pageParam.get("viNumber"), "UTF-8"); } result = ownerMessage.queryCategoryApp(userMap, super.districtToCity(pageParam.get("cityCode")), viNumber); } catch (Exception e) { if (logger.isErrorEnabled()) { logger.error("??", e); } } return result; } }