com.tmount.business.carhot.controller.CarHotInsertCarInfo.java Source code

Java tutorial

Introduction

Here is the source code for com.tmount.business.carhot.controller.CarHotInsertCarInfo.java

Source

package com.tmount.business.carhot.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.tmount.bundle.ShopBusiErrorBundle;
import com.tmount.business.car.service.CarInfoService;
import com.tmount.business.user.service.UserService;
import com.tmount.db.car.dto.CarInfo;
import com.tmount.db.car.dto.TestUpd;
import com.tmount.db.car.dto.UserRelationCarInfo;
import com.tmount.exception.ShopBusiException;
import com.tmount.exception.ShopException;
import com.tmount.util.ControllerBase;
import com.tmount.util.ParamData;
import com.tmount.util.RequestParam;

@Controller
public class CarHotInsertCarInfo extends ControllerBase {
    @Autowired
    private CarInfoService carInfoService;
    @Autowired
    private UserService userService;

    @RequestMapping(value = "carHotInsert.get")
    @Override
    public void doRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
        sendData(request, response);
    }

    @Override
    protected void doService(RequestParam requestParam, JsonGenerator responseBodyJson)
            throws ShopException, JsonGenerationException, IOException {
        long account_id = ParamData.getLong(requestParam.getBodyNode(), "account_id"); //account_id
        String car_color = ParamData.getString(requestParam.getBodyNode(), "car_color"); //
        int car_type = ParamData.getInt(requestParam.getBodyNode(), "car_type"); //
        String car_plate_number = ParamData.getString(requestParam.getBodyNode(), "car_plate_number"); //?
        String car_carcase_num = ParamData.getString(requestParam.getBodyNode(), "car_carcase_num"); //?
        String car_engine_num = ParamData.getString(requestParam.getBodyNode(), "car_engine_num"); //??
        String car_driving_license_date = ParamData.getString(requestParam.getBodyNode(),
                "car_driving_license_date"); //
        String city_code = ParamData.getString(requestParam.getBodyNode(), "city_code"); //
        CarInfo carinfo = new CarInfo();
        carinfo.setAccount_id(account_id);
        carinfo.setCar_color(car_color);
        carinfo.setCar_driving_license_date(car_driving_license_date);
        carinfo.setCar_type(car_type);
        carinfo.setCar_plate_number(car_plate_number);
        if (StringUtils.isNotBlank(car_carcase_num)) {
            carinfo.setCar_carcase_num(car_carcase_num);
        }
        if (StringUtils.isNotBlank(city_code)) {
            carinfo.setCity_code(city_code);
        }
        carinfo.setCar_engine_num(car_engine_num);
        Long user_id = userService.getUserMessage(account_id); //?account_iduser_id
        if (null != user_id) {
            List<CarInfo> carList = carInfoService.getCarInfoByPlateNum(carinfo);
            if (carList == null || (carList != null && carList.size() <= 0)) {

                List<UserRelationCarInfo> list = userService.getRelationCarInfo(user_id); //?user_id ?
                int i = 0;
                for (UserRelationCarInfo terminalCar : list) {
                    if ("1".equals(terminalCar.getIs_default())) {
                        i++;
                    }
                }
                UserRelationCarInfo userRelationCarInfo = new UserRelationCarInfo();
                ////// 20150421
                int car_id = carInfoService.queryId("car_id") + 1; //??
                TestUpd testupd = new TestUpd();
                testupd.setName("car_id");
                testupd.setValue(car_id);
                carInfoService.updtestupd(testupd); //??         
                /////end
                carinfo.setCar_id(car_id);
                carInfoService.carhotInsert(carinfo);
                userRelationCarInfo.setCar_id(car_id);
                userRelationCarInfo.setUser_id(user_id.intValue());
                if (i > 0) {
                    userRelationCarInfo.setIs_default("0");
                    userService.insertRelationUserAndCar(userRelationCarInfo); //terminal_car??
                } else {
                    userRelationCarInfo.setIs_default("1");
                    userService.insertRelationUserAndCar(userRelationCarInfo);
                }
                responseBodyJson.writeNumberField("result", 1); //??

            } else {
                throw new ShopBusiException(ShopBusiErrorBundle.COMMON, new Object[] { "?" });
            }

        } else {
            throw new ShopBusiException(ShopBusiErrorBundle.COMMON, new Object[] { "?" });
        }

    }
}