CarDeviceController.java 2 KB
package com.bsth.controller;

import com.bsth.common.ResponseCode;
import com.bsth.entity.CarDevice;
import com.bsth.service.CarDeviceService;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * Created by xu on 16/6/15.
 */
@RestController
@RequestMapping("cde")
public class CarDeviceController extends BaseController<CarDevice, Long> {
    @Autowired
    private CarDeviceService carDeviceService;
    /**
     * 覆写方法,因为form提交的方式参数不全,改用 json形式提交 @RequestBody
     * @Title: save
     * @Description: TODO(持久化对象)
     * @param @param t
     * @param @return    设定文件
     * @return Map<String,Object>  {status: 1(成功),-1(失败)}
     * @throws
     */
    @RequestMapping(method = RequestMethod.POST)
    public Map<String, Object> save(@RequestBody CarDevice t){
        return baseService.save(t);
    }

    @RequestMapping(value = "/validate/qyrq", method = RequestMethod.GET)
    public Map<String, Object> validateQyrq(String qyrq, Integer xl, Integer cl) {
        // 验证启用日期,必须是最大的日期,就是最晚的日期
        Map<String, Object> obj = new HashMap<>();
        obj.put("xl_eq", xl);
        obj.put("cl_eq", cl);
        obj.put("qyrq_ge", new DateTime(qyrq).toDate());
        Iterator<CarDevice> iterator = carDeviceService.list(obj).iterator();
        if (iterator.hasNext()) {
            obj.clear();
            obj.put("status", ResponseCode.ERROR);
        } else {
            obj.clear();
            obj.put("status", ResponseCode.SUCCESS);
        }
        return obj;
    }
}