浏览代码

道和银行接口 设备异常预警
2022年8月2日17时40分

纪新园 3 年之前
父节点
当前提交
9375adde32

+ 100 - 14
ruoyi-admin/src/main/java/com/ruoyi/web/controller/plugin/CcbController.java

@@ -1,12 +1,30 @@
 package com.ruoyi.web.controller.plugin;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.ruoyi.ccb.domain.*;
 import com.ruoyi.ccb.domain.basic.Page;
 import com.ruoyi.ccb.service.CcbHttpService;
+import com.ruoyi.common.constant.CcbConstants;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.JsonUtil;
+import com.ruoyi.common.utils.ShaUtil;
+import com.ruoyi.framework.web.domain.server.Sys;
 import lombok.AllArgsConstructor;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
 import org.springframework.web.bind.annotation.*;
 
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
+
 /**
  * CCB接口
  *
@@ -15,9 +33,9 @@ import org.springframework.web.bind.annotation.*;
 @AllArgsConstructor
 @RestController
 @RequestMapping("/ccb")
-public class CcbController{
+public class CcbController {
 
-//    private final CcbHttpService ccbHttpService;
+    //    private final CcbHttpService ccbHttpService;
     @Autowired
     private CcbHttpService ccbHttpService;
 
@@ -94,8 +112,7 @@ public class CcbController{
      * @return 结果
      */
     @PostMapping("/syncOrg")
-    public Page syncOrg(@RequestBody SyncOrg syncOrg)
-    {
+    public Page syncOrg(@RequestBody SyncOrg syncOrg) {
         return ccbHttpService.syncOrg(syncOrg);
     }
 
@@ -195,8 +212,7 @@ public class CcbController{
      * @return 结果
      */
     @PostMapping("/listAllDevices")
-    public Devices listAllDevices(@RequestBody Devices devices)
-    {
+    public Devices listAllDevices(@RequestBody Devices devices) {
         return ccbHttpService.listAllDevices(devices);
     }
 
@@ -207,8 +223,7 @@ public class CcbController{
      * @return 结果
      */
     @GetMapping("/findDeviceById")
-    public DeviceDetail findDeviceById(@RequestParam(value = "deviceId") String deviceId)
-    {
+    public DeviceDetail findDeviceById(@RequestParam(value = "deviceId") String deviceId) {
         return ccbHttpService.findDeviceById(deviceId);
     }
 
@@ -219,8 +234,7 @@ public class CcbController{
      * @return 结果
      */
     @PostMapping("/findDevicesByStorage")
-    public Devices findDevicesByStorage(@RequestBody DevicesByStorage devicesByStorage)
-    {
+    public Devices findDevicesByStorage(@RequestBody DevicesByStorage devicesByStorage) {
         return ccbHttpService.findDevicesByStorage(devicesByStorage);
     }
 
@@ -231,8 +245,7 @@ public class CcbController{
      * @return 结果
      */
     @GetMapping("/findDeviceData")
-    public FindDeviceData findDeviceData(@RequestParam(value = "deviceId") String deviceId)
-    {
+    public FindDeviceData findDeviceData(@RequestParam(value = "deviceId") String deviceId) {
         return ccbHttpService.findDeviceData(deviceId);
     }
 
@@ -243,9 +256,82 @@ public class CcbController{
      * @return 结果
      */
     @PostMapping("/findDeviceHistoryData")
-    public FindDeviceData findDeviceHistoryData(@RequestBody HistoryData historyData)
-    {
+    public FindDeviceData findDeviceHistoryData(@RequestBody HistoryData historyData) {
         return ccbHttpService.findDeviceHistoryData(historyData);
     }
 
+    /**
+     * 设备异常告警
+     *
+     * @return 结果
+     */
+    @GetMapping("/deviceAlarm")
+    public AjaxResult deviceAlarm() {
+
+        Date date = new Date();
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        String time = simpleDateFormat.format(date);
+
+
+        DeviceAlarm deviceAlarm = new DeviceAlarm();
+        deviceAlarm.setReqUser("涂宝");
+
+        List<DeviceException> deviceExceptionList = new ArrayList<>();
+
+        DeviceException deviceException = new DeviceException();
+        deviceException.setWarehouseName("630号 ");
+        deviceException.setWarehouseNo("630号");
+        deviceException.setShelvesName("黄岛区");
+        deviceException.setBTypeName("设备异常");
+        deviceException.setBType("异常");
+        deviceException.setReMark("设备连接异常");
+        deviceException.setETime(time);
+        deviceException.setElectronicTag("0101");
+
+        List<DevicesDetail> devicesDetailList = DevicesDetail.date();
+        deviceException.setDeviceInfo(devicesDetailList.get(0));
+
+        deviceExceptionList.add(deviceException);
+
+        deviceAlarm.setDeviceException(deviceExceptionList);
+
+        System.out.println("请求内容:"+JsonUtil.toJson(deviceAlarm));
+
+        String requestTime = DateUtils.dateTimeNow() + (Math.random() * 9 + 1) * 100000;
+        // 签名内容
+        String str = "appId=" + CcbConstants.APP_ID + "&"
+                + "secretKey=" + CcbConstants.SECRET_KEY + "&"
+                + "platformId=" + CcbConstants.PLATFORM_ID + "&"
+                + "requestTime=" + requestTime + "&"
+                + "body=" + JsonUtil.toJson(deviceAlarm);
+
+        OkHttpClient okHttpClient = new OkHttpClient();
+        Request request = new Request.Builder()
+                .addHeader("content-type", "application/json")
+                .addHeader("X-RC-AppId", CcbConstants.APP_ID)
+                .addHeader("X-RC-Sign", ShaUtil.sha256(str))
+                .addHeader("X-RC-SignType", "SHA256")
+                .addHeader("X-RC-RequestTime", requestTime)
+                .addHeader("X-RC-RLF-Uid", CcbConstants.PLATFORM_ID)
+                .url(CcbConstants.DEVICE_ALARM)
+                .post(okhttp3.RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), JsonUtil.toJson(deviceAlarm)))
+                .build();
+
+        String s;
+        try {
+            s = Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
+            System.out.println("请求成功返回信息:"+s);
+        } catch (IOException e) {
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+            return AjaxResult.error("请求银行反馈异常," + e.getMessage());
+        }
+
+        JSONObject result = JSON.parseObject(s);
+        if (!CcbConstants.SUCCESS.equals(result.getString("result"))) {
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+            return AjaxResult.error("请求银行反馈失败," + result.getString("reason"));
+        }
+        return AjaxResult.success("成功");
+    }
+
 }

+ 2 - 0
ruoyi-common/src/main/java/com/ruoyi/common/constant/CcbConstants.java

@@ -7,6 +7,8 @@ public class CcbConstants {
 
     public static final String OUT_URL = "http://124.127.94.35:6066/api/cargo/outCargoResp";
 
+    public static final String DEVICE_ALARM = "http://124.127.94.35:6066/api/alarm/deviceAlarm";
+
     public static final String SUCCESS = "Y";
 
     public static final String APP_ID = "CCB-DH-WR-01-01";

+ 1 - 0
ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java

@@ -115,6 +115,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
                 .antMatchers("/*/api-docs").anonymous()
                 .antMatchers("/druid/**").anonymous()
                 .antMatchers("/api/**").anonymous()
+//                .antMatchers("/ccb/**").anonymous()
                 // 除上面外的所有请求全部需要鉴权认证
                 .anyRequest().authenticated()
                 .and()

+ 16 - 0
ruoyi-plugin/src/main/java/com/ruoyi/ccb/domain/DeviceAlarm.java

@@ -0,0 +1,16 @@
+package com.ruoyi.ccb.domain;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class DeviceAlarm {
+
+    //请求用户
+    private String reqUser;
+
+    //设备异常信息
+    private List<DeviceException> deviceException;
+
+}

+ 59 - 0
ruoyi-plugin/src/main/java/com/ruoyi/ccb/domain/DeviceException.java

@@ -0,0 +1,59 @@
+package com.ruoyi.ccb.domain;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+
+@Data
+public class DeviceException {
+
+
+    /**
+     * 仓库名称
+     */
+    @JsonProperty("warehouseName")
+    private String warehouseName;
+    /**
+     * 库号
+     */
+    @JsonProperty("warehouseNo")
+    private String warehouseNo;
+    /**
+     * 库位
+     */
+    @JsonProperty("shelvesName")
+    private String shelvesName;
+    /**
+     * 告警名称
+     */
+    @JsonProperty("bTypeName")
+    private String bTypeName;
+    /**
+     * 告警类型
+     */
+    @JsonProperty("bType")
+    private String bType;
+    /**
+     * 告警详情
+     */
+    @JsonProperty("reMark")
+    private String reMark;
+    /**
+     * 告警时间
+     */
+    @JsonProperty("eTime")
+    private String eTime;
+    /**
+     * 电子标签
+     */
+    @JsonProperty("electronicTag")
+    private String electronicTag;
+    /**
+     * 设备信息
+     */
+    private DevicesDetail deviceInfo;
+    /**
+     * 时间索引
+     */
+    @JsonProperty("period")
+    private String period;
+}

+ 9 - 19
ruoyi-warehouse/src/main/java/com/ruoyi/warehouseBusiness/service/impl/TWarehouseBillsServiceImpl.java

@@ -4503,20 +4503,11 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
         tWarehouseBills.setUpdateBy(loginUser.getUser().getUserName());
         tWarehouseBills.setUpdateTime(new Date());
         fPid = tWarehouseBills.getfId();
-        //李俊平测试 2022-7-31
-        List<Map<String, Object>> stockList1 = tWhgenlegMapper.selectStockListCk(tWarehouseBills.getfMblno(), tWarehouseBills.getfCorpid());
-        if (CollectionUtil.isEmpty(stockList1)) {
-            return AjaxResult.error("请求银行反馈异常,未找到库存"+stockList1);
-        }
-
         tEnclosureMapper.deleteByFPid(fPid);
         tWarehousebillsfeesMapper.deleteByFPid(fPid);
         tWarehousebillsCntrMapper.deleteTWarehousebillsCntrfPid(fPid);
         JSONArray warehouseJSON = JSONArray.parseArray(warehousebillsitems);
 
-
-
-
         List<TWarehousebillsitems> warehousebillsitemsList = JSONObject.parseArray(warehouseJSON.toJSONString(), TWarehousebillsitems.class);
         int i = 1;
         List<TFees> feesList = new ArrayList<>();
@@ -4553,6 +4544,13 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
             if (wbItem.getfBsdate().before(tWhgenle.getfChargedate())) {
                 throw new WarehouseException("业务日期不得超出库存总帐日期");
             }
+
+            List<Map<String, Object>> stockList = tWhgenlegMapper.selectStockListCk(tWarehouseBills.getfMblno(), tWarehouseBills.getfCorpid());
+            if (CollectionUtil.isEmpty(stockList)) {
+                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                return AjaxResult.error("请求银行反馈异常,未找到库存");
+            }
+
             //  入库数特殊不判断入账
             if (WarehouseTypeEnum.SJCK.getType().equals(billsType)) { // 出库 查询
                 if (StringUtils.isNull(tWarehouseBills.getfBsdate()) || StringUtils.isNull(wbItem.getfChargedate())) {
@@ -4652,7 +4650,6 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
                 return AjaxResult.error("库存明细更新失败");
             }
 
-
             // 处理银行反馈
             if (WarehouseTypeEnum.SJCK.getType().equals(billsType)) {
                 SysConfig feedbackConfig = sysConfigMapper.checkConfigKeyUnique("bank.feedback");
@@ -4670,17 +4667,11 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
 
                     System.out.println("提单号="+tWarehouseBills.getfMblno());
 
-                    List<Map<String, Object>> stockList = tWhgenlegMapper.selectStockListCk(tWarehouseBills.getfMblno(), tWarehouseBills.getfCorpid());
-                    if (CollectionUtil.isEmpty(stockList)) {
-                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
-                        return AjaxResult.error("请求银行反馈异常,未找到库存");
-                    }
                     List<CargoInfo> cargos = new ArrayList<>();
                     stockList.forEach(stockMap -> {
                         String temp = JSON.toJSONString(stockMap);
 
                         CargoInfo detail = JSON.parseObject(temp, CargoInfo.class);
-                        if (detail.getNumber() != 0 && detail.getNumberLeft() >0 && detail.getWeightLeft() >0){
                             detail.setNumberUnit("件");
                             detail.setWeightUnit("千克");
                             detail.setCargoBelong(corp.getfCname());
@@ -4689,7 +4680,6 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
                             detail.setRemainWeight(detail.getWeightLeft());
                             detail.setElectronicTags(warehousebillsitemsElabelMapper.getLabelByTop(tWarehouseBills.getfId()));
                             cargos.add(detail);
-                        }
                     });
 
                     String requestTime = DateUtils.dateTimeNow() + (Math.random() * 9 + 1) * 100000;
@@ -4716,7 +4706,7 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
                             .build();
 
                     String s;
-                  /*  try {
+                    try {
                         s = Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
                     } catch (IOException e) {
                         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
@@ -4727,7 +4717,7 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
                     if (!CcbConstants.SUCCESS.equals(result.getString("result"))) {
                         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                         return AjaxResult.error("请求银行反馈失败," + result.getString("reason"));
-                    }*/
+                    }
                 }
             }
         }

+ 8 - 10
ruoyi-warehouse/src/main/resources/mapper/reportManagement/TWhgenlegMapper.xml

@@ -153,7 +153,7 @@
             <if test="fCntrno != null ">and f_cntrno = #{fCntrno}</if>
             <if test="fBusinessType != null ">and f_business_type = #{fBusinessType}</if>
             <if test="fMarks != null ">and f_marks = #{fMarks}</if>
-            <if test="fBsdate != null ">and f_bsdate = #{fBsdate}</if>
+            <if test="fBsdate != null ">and f_bsdate = date_format(#{fBsdate},'%Y-%m-%d')</if>
             <if test="fOriginalbilldate != null ">and f_originalbilldate = #{fOriginalbilldate}</if>
             <if test="fWarehouseLocationid != null ">and f_warehouse_locationid = #{fWarehouseLocationid}</if>
             <if test="fGoodsid != null ">and f_goodsid = #{fGoodsid}</if>
@@ -1590,15 +1590,13 @@
         left join t_warehouse t5 on t5.f_id = t1.f_warehouseid
         left join t_warehousebillsitems t6 on t6.f_billno = t1.f_originalbillno
         <where>
-            <if test="corpId != null "> and t3.status = 0 </if>
-            <if test="corpId != null "> and t3.dict_type = 'data_goods_category' </if>
-            <if test="corpId != null "> and t1.f_qtyD != 0 </if>
-            <if test="corpId != null "> and t1.f_qtyblc &gt; 0 </if>
-            <if test="corpId != null "> and t1.f_grossweightblc &gt; 0 </if>
-            <if test="fMblno != null and fMblno != ''"> and t1.f_mblno = #{fMblno}</if>
-
-
-            <if test="corpId != null "> and t1.f_corpid = #{corpId}</if>
+           t3.dict_type = 'data_goods_category'
+            AND t3.status = 0
+            AND t1.f_qtyD != 0
+            AND t1.f_qtyblc > 0
+            AND t1.f_grossweightblc > 0
+            <if test="corpId != null "> AND t1.f_corpid = #{corpId}</if>
+            <if test="fMblno != null and fMblno != ''"> AND t1.f_mblno = #{fMblno}</if>
         </where>
     </select>
     <update id="changeBelongTo" parameterType="TWhgenleg">