package com.ruoyi.web.controller.info;

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

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.domain.UserInfo;
import com.ruoyi.system.service.IUserInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 导入人员信息Controller
 * 
 * @author ruoyi
 * @date 2022-08-11
 */
@RestController
@RequestMapping("/system/info")
public class UserInfoController extends BaseController
{
    @Autowired
    private IUserInfoService userInfoService;

    /**
     * 查询导入人员信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserInfo userInfo)
    {
        startPage();
        List<UserInfo> list = userInfoService.selectUserInfoList(userInfo);
        return getDataTable(list);
    }


    /**
     * 导出导入人员信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "导入人员信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserInfo userInfo)
    {
        List<UserInfo> list = userInfoService.selectUserInfoList(userInfo);
        ExcelUtil<UserInfo> util = new ExcelUtil<UserInfo>(UserInfo.class);
        util.exportExcel(response, list, "导入人员信息数据");
    }


    /**
     * 核酸比对人员导入
     * @param file
     * @param jobStyle  jobStyle
     * @param focusCrowdStyle focusCrowdStyle
     * @param detectionNumber detectionNumber
     * @param detectionScope detectionScope
     * @param startTime startTime
     * @param endTime 比对结束时间
     * @return
     * @throws Exception
     */
    @Log(title = "导入人员信息", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:info:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, String jobStyle, String focusCrowdStyle, String detectionNumber,
                                 String detectionScope,String startTime,String endTime) throws Exception
    {
        ExcelUtil<UserInfo> util = new ExcelUtil<UserInfo>(UserInfo.class);
        List<UserInfo> userList = util.importExcel(file.getInputStream());
        //String operName = getUsername();
        String message = userInfoService.importUser(userList, jobStyle, focusCrowdStyle, detectionNumber, detectionScope,startTime,endTime);
        return AjaxResult.success(message);
    }

    /**
     * 获取导入人员信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(userInfoService.selectUserInfoById(id));
    }

    /**
     * 新增导入人员信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "导入人员信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserInfo userInfo)
    {
        return toAjax(userInfoService.insertUserInfo(userInfo));
    }

    /**
     * 修改导入人员信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "导入人员信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserInfo userInfo)
    {
        return toAjax(userInfoService.updateUserInfo(userInfo));
    }

    /**
     * 删除导入人员信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "导入人员信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userInfoService.deleteUserInfoByIds(ids));
    }
}
