package com.huiju.estateagents.property.controller;

import com.huiju.estateagents.base.BaseController;
import com.huiju.estateagents.base.ResponseBean;
import com.huiju.estateagents.property.model.TaUserLicenseCount;
import com.huiju.estateagents.property.service.ITaUserLicenseCountService;
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 TaUserLicenseCountController extends BaseController {

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

    @Autowired
    public ITaUserLicenseCountService iTaUserLicenseCountService;


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

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

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

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