package com.willalp.web.controller.baseinfo;

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.control.userinfo.domain.HsSysUserinfo;
import com.willalp.control.userinfo.service.IHsSysUserinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 注册用户信息Controller
 *
 * @author willalp
 * @date 2021-11-24
 */
@RestController
@RequestMapping("/baseinfo/userinfo")
public class HsSysUserinfoController extends BaseController
{
    @Autowired
    private IHsSysUserinfoService hsSysUserinfoService;

    /**
     * 查询注册用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:userinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsSysUserinfo hsSysUserinfo) {
        startPage();
        List<HsSysUserinfo> list = hsSysUserinfoService.selectHsSysUserinfoList(hsSysUserinfo);
        return getDataTable(list);
    }

    /**
     * 导出注册用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:userinfo:export')")
    @Log(title = "注册用户信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsSysUserinfo hsSysUserinfo) {
        List<HsSysUserinfo> list = hsSysUserinfoService.selectHsSysUserinfoList(hsSysUserinfo);
        ExcelUtil<HsSysUserinfo> util = new ExcelUtil<HsSysUserinfo>(HsSysUserinfo.class);
        return util.exportExcel(list, "注册用户信息数据");
    }

    /**
     * 获取注册用户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:userinfo:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") String userId) {
        return AjaxResult.success(hsSysUserinfoService.getById(userId));
    }

    /**
     * 新增注册用户信息
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:userinfo:add')")
    @Log(title = "注册用户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsSysUserinfo hsSysUserinfo) {
        hsSysUserinfoService.saveUserInfo(hsSysUserinfo);
        return AjaxResult.success();
    }

    /**
     * 修改注册用户信息
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:userinfo:edit')")
    @Log(title = "注册用户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsSysUserinfo hsSysUserinfo)
    {
        hsSysUserinfo.setUpdateBy(SecurityUtils.getUsername());
        hsSysUserinfo.setUpdateTime(DateUtils.getNowDate());
        return toAjax(hsSysUserinfoService.updateById(hsSysUserinfo));
    }

    /**
     * 删除注册用户信息
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:userinfo:remove')")
    @Log(title = "注册用户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable String[] userIds)
    {
        return toAjax(hsSysUserinfoService.removeByIds(Arrays.asList(userIds)));
    }
}
