package com.willalp.web.controller.push;

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.push.domain.HsAppPush;
import com.willalp.push.service.IHsAppPushService;
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-05-13
 */
@RestController
@RequestMapping("/push/push")
public class HsAppPushController extends BaseController
{
    @Resource
    private IHsAppPushService hsAppPushService;

    /**
     * 查询APP用户推送标识信息列表
     */
    @PreAuthorize("@ss.hasPermi('push:push:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsAppPush hsAppPush)
    {
        startPage();
        List<HsAppPush> list = hsAppPushService.selectHsAppPushList(hsAppPush);
        return getDataTable(list);
    }

    /**
     * 导出APP用户推送标识信息列表
     */
    @PreAuthorize("@ss.hasPermi('push:push:export')")
    @Log(title = "APP用户推送标识信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsAppPush hsAppPush)
    {
        List<HsAppPush> list = hsAppPushService.selectHsAppPushList(hsAppPush);
        ExcelUtil<HsAppPush> util = new ExcelUtil<HsAppPush>(HsAppPush.class);
        return util.exportExcel(list, "APP用户推送标识信息数据");
    }

    /**
     * 获取APP用户推送标识信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('push:push:query')")
    @GetMapping(value = "/{pushId}")
    public AjaxResult getInfo(@PathVariable("pushId") String pushId)
    {
        return AjaxResult.success(hsAppPushService.getById(pushId));
    }

    /**
     * 新增APP用户推送标识信息
     */
    @PreAuthorize("@ss.hasPermi('push:push:add')")
    @Log(title = "APP用户推送标识信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsAppPush hsAppPush)
    {
        hsAppPush.setCreateBy(SecurityUtils.getUsername());
        hsAppPush.setCreateTime(DateUtils.getNowDate());
        return toAjax(hsAppPushService.save(hsAppPush));
    }

    /**
     * 修改APP用户推送标识信息
     */
    @PreAuthorize("@ss.hasPermi('push:push:edit')")
    @Log(title = "APP用户推送标识信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsAppPush hsAppPush)
    {
        hsAppPush.setUpdateBy(SecurityUtils.getUsername());
        hsAppPush.setUpdateTime(DateUtils.getNowDate());
        return toAjax(hsAppPushService.updateById(hsAppPush));
    }

    /**
     * 删除APP用户推送标识信息
     */
    @PreAuthorize("@ss.hasPermi('push:push:remove')")
    @Log(title = "APP用户推送标识信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pushIds}")
    public AjaxResult remove(@PathVariable String[] pushIds)
    {
        return toAjax(hsAppPushService.removeByIds(Arrays.asList(pushIds)));
    }
}
