package com.uas.eis.controller;

import com.uas.eis.dao.BaseDao;
import com.uas.eis.utils.JacksonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.net.Socket;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * Created by luhg on 2018/4/24.
 * 测试用
 */
@RestController
@Transactional
public class TestController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    BaseDao baseDao;

    @GetMapping(value = "/test/jdbc")
    public String testJdbc(Integer id){
        String res = "1";
        SqlRowSet rs = baseDao.getJdbcTemplate().queryForRowSet("select pi_inoutno from prodinout where rownum=1");
        if(rs.next()){
            res = rs.getString("pi_inoutno");
            System.out.println(res);
        }
        return res;
    }

    @GetMapping(value = "/test/socket")
    public void testSocket(Integer id){
        logger.error("test");
        try{
            Socket socket = new Socket("scope2015.oicp.net",1521);
            System.out.println("connect success");
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @PostMapping(value = "/test/stock")
    public Map<String,Object> testStock(@RequestBody String str){
        System.out.println("request body:" + str);

        Map<String,Object> res = new HashMap<>();

        Map<String,Object> msg_json = new HashMap<>();
        List<String> sno = new LinkedList<>();
        List<String> fno = new LinkedList<>();
        sno.add("YS180400051");
        fno.add("2");
        msg_json.put("s_no",sno);
        msg_json.put("f_no",fno);

        res.put("code",0);
        res.put("message","test");
        res.put("msg_json",msg_json);
        return res;
    }

    @PostMapping(value = "/test/stockpost")
    public Map<String,Object> testStockPost(@RequestBody String str){
        System.out.println("request body:" + str);

        Map<String,Object> res = new HashMap<>();

        List<Map<String,Object>> data = new LinkedList<>();

        Map<String,Object> code1 = new HashMap<>();
        code1.put("outer_no","YS180400051");
        code1.put("order_status",2);
        code1.put("src_order_type","采购验收单");
        data.add(code1);

        Map<String,Object> code2 = new HashMap<>();
        code2.put("outer_no","YS1803232");
        code2.put("order_status",2);
        code2.put("src_order_type","采购验退单");
        data.add(code2);

        res.put("code",132);
        res.put("message","test");
        res.put("total_count",100);
        res.put("data",data);
        return res;
    }

    @PostMapping(value = "/test/getoutstorage")
    public Map<String,Object> getOutStorage(@RequestBody String str){
        System.out.println("request body:" + str);

        Map<String,Object> res = new HashMap<>();

        List<Map<String,Object>> data = new LinkedList<>();

        List<Map<String,Object>> detail = new LinkedList<>();
        Map<String,Object> detailMap = new HashMap<>();
        detailMap.put("spec_no","A.BA00002");
        detailMap.put("goods_count",123);
        detailMap.put("sell_price",100);
        detailMap.put("id123",100);
        detail.add(detailMap);

        Map<String,Object> code1 = new HashMap<>();
        code1.put("order_no","abc123");
        code1.put("consign_time","2015-07-01 16:39:35");
        code1.put("customer_no","2017070003");
        code1.put("customer_name","创趣-华米分销商");
        code1.put("details_list",detail);

        data.add(code1);

        res.put("code",0);
        res.put("message","test");
        res.put("total_count",100);
        res.put("stockout_list",data);
        return res;
    }

    @PostMapping(value = "/test/getoutrefund")
    public Map<String,Object> getOutRefund(@RequestBody String str){
        System.out.println("request body:" + str);

        Map<String,Object> res = new HashMap<>();

        List<Map<String,Object>> data = new LinkedList<>();

        List<Map<String,Object>> detail = new LinkedList<>();
        Map<String,Object> detailMap = new HashMap<>();
        detailMap.put("tid","SS17060005");
        detailMap.put("spec_no","A.AA00010");
        detailMap.put("stockin_num",100);
        detail.add(detailMap);

        Map<String,Object> code1 = new HashMap<>();
        code1.put("refund_no","abc123");
        code1.put("warehouse_no","YD001");
        code1.put("shop_n","2017070003");
        code1.put("refund_orders_list",detail);
        data.add(code1);

        res.put("code",0);
        res.put("message","test");
        res.put("total_count",100);
        res.put("data",data);
        return res;
    }
}
