From 8aec80ae2803a1aff3c637b4685873b373809248 Mon Sep 17 00:00:00 2001
From: lyfO_o <764716047@qq.com>
Date: 星期四, 19 八月 2021 15:23:21 +0800
Subject: [PATCH] 2点任务:(姑苏实验室)(国药苏州)发送试剂价格不等的试剂价格情况给admin

---
 src/main/java/com/nanometer/smartlab/email/EmailSendSchedule.java |  123 ++++++++++++++++++++++++++++++++++++++++
 src/main/webapp/WEB-INF/szygs/szygs.properties                    |    1 
 src/main/webapp/WEB-INF/zkyshs/zkyshs.properties                  |    1 
 src/main/webapp/WEB-INF/gcs/gcs.properties                        |    1 
 src/main/webapp/WEB-INF/gslab/gslab.properties                    |    1 
 src/main/java/com/nanometer/smartlab/util/HttpUtil.java           |   38 ++++++++++++
 src/main/webapp/WEB-INF/lzhws/lzhws.properties                    |    1 
 src/main/webapp/WEB-INF/shgjs/shgjs.properties                    |    1 
 src/main/webapp/WEB-INF/xjdx/xjdx.properties                      |    1 
 src/main/webapp/WEB-INF/zkysh/zkysh.properties                    |    1 
 src/main/webapp/WEB-INF/qhyhs/qhyhs.properties                    |    1 
 src/main/webapp/WEB-INF/zkdsz/zkdsz.properties                    |    1 
 src/main/webapp/WEB-INF/twt/twt.properties                        |    1 
 src/main/webapp/WEB-INF/aky/aky.properties                        |    1 
 src/main/webapp/WEB-INF/lhs/lhs.properties                        |    1 
 src/main/webapp/WEB-INF/sds/sds.properties                        |    1 
 src/main/webapp/WEB-INF/config.properties                         |    2 
 src/main/webapp/WEB-INF/sin/sin.properties                        |    1 
 src/main/webapp/WEB-INF/hws/hws.properties                        |    1 
 src/main/webapp/WEB-INF/test/test.properties                      |    1 
 20 files changed, 178 insertions(+), 2 deletions(-)

diff --git a/src/main/java/com/nanometer/smartlab/email/EmailSendSchedule.java b/src/main/java/com/nanometer/smartlab/email/EmailSendSchedule.java
index f9e8eae..387622c 100644
--- a/src/main/java/com/nanometer/smartlab/email/EmailSendSchedule.java
+++ b/src/main/java/com/nanometer/smartlab/email/EmailSendSchedule.java
@@ -1,20 +1,31 @@
 package com.nanometer.smartlab.email;
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.nanometer.smartlab.entity.EmailStatus;
 import com.nanometer.smartlab.entity.OpeWarehouseReserve;
 import com.nanometer.smartlab.entity.SysReagent;
+import com.nanometer.smartlab.entity.SysUser;
 import com.nanometer.smartlab.entity.enumtype.EmailSendStatus;
 import com.nanometer.smartlab.exception.BusinessException;
+import com.nanometer.smartlab.exception.ExceptionEnumCode;
 import com.nanometer.smartlab.service.*;
 import com.nanometer.smartlab.util.EmailSend;
+import com.nanometer.smartlab.util.HttpUtil;
+import net.sf.cglib.asm.$ByteVector;
+import org.apache.commons.lang.StringUtils;
+import org.apache.http.message.BasicNameValuePair;
 import org.apache.log4j.Logger;
+import org.omg.CORBA.NameValuePair;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.List;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.*;
 
 /**
  * Created by wjd on 18/6/18.
@@ -33,6 +44,8 @@
     private OpeWarehouseReserveService opeWarehouseReserveService;
     @Resource
     private SysUserService userService;
+    @Resource
+    private SysSupplierService sysSupplierService;
 
     @Scheduled(fixedDelayString = "${emailSend.schedule.delay}")
     public void EmailSendSchedule(){
@@ -136,4 +149,110 @@
         }
     }
 
+
+
+    @Value("${reagent.detail.price.api}")
+    private String reagentApi;
+
+    private final static String send_supplier_name = "国药集团化学试剂苏州有限公司";
+    private final static BigDecimal SALE_85 = BigDecimal.valueOf(0.85);
+    private final static Map discountMap = new HashMap<BigDecimal,String>(){{
+        put(SALE_85, "85折价格");
+    }};
+
+    /**
+    * @Description: 姑苏实验室 发给admin管理员邮箱 国药试剂(价格不同的)信息  执行时间 :每天早上2点
+    * @date 2021/8/19 9:06
+    */
+    @Scheduled(cron = "0 0 2 * * ?")
+    public void ReagentPriceSend(){
+        //0.限制在姑苏实验室
+        if (StringUtils.isBlank(reagentApi) || reagentApi.length() == 0) return;
+
+        try {
+            //1.获取管理员邮箱
+            SysUser admin = userService.getSysUserByAccount("admin");
+            if (admin == null ||StringUtils.isBlank(admin.getEmail())) throw new BusinessException(ExceptionEnumCode.PARAM_NULL,"找不到管理员或者管理员邮箱信息");
+
+            //2.获取国药试剂
+            String supplierId = sysSupplierService.getSysSupplierIdByname(send_supplier_name);
+            if (StringUtils.isBlank(supplierId))
+                throw new BusinessException(ExceptionEnumCode.PARAM_NO_EXIST, "没有找到与(" + send_supplier_name + ")相关供应商,请检查最近信息更新");
+
+            List<SysReagent> guoyao_reagents = sysReagentService.getSysReagentListNew(null, null, supplierId, 1, null, null, null);
+            if (guoyao_reagents.size() < 1)
+                throw new BusinessException(ExceptionEnumCode.PARAM_NULL, "供应商:" + send_supplier_name + ",没有查询到相关试剂");
+
+            List<JSONObject> sendDataList = new ArrayList<>();
+            for (SysReagent reagent : guoyao_reagents) {
+                String productSn = reagent.getProductSn();
+                List params = new ArrayList<BasicNameValuePair>() {{
+                    add(new BasicNameValuePair("goodsErpCode", productSn));
+                }};
+                String res = HttpUtil.doGet(reagentApi, params);
+                JSONObject resJson = JSONObject.parseObject(res);
+                JSONArray data = resJson.getJSONArray("data");
+                JSONObject dataJson = data.getJSONObject(0);
+                Integer totalRows = dataJson.getInteger("totalRows");
+                if (totalRows != 1) continue;
+
+                JSONArray listApiGoods = dataJson.getJSONArray("listApiGoods");
+                if (listApiGoods.size() != 1) logger.info("产品编号:" + productSn + ",接口查询到多个数据,无法判断");
+
+                JSONObject goodJson = listApiGoods.getJSONObject(0);
+                String goodsName = goodJson.getString("goodsName");
+                BigDecimal goodsCostPrice = goodJson.getBigDecimal("goodsCostPrice");
+                BigDecimal price = reagent.getPrice();
+                //保留两位
+                BigDecimal price_afterDiscount = SALE_85.multiply(price).setScale(2, RoundingMode.HALF_UP);
+                if (price_afterDiscount.compareTo(goodsCostPrice) != 0) {
+                    sendDataList.add(new JSONObject() {{
+                        put("goodsName", goodsName);
+                        put("goodsCostPrice", goodsCostPrice);
+                        put("priceAfterDiscount", price_afterDiscount);
+                        put("currentSystemPrice", price);
+                        put("goodsCode", productSn);
+                    }});
+                }
+            }
+            //制作表格
+                StringBuilder content = new StringBuilder("<html><body>");
+                content.append("<div style=\"line-height:1.7;color:#000000;font-size:14px;font-family:Arial\">");
+                content.append("<table border=\"1\">");
+                content.append("<tbody>");
+                content.append("<tr>");
+                content.append("<th>产品编号</th>");
+                content.append("<th>产品名称</th>");
+                content.append("<th>官网售价</th>");
+                content.append("<th>").append(discountMap.get(SALE_85)).append("</th>");
+                content.append("<th>当前系统价格</th>");
+                content.append("</tr>");
+                for (JSONObject goodJson : sendDataList){
+                    content.append("<tr>")
+                            .append("<td>").append(goodJson.getString("goodsCode")).append("</td>")
+                            .append("<td>").append(goodJson.getString("goodsName")).append("</td>")
+                            .append("<td>").append(goodJson.getBigDecimal("goodsCostPrice")).append("</td>")
+                            .append("<td>").append(goodJson.getBigDecimal("priceAfterDiscount")).append("</td>")
+                            .append("<td>").append(goodJson.getBigDecimal("currentSystemPrice")).append("</td>")
+                            .append("</tr>");
+                }
+                content.append("</tbody></table></div>");
+                content.append("</body></html>");
+
+
+                //发送邮件
+                EmailSend.sendArrivalEmail(Collections.singletonList(admin.getEmail()),content.toString());
+                    //  发送成功,更新邮件发送状态为:已发送
+
+        } catch (BusinessException e) {
+            e.printStackTrace();
+            logger.warn(e.getMessage());
+        } catch (Exception e) {
+            e.printStackTrace();
+            logger.warn("系统内部错误,请检查代码");
+        }
+
+
+    }
+
 }
diff --git a/src/main/java/com/nanometer/smartlab/util/HttpUtil.java b/src/main/java/com/nanometer/smartlab/util/HttpUtil.java
new file mode 100644
index 0000000..38008a0
--- /dev/null
+++ b/src/main/java/com/nanometer/smartlab/util/HttpUtil.java
@@ -0,0 +1,38 @@
+package com.nanometer.smartlab.util;
+
+import com.nanometer.smartlab.exception.BusinessException;
+import com.nanometer.smartlab.exception.ExceptionEnumCode;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.utils.URIBuilder;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+
+import javax.swing.text.html.parser.Entity;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.List;
+
+public class HttpUtil {
+
+
+    public static String doGet(String url, List<NameValuePair> params){
+        try{
+            CloseableHttpClient client = HttpClients.createDefault();
+            URIBuilder builder = new URIBuilder(url);
+            URIBuilder uriBuilder = builder.setParameters(params);
+            HttpGet get = new HttpGet(uriBuilder.build());
+            CloseableHttpResponse res = client.execute(get);
+            return EntityUtils.toString(res.getEntity(), "UTF-8");
+        } catch (IOException | URISyntaxException e) {
+            e.printStackTrace();
+            throw new BusinessException(ExceptionEnumCode.SYS_ERR, "GET请求发生错误,请检查代码");
+        }
+
+
+    }
+}
diff --git a/src/main/webapp/WEB-INF/aky/aky.properties b/src/main/webapp/WEB-INF/aky/aky.properties
index d5c16df..d1810ce 100644
--- a/src/main/webapp/WEB-INF/aky/aky.properties
+++ b/src/main/webapp/WEB-INF/aky/aky.properties
@@ -8,3 +8,4 @@
 institute.app.id =
 institute.app.secret =
 alarm.url =
+reagent.detail.price.api =
diff --git a/src/main/webapp/WEB-INF/config.properties b/src/main/webapp/WEB-INF/config.properties
index 21165d9..1febb0c 100644
--- a/src/main/webapp/WEB-INF/config.properties
+++ b/src/main/webapp/WEB-INF/config.properties
@@ -57,3 +57,5 @@
 institute.id = ${institute.id}
 institute.name = ${institute.name}
 institute.url = ${institute.url}
+
+reagent.detail.price.api = ${reagent.detail.price.api}
diff --git a/src/main/webapp/WEB-INF/gcs/gcs.properties b/src/main/webapp/WEB-INF/gcs/gcs.properties
index e608d09..574a1ff 100644
--- a/src/main/webapp/WEB-INF/gcs/gcs.properties
+++ b/src/main/webapp/WEB-INF/gcs/gcs.properties
@@ -8,3 +8,4 @@
 institute.app.id = wx7ab4d938ce5ce618
 institute.app.secret = c66b740b60220698570767c807361d3a
 alarm.url = http://gcs.sinanoaq.com/daping/sendWarnInfo.json
+reagent.detail.price.api =
diff --git a/src/main/webapp/WEB-INF/gslab/gslab.properties b/src/main/webapp/WEB-INF/gslab/gslab.properties
index 3b91780..72d1871 100644
--- a/src/main/webapp/WEB-INF/gslab/gslab.properties
+++ b/src/main/webapp/WEB-INF/gslab/gslab.properties
@@ -9,3 +9,4 @@
 institute.app.id =
 institute.app.secret =
 alarm.url =
+reagent.detail.price.api = https://www.reagent.com.cn/reagent-front/goodsApi/getGoodsListExact
diff --git a/src/main/webapp/WEB-INF/hws/hws.properties b/src/main/webapp/WEB-INF/hws/hws.properties
index adf63de..cd5bb1c 100644
--- a/src/main/webapp/WEB-INF/hws/hws.properties
+++ b/src/main/webapp/WEB-INF/hws/hws.properties
@@ -8,3 +8,4 @@
 institute.app.id = wx7ab4d938ce5ce618
 institute.app.secret = c66b740b60220698570767c807361d3a
 alarm.url = http://hws.sinanoaq.com/daping/sendWarnInfo.json
+reagent.detail.price.api =
diff --git a/src/main/webapp/WEB-INF/lhs/lhs.properties b/src/main/webapp/WEB-INF/lhs/lhs.properties
index fd50659..5907cda 100644
--- a/src/main/webapp/WEB-INF/lhs/lhs.properties
+++ b/src/main/webapp/WEB-INF/lhs/lhs.properties
@@ -8,3 +8,4 @@
 institute.app.id = wxc1c97c50f32a13f9
 institute.app.secret = fc932330d22c3bc8e94b9f9b790fec98
 alarm.url = http://lhs.sinanoaq.com/daping/sendWarnInfo.json
+reagent.detail.price.api =
diff --git a/src/main/webapp/WEB-INF/lzhws/lzhws.properties b/src/main/webapp/WEB-INF/lzhws/lzhws.properties
index e57679d..4e041fb 100644
--- a/src/main/webapp/WEB-INF/lzhws/lzhws.properties
+++ b/src/main/webapp/WEB-INF/lzhws/lzhws.properties
@@ -8,3 +8,4 @@
 institute.app.id =
 institute.app.secret =
 alarm.url =
+reagent.detail.price.api =
diff --git a/src/main/webapp/WEB-INF/qhyhs/qhyhs.properties b/src/main/webapp/WEB-INF/qhyhs/qhyhs.properties
index 754fd3e..c91f85f 100644
--- a/src/main/webapp/WEB-INF/qhyhs/qhyhs.properties
+++ b/src/main/webapp/WEB-INF/qhyhs/qhyhs.properties
@@ -8,3 +8,4 @@
 institute.app.id =
 institute.app.secret =
 alarm.url =
+reagent.detail.price.api =
diff --git a/src/main/webapp/WEB-INF/sds/sds.properties b/src/main/webapp/WEB-INF/sds/sds.properties
index 7dc5953..712d862 100644
--- a/src/main/webapp/WEB-INF/sds/sds.properties
+++ b/src/main/webapp/WEB-INF/sds/sds.properties
@@ -8,3 +8,4 @@
 institute.app.id = wx33de06d906c68d43
 institute.app.secret = 0170d9126bcd16bda4f171bc4a33251f
 alarm.url = http://sds.sinanoaq.com/daping/sendWarnInfo.json
+reagent.detail.price.api =
diff --git a/src/main/webapp/WEB-INF/shgjs/shgjs.properties b/src/main/webapp/WEB-INF/shgjs/shgjs.properties
index 3bc2ee9..8335f34 100644
--- a/src/main/webapp/WEB-INF/shgjs/shgjs.properties
+++ b/src/main/webapp/WEB-INF/shgjs/shgjs.properties
@@ -8,3 +8,4 @@
 institute.app.id =
 institute.app.secret =
 alarm.url =
+reagent.detail.price.api =
diff --git a/src/main/webapp/WEB-INF/sin/sin.properties b/src/main/webapp/WEB-INF/sin/sin.properties
index 195d4ec..2a83d8f 100644
--- a/src/main/webapp/WEB-INF/sin/sin.properties
+++ b/src/main/webapp/WEB-INF/sin/sin.properties
@@ -8,3 +8,4 @@
 institute.app.id = wx81a00e3350861b25
 institute.app.secret = c307d394875af2cbbe25e01b9e43dcb2
 alarm.url = http://sinanoaq.com/daping/sendWarnInfo.json
+reagent.detail.price.api =
diff --git a/src/main/webapp/WEB-INF/szygs/szygs.properties b/src/main/webapp/WEB-INF/szygs/szygs.properties
index 07f9aaa..b9ee41f 100644
--- a/src/main/webapp/WEB-INF/szygs/szygs.properties
+++ b/src/main/webapp/WEB-INF/szygs/szygs.properties
@@ -8,3 +8,4 @@
 institute.app.id =
 institute.app.secret =
 alarm.url = http://58.210.42.60:8001/daping/sendWarnInfo.json
+reagent.detail.price.api =
diff --git a/src/main/webapp/WEB-INF/test/test.properties b/src/main/webapp/WEB-INF/test/test.properties
index 6a5198c..d0edcf4 100644
--- a/src/main/webapp/WEB-INF/test/test.properties
+++ b/src/main/webapp/WEB-INF/test/test.properties
@@ -8,3 +8,4 @@
 institute.app.id =
 institute.app.secret =
 alarm.url =
+reagent.detail.price.api = https://www.reagent.com.cn/reagent-front/goodsApi/getGoodsListExact
diff --git a/src/main/webapp/WEB-INF/twt/twt.properties b/src/main/webapp/WEB-INF/twt/twt.properties
index 4db6421..f6770e9 100644
--- a/src/main/webapp/WEB-INF/twt/twt.properties
+++ b/src/main/webapp/WEB-INF/twt/twt.properties
@@ -8,3 +8,4 @@
 institute.app.id = wxef5464cb3cd407ea
 institute.app.secret = f0b8dec4bc340a9863ed7de08cf2dcf1
 alarm.url =
+reagent.detail.price.api =
diff --git a/src/main/webapp/WEB-INF/xjdx/xjdx.properties b/src/main/webapp/WEB-INF/xjdx/xjdx.properties
index d4c4662..602fcf2 100644
--- a/src/main/webapp/WEB-INF/xjdx/xjdx.properties
+++ b/src/main/webapp/WEB-INF/xjdx/xjdx.properties
@@ -8,3 +8,4 @@
 institute.app.id =
 institute.app.secret =
 alarm.url =
+reagent.detail.price.api =
diff --git a/src/main/webapp/WEB-INF/zkdsz/zkdsz.properties b/src/main/webapp/WEB-INF/zkdsz/zkdsz.properties
index 3d43193..2e47ee7 100644
--- a/src/main/webapp/WEB-INF/zkdsz/zkdsz.properties
+++ b/src/main/webapp/WEB-INF/zkdsz/zkdsz.properties
@@ -8,3 +8,4 @@
 institute.app.id =
 institute.app.secret =
 alarm.url =
+reagent.detail.price.api =
diff --git a/src/main/webapp/WEB-INF/zkysh/zkysh.properties b/src/main/webapp/WEB-INF/zkysh/zkysh.properties
index ed6c610..1d3b6ef 100644
--- a/src/main/webapp/WEB-INF/zkysh/zkysh.properties
+++ b/src/main/webapp/WEB-INF/zkysh/zkysh.properties
@@ -8,3 +8,4 @@
 institute.app.id =
 institute.app.secret =
 alarm.url =
+reagent.detail.price.api =
diff --git a/src/main/webapp/WEB-INF/zkyshs/zkyshs.properties b/src/main/webapp/WEB-INF/zkyshs/zkyshs.properties
index b09d7c6..54c89c4 100644
--- a/src/main/webapp/WEB-INF/zkyshs/zkyshs.properties
+++ b/src/main/webapp/WEB-INF/zkyshs/zkyshs.properties
@@ -8,3 +8,4 @@
 institute.app.id =
 institute.app.secret =
 alarm.url =
+reagent.detail.price.api =

--
Gitblit v1.9.2