package com.fs.company.controller;

import java.math.BigDecimal;
import java.util.List;

import com.fs.common.core.domain.R;
import com.fs.common.utils.ServletUtils;
import com.fs.company.domain.CompanyUser;
import com.fs.core.security.LoginUser;
import com.fs.core.web.service.TokenService;
import com.fs.system.domain.SysConfig;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.company.domain.CompanyRedPackageLogs;
import com.fs.company.service.ICompanyRedPackageLogsService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 公司红包余额日志Controller
 * 
 * @author 吴树波
 * @date 2025-04-15
 */
@RestController
@RequestMapping("/company/CompanyRedPackageLogs")
public class CompanyRedPackageLogsController extends BaseController
{
    @Autowired
    private ICompanyRedPackageLogsService companyRedPackageLogsService;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询公司红包余额日志列表
     */
    @PreAuthorize("@ss.hasPermi('company:CompanyRedPackageLogs:list')")
    @GetMapping("/list")
    public TableDataInfo list(CompanyRedPackageLogs companyRedPackageLogs)
    {
        startPage();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        CompanyUser user = loginUser.getUser();
        companyRedPackageLogs.setCompanyId(user.getCompanyId());
        List<CompanyRedPackageLogs> list = companyRedPackageLogsService.selectCompanyRedPackageLogsList(companyRedPackageLogs);
        return getDataTable(list);
    }

    /**
     * 导出公司红包余额日志列表
     */
    @PreAuthorize("@ss.hasPermi('company:CompanyRedPackageLogs:export')")
    @Log(title = "公司红包余额日志", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CompanyRedPackageLogs companyRedPackageLogs)
    {
        List<CompanyRedPackageLogs> list = companyRedPackageLogsService.selectCompanyRedPackageLogsList(companyRedPackageLogs);
        ExcelUtil<CompanyRedPackageLogs> util = new ExcelUtil<CompanyRedPackageLogs>(CompanyRedPackageLogs.class);
        return util.exportExcel(list, "公司红包余额日志数据");
    }

    /**
     * 获取公司红包余额日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('company:CompanyRedPackageLogs:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(companyRedPackageLogsService.selectCompanyRedPackageLogsById(id));
    }

    /**
     * 新增公司红包余额日志
     */
    @PreAuthorize("@ss.hasPermi('company:CompanyRedPackageLogs:add')")
    @Log(title = "公司红包余额日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CompanyRedPackageLogs companyRedPackageLogs)
    {
        return toAjax(companyRedPackageLogsService.insertCompanyRedPackageLogs(companyRedPackageLogs));
    }

    /**
     * 修改公司红包余额日志
     */
    @PreAuthorize("@ss.hasPermi('company:CompanyRedPackageLogs:edit')")
    @Log(title = "公司红包余额日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CompanyRedPackageLogs companyRedPackageLogs)
    {
        return toAjax(companyRedPackageLogsService.updateCompanyRedPackageLogs(companyRedPackageLogs));
    }

    /**
     * 删除公司红包余额日志
     */
    @PreAuthorize("@ss.hasPermi('company:CompanyRedPackageLogs:remove')")
    @Log(title = "公司红包余额日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(companyRedPackageLogsService.deleteCompanyRedPackageLogsByIds(ids));
    }

    /**
     * 删除公司红包余额日志
     */
    @PreAuthorize("@ss.hasPermi('company:CompanyRedPackageLogs:add')")
    @Log(title = "充值余额", businessType = BusinessType.INSERT)
	@PostMapping("/recharge")
    public R recharge(@RequestBody CompanyRedPackageLogs companyRedPackageLogs){
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        CompanyUser user = loginUser.getUser();
        companyRedPackageLogs.setCompanyId(user.getCompanyId());
        companyRedPackageLogs.setCreateBy(user.getUserId().toString());
        companyRedPackageLogsService.recharge(companyRedPackageLogs);
        return R.ok();
    }



    @GetMapping(value = "/getMoneyPri")
    public R getMoneyPri(){
        return R.ok().put("data", companyRedPackageLogsService.getMoneyPri());
    }
    // 充值审核
    @PostMapping(value = "/rew")
    public R rew(@RequestBody CompanyRedPackageLogs companyRedPackageLogs){
        companyRedPackageLogsService.rew(companyRedPackageLogs);
        return R.ok();
    }
}
