package com.ruoyi.web.controller.doubleDefense;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.dto.ContractorUserDTO;
import com.ruoyi.system.service.IContractorUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 承包商用户Controller
 *
 * @author ruoyi
 * @date 2023-08-04
 */
@Api(tags = "承包商用户")
@RestController
@RequestMapping("/doubledefense/user")
public class ContractorUserController extends BaseController
{
    @Autowired
    private IContractorUserService contractorUserService;


    /**
     * 查询承包商用户列表
     */
    @ApiOperation("查询承包商用户列表")
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(ContractorUserDTO contractorUser)
    {
        startPage();
        List<ContractorUserDTO> list = contractorUserService.selectContractorUserList(contractorUser);
        return getDataTable(list);
    }

    /**
     * 导出承包商用户列表
     */
    @ApiOperation("导出承包商用户列表")
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:user:export')")
    @Log(title = "承包商用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ContractorUserDTO contractorUser)
    {
        List<ContractorUserDTO> list = contractorUserService.selectContractorUserList(contractorUser);
        ExcelUtil<ContractorUserDTO> util = new ExcelUtil<ContractorUserDTO>(ContractorUserDTO.class);
        util.exportExcel(response, list, "承包商用户数据");
    }

    /**
     * 获取承包商用户详细信息
     */
    @ApiOperation("获取承包商用户详细信息")
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:user:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(contractorUserService.selectContractorUserById(id));
    }

    /**
     * 新增承包商用户
     */
    @ApiOperation("新增承包商用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "contractorId", value = "承包商UUID", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "compellation", value = "姓名", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "idNumber", value = "身份证号", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "sex", value = "性别", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "education", value = "学历：1小学，2初中，3高中，4中专，5大专，6本科，7硕士，8博士，9其他", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "loginApp", value = "是否可登录app:0不可登录app,1可登录", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "userName", value = "用户名", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "password", value = "密码", dataType = "String", dataTypeClass = String.class)
    })
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:user:add')")
    @Log(title = "承包商用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ContractorUserDTO contractorUser)
    {
        return toAjax(contractorUserService.insertContractorUser(contractorUser));
    }

    /**
     * 修改承包商用户
     */
    @ApiOperation("修改承包商用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "contractorId", value = "承包商UUID", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "compellation", value = "姓名", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "idNumber", value = "身份证号", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "sex", value = "性别", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "education", value = "学历：1小学，2初中，3高中，4中专，5大专，6本科，7硕士，8博士，9其他", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "loginApp", value = "是否可登录app:0不可登录app,1可登录", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "userName", value = "用户名", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "password", value = "密码", dataType = "String", dataTypeClass = String.class)
    })
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:user:edit')")
    @Log(title = "承包商用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ContractorUserDTO contractorUser)
    {
        return toAjax(contractorUserService.updateContractorUser(contractorUser));
    }

    /**
     * 删除承包商用户
     */
    @ApiOperation("删除承包商用户")
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:user:remove')")
    @Log(title = "承包商用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(contractorUserService.deleteContractorUserByIds(ids));
    }
}
