package com.microservices.dms.behaviorImage.controller;

import com.microservices.common.core.utils.poi.ExcelUtil;
import com.microservices.common.core.web.controller.BaseController;
import com.microservices.common.core.web.domain.AjaxResult;
import com.microservices.common.core.web.page.TableDataInfo;
import com.microservices.common.log.annotation.Log;
import com.microservices.common.log.enums.BusinessType;
import com.microservices.dms.behaviorImage.domain.ActivityUserLibrary;
import com.microservices.dms.behaviorImage.domain.BehaviorImageWeight;
import com.microservices.dms.behaviorImage.service.IBehaviorImageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.microservices.common.core.utils.PageUtils.startPage;

/**
 * 成果画像Controller
 *
 * @author microservices
 * @date 2025-04-17
 */
@RestController
@RequestMapping("/behaviorImage")
@Api(tags = "数据管理体系-画像接口")
public class BehaviorImageController extends BaseController {

    @Autowired
    private IBehaviorImageService behaviorImageService;
    /**
     * 根据成果ID，获取对应的成果画像
     */
    //@RequiresPermissions("dms:achievements:query")
    @ApiOperation(value = "根据成果ID，获取对应的成果画像")
    @GetMapping(value = "/achievementImage")
    public AjaxResult getAchievementImageById(Long id)
    {
        return AjaxResult.success(behaviorImageService.getAchievementImageById(id));
    }

    /**
     * 查询画像行为权重列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BehaviorImageWeight behaviorImageWeight)
    {
        startPage();
        List<BehaviorImageWeight> list = behaviorImageService.selectBehaviorImageWeightList(behaviorImageWeight);
        return getDataTable(list);
    }

    /**
     * 导出画像行为权重列表
     */
    @Log(title = "画像行为权重", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BehaviorImageWeight behaviorImageWeight)
    {
        List<BehaviorImageWeight> list = behaviorImageService.selectBehaviorImageWeightList(behaviorImageWeight);
        ExcelUtil<BehaviorImageWeight> util = new ExcelUtil<BehaviorImageWeight>(BehaviorImageWeight.class);
        util.exportExcel(response, list, "画像行为权重数据");
    }

    /**
     * 获取画像行为权重详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(behaviorImageService.selectBehaviorImageWeightById(id));
    }

    /**
     * 新增画像行为权重
     */
    @Log(title = "画像行为权重", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BehaviorImageWeight behaviorImageWeight)
    {
        return toAjax(behaviorImageService.insertBehaviorImageWeight(behaviorImageWeight));
    }

    /**
     * 修改画像行为权重
     */
    @Log(title = "画像行为权重", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BehaviorImageWeight behaviorImageWeight)
    {
        return toAjax(behaviorImageService.updateBehaviorImageWeight(behaviorImageWeight));
    }

    /**
     * 删除画像行为权重
     */
    @Log(title = "画像行为权重", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(behaviorImageService.deleteBehaviorImageWeightByIds(ids));
    }

    /**
     * 获取活跃用户数据
     */
    @GetMapping(value = "/activityList")
    @ApiOperation("获取用户资源库数据")
    public TableDataInfo activityList(ActivityUserLibrary activityUserLibrary)
    {
        startPage();
        List<ActivityUserLibrary> list = behaviorImageService.selectActivityUserLibraryList(activityUserLibrary);
        return getDataTable(list);
    }

    @ApiOperation("/根据用户ID,获取用户对应的成果汇总")
    @GetMapping(value = "/getUserTypeStatistic")
    public AjaxResult getUserTypeStatistic(@PathVariable("userId") Long userId)
    {
        return AjaxResult.success(behaviorImageService.getUserTypeStatistic(userId));
    }



    @GetMapping(value = "/getUserProjectStatistic")
    @ApiOperation("/获取用户开源项目相关数据")
    public AjaxResult getUserProjectStatistic(@PathVariable("userId") Long userId)
    {
        return AjaxResult.success(behaviorImageService.getUserProjectStatistic(userId));
    }

    @GetMapping(value = "/getUserTaskStatistic")
    @ApiOperation("/获取用户创客任务相关数据")
    public AjaxResult getUserTaskStatistic(@PathVariable("userId") Long userId)
    {
        return AjaxResult.success(behaviorImageService.getUserTaskStatistic(userId));
    }

    @GetMapping(value = "/getUserCompStatistic")
    @ApiOperation("/获取用户开放竞赛相关数据")
    public AjaxResult getUserCompStatistic(@PathVariable("userId") Long userId)
    {
        return AjaxResult.success(behaviorImageService.getUserCompStatistic(userId));
    }

    @GetMapping(value = "/getUserMemoStatistic")
    @ApiOperation("/获取用户论坛交流相关数据")
    public AjaxResult getUserMemoStatistic(@PathVariable("userId") Long userId)
    {
        return AjaxResult.success(behaviorImageService.getUserMemoStatistic(userId));
    }

    @GetMapping(value = "/getUserExpertStatistic")
    @ApiOperation("/获取用户专家资源相关数据")
    public AjaxResult getUserExpertStatistic(@PathVariable("userId") Long userId)
    {
        return AjaxResult.success(behaviorImageService.getUserExpertStatistic(userId));
    }

    /**
     * 获取活跃用户相关统计数据
     */
    @GetMapping(value = "/getActivityStatistic")
    @ApiOperation("获取用户资源库相关统计数据")
    public AjaxResult getActivityStatistic()
    {
        return  AjaxResult.success(behaviorImageService.getActivityStatistic());
    }


    @GetMapping(value = "/getUserBehaviorSum")
    @ApiOperation("获取用户的所有关注、点赞数")
    public AjaxResult getUserBehaviorSum(Long userId)
    {
        return  AjaxResult.success(behaviorImageService.getUserBehaviorSum(userId));
    }
}
