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

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hzs.activity.base.param.ActivityParam;
import com.hzs.activity.base.param.ConsumeRuleConfigParam;
import com.hzs.activity.base.service.IAcBaseConfigService;
import com.hzs.activity.base.service.IAcGoalMemberConfigService;
import com.hzs.activity.base.service.IActivityService;
import com.hzs.activity.recommend.param.AcRecommendParam;
import com.hzs.activity.tourism.param.TourismDataParam;
import com.hzs.activity.tourism.service.IAcTourismDataService;
import com.hzs.activity.tourism.vo.TourismDataVo;
import com.hzs.common.core.annotation.Log;
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.domain.activity.base.AcBaseConfig;
import com.hzs.common.domain.activity.base.AcGoalMemberConfig;
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.ArrayList;
import java.util.List;

/**
 * @BelongsProject: hzs_cloud
 * @BelongsPackage: com.hzs.activity.tourism.controller.manage
 * @Author: yh
 * @CreateTime: 2024-02-22  16:30
 * @Description: TODO
 * @Version: 1.0
 */
@RestController
@RequestMapping("/manage/tourism")
public class AcTourismController extends BaseController {

    @Autowired
    private UserTokenService userTokenService;
    @Autowired
    private IActivityService activityService;
    @Autowired
    private IAcBaseConfigService baseConfigService;
    @Autowired
    private IAcGoalMemberConfigService goalMemberConfigService;
    @Autowired
    private IAcTourismDataService tourismDataService;

    /**
     * 在线签呈
     *
     * @param recommendParam 直推参数
     * @return AjaxResult
     */
    @Log(module = EOperationModule.AC_TOURISM_CONFIG, business = EOperationBusiness.AC_TOURISM_CONFIG, method = EOperationMethod.INSERT, remark = "在线签呈")
    @PostMapping("/online-petition")
    public AjaxResult onLinePetition(@RequestBody AcRecommendParam recommendParam) {
        recommendParam.setPkCountry(SecurityUtils.getPkCountry());
        recommendParam.setPkMember(SecurityUtils.getUserId());
        recommendParam.setLoginUser(userTokenService.getLoginUser());
        return toAjax(activityService.onLinePetition(recommendParam));
    }


    /**
     * 查询详情
     *
     * @param pkId
     * @return
     */
    @GetMapping("detail")
    public AjaxResult detail(Long pkId) {
        // 基础表查询
        AcBaseConfig baseConfig = baseConfigService.getById(pkId);
        ActivityParam activityParam = BeanUtil.copyProperties(baseConfig, ActivityParam.class);
        //查询目标群体
        LambdaQueryWrapper<AcGoalMemberConfig> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AcGoalMemberConfig::getPkBaseId, baseConfig.getPkId());
        List<AcGoalMemberConfig> goalMemberConfigList = goalMemberConfigService.list(queryWrapper);
        activityParam.setGoalMemberConfigList(goalMemberConfigList);
        List<ConsumeRuleConfigParam> consumeRuleConfigParamList = new ArrayList<>();
        activityParam.setConsumeRuleConfigParamList(consumeRuleConfigParamList);

        return AjaxResult.success(activityParam);
    }

    /**
     * 查询
     *
     * @param tourismDataParam
     * @return
     */

    @GetMapping("list")
    public TableDataInfo list(TourismDataParam tourismDataParam) {
        startPage();
        List<TourismDataVo> list = tourismDataService.queryList(tourismDataParam);
        return getDataTable(list);
    }

    /**
     * 导出
     *
     * @param tourismDataParam
     * @return
     */

    @PostMapping("export")
    public void export(TourismDataParam tourismDataParam, HttpServletResponse response) {
        startPage();
        List<TourismDataVo> list = tourismDataService.queryList(tourismDataParam);
        ExcelUtil<TourismDataVo> util = new ExcelUtil<>(TourismDataVo.class);
        util.exportExcel(response, list, "旅游活动数据导出");
    }

}
