package com.ssyf.module.robot.controller.auth;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.PageInfo;
import com.ssyf.common.core.util.EntityUtil;
import com.ssyf.common.web.aop.RequestSynchronization;
import com.ssyf.common.web.apicode.ApiCodeUser;
import com.ssyf.common.web.result.Result;
import com.ssyf.common.web.valid.ValidA;
import com.ssyf.module.robot.domain.vo.FeeStatistics;
import com.ssyf.third.bmiss.services.FundPoolService;
import com.ssyf.module.robot.domain.entity.RRobotFee;
import com.ssyf.module.robot.domain.query.RRobotFeeQuery;
import com.ssyf.module.robot.domain.vo.RRobotFeeVo;
import com.ssyf.module.robot.service.RRobotFeeService;
import com.ssyf.plugs.logger.Log;
import com.ssyf.plugs.mysql.helper.PageEnhanceHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
* com.ssyf.auth.entity.RRobotFee模型开放接口
*
* @author: auth
* @date: 2022-12-12
*/
@Api(tags="基础-机器人费用记录")
@RestController
@RequestMapping("/auth/RobotFee")
public class RRobotFeeAuthController {

    @Autowired
    private RRobotFeeService baseService;
    
    @Autowired
    private FundPoolService fundPoolService;

    @Log(title = "机器人费用记录-新增数据")
    @RequestSynchronization
    @ApiOperation(value = "新增数据", notes = "新增数据")
    @PostMapping(value = "/addOne")
    public Result<RRobotFeeVo> addOne(@Validated({ValidA.class}) @RequestBody RRobotFeeQuery query) {
        if(BeanUtil.isEmpty(query)){
            return Result.fail(ApiCodeUser.PARAMETER_ERROR);
        }
        RRobotFee menuRRobotFee = this.baseService.addOne(query);
        return Result.success(BeanUtil.copyProperties(menuRRobotFee , RRobotFeeVo.class));
    }

    @Log(title = "机器人费用记录-更新数据")
    @RequestSynchronization
    @ApiOperation(value = "更新数据", notes = "uid更新")
    @PostMapping(value = "/updateByUid/{uid}")
    public Result updateByUid(@PathVariable String uid , @Validated @RequestBody RRobotFeeQuery query){
        if(BeanUtil.isEmpty(query)){
            return Result.fail(ApiCodeUser.PARAMETER_ERROR.getCode() ,"更新数据不能为空");
        }
        this.baseService.updateByUid(uid ,query);
        return Result.success();
    }

    @Log(title = "机器人费用记录-删除数据")
    @RequestSynchronization
    @ApiOperation(value = "删除数据", notes = "uid删除")
    @PostMapping(value = "/removeByUid/{uid}")
    public Result removeByUid(@PathVariable String uid){
        this.baseService.removeByUid(uid);
        return Result.success();
    }

    @Log(title = "机器人费用记录-批量删除")
    @RequestSynchronization
    @ApiOperation(value = "批量删除", notes = "批量删除")
    @PostMapping(value = "/removeBatchByUid")
    public Result removeBatchByUid(@Validated @RequestBody RRobotFeeQuery query){
        this.baseService.removeBatchByUids(query.getUids());
        return Result.success();
    }


    @ApiOperation(value = "/查询指定数据" ,notes = "uid查询")
    @PostMapping(value = "/getOneByUid/{uid}")
    public Result<RRobotFeeVo> getOneByUid(@PathVariable String uid) {
        return Result.success(BeanUtil.toBean(this.baseService.getOneByUid(uid) ,RRobotFeeVo.class));
    }

    @ApiOperation(value = "/查询分页数据", notes = "分页查询")
    @PostMapping(value = "/queryPage")
    public Result<PageInfo<RRobotFeeVo>> queryPage(@Validated @RequestBody RRobotFeeQuery query) {
        PageInfo<RRobotFee> temp = this.baseService.getPage(query);
        return Result.success(PageEnhanceHelper.switchPageInfo(temp ,RRobotFeeVo.class));
    }

    @ApiOperation(value = "/查询所有数据")
    @PostMapping(value = "/queryList")
    public Result<List<RRobotFeeVo>> queryList(@Validated @RequestBody RRobotFeeQuery query) {
        List<RRobotFee> menuRRobotFeeList = this.baseService.getList(query);
        List<RRobotFeeVo> t = EntityUtil.copyProperties(menuRRobotFeeList, RRobotFeeVo.class);
        return Result.success(t);
    }
    
    @ApiOperation(value = "/查询总数")
    @PostMapping(value = "/count")
    public Result<Integer> count(@Validated @RequestBody RRobotFeeQuery query) {
        Integer count = this.baseService.countBy(query);
        return Result.success(count);
    }
    
    @Log(title = "资金池统计-查询资金池统计信息")
    @ApiOperation(value = "查询资金池统计信息", notes = "返回资金池总金额和已分配金额")
    @PostMapping(value = "/getFeeStatistics")
    public Result<FeeStatistics> getFeeStatistics() {
        FeeStatistics statistics = baseService.getFeeStatistics();
        return Result.success(statistics);
    }

}