package com.fs.company.controller.company;

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.ServletUtils;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.company.domain.CompanyDept;
import com.fs.framework.security.LoginUser;
import com.fs.framework.service.TokenService;
import com.fs.his.param.FsUserIntegralLogsParam;
import com.fs.his.service.IFsUserIntegralLogsService;
import com.fs.his.vo.FsUserIntegralLogsListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 积分信息
 *

 */
@RestController
@RequestMapping("/company/companyIntegral")
public class CompanyIntegralController extends BaseController
{
    @Autowired
    private IFsUserIntegralLogsService fsUserIntegralLogsService;
    @Autowired
    private TokenService tokenService;
    /**
     * 获取积分信息
     */
    @GetMapping("/list")
    public TableDataInfo list(FsUserIntegralLogsParam userIntegralLogs)
    {
        startPage();
        List<FsUserIntegralLogsListVO> list = fsUserIntegralLogsService.selectFsUserIntegralLogsListVO(userIntegralLogs);
        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('company:integral: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, "积分记录数据");
    }

    /**
     * 根id获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('company:integral:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id)
    {
        return AjaxResult.success();
    }

    /**
     * 修改积分
     */
    @PreAuthorize("@ss.hasPermi('company:integral:edit')")
    @Log(title = "积分记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody CompanyDept dept)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        dept.setCompanyId(loginUser.getCompany().getCompanyId());
        return toAjax(0);
    }

    /**
     * 删除积分
     */
    @PreAuthorize("@ss.hasPermi('company:integral:remove')")
    @Log(title = "积分记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(0);
    }





}
