package com.huiju.estateagents.property.controller;

import com.huiju.estateagents.base.BaseController;
import com.huiju.estateagents.base.ResponseBean;
import com.huiju.estateagents.property.model.TpBillInvoiceCount;
import com.huiju.estateagents.property.service.ITpBillInvoiceCountService;
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 TpBillInvoiceCountController extends BaseController {

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

    @Autowired
    public ITpBillInvoiceCountService iTpBillInvoiceCountService;


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

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

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

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