package com.yiqi.admin.controller.activity;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yiqi.activity.domain.dto.ChangeActivityCouponItemStockDTO;
import com.yiqi.activity.domain.vo.ActivityCouponItemVO;
import com.yiqi.common.constant.UrlConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.yiqi.common.annotation.Log;
import com.yiqi.common.core.controller.BaseController;
import com.yiqi.common.core.domain.AjaxResult;
import com.yiqi.common.enums.BusinessType;
import com.yiqi.activity.domain.ActivityCouponItem;
import com.yiqi.activity.service.IActivityCouponItemService;
import com.yiqi.common.utils.poi.ExcelUtil;
import com.yiqi.common.core.page.TableDataInfo;

/**
 * 注册送券活动优惠券明细Controller
 *
 * @author xiaohei
 * @date 2023-09-09
 */
@Api(tags = "管理后台 - 注册送券活动优惠券明细")
@RestController
@RequestMapping(UrlConstants.managerApi + "/activity/couponItem")
public class ActivityCouponItemController extends BaseController {
    @Autowired
    private IActivityCouponItemService activityCouponItemService;

    /**
     * 查询注册送券活动优惠券明细列表
     */
    @PreAuthorize("@ss.hasPermi('activity:couponInfo:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询注册送券活动优惠券明细列表")
    public TableDataInfo list(ActivityCouponItem activityCouponItem) {
        startPage();
        List<ActivityCouponItemVO> list = activityCouponItemService.selectActivityCouponItemList(activityCouponItem);
        return getDataTable(list);
    }

    /**
     * 导出注册送券活动优惠券明细列表
     */
    @PreAuthorize("@ss.hasPermi('activity:couponInfo:export')")
    @Log(title = "注册送券活动优惠券明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出注册送券活动优惠券明细列表")
    public void export(HttpServletResponse response, ActivityCouponItem activityCouponItem) {
        List<ActivityCouponItemVO> list = activityCouponItemService.selectActivityCouponItemList(activityCouponItem);
        ExcelUtil<ActivityCouponItemVO> util = new ExcelUtil<ActivityCouponItemVO>(ActivityCouponItemVO. class);
        util.exportExcel(response, list, "注册送券活动优惠券明细数据");
    }

    /**
     * 获取注册送券活动优惠券明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('activity:couponInfo:list')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取注册送券活动优惠券明细详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(activityCouponItemService.selectActivityCouponItemById(id));
    }

    /**
     * 新增注册送券活动优惠券明细
     */
    @PreAuthorize("@ss.hasPermi('activity:couponInfo:add')")
    @Log(title = "注册送券活动优惠券明细", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增注册送券活动优惠券明细")
    public AjaxResult add(@RequestBody ActivityCouponItem activityCouponItem) {
        activityCouponItem.setCreateById(getUserId());
        activityCouponItem.setCreateBy(getUsername());
        return toAjax(activityCouponItemService.insertActivityCouponItem(activityCouponItem));
    }

    /**
     * 修改注册送券活动优惠券明细
     */
    @PreAuthorize("@ss.hasPermi('activity:couponInfo:edit')")
    @Log(title = "注册送券活动优惠券明细", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改注册送券活动优惠券明细")
    public AjaxResult edit(@RequestBody ActivityCouponItem activityCouponItem) {
        activityCouponItem.setUpdateById(getUserId());
        activityCouponItem.setUpdateBy(getUsername());
        return toAjax(activityCouponItemService.updateActivityCouponItem(activityCouponItem));
    }

    @PreAuthorize("@ss.hasPermi('activity:couponInfo:edit')")
    @Log(title = "修改优惠券库存", businessType = BusinessType.UPDATE)
    @PostMapping("editStock")
    @ApiOperation(value = "修改优惠券库存")
    public AjaxResult editStock(@RequestBody ChangeActivityCouponItemStockDTO changeActivityCouponItemStockDTO) {
        return toAjax(activityCouponItemService.editStock(changeActivityCouponItemStockDTO));
    }

    /**
     * 删除注册送券活动优惠券明细
     */
    @PreAuthorize("@ss.hasPermi('activity:couponInfo:remove')")
    @Log(title = "注册送券活动优惠券明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除注册送券活动优惠券明细")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(activityCouponItemService.deleteActivityCouponItemByIds(ids));
    }

}
