package com.willalp.web.controller.yiqing;

import com.willalp.common.annotation.Log;
import com.willalp.common.core.controller.BaseController;
import com.willalp.common.core.domain.AjaxResult;
import com.willalp.common.core.page.TableDataInfo;
import com.willalp.common.enums.BusinessType;
import com.willalp.common.utils.DateUtils;
import com.willalp.common.utils.SecurityUtils;
import com.willalp.common.utils.poi.ExcelUtil;
import com.willalp.yiqing.domain.HsYiqingRegister;
import com.willalp.yiqing.domain.vo.RegisterVo;
import com.willalp.yiqing.domain.vo.RegisterVo2;
import com.willalp.yiqing.service.IHsYiqingRegisterService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * 疫情登记信息Controller
 *
 * @author willalp
 * @date 2022-05-16
 */
@RestController
@RequestMapping("/yiqing/register")
public class HsYiqingRegisterController extends BaseController {
    @Resource
    private IHsYiqingRegisterService hsYiqingRegisterService;


    /**
     * 第 14天核酸人员导出
     *
     * @param hsYiqingRegister
     */
    @Log(title = "疫情登记信息", businessType = BusinessType.EXPORT)
    @GetMapping("/fourteenImport")
    public AjaxResult fourteenDayNucleicAcid(HsYiqingRegister hsYiqingRegister) {
        ExcelUtil<RegisterVo> util = new ExcelUtil<>(RegisterVo.class);

        return util.exportExcel(null, "14天派单信息表");
    }


    /**
     * 查询疫情登记信息列表
     */
    @PreAuthorize("@ss.hasPermi('yiqing:register:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsYiqingRegister hsYiqingRegister) {
        startPage();
        List<RegisterVo2> list = hsYiqingRegisterService.selectHsYiqingRegisterList(hsYiqingRegister);
        return getDataTable(list);
    }


    /**
     * 导出疫情登记信息列表
     */
    @PreAuthorize("@ss.hasPermi('yiqing:register:export')")
    @Log(title = "疫情登记信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsYiqingRegister hsYiqingRegister) {
        List<RegisterVo2> list = hsYiqingRegisterService.selectHsYiqingRegisterList(hsYiqingRegister);
        ExcelUtil<RegisterVo2> util = new ExcelUtil<>(RegisterVo2.class);
        return util.exportExcel(list, "疫情登记信息数据");
    }

    @Log(title = "疫情地理地址数据", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception {
        ExcelUtil<RegisterVo2> util = new ExcelUtil<>(RegisterVo2.class);
        List<RegisterVo2> list = util.importExcel(file.getInputStream());
        hsYiqingRegisterService.importData(list);
        return AjaxResult.success();
    }

    /**
     * 获取疫情登记信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('yiqing:register:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(hsYiqingRegisterService.getById(id));
    }

    /**
     * 新增疫情登记信息
     */
    @PreAuthorize("@ss.hasPermi('yiqing:register:add')")
    @Log(title = "疫情登记信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsYiqingRegister hsYiqingRegister) {
        hsYiqingRegister.setCreateBy(SecurityUtils.getUsername());
        hsYiqingRegister.setCreateTime(DateUtils.getNowDate());
        return toAjax(hsYiqingRegisterService.save(hsYiqingRegister));
    }

    /**
     * 修改疫情登记信息
     */
    @PreAuthorize("@ss.hasPermi('yiqing:register:edit')")
    @Log(title = "疫情登记信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsYiqingRegister hsYiqingRegister) {
        hsYiqingRegister.setUpdateBy(SecurityUtils.getUsername());
        hsYiqingRegister.setUpdateTime(DateUtils.getNowDate());
        return toAjax(hsYiqingRegisterService.updateById(hsYiqingRegister));
    }

    /**
     * 删除疫情登记信息
     */
    @PreAuthorize("@ss.hasPermi('yiqing:register:remove')")
    @Log(title = "疫情登记信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(hsYiqingRegisterService.removeByIds(Arrays.asList(ids)));
    }
}
