ソースを参照

增加物料接口

zhoudw 7 年 前
コミット
45c7d177df

+ 28 - 0
src/main/java/com/uas/eis/controller/ProductController.java

@@ -0,0 +1,28 @@
+package com.uas.eis.controller;
+
+import com.uas.eis.service.ProductService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Map;
+
+/**
+ * Created by luhg on 2018/4/19.
+ * 出入库相关
+ */
+@RestController
+public class ProductController {
+
+    @Autowired
+    private ProductService productService;
+
+
+    @PostMapping(value = "/yunding/product")
+    public Map<String,Object> postProductToYunding(@RequestParam Integer id){
+        return productService.postProductToYunding(id);
+    }
+
+
+}

+ 11 - 0
src/main/java/com/uas/eis/service/ProductService.java

@@ -0,0 +1,11 @@
+package com.uas.eis.service;
+
+import java.util.Map;
+
+/**
+ * Created by luhg on 2018/4/19.
+ * 出入库相关
+ */
+public interface ProductService {
+    Map<String,Object> postProductToYunding(Integer id);
+}

+ 124 - 0
src/main/java/com/uas/eis/serviceImpl/ProductServiceImpl.java

@@ -0,0 +1,124 @@
+package com.uas.eis.serviceImpl;
+
+import com.uas.eis.dao.BaseDao;
+import com.uas.eis.dao.EdiLogDao;
+import com.uas.eis.dao.EdiSuccessLogDao;
+import com.uas.eis.service.ProductService;
+import com.uas.eis.utils.Constant;
+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.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by zdw
+ * 2018-05-15 08:29.
+ */
+@Service
+public class ProductServiceImpl implements ProductService{
+
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+    private static final String sendProductToYundingUrl = "";
+
+    @Autowired
+    BaseDao baseDao;
+    @Autowired
+    EdiLogDao ediLogDao;
+    @Autowired
+    EdiSuccessLogDao ediSuccessLogDao;
+
+
+    @Override
+    public Map<String, Object> postProductToYunding(Integer id) {
+        Map<String,Object> data = getMainData(id);
+        List<Map<String,Object>> datas = new LinkedList<Map<String,Object>>();
+        datas.add(data);
+
+        String timestamp = String.valueOf(System.currentTimeMillis()/1000);
+        String outerNo = String.valueOf(data.get(""));
+
+        Map<String,Object> postMapData = new HashMap<>();
+        postMapData.put("app_key", Constant.yundingAppKey);
+        postMapData.put("time_stamp",timestamp);
+        postMapData.put("spec_list",datas);
+
+        return postData(outerNo,postMapData,timestamp);
+    }
+
+    private Map<String,Object> postData(String outerNo,Map<String,Object> data,String timestamp){
+        Map<String,Object> res = new HashMap<>();
+        String jsonData = JacksonUtil.toSortJson(data);
+        System.out.println(jsonData);
+//        try{
+//
+//            HttpUtil.Response response = HttpUtil.doPostToYunding(sendProductToYundingUrl,jsonData,timestamp);
+//
+//            String responseText = response.getResponseText();
+//
+//            logger.info("responseText:" + responseText);
+//            logger.info("responseCode:" + response.getStatusCode());
+//
+//            if(response.getStatusCode()!=200){
+//                throw new RuntimeException("yunding server error:" + responseText);
+//            }
+//
+//            Map<String,Object> responseMap = JacksonUtil.fromJson(response.getResponseText());
+//
+//            if(!"0".equals(String.valueOf(responseMap.get("code")))){
+//                res.put("success",false);
+//                res.put("remark",responseMap.get("message"));
+//            }else{
+//                Map<String,Object> msgJson = (Map<String,Object>) responseMap.get("msg_json");
+//                List<String> successCodes = (List<String>)msgJson.get("s_no");
+//                if(successCodes.contains(outerNo)){
+//                    res.put("success",true);
+//                    ediLogDao.save(LogUtil.getSendSuccessLog(outerNo,jsonData,"send success"));
+//                }else{
+//                    res.put("success",false);
+//                    res.put("remark","云顶数据中心处理失败!");
+//                }
+//            }
+//        }catch (Exception e){
+//            e.printStackTrace();
+//            logger.error("error",e);
+//
+//            res.put("success",false);
+//            res.put("remark",e.getMessage());
+//        }
+        return res;
+    }
+
+    private Map<String,Object> getMainData(Integer id){
+        Map<String,Object> data = new HashMap<>();
+        SqlRowSet rs = baseDao.getJdbcTemplate().queryForRowSet("select pr_code,pr_detail,pr_brand,pr_unit,pr_code,pr_spec,pr_description from Product where pr_id=" + id);
+        if(rs.next()){
+            data.put("goods_no",rs.getString("pr_code"));
+            data.put("goods_name",rs.getString("pr_detail"));
+            data.put("goods_type",1);
+            data.put("class_name","");
+            data.put("brand_name",rs.getString("pr_brand"));
+            data.put("unit_name",rs.getString("pr_unit"));
+            data.put("spec_no",rs.getString("pr_code"));
+            data.put("spec_code","");
+            data.put("spec_name",rs.getString("pr_spec"));
+            data.put("bar_code","");
+            data.put("price","");
+            data.put("guarantee","");
+            data.put("description",rs.getString("pr_description"));
+        }
+        return data;
+    }
+
+
+
+
+
+}