package com.crm.activity.controller;

import com.crm.activity.service.ActivityRaceRankingService;
import com.crm.activity.task.ActivityRaceTask;
import com.crm.rely.backend.core.constant.Constants;
import com.crm.rely.backend.model.pojo.table.ActivityRaceRuleTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName ManualController
 * @Description
 * @Author y
 * @Date 2022/8/5 10:14
 */
@RestController
@RequestMapping("/manual")
public class ManualController {

    @Autowired
    private ActivityRaceRankingService activityRaceRankingService;
    @Autowired
    private ActivityRaceTask activityRaceTask;

    @GetMapping("/reOrder/{ruleId}")
    public String reOrder(@PathVariable("ruleId") Long ruleId){
        try {
            activityRaceRankingService.reOrderRanking(ruleId);
            return Constants.SUCCESS;
        }catch (Exception e){
            return e.getMessage();
        }
    }

    @GetMapping("/ranking/{ruleId}")
    public String ranking(@PathVariable("ruleId") Long ruleId){
        try {
            ActivityRaceRuleTable raceRuleTable = new ActivityRaceRuleTable();
            raceRuleTable.setId(ruleId);
            activityRaceTask.calcRuleProfit(raceRuleTable);
            return Constants.SUCCESS;
        }catch (Exception e){
            return e.getMessage();
        }
    }

}
