package com.willalp.web.controller.yiqing;

import java.util.Arrays;
import java.util.List;

import com.willalp.common.utils.DateUtils;
import com.willalp.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
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.willalp.common.annotation.Log;
import com.willalp.common.core.controller.BaseController;
import com.willalp.common.core.domain.AjaxResult;
import com.willalp.common.enums.BusinessType;
import com.willalp.yiqing.domain.HsYiqingQuestion;
import com.willalp.yiqing.service.IHsYiqingQuestionService;
import com.willalp.common.utils.poi.ExcelUtil;

import javax.annotation.Resource;

/**
 * 疫情登记问题Controller
 *
 * @author willalp
 * @date 2022-05-10
 */
@RestController
@RequestMapping("/yiqing/question")
public class HsYiqingQuestionController extends BaseController
{
    @Resource
    private IHsYiqingQuestionService hsYiqingQuestionService;

    /**
     * 查询疫情登记问题列表
     */
    @PreAuthorize("@ss.hasPermi('yiqing:question:list')")
    @GetMapping("/list")
    public AjaxResult list(HsYiqingQuestion hsYiqingQuestion)
    {
        List<HsYiqingQuestion> list = hsYiqingQuestionService.selectHsYiqingQuestionList(hsYiqingQuestion);
        return AjaxResult.success(list);
    }

    /**
     * 导出疫情登记问题列表
     */
    @PreAuthorize("@ss.hasPermi('yiqing:question:export')")
    @Log(title = "疫情登记问题", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsYiqingQuestion hsYiqingQuestion)
    {
        List<HsYiqingQuestion> list = hsYiqingQuestionService.selectHsYiqingQuestionList(hsYiqingQuestion);
        ExcelUtil<HsYiqingQuestion> util = new ExcelUtil<HsYiqingQuestion>(HsYiqingQuestion.class);
        return util.exportExcel(list, "疫情登记问题数据");
    }

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

    /**
     * 新增疫情登记问题
     */
    @PreAuthorize("@ss.hasPermi('yiqing:question:add')")
    @Log(title = "疫情登记问题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsYiqingQuestion hsYiqingQuestion)
    {
        hsYiqingQuestion.setCreateBy(SecurityUtils.getUsername());
        hsYiqingQuestion.setCreateTime(DateUtils.getNowDate());
        return toAjax(hsYiqingQuestionService.save(hsYiqingQuestion));
    }

    /**
     * 修改疫情登记问题
     */
    @PreAuthorize("@ss.hasPermi('yiqing:question:edit')")
    @Log(title = "疫情登记问题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsYiqingQuestion hsYiqingQuestion)
    {
        hsYiqingQuestion.setUpdateBy(SecurityUtils.getUsername());
        hsYiqingQuestion.setUpdateTime(DateUtils.getNowDate());
        return toAjax(hsYiqingQuestionService.updateById(hsYiqingQuestion));
    }

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