VehicleMappingController.java 1.85 KB
package com.bsth.controller;

import com.bsth.common.ResponseCode;
import com.bsth.entity.VehicleMapping;
import com.bsth.service.VehicleMappingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("vehicle-mapping")
public class VehicleMappingController {

    private final static Logger log = LoggerFactory.getLogger(VehicleMappingController.class);

    @Autowired
    private VehicleMappingService vehicleMappingService;

    @RequestMapping(method = RequestMethod.POST)
    public Map<String, Object> save(VehicleMapping vehicleMapping) {
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("status", ResponseCode.ERROR);
        try {
            vehicleMappingService.save(vehicleMapping);
            result.put("status", ResponseCode.SUCCESS);
        } catch (Exception e) {
            log.error("", e);
            result.put("msg", e.getMessage());
        }

        return result;
    }

    @RequestMapping(value = "/all", method = RequestMethod.GET)
    public Map<String, Object> findByParams(@RequestParam Map<String, Object> params) {
        Map<String, Object> result = new HashMap<>();
        result.put("status", ResponseCode.ERROR);
        try {
            result.put("data", vehicleMappingService.findByParams(params));
            result.put("status", ResponseCode.SUCCESS);
        } catch (Exception e) {
            log.error("", e);
            result.put("msg", e.getMessage());
        }

        return result;
    }
}