package org.dromara.zhishu.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.zhishu.domain.SinglePrint;
import org.dromara.zhishu.domain.bo.SinglePrintBo;
import org.dromara.zhishu.service.IProductService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.concurrent.CompletableFuture;

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zhishu/product")
public class ProductController extends BaseController {

    private final IProductService productService;


    @GetMapping("/getMappingList")
    @SaIgnore
    public Map getMappingList(){
        return productService.getMappingList();
    }

    /**
     * 查询单票打印列表
     */
    @GetMapping("/list")
    @SaIgnore
    public TableDataInfo<Map> list(@RequestParam Map bo) {
        return productService.queryPageList(bo);
    }

    @PostMapping("/releaseGoods")
    public R<Void> releaseGoods(@RequestBody  Map map){
        // 异步执行
        CompletableFuture.runAsync(() -> {
            productService.releaseGoods(map);
        });
        return R.ok();
    }

    @PostMapping("/releaseGoodsAuto")
    @SaIgnore
    public R<Void> releaseGoodsAuto(@RequestParam  Map map){
        try{
            // 用户id
            String userId = map.get("userId").toString();
            // 仓库id
            String warehouseId = map.get("warehouseId").toString();
            String productId = map.get("productId").toString();
            System.out.println("用户id:"+userId+";仓库id:"+warehouseId+";商品id："+productId);
            // 异步执行
            CompletableFuture.runAsync(() -> {
                productService.releaseGoodsAuto(map);
            });
            return R.ok();
        }catch (Exception e){
            return R.fail(e.getMessage());
        }

    }
}
