package com.sien.common.controller;

import com.sien.common.entity.DonationRecord;
import com.sien.common.service.DonationRecordService;
import lombok.extern.slf4j.Slf4j;
        import com.sien.common.param.DonationRecordPageParam;
        import io.geekidea.springbootplus.framework.common.controller.BaseController;
        import com.sien.common.param.DonationRecordQueryVo;
    import io.geekidea.springbootplus.framework.common.api.ApiResult;
    import io.geekidea.springbootplus.framework.core.pagination.Paging;
    import io.geekidea.springbootplus.framework.common.param.IdParam;
        import io.geekidea.springbootplus.framework.log.annotation.Module;
        import io.geekidea.springbootplus.framework.log.annotation.OperationLog;
        import io.geekidea.springbootplus.framework.log.enums.OperationLogType;
        import io.geekidea.springbootplus.framework.core.validator.groups.Add;
        import io.geekidea.springbootplus.framework.core.validator.groups.Update;
        import org.springframework.validation.annotation.Validated;
    import io.swagger.annotations.Api;
    import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 捐款记录 控制器
 *
 * @author hewei
 * @since 2021-02-25
 */
@Slf4j
@RestController
@RequestMapping("/donationRecord")
@Api(value = "捐款记录API", tags = {"捐款记录"})
    public class DonationRecordController extends BaseController {

@Autowired
private DonationRecordService donationRecordService;

    /**
     * 添加捐款记录
     */
    @PostMapping("/add")
        @OperationLog(name = "添加捐款记录", type = OperationLogType.ADD)
    @ApiOperation(value = "添加捐款记录")
    public ApiResult<Boolean> addDonationRecord(@Validated(Add.class) @RequestBody DonationRecord donationRecord)throws Exception{
            boolean flag= donationRecordService.saveDonationRecord(donationRecord);
            return ApiResult.result(flag);
            }

    /**
     * 修改捐款记录
     */
    @PostMapping("/update")
        @OperationLog(name = "修改捐款记录", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改捐款记录")
    public ApiResult<Boolean> updateDonationRecord(@Validated(Update.class) @RequestBody DonationRecord donationRecord)throws Exception{
            boolean flag= donationRecordService.updateDonationRecord(donationRecord);
            return ApiResult.result(flag);
            }

    /**
     * 删除捐款记录
     */
    @PostMapping("/delete/{id}")
        @OperationLog(name = "删除捐款记录", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除捐款记录")
    public ApiResult<Boolean> deleteDonationRecord(@PathVariable("id") Long id)throws Exception{
            boolean flag= donationRecordService.deleteDonationRecord(id);
            return ApiResult.result(flag);
            }

    /**
     * 获取捐款记录详情
     */
    @GetMapping("/info/{id}")
        @OperationLog(name = "捐款记录详情", type = OperationLogType.INFO)
    @ApiOperation(value = "捐款记录详情")
    public ApiResult<DonationRecordQueryVo> getDonationRecord(@PathVariable("id") Long id)throws Exception{
            DonationRecordQueryVo donationRecordQueryVo = donationRecordService.getDonationRecordById(id);
            return ApiResult.ok(donationRecordQueryVo);
            }

    /**
     * 捐款记录分页列表
     */
    @PostMapping("/getPageList")
        @OperationLog(name = "捐款记录分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "捐款记录分页列表")
    public ApiResult<Paging<DonationRecordQueryVo>>getDonationRecordPageList(@Validated @RequestBody DonationRecordPageParam donationRecordPageParam)throws Exception{
            Paging<DonationRecordQueryVo> paging = donationRecordService.getDonationRecordPageList(donationRecordPageParam);
            return ApiResult.ok(paging);
            }

        }

