package com.hzs.activity.add.controller.manage;


import com.hzs.activity.add.param.AcAddUpgradeListParam;
import com.hzs.activity.add.param.AcAddUpgradeParam;
import com.hzs.activity.add.service.IAcAddUpgradeConfigService;
import com.hzs.activity.add.vo.AcAddUpgradeListVO;
import com.hzs.activity.base.param.QueryActivityParam;
import com.hzs.activity.base.service.IActivityService;
import com.hzs.activity.base.vo.BaseConfigVo;
import com.hzs.common.core.annotation.Log;
import com.hzs.common.core.enums.EActType;
import com.hzs.common.core.enums.EOperationBusiness;
import com.hzs.common.core.enums.EOperationMethod;
import com.hzs.common.core.enums.EOperationModule;
import com.hzs.common.core.utils.poi.ExcelUtil;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.core.web.page.TableDataInfo;
import com.hzs.common.security.service.UserTokenService;
import com.hzs.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

import static com.hzs.common.core.utils.PageUtils.startPage;

/**
 * <p>
 * 加购升级配置表 前端控制器
 * </p>
 *
 * @author bd
 * @since 2025-10-13
 */
@RestController
@RequestMapping("/manage/addUpgradeConfig")
public class AcAddUpgradeConfigController extends BaseController {

    @Autowired
    private UserTokenService userTokenService;

    @Autowired
    private IAcAddUpgradeConfigService  iAcAddUpgradeConfigService;

    @Autowired
    private IActivityService iActivityService;
    /**
     * 加购升级活动操作
     *
     * @param acAddUpgradeParam 加购升级活动
     * @return AjaxResult
     */
    @Log(module = EOperationModule.AC_ADD_UPGRADE_SUBMIT, business = EOperationBusiness.AC_ADD_UPGRADE_SUBMIT, method = EOperationMethod.INSERT, remark = "加购活动")
    @PostMapping("/submit")
    public AjaxResult onLinePetition(@RequestBody AcAddUpgradeParam acAddUpgradeParam) {
        acAddUpgradeParam.setPkCountry(SecurityUtils.getPkCountry());
        acAddUpgradeParam.setPkMember(SecurityUtils.getUserId());
        acAddUpgradeParam.setLoginUser(userTokenService.getLoginUser());
        String str = iAcAddUpgradeConfigService.onLinePetition(acAddUpgradeParam);
        if (str != null) {
            return AjaxResult.error(str);
        }
        return AjaxResult.success();
    }

    /**
     * 加购升级活动操作
     *
     * @param pkId 加购升级活动
     * @return AjaxResult
     */
    @Log(module = EOperationModule.AC_ADD_UPGRADE_DETAIL, business = EOperationBusiness.AC_ADD_UPGRADE_DETAIL, method = EOperationMethod.SELECT, remark = "加购升级详情")
    @GetMapping("/get-detail")
    public AjaxResult getDetail(Integer pkId) {
        return iAcAddUpgradeConfigService.getDetail(pkId);
    }

    /**
     * 加购升级导出
     */
    @Log(module = EOperationModule.AC_ADD_UPGRADE_EXPORT, business = EOperationBusiness.AC_ADD_UPGRADE_DETAIL, method = EOperationMethod.EXPORT, remark = "加购升级导出")
    @PostMapping("/export")
    public void export(QueryActivityParam queryActivityParam, HttpServletResponse response) {
        queryActivityParam.setActType(EActType.ADD_UPGRADE.getValue());
        queryActivityParam.setPkCountry(SecurityUtils.getPkCountry());
        List<BaseConfigVo> resultList = iActivityService.activityList(queryActivityParam);
        ExcelUtil<BaseConfigVo> util = new ExcelUtil<>(BaseConfigVo.class);
        util.exportExcel(response, resultList, "加购升级导出");
    }

}
