package com.qnfhq.modules.business.controller;


import cn.dev33.satoken.stp.StpUtil;
import com.qnfhq.common.ApiBaseController;
import com.qnfhq.common.redis.RedisCache;
import com.qnfhq.common.utils.Result;
import com.qnfhq.common.utils.StringUtils;
import com.qnfhq.modules.business.entity.TMingOrder;
import com.qnfhq.modules.business.service.ITMingOrderService;
import com.qnfhq.modules.user.service.SettingService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;


/**
 * 挖矿Controller
 * 
 * @author ruoyi
 * @date 2023-07-17
 */
@RestController
@RequestMapping("/api/mingOrder")
public class TMingOrderController extends ApiBaseController
{
    @Autowired
     private SettingService settingService;
    @Autowired
    private ITMingOrderService itMingOrderService;
    @Resource
    private RedisCache redisCache;



    @PostMapping("/submit")
     public Result submit(@RequestBody  TMingOrder mingOrder) {
        Result result = new Result();
        String keyCache = StringUtils.format("api-currency-submit:{}", StpUtil.getLoginIdAsLong());
        if(StringUtils.isNotNull(redisCache.getCacheObject(keyCache))) {
            return error("请勿重复操作");
        }
        redisCache.setCacheObject(keyCache, "1", 30, TimeUnit.SECONDS);

        String msg = itMingOrderService.bugMingOrder(mingOrder.getPlanId(),mingOrder.getAmount(),getStpUserId());
        if(!"success".equals(msg)){
            redisCache.deleteObject(keyCache);

            return result.error(msg);
        }
        redisCache.deleteObject(keyCache);
        return  null;
    }





}
