package com.huiju.estateagents.property.controller;

import com.huiju.estateagents.base.BaseController;
import com.huiju.estateagents.base.ResponseBean;
import com.huiju.estateagents.property.model.TaTemporaryLicenseCount;
import com.huiju.estateagents.property.service.ITaTemporaryLicenseCountService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
    * 临时车统计表，按天计算 前端控制器
    * </p>
 *
 * @author jobob
 * @since 2019-05-28
 */
@RestController
@RequestMapping("/")
public class TaTemporaryLicenseCountController extends BaseController {

    private final Logger logger = LoggerFactory.getLogger(TaTemporaryLicenseCountController.class);

    @Autowired
    public ITaTemporaryLicenseCountService iTaTemporaryLicenseCountService;


    /**
     * 保存对象
     * @param taTemporaryLicenseCount 实体对象
     * @return
     */
    @RequestMapping(value="/taTemporaryLicenseCount/add",method= RequestMethod.POST)
    public ResponseBean tpShopImgAdd(@RequestBody TaTemporaryLicenseCount taTemporaryLicenseCount){
        ResponseBean responseBean = new ResponseBean();
        try {
            if (iTaTemporaryLicenseCountService.save(taTemporaryLicenseCount)){
                responseBean.addSuccess("success");
            }else {
                responseBean.addError("fail");
            }
        }catch (Exception e){
            logger.error("taTemporaryLicenseCountAdd -=- {}",e.toString());
            responseBean.addError(e.getMessage());
        }
        return responseBean;
    }

    /**
     * 根据id删除对象
     * @param id  实体ID
     */
    @ResponseBody
    @RequestMapping(value="/taTemporaryLicenseCount/delete/{id}", method= RequestMethod.DELETE)
    public ResponseBean taTemporaryLicenseCountDelete(@PathVariable Integer id){
        ResponseBean responseBean = new ResponseBean();
        try {
            if(iTaTemporaryLicenseCountService.removeById(id)){
                responseBean.addSuccess("success");
            }else {
                responseBean.addError("fail");
            }
        }catch (Exception e){
            logger.error("taTemporaryLicenseCountDelete -=- {}",e.toString());
            responseBean.addError(e.getMessage());
        }
        return responseBean;
    }

    /**
     * 修改对象
     * @param taTemporaryLicenseCount 实体对象
     * @return
     */
    @RequestMapping(value="/taTemporaryLicenseCount/update",method= RequestMethod.PUT)
    public ResponseBean tpShopImgUpdate(@RequestBody TaTemporaryLicenseCount taTemporaryLicenseCount){
        ResponseBean responseBean = new ResponseBean();
        try {
            if (iTaTemporaryLicenseCountService.updateById(taTemporaryLicenseCount)){
                responseBean.addSuccess("success");
            }else {
                responseBean.addError("fail");
            }
        }catch (Exception e){
            logger.error("taTemporaryLicenseCountUpdate -=- {}",e.toString());
            responseBean.addError(e.getMessage());
        }
        return responseBean;
    }

    /**
     * 根据id查询对象
     * @param id  实体ID
     */
    @RequestMapping(value="/taTemporaryLicenseCount/get/{id}",method= RequestMethod.GET)
    public ResponseBean tpShopImgGet(@PathVariable Integer id){
        ResponseBean responseBean = new ResponseBean();
        try {
            responseBean.addSuccess(iTaTemporaryLicenseCountService.getById(id));
        }catch (Exception e){
            logger.error("taTemporaryLicenseCountDelete -=- {}",e.toString());
            responseBean.addError(e.getMessage());
        }
        return responseBean;
    }
}
