package cn.com.tenlion.staff.controller.apis.basicstaffinfo;

import cn.com.tenlion.staff.pojo.dtos.basicstaffinfo.BasicStaffInfoDTO;
import cn.com.tenlion.staff.pojo.vos.basicstaffinfo.BasicStaffInfoVO;
import cn.com.tenlion.staff.service.basicstaffinfo.IBasicStaffInfoService;
import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.exceptions.RemoveException;
import ink.wgink.exceptions.SearchException;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResult;
import ink.wgink.pojo.result.SuccessResultData;
import ink.wgink.pojo.result.SuccessResultList;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 人员信息接口
 * @author xwangs
 * @create 2021-04-29 14:24
 * @description
 */
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "人员信息接口")
@RestController
@RequestMapping(ISystemConstant.API_PREFIX + "/basic-staff-info")
public class BasicStaffInfoController extends DefaultBaseController {

    @Autowired
    private IBasicStaffInfoService basicStaffInfoService;

    @ApiOperation(value = "人员信息分页", notes = "人员信息分页接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
            @ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listpage")
    public SuccessResultList<List<BasicStaffInfoDTO>> listPage(ListPage page) throws SearchException {
        Map<String, Object> params = requestParams();
        page.setParams(params);
        return basicStaffInfoService.listPage(page);
    }

    @ApiOperation(value = "人员信息新增", notes = "人员信息新增接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("save")
    public SuccessResultData save(@RequestParam(required = false) String token,
                                  @RequestBody BasicStaffInfoVO basicStaffInfoVO) throws Exception {
        return basicStaffInfoService.save(token,basicStaffInfoVO);
    }

    @ApiOperation(value = "人员信息详情(通过ID)", notes = "人员信息详情(通过ID)接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "basicStaffInfoId", value = "人员信息ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("getbyid/{basicStaffInfoId}")
    public BasicStaffInfoDTO getbyid(@PathVariable("basicStaffInfoId") String basicStaffInfoId) throws SearchException {
        return basicStaffInfoService.getById(basicStaffInfoId);
    }

    @ApiOperation(value = "人员信息修改", notes = "人员信息修改接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "basicStaffInfoId", value = "人员信息基础表ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("update/{basicStaffInfoId}")
    public SuccessResult update(@PathVariable("basicStaffInfoId") String basicStaffInfoId,
                                                  @RequestBody BasicStaffInfoVO basicStaffInfoVO) throws Exception {
        return basicStaffInfoService.update(null,basicStaffInfoId, basicStaffInfoVO);
    }

    @ApiOperation(value = "逻辑删除人员信息", notes = "逻辑删除人员信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "ID(1_2_3)", paramType = "path", example = "1_2_3")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @DeleteMapping("remove/{ids}")
    public SuccessResult remove(@PathVariable("ids") String ids) throws RemoveException {
        return basicStaffInfoService.remove(null,ids);
    }

    @ApiOperation(value = "物理删除人员信息", notes = "物理删除人员信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "ID(1_2_3)", paramType = "path", example = "1_2_3")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @DeleteMapping("delete/{ids}")
    public SuccessResult delete(@PathVariable("ids") String ids) throws RemoveException {
        return basicStaffInfoService.delete(ids);
    }
}
