package com.sy.coinage.app.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.sy.coinage.core.annotation.CurrentUser;
import com.sy.coinage.core.util.HttpClientUtil;
import com.sy.coinage.core.vo.CacheUserVO;
import com.sy.coinage.core.vo.OptVO;
import com.sy.coinage.sys.service.IDictService;
import com.sy.coinage.sys.service.IUserService;
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.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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


@Api(tags = "App获取barcode接口")
@RestController
@RequestMapping(value = "/app")
@Slf4j
public class BarCodeController {

    public String barCodeUrl = "http://127.0.0.1:9999/syn/findByPacketCode";

    @ApiOperation(value = "App获取barcode")
    @GetMapping(value = "/barcode/{ts}")
    public String barcode(@PathVariable String ts) {
//        Map<String, String> data = new HashMap<>();
//        for (int i = 1; i < 20; i++) {
//            Integer t = i * 5;
//            data.put("1000" + i, "003-" + String.format("%04d", t));
//        }
//        data.put("1001", "003-0652");
//        data.put("1002", "003-0655");
//        data.put("1003", "003-0811");
//        data.put("1004", "003-0884");
//        data.put("1005", "003-0924");
//        data.put("1006", "003-0984");
//        data.put("1007", "003-1044");
//        data.put("1008", "003-1114");
//        return data.get(ts);

        //查询条件 正式环境下调用
        try {
            JSONObject jsonObj = new JSONObject();
            jsonObj.put("packCode",ts);
            String body = HttpClientUtil.post(barCodeUrl, jsonObj.toJSONString());
            log.debug("findByPacketCode response={}", body);
            JSONObject o = JSON.parseObject(body);
            // TODO 解析响应信息
            if ("200".equals(o.get("code").toString())) {
                String crown = String.valueOf(o.get("retObj"));
                return crown;
            }
        } catch (Exception e) {
            e.printStackTrace();

        }
        return null;


    }



}