ExpOperationController.java 1.96 KB
package com.topdraw.business.process.rest;

import com.topdraw.business.process.domian.TempExp;
import com.topdraw.business.process.service.ExpOperationService;
import com.topdraw.common.ResultInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * @author XiangHan
 * @date 2021-10-22
 */
@Api(tags = "成长值管理")
@RestController
@RequestMapping("/uce/expOperation")
@Slf4j
public class ExpOperationController {

    @Autowired
    private ExpOperationService expOperationService;

    @PostMapping(value = "/addExp")
    @ApiOperation("手动发放成长值")
    public ResultInfo grantExpByManual(@Validated @RequestBody TempExp tempExp) {
        log.info("手动发放成长值,参数 ==>> {}", tempExp);
        Long memberId = tempExp.getMemberId();
        if (Objects.isNull(memberId)) {
            log.error("发放成长值失败,参数错误,无会员id");
            return ResultInfo.failure("发放成长值失败,参数错误,无会员id");
        }

        Long rewardExp = tempExp.getRewardExp();
        if (Objects.isNull(rewardExp) || rewardExp <= 0L) {
            log.error("发放成长值失败,参数错误,成长值为空或者小于0 ==>> {}", rewardExp);
            return ResultInfo.failure("发放成长值失败,参数错误,成长值为空或者小于0");
        }
        this.expOperationService.grantExpByManual(Collections.singletonList(tempExp));
        return ResultInfo.success();
    }

}