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.entity.RRunningConfig;
import com.ssyf.module.robot.domain.entity.RRunningConfig;
import com.ssyf.module.robot.domain.query.RRunningConfigQuery;
import com.ssyf.module.robot.domain.vo.RRunningConfigVo;
import com.ssyf.module.robot.domain.vo.RRunningConfigVo;
import com.ssyf.module.robot.service.RRunningConfigService;
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.RRunningConfig模型开放接口
*
* @author: auth
* @date: 2022-12-12
*/
@Api(tags="基础-运行配置")
@RestController
@RequestMapping("/auth/RunningConfig")
public class RRunningConfigAuthController {

    @Autowired
    private RRunningConfigService baseService;

    /**
     * 新增一条记录
     */
    @Log(title = "运行配置-新增数据")
    @ApiOperation("新增运行配置")
    @PostMapping("/addOne")
    @RequestSynchronization
    public Result<RRunningConfigVo> addOne(@Validated({ValidA.class}) @RequestBody RRunningConfigQuery query) {
        if(BeanUtil.isEmpty(query)){
            return Result.fail(ApiCodeUser.PARAMETER_ERROR);
        }
        RRunningConfig entity = this.baseService.addOne(query);
        return Result.success(BeanUtil.copyProperties(entity, RRunningConfigVo.class));
    }

    /**
     * 根据uuid删除记录
     */
    @Log(title = "运行配置-删除数据")
    @ApiOperation("删除运行配置")
    @PostMapping("/removeByUid/{uuid}")
    @RequestSynchronization
    public Result removeByUid(@PathVariable String uuid) {
        this.baseService.removeByUid(uuid);
        return Result.success();
    }

    /**
     * 根据uuid列表批量删除记录
     */
    @Log(title = "运行配置-批量删除")
    @ApiOperation("批量删除运行配置")
    @PostMapping("/removeBatchByUids")
    @RequestSynchronization
    public Result removeBatchByUids(@RequestBody List<String> uuids) {
        this.baseService.removeBatchByUids(uuids);
        return Result.success();
    }

    /**
     * 根据uuid更新记录
     */
    @Log(title = "运行配置-更新数据")
    @ApiOperation("更新运行配置")
    @PostMapping("/updateByUid")
    @RequestSynchronization
    public Result updateByUid(@Validated({ValidA.class}) @RequestBody RRunningConfigQuery query) {
        if(BeanUtil.isEmpty(query)){
            return Result.fail(ApiCodeUser.PARAMETER_ERROR.getCode() ,"更新数据不能为空");
        }
        this.baseService.updateByUid(query.getUuid() ,query);
        return Result.success();
    }

    /**
     * 根据uuid查询记录
     */
    @Log(title = "运行配置-查询详情")
    @ApiOperation("查询运行配置详情")
    @GetMapping("/getOneByUid")
    public Result<RRunningConfigVo> getOneByUid(@RequestParam String uuid) {
        return Result.success(this.baseService.getOneByUid(uuid));
    }

    /**
     * 分页查询记录
     */
    @Log(title = "运行配置-分页查询")
    @ApiOperation("分页查询运行配置")
    @PostMapping("/queryPage")
    public Result<PageInfo<RRunningConfigVo>> queryPage(@Validated @RequestBody RRunningConfigQuery query) {
        PageInfo<RRunningConfig> temp = this.baseService.getPage(query);
        return Result.success(PageEnhanceHelper.switchPageInfo(temp , RRunningConfigVo.class));}

    /**
     * 查询记录列表
     */
    @Log(title = "运行配置-查询列表")
    @ApiOperation("查询运行配置列表")
    @PostMapping("/queryList")
    public Result<List<RRunningConfigVo>> queryList(@Validated @RequestBody RRunningConfigQuery query) {
        return Result.success(baseService.getList(query));
    }

    /**
     * 统计记录数量
     */
    @Log(title = "运行配置-统计数量")
    @ApiOperation("统计运行配置数量")
    @PostMapping("/count")
    public Result<Long> count(@Validated @RequestBody RRunningConfigQuery query) {
        return Result.success(baseService.countBy(query));
    }
}