package com.iformall.controller;

import com.github.pagehelper.PageInfo;
import com.iformall.annotation.SystemControllerLog;
import com.iformall.common.Result;
import com.iformall.common.ResultData;
import com.iformall.domain.po.WxBillDaily;
import com.iformall.service.WxBillDailyService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author gongbiao
 */
@RestController
@RequestMapping("wxBillDaily")
public class WxBillDailyController extends BaseController {
    @Autowired
    private WxBillDailyService wxBillDailyService;

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @GetMapping("list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)})
    @SystemControllerLog(description = "日常账单-列表")
    public ResultData list(@ModelAttribute WxBillDaily wxBillDaily, Integer pageNum, Integer pageSize) {
        logger.debug("[" + getIpAddr() + "] WxBillDailyController::list");
        if (null == wxBillDaily) {
            wxBillDaily = new WxBillDaily();
        }
        wxBillDaily.setTenantId(getTenantId());
        final PageInfo<Map<String, Object>> page = wxBillDailyService.listAsPage(wxBillDaily, pageNum, pageSize);
        return new ResultData(page);
    }

    @PostMapping("add")
    @SystemControllerLog(description = "日常账单-新增")
    public ResultData add(@RequestBody WxBillDaily wxBillDaily) {
        logger.debug("[" + getIpAddr() + "] WxBillDailyController::add");
        wxBillDaily.setTenantId(getTenantId());
        wxBillDaily.setUserId(getUser().getId());
        return wxBillDailyService.saveOrUpdate(wxBillDaily, getUser());
    }

    @PostMapping("update")
    @SystemControllerLog(description = "日常账单-更新")
    public ResultData update(@RequestBody WxBillDaily wxBillDaily) {
        logger.debug("[" + getIpAddr() + "] WxBillDailyController::update");
        wxBillDaily.setUserId(getUser().getId());
        return wxBillDailyService.saveOrUpdate(wxBillDaily, getUser());
    }

    @GetMapping("/del")
    @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
    @SystemControllerLog(description = "日常账单-删除")
    public ResultData delete(Long id) {
        logger.debug("[" + getIpAddr() + "] WxBillDailyController::delete");
        wxBillDailyService.deleteById(id);
        return new ResultData(Result.SUCCESS, "删除成功", null);
    }

    @GetMapping("/findById")
    @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
    @SystemControllerLog(description = "日常账单-id查找")
    public ResultData findById(Long id) {
        logger.debug("[" + getIpAddr() + "] WxBillDailyController::findById");
        return new ResultData(Result.SUCCESS, "查询成功", wxBillDailyService.getById(id));
    }

    @GetMapping("/updatePaid")
    @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
    @SystemControllerLog(description = "日常账单-支付更新")
    public ResultData updatePaid(Long id) {
        logger.debug("[" + getIpAddr() + "] WxBillDailyController::updatePaid");
        return wxBillDailyService.updatePaid(id);
    }


}
