package com.fjhx.u.controller;

import com.fjhx.stock.service.StockCheckrecordService;
import com.fjhx.u.service.UUserService;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.ThreadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 管理员 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-11-28
 */
@RestController
@RequestMapping("/uUser")
public class UUserController {

    @Autowired
    private UUserService uUserService;

    @Autowired
    private StockCheckrecordService stockCheckrecordService;

    @GetMapping("/test")
    public R test(@RequestParam("sleep") Integer sleep) {
        new Thread(() -> {
            stockCheckrecordService.checkStart("check1", "c185883dba22478cb593d33f6b66cc53");
            ThreadUtil.sleep(1000L * 60 * sleep);
            stockCheckrecordService.checkEnd("check1", "c185883dba22478cb593d33f6b66cc53");
        }).start();

        return R.success();
    }

    @GetMapping("/test4")
    public R test4(@RequestParam("sleep") Integer sleep) {
        new Thread(() -> {
            stockCheckrecordService.checkStart("check4", "0b8f584250bb4b40b72d641ce4849d15");
            ThreadUtil.sleep(1000L * 60 * sleep);
            stockCheckrecordService.checkEnd("check4", "0b8f584250bb4b40b72d641ce4849d15");
        }).start();

        return R.success();
    }


//    @PostMapping("/page")
//    public R page(@RequestBody Map<String, Object> condition){
//        Page<UUser> result = uUserService.getPage(condition);
//        return R.success(result);
//    }
//
//    @PostMapping("/add")
//    public R add(@RequestBody UUserVo uUserVo){
//        uUserService.add(uUserVo);
//        return R.success();
//    }
//
//    @PostMapping("/edit")
//    public R edit(@RequestBody UUserVo uUserVo){
//        uUserService.edit(uUserVo);
//        return R.success();
//    }
//
//    @PostMapping("/delete")
//    public R delete(@RequestBody UUserVo uUserVo){
//        uUserService.delete(uUserVo);
//        return R.success();
//    }

    @PostMapping("/list")
    public R list(@RequestBody Map<String, Object> condition) {
        List<Map<String, Object>> result = uUserService.getList(condition);
        return R.success(result);
    }

}

