瀏覽代碼

维修手册和使用手册推送

bmmx 1 年之前
父節點
當前提交
b21b663b36

+ 6 - 0
src/main/java/com/om/controller/admin/ManualController.java

@@ -88,4 +88,10 @@ public class ManualController {
                          @RequestParam(defaultValue = "") String title) {
     return Result.succ(manualService.findManual(new Page<>(pageNum, pageSize), code, title));
   }
+
+    @GetMapping("/push")
+    @ApiOperation("推送使用手册")
+    public Result pushManual(@RequestParam Integer id) {
+        return manualService.pushManual(id);
+    }
 }

+ 2 - 0
src/main/java/com/om/handler/GlobalExceptionHandler.java

@@ -44,6 +44,7 @@ public class GlobalExceptionHandler {
     public Result BizException(BizException e) {
         // 记录异常信息到日志
         log.error("业务异常信息 : ", e);
+        e.printStackTrace();
         // 返回错误格式信息
         return Result.error().message(e.getMessage()).result(e.getCode());
     }
@@ -54,6 +55,7 @@ public class GlobalExceptionHandler {
     public Result BadReqException(BadReqException e) {
         // 记录异常信息到日志
         log.error("请求错误信息 : ", e);
+        e.printStackTrace();
         // 返回错误格式信息
         return Result.error().message(e.getMessage()).result(e.getCode());
     }

+ 1 - 0
src/main/java/com/om/service/IManualService.java

@@ -21,4 +21,5 @@ public interface IManualService extends IService<Manual> {
 
     Result<AppManual> AppGetByLang(AppBaseDTO dto);
 
+    Result pushManual(Integer id);
 }

+ 69 - 2
src/main/java/com/om/service/impl/ManualServiceImpl.java

@@ -1,22 +1,31 @@
 package com.om.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.om.entity.dto.AppBaseDTO;
-import com.om.entity.dto.GuidDTO;
+import com.om.entity.dto.*;
+import com.om.entity.po.Client;
 import com.om.entity.po.Manual;
+import com.om.entity.po.Wxsc;
 import com.om.entity.vo.AppManual;
 import com.om.exception.BadReqException;
+import com.om.exception.BizException;
 import com.om.mapper.ManualMapper;
+import com.om.service.IClientService;
 import com.om.service.IManualService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.om.utils.AesUtil;
 import com.om.utils.JwtUtils;
+import com.om.utils.PushUtil;
 import com.om.utils.Result;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.time.ZoneOffset;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * <p>
@@ -37,6 +46,12 @@ public class ManualServiceImpl extends ServiceImpl<ManualMapper, Manual> impleme
   @Resource
   private JwtUtils jwtUtils;
 
+  @Resource
+  private IClientService clientService;
+
+  @Resource
+  private PushUtil pushUtil;
+
   @Override
   public Page<Manual> findManual(Page<Manual> page, String code, String title) {
     return manualMapper.findManual(page, code, title);
@@ -61,4 +76,56 @@ public class ManualServiceImpl extends ServiceImpl<ManualMapper, Manual> impleme
         vo.setCreateTime(one.getCreateTime().toInstant(ZoneOffset.of("+8")).toEpochMilli());
         return Result.ok(vo);
     }
+
+    @Override
+    public Result pushManual(Integer id) {
+        Manual manual = this.getById(id);
+        if (BeanUtil.isEmpty(manual)){
+            throw new BadReqException("该使用手册不存在");
+        }
+        PushInfo pushInfo = new PushInfo();
+        pushInfo.setPushInfoType(4);
+
+        MaintenanceManualInfo maintenanceManualInfo = new MaintenanceManualInfo();
+        maintenanceManualInfo.setType("1");
+        List<Describe> describeList = new ArrayList<>();
+        String title = manual.getTitle();
+        List<Manual> manuals = this.lambdaQuery()
+                .eq(Manual::getTitle, title)
+                .eq(Manual::getClientCode,manual.getClientCode())
+                .list();
+        if (CollectionUtil.isNotEmpty(manuals)){
+            for (Manual m : manuals) {
+                Describe describe = new Describe();
+                describe.setLanguage(m.getLang());
+                describe.setDescription(m.getFileName());
+                describeList.add(describe);
+            }
+        }
+
+        maintenanceManualInfo.setDescribeList(describeList);
+        pushInfo.setJson(JSONUtil.parseObj(maintenanceManualInfo));
+
+        String clientCode = manual.getClientCode();
+        if (StringUtils.isNotBlank(clientCode)){
+
+            Client client = clientService.lambdaQuery()
+                    .eq(Client::getNumber, clientCode)
+                    .one();
+
+            if (BeanUtil.isEmpty(client)){
+                throw new BadReqException("该客户端编号不存在");
+            }
+            String deviceToken = client.getDeviceToken();
+            if (StringUtils.isNotBlank(deviceToken)){
+                String[] token = new String[]{deviceToken};
+                try {
+                    pushUtil.sendAndroidListcastJSON(token,pushInfo);
+                } catch (Exception e) {
+                    throw new BizException("推送失败");
+                }
+            }
+        }
+        return Result.ok();
+    }
 }

+ 9 - 3
src/main/java/com/om/service/impl/VciInfoServiceImpl.java

@@ -2,6 +2,7 @@ package com.om.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.om.entity.dto.AppBaseDTO;
 import com.om.entity.dto.GuidDTO;
@@ -68,6 +69,9 @@ public class VciInfoServiceImpl extends ServiceImpl<VciInfoMapper, VciInfo> impl
     @Resource
     private HuaweiObsUtil obsUtil;
 
+    @Resource
+    private PushUtil pushUtil;
+
 
     @Override
     public Result addVci(VciInfo vciInfo) {
@@ -322,12 +326,14 @@ public class VciInfoServiceImpl extends ServiceImpl<VciInfoMapper, VciInfo> impl
         PushInfo pushInfo = new PushInfo();
         pushInfo.setPushInfoType(3);
 
-        com.om.entity.dto.VciInfo vciInfo1 = new com.om.entity.dto.VciInfo();
+    /*    com.om.entity.dto.VciInfo vciInfo1 = new com.om.entity.dto.VciInfo();
         List<SDKData> sdkData = new ArrayList<>();
         List<AppData> appData = new ArrayList<>();
+*/
 
-
-
+        String json = "{}";
+        pushInfo.setJson(JSONUtil.createObj().append("message", "有vci固件升级了"));
+       // pushUtil.sendAndroidListcastJSON();
 
         return null;
     }

+ 50 - 5
src/main/java/com/om/service/impl/WxscServiceImpl.java

@@ -1,20 +1,22 @@
 package com.om.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.PageUtil;
+import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.om.entity.dto.*;
+import com.om.entity.po.Client;
 import com.om.entity.po.Wxsc;
 import com.om.entity.vo.AppWxscQueryPageVO;
 import com.om.entity.vo.AppWxscVO;
 import com.om.exception.BadReqException;
+import com.om.exception.BizException;
 import com.om.mapper.WxscMapper;
+import com.om.service.IClientService;
 import com.om.service.IWxscService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.om.utils.AesUtil;
-import com.om.utils.HuaweiObsUtil;
-import com.om.utils.Result;
-import com.om.utils.ResultCode;
+import com.om.utils.*;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.context.annotation.Bean;
 import org.springframework.stereotype.Service;
@@ -43,6 +45,12 @@ public class WxscServiceImpl extends ServiceImpl<WxscMapper, Wxsc> implements IW
   @Resource
   private HuaweiObsUtil obsUtil;
 
+  @Resource
+  private IClientService clientService;
+
+  @Resource
+  private PushUtil pushUtil;
+
   @Override
   public Page<Wxsc> findManual(Page<Wxsc> page, String code, String title) {
     return wxscMapper.findManual(page, code, title);
@@ -131,7 +139,44 @@ public class WxscServiceImpl extends ServiceImpl<WxscMapper, Wxsc> implements IW
         MaintenanceManualInfo maintenanceManualInfo = new MaintenanceManualInfo();
         maintenanceManualInfo.setType("0");
         List<Describe> describeList = new ArrayList<>();
+        String title = wxsc.getTitle();
+        List<Wxsc> wxscList = this.lambdaQuery()
+                .eq(Wxsc::getTitle, title)
+                .eq(Wxsc::getClientCode,wxsc.getClientCode())
+                .eq(Wxsc::getBrandCode,wxsc.getBrandCode())
+                .list();
+        if (CollectionUtil.isNotEmpty(wxscList)){
+            for (Wxsc sc : wxscList) {
+                Describe describe = new Describe();
+                describe.setLanguage(sc.getLang());
+               describe.setDescription(sc.getScName());
+                describeList.add(describe);
+            }
+        }
 
-        return null;
+        maintenanceManualInfo.setDescribeList(describeList);
+        pushInfo.setJson(JSONUtil.parseObj(maintenanceManualInfo));
+
+        String clientCode = wxsc.getClientCode();
+        if (StringUtils.isNotBlank(clientCode)){
+
+            Client client = clientService.lambdaQuery()
+                    .eq(Client::getNumber, clientCode)
+                    .one();
+
+            if (BeanUtil.isEmpty(client)){
+                throw new BadReqException("该客户端编号不存在");
+            }
+            String deviceToken = client.getDeviceToken();
+            if (StringUtils.isNotBlank(deviceToken)){
+                String[] token = new String[]{deviceToken};
+                try {
+                    pushUtil.sendAndroidListcastJSON(token,pushInfo);
+                } catch (Exception e) {
+                    throw new BizException("推送失败");
+                }
+            }
+        }
+        return Result.ok();
     }
 }