package io.hmit.modules.fhjw.controller;

import io.hmit.annotation.Login;
import io.hmit.common.constant.Constant;
import io.hmit.common.page.PageData;
import io.hmit.common.utils.Result;
import io.hmit.common.validator.AssertUtils;
import io.hmit.common.validator.ValidatorUtils;
import io.hmit.common.validator.group.AddGroup;
import io.hmit.common.validator.group.DefaultGroup;
import io.hmit.common.validator.group.UpdateGroup;
import io.hmit.modules.fhjw.dto.FhiwFunctionDTO;
import io.hmit.modules.fhjw.dto.FhjwRoleFunctionDTO;
import io.hmit.modules.fhjw.service.FhiwFunctionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;


/**
 * 评价模块
 *
 * @author zsh 408538940@qq.com
 * @since 1.0.0 2021-06-22
 */
@RestController
@RequestMapping("api/fhiwfunction")
@Api(tags="评价模块")
public class FhiwFunctionController {
    @Autowired
    private FhiwFunctionService fhiwFunctionService;

    @Login
    @GetMapping("{id}")
    @ApiOperation("信息")
    public Result<FhiwFunctionDTO> get(@PathVariable("id") Long id){
        FhiwFunctionDTO data = fhiwFunctionService.get(id);

        return new Result<FhiwFunctionDTO>().ok(data);
    }

    @Login
    @GetMapping("/getByRole")
    @ApiOperation("根据用户权限获取对应的评价模块")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleId", value = "用户权限ID", paramType = "query", required = true, dataType="int") ,
            @ApiImplicitParam(name = "userId", value = "用户ID", paramType = "query",required = true, dataType="int") ,
            @ApiImplicitParam(name = "caseNum", value = "受案号", paramType = "query", dataType="String")
    })
    public Result<List<FhiwFunctionDTO>> getByRole(@ApiIgnore @RequestParam Map<String, Object> params){
        List<FhiwFunctionDTO> data = fhiwFunctionService.getByRole(params);

        return new Result<List<FhiwFunctionDTO>>().ok(data);
    }

    @Login
    @PostMapping
    @ApiOperation("保存")
    public Result save(@RequestBody FhiwFunctionDTO dto){
        //校验数据
        ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);

        fhiwFunctionService.save(dto);

        return new Result();
    }

    @Login
    @PutMapping
    @ApiOperation("修改")
    public Result update(@RequestBody FhiwFunctionDTO dto){
        //校验数据
        ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);

        fhiwFunctionService.update(dto);

        return new Result();
    }

    @Login
    @Delete("未使用到")
    @DeleteMapping
    @ApiOperation("删除")
    public Result delete(@RequestBody Long[] ids){
        //校验数据
        AssertUtils.isArrayEmpty(ids, "id");

        fhiwFunctionService.delete(ids);

        return new Result();
    }

}
