package com.sqx.modules.pay.controller;

import com.sqx.common.utils.Result;
import com.sqx.modules.pay.entity.PayClassifyDetail;
import com.sqx.modules.pay.service.PayClassifyDetailService;
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.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author fang
 * @date 2022/4/16
 */
@Slf4j
@RestController
@Api(value = "充值分类子表", tags = {"充值分类子表"})
@RequestMapping(value = "/payClassify/detail")
public class PayClassifyDetailController {

    @Autowired
    private PayClassifyDetailService payClassifyDetailService;

    @PostMapping("/insertPayClassifyDetail")
    @ApiOperation("添加充值分类子表")
    public Result insertPayClassifyDetail(@RequestBody PayClassifyDetail payClassifyDetail){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        payClassifyDetail.setCreateTime(sdf.format(new Date()));
        payClassifyDetailService.save(payClassifyDetail);
        return Result.success();
    }

    @PostMapping("/updatePayClassifyDetail")
    @ApiOperation("修改充值分类子表")
    public Result updatePayClassifyDetail(@RequestBody PayClassifyDetail payClassifyDetail){
        payClassifyDetailService.updateById(payClassifyDetail);
        if(payClassifyDetail.getCouponId()==null){
            payClassifyDetailService.updatePayClassifyDetailCouponId(payClassifyDetail.getPayClassifyDetailId());
        }
        return Result.success();
    }

    @PostMapping("/deletePayClassifyDetail")
    @ApiOperation("删除充值分类子表")
    public Result deletePayClassifyDetail(Long payClassifyDetailId){
        payClassifyDetailService.removeById(payClassifyDetailId);
        return Result.success();
    }

    @GetMapping("/selectPayClassifyDetailList")
    @ApiOperation("查询充值分类子表")
    public Result selectPayClassifyDetailList(@RequestBody PayClassifyDetail payClassifyDetail){
        return Result.success().put("data",payClassifyDetailService.findList(payClassifyDetail.getPayClassifyId()));
    }

}