package com.fs.store.controller;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.store.domain.FsUserIntegralLogs;
import com.fs.store.param.FsUserIntegralLogsParam;
import com.fs.store.service.IFsUserIntegralLogsService;
import com.fs.store.vo.FsUserIntegralLogsListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 积分记录Controller
 *
 * @author fs
 * @date 2023-11-02
 */
@RestController
@RequestMapping("/his/userIntegralLogs")
public class FsUserIntegralLogsController extends BaseController
{
    @Autowired
    private IFsUserIntegralLogsService fsUserIntegralLogsService;

    /**
     * 查询积分记录列表
     */
    @PreAuthorize("@ss.hasPermi('his:userIntegralLogs:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsUserIntegralLogsParam fsUserIntegralLogs)
    {
        startPage();
        List<FsUserIntegralLogsListVO> list = fsUserIntegralLogsService.selectFsUserIntegralLogsListVO(fsUserIntegralLogs);
        for (FsUserIntegralLogsListVO vo : list) {
            if (vo.getPhone()!=null&&vo.getPhone()!=""){
                vo.setPhone(vo.getPhone().replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2"));
            }

        }
        return getDataTable(list);
    }

    /**
     * 导出积分记录列表
     */
    @PreAuthorize("@ss.hasPermi('his:userIntegralLogs:export')")
    @Log(title = "积分记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsUserIntegralLogsParam fsUserIntegralLogs)
    {
        List<FsUserIntegralLogsListVO> list = fsUserIntegralLogsService.selectFsUserIntegralLogsListVO(fsUserIntegralLogs);
        for (FsUserIntegralLogsListVO vo : list) {
            if (vo.getPhone()!=null&&vo.getPhone()!=""){
                vo.setPhone(vo.getPhone().replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2"));
            }

        }
        ExcelUtil<FsUserIntegralLogsListVO> util = new ExcelUtil<FsUserIntegralLogsListVO>(FsUserIntegralLogsListVO.class);
        return util.exportExcel(list, "积分记录数据");
    }

    /**
     * 获取积分记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:userIntegralLogs:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fsUserIntegralLogsService.selectFsUserIntegralLogsById(id));
    }

    /**
     * 新增积分记录
     */
    @PreAuthorize("@ss.hasPermi('his:userIntegralLogs:add')")
    @Log(title = "积分记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsUserIntegralLogs fsUserIntegralLogs)
    {
        return toAjax(fsUserIntegralLogsService.insertFsUserIntegralLogs(fsUserIntegralLogs));
    }

    /**
     * 修改积分记录
     */
    @PreAuthorize("@ss.hasPermi('his:userIntegralLogs:edit')")
    @Log(title = "积分记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsUserIntegralLogs fsUserIntegralLogs)
    {
        return toAjax(fsUserIntegralLogsService.updateFsUserIntegralLogs(fsUserIntegralLogs));
    }

    /**
     * 删除积分记录
     */
    @PreAuthorize("@ss.hasPermi('his:userIntegralLogs:remove')")
    @Log(title = "积分记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fsUserIntegralLogsService.deleteFsUserIntegralLogsByIds(ids));
    }
}
