package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.IntegralOrder;
import com.ruoyi.system.service.IIntegralOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.system.service.IServiceGoodsService;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.domain.ServiceGoods;

/**
 * 积分订单Controller
 * 
 * @author ruoyi
 * @date 2025-05-13
 */
@RestController
@RequestMapping("/system/IntegralOrder")
public class IntegralOrderController extends BaseController
{
    @Autowired
    private IIntegralOrderService integralOrderService;
    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private IServiceGoodsService serviceGoodsService;

    /**
     * 查询积分订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:IntegralOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(IntegralOrder integralOrder)
    {
        startPage();
        List<IntegralOrder> list = integralOrderService.selectIntegralOrderList(integralOrder);
        return getDataTable(list);
    }

    /**
     * 导出积分订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:IntegralOrder:export')")
    @Log(title = "积分订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IntegralOrder integralOrder)
    {
        List<IntegralOrder> list = integralOrderService.selectIntegralOrderList(integralOrder);
        ExcelUtil<IntegralOrder> util = new ExcelUtil<IntegralOrder>(IntegralOrder.class);
        util.exportExcel(response, list, "积分订单数据");
    }

    /**
     * 获取积分订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:IntegralOrder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(integralOrderService.selectIntegralOrderById(id));
    }

    /**
     * 新增积分订单
     */
    @PreAuthorize("@ss.hasPermi('system:IntegralOrder:add')")
    @Log(title = "积分订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IntegralOrder integralOrder)
    {
        return toAjax(integralOrderService.insertIntegralOrder(integralOrder));
    }

    /**
     * 修改积分订单
     */
    @PreAuthorize("@ss.hasPermi('system:IntegralOrder:edit')")
    @Log(title = "积分订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IntegralOrder integralOrder)
    {
        return toAjax(integralOrderService.updateIntegralOrder(integralOrder));
    }

    /**
     * 删除积分订单
     */
    @PreAuthorize("@ss.hasPermi('system:IntegralOrder:remove')")
    @Log(title = "积分订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(integralOrderService.deleteIntegralOrderByIds(ids));
    }

    /**
     * 获取用户下拉列表
     */
    @GetMapping("/userOptions")
    public AjaxResult getUserOptions() {
        List<SysUser> users = sysUserService.selectUserList(new SysUser());
        return AjaxResult.success(users);
    }

    /**
     * 获取商品下拉列表
     */
    @GetMapping("/goodsOptions")
    public AjaxResult getGoodsOptions() {
        List<ServiceGoods> goods = serviceGoodsService.selectServiceGoodsList(new ServiceGoods());
        return AjaxResult.success(goods);
    }

    /**
     * 获取状态下拉列表
     */
    @GetMapping("/statusOptions")
    public AjaxResult getStatusOptions() {
        return AjaxResult.success(java.util.Arrays.asList(
            new java.util.HashMap<String, Object>() {{ put("label", "待发货"); put("value", "1"); }},
            new java.util.HashMap<String, Object>() {{ put("label", "待收货"); put("value", "2"); }},
            new java.util.HashMap<String, Object>() {{ put("label", "已完成"); put("value", "3"); }}
        ));
    }
}
