package com.yonge.cooleshow.tenant.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.microsvc.toolkit.common.response.paging.PageInfo;
import com.microsvc.toolkit.common.response.paging.QueryInfo;
import com.microsvc.toolkit.common.response.template.R;
import com.yonge.cooleshow.biz.dal.entity.PaymentDivMemberRecord;
import com.yonge.cooleshow.biz.dal.service.PaymentDivMemberRecordService;
import com.yonge.cooleshow.biz.dal.wrapper.PaymentDivMemberRecordWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Validated
@RestController
@RequestMapping("${app-config.url.tenant:}/paymentDivMemberRecord")
@Api(tags = "分账子账户记录表")
public class PaymentDivMemberRecordController {

    @Autowired
    private PaymentDivMemberRecordService paymentDivMemberRecordService;

	@ApiOperation(value = "详情", notes = "分账子账户记录表-根据详情ID查询单条, 传入id")
//    @PreAuthorize("@auditsvc.hasPermissions('paymentDivMemberRecord/detail', {'BACKEND'})")
    //@GetMapping("/detail/{id}")
    public R<PaymentDivMemberRecord> detail(@PathVariable("id") Long id) {
    
    	PaymentDivMemberRecord wrapper = paymentDivMemberRecordService.detail(id);
        
        return R.from(wrapper);
	}
    
    @ApiOperation(value = "查询分页", notes = "分账子账户记录表- 传入 PaymentDivMemberRecordWrapper.PaymentDivMemberRecordQuery") 
//    @PreAuthorize("@auditsvc.hasPermissions('paymentDivMemberRecord/page', {'BACKEND'})")
    @PostMapping("/page")
    public R<PageInfo<PaymentDivMemberRecord>> page(@RequestBody PaymentDivMemberRecordWrapper.PaymentDivMemberRecordQuery query) {
        
        IPage<PaymentDivMemberRecord> pages = paymentDivMemberRecordService.selectPage(QueryInfo.getPage(query), query);
        
        return R.from(QueryInfo.pageInfo(pages));
	}
    
    @ApiOperation(value = "新增", notes = "分账子账户记录表- 传入 PaymentDivMemberRecordWrapper.PaymentDivMemberRecord")
//    @PreAuthorize("@auditsvc.hasPermissions('paymentDivMemberRecord/save', {'BACKEND'})")
	//@PostMapping("/save")
	public R<JSONObject> add(@Validated @RequestBody PaymentDivMemberRecord paymentDivMemberRecord) {
        
        // 新增数据
        paymentDivMemberRecordService.save(paymentDivMemberRecord);
        
        return R.defaultR();
	}
    
    @ApiOperation(value = "修改", notes = "分账子账户记录表- 传入 PaymentDivMemberRecordWrapper.PaymentDivMemberRecord")
//    @PreAuthorize("@auditsvc.hasPermissions('paymentDivMemberRecord/update', {'BACKEND'})")
	public R<JSONObject> update(@Validated @RequestBody PaymentDivMemberRecord paymentDivMemberRecord) {
        
        // 更新数据
        paymentDivMemberRecordService.updateById(paymentDivMemberRecord);
        
        return R.defaultR();
	}

	@ApiOperation(value = "删除", notes = "分账子账户记录表- 传入id")
//    @PreAuthorize("@auditsvc.hasPermissions('paymentDivMemberRecord/remove', {'BACKEND'})")
	public R<Boolean> remove(@RequestParam Long id) {
    
		return R.from(paymentDivMemberRecordService.removeById(id));
	}
}