package com.unis.crk.basic.controller;

import com.unis.crk.basic.entity.UserOperationtype;
import com.unis.crk.basic.service.IUserOperationtypeService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.unis.crk.utils.ResultUtil;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.unis.crk.basic.entity.vo.UserOperationtypeVo;
import io.swagger.annotations.ApiOperation;
import cn.hutool.json.JSONObject;


/**
 * <p>
 * 操作类型表 前端控制器
 * </p>
 *
 * @author ghh
 * @since 2021-12-13
 */
@Api(value = "操作类型表",tags = {"操作类型表"})
@RestController
@RequestMapping("userOperationtype")
public class UserOperationtypeController {

    private final static Logger LOGGER = LoggerFactory.getLogger(UserOperationtypeController.class);


    @Autowired
    private IUserOperationtypeService userOperationtypeService;


    /**
     * 根据ID查询数据
     * @param id
     * @return
     */
    @ApiOperation(value="查询", notes="根据ID查询数据")
    @GetMapping("getOne/{id}")
    public ResultUtil getOne(@PathVariable("id") String id){
        LOGGER.info("入参为:{}",id);
        ResultUtil<UserOperationtype> data = new ResultUtil<>();
        if (StringUtils.isEmpty(id)){
            data.failed("传入的主键为空");
            return data;
        }
        data.success(this.userOperationtypeService.getById(id));
        return data;
    }

    /**
         * 分页高级查询
         * @return
         */
    @ApiOperation(value="查询", notes="分页高级查询")
    @PostMapping(value="/findPage")
    public ResultUtil findPage(@RequestBody UserOperationtypeVo pageQuery) {
        ResultUtil<IPage<Map<String,Object>>> data = new ResultUtil<>();
        data.success(this.userOperationtypeService.findPageVo(pageQuery));
        return data;
    }
    /**
     * 查询待处理列表数据
     * @return
     */
    @ApiOperation(value="查询", notes="查询待处理列表数据")
    @PostMapping(value="/getPerData")
    public ResultUtil getPerData(@RequestBody UserOperationtypeVo pageQuery) {
        ResultUtil<List<Map<String,Object>>> data = new ResultUtil<>();
        data.success(this.userOperationtypeService.getPerData(pageQuery));
        return data;
    }


    /**
     * 修改一条数据
     * @param qcrk
     * @return
     */
    @ApiOperation(value="修改", notes="修改一条数据")
    @PatchMapping("edit")
    public ResultUtil edit(@RequestBody  UserOperationtype qcrk){
        LOGGER.info("入参为:{}", qcrk);
        ResultUtil<Boolean> data = new ResultUtil<>();
        if (ObjectUtils.isEmpty(qcrk)){
        data.failed("所接收对象为null");
        return data;
        }
        JSONObject ret  = this.userOperationtypeService.update(qcrk);
        if (ret.getBool("success")){
        data.success(ret.getStr("msg"));
        }else {
        data.failed(ret.getStr("msg"));
        }

        return data;
    }


    /**
     * 根据ID删除数据
     * @param id
     * @return
     */
    @ApiOperation(value="删除", notes="根据ID删除数据")
    @DeleteMapping("delete/{id}")
    public ResultUtil delete(@PathVariable("id") String id){
        LOGGER.info("入参为:{}", id);
        ResultUtil<Boolean> data = new ResultUtil<>();
        if (StringUtils.isEmpty(id)){
            data.failed("所接收id为null");
            return data;
        }
        JSONObject ret  = this.userOperationtypeService.delete(id);
        if (ret.getBool("success")){
        data.success(ret.getStr("msg"));
        }else {
        data.failed(ret.getStr("msg"));
        }
        return data;
    }


}

