package com.willalp.web.controller.clockingin;

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.msg.domain.HsAppUserMsg;
import com.willalp.msg.service.IHsAppUserMsgService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * APP用户消息Controller
 *
 * @author willalp
 * @date 2022-10-26
 */
@RestController
@RequestMapping("/clockingin/appMsg")
public class HsAppUserMsgController extends BaseController
{
    @Resource
    private IHsAppUserMsgService hsAppUserMsgService;

    /**
     * 查询APP用户消息列表
     */
    @PreAuthorize("@ss.hasPermi('clockingin:appMsg:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsAppUserMsg hsAppUserMsg)
    {
        startPage();
        List<HsAppUserMsg> list = hsAppUserMsgService.selectHsAppUserMsgList(hsAppUserMsg);
        return getDataTable(list);
    }

    /**
     * 导出APP用户消息列表
     */
    @PreAuthorize("@ss.hasPermi('clockingin:appMsg:export')")
    @Log(title = "APP用户消息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsAppUserMsg hsAppUserMsg)
    {
        List<HsAppUserMsg> list = hsAppUserMsgService.selectHsAppUserMsgList(hsAppUserMsg);
        ExcelUtil<HsAppUserMsg> util = new ExcelUtil<HsAppUserMsg>(HsAppUserMsg.class);
        return util.exportExcel(list, "APP用户消息数据");
    }

    /**
     * 获取APP用户消息详细信息
     */
    @PreAuthorize("@ss.hasPermi('clockingin:appMsg:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(hsAppUserMsgService.getById(id));
    }

    /**
     * 新增APP用户消息
     */
    @PreAuthorize("@ss.hasPermi('clockingin:appMsg:add')")
    @Log(title = "APP用户消息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsAppUserMsg hsAppUserMsg)
    {
        hsAppUserMsg.setCreateBy(SecurityUtils.getUsername());
        hsAppUserMsg.setCreateTime(DateUtils.getNowDate());
        return toAjax(hsAppUserMsgService.save(hsAppUserMsg));
    }

    /**
     * 修改APP用户消息
     */
    @PreAuthorize("@ss.hasPermi('clockingin:appMsg:edit')")
    @Log(title = "APP用户消息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsAppUserMsg hsAppUserMsg)
    {
        hsAppUserMsg.setUpdateBy(SecurityUtils.getUsername());
        hsAppUserMsg.setUpdateTime(DateUtils.getNowDate());
        return toAjax(hsAppUserMsgService.updateById(hsAppUserMsg));
    }

    /**
     * 删除APP用户消息
     */
    @PreAuthorize("@ss.hasPermi('clockingin:appMsg:remove')")
    @Log(title = "APP用户消息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(hsAppUserMsgService.removeByIds(Arrays.asList(ids)));
    }
}
