Przeglądaj źródła

4/10 导入专利

lwhhszx 1 rok temu
rodzic
commit
66439def3d

+ 13 - 0
src/main/java/com/example/xiaoshiweixinback/business/common/Response.java

@@ -144,4 +144,17 @@ public class Response {
         this.code = responseEnum.getCode();
         this.message = responseEnum.getMessage();
     }
+
+    /**无权限
+     *
+     * @param message
+     * @return
+     */
+    public static Response noAdmin(String message) {
+        Response response = new Response();
+        response.setCode(ResponseEnum.NOT_PERMISSION.getCode());
+        response.setData(Boolean.FALSE);
+        response.setMessage(message);
+        return response;
+    }
 }

+ 27 - 0
src/main/java/com/example/xiaoshiweixinback/business/config/MailConstants.java

@@ -0,0 +1,27 @@
+package com.example.xiaoshiweixinback.business.config;
+
+public class MailConstants {
+    //消息投递中
+    public static final Integer DELIVERING = 0;
+
+    //消息投成功
+    public static final Integer SUCCESS = 1;
+
+    //消息投递失败
+    public static final Integer FAILURE = 2;
+
+    //最大重试次数
+    public static final Integer MAX_TRY_COUNT = 2;
+
+    //消息超时时间
+    public static final Integer MSG_TIMEOUT = 1;
+
+    //队列
+
+    //交换机
+    public static final String MAIL_EXCHANGE_NAME = "mail.exchange";
+
+    //路由键
+    public static final String MAIL_ROUTING_KEY_NAME = "mail.routing.key";
+
+}

+ 26 - 0
src/main/java/com/example/xiaoshiweixinback/business/utils/RabbitMQUtils.java

@@ -0,0 +1,26 @@
+package com.example.xiaoshiweixinback.business.utils;
+
+import com.example.xiaoshiweixinback.business.config.MailConstants;
+import org.springframework.amqp.rabbit.connection.CorrelationData;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import java.util.Map;
+
+@Component
+public class RabbitMQUtils {
+    @Autowired
+    private RabbitTemplate rabbitTemplate;
+    @Value("${queueName}")
+     private String queueName;
+    /**
+     * 向用户邮箱发送短信
+     *
+     * @param map 所需参数
+     */
+    public void sendEmailMessage(Map<String, Object> map) {
+        rabbitTemplate.convertAndSend(MailConstants.MAIL_EXCHANGE_NAME, MailConstants.MAIL_ROUTING_KEY_NAME, map, new CorrelationData("1"));
+    }
+}

+ 1 - 1
src/main/java/com/example/xiaoshiweixinback/controller/ImportPatentController.java

@@ -24,7 +24,7 @@ public class ImportPatentController {
 private final GetPatentFromSzService getPatentFromSzService;
     @Operation(summary = "查询会员")
     @GetMapping("/import")
-    private Response importPatent(String path) {
+    private Response importPatent(String path) throws Exception {
         getPatentFromSzService.test(path);
         return Response.success("records");
     }

+ 6 - 3
src/main/java/com/example/xiaoshiweixinback/controller/ProductController.java

@@ -47,9 +47,12 @@ public class ProductController {
     public Response follow(@RequestBody AssoPersonProductDTO assoPersonProductDTO){
         Records records = new Records();
         Integer id = assoPersonProductService.add(assoPersonProductDTO);
-        if (id.equals(-1)) {
-            return Response.error("未查询到登陆人");
-        }
+    if(id ==null){
+        return Response.noPermissions("已超过可关注数量");
+    }
+    if(id.equals(-2)){
+        return Response.noPermissions("无关注产品的权益");
+    }
         records.setData(id);
         return Response.success(records);
     }

+ 4 - 4
src/main/java/com/example/xiaoshiweixinback/controller/VIPController.java

@@ -26,21 +26,21 @@ public class VIPController {
 
     @Operation(summary = "查询会员")
     @PostMapping("/queryAllVip")
-    private Response getAllvip() {
+    public Response getAllvip() {
         Records records = vipService.getAllVip();
         return Response.success(records);
     }
 
     @Operation(summary = "激活会员")
     @PostMapping("/activeVip")
-    private Response activeVip(@RequestBody ActiveVipDTO activeVipDTO) {
+    public Response activeVip(@RequestBody ActiveVipDTO activeVipDTO) {
         vipService.activateVIP(null);
         return Response.success("激活成功");
     }
 
     @Operation(summary = "查询会员权益")
     @GetMapping("/getVipRights")
-    private Response getVipRights() {
+    public Response getVipRights() {
         Records records = new Records();
         List<FunctionRightVO> functionRightVOList = vipService.getVipRights();
         records.setData(functionRightVOList);
@@ -51,7 +51,7 @@ public class VIPController {
     @checkLogin
     @Operation(summary = "查询登录人会员权益")
     @GetMapping("/getPersonRights")
-    private Response getPersonRights() {
+    public Response getPersonRights() {
         Records records = new Records();
         List<PersonFunctionVO> functionRightVOList = vipService.getPersonRights();
         records.setData(functionRightVOList);

+ 11 - 0
src/main/java/com/example/xiaoshiweixinback/entity/shortMessage/ShortMessageVO.java

@@ -0,0 +1,11 @@
+package com.example.xiaoshiweixinback.entity.shortMessage;
+
+import lombok.Data;
+
+@Data
+public class ShortMessageVO {
+    private String phoneNum;
+    private String templateParam;
+    private String signName;
+    private String templateCode;
+}

+ 6 - 2
src/main/java/com/example/xiaoshiweixinback/service/AssoPersonProductService.java

@@ -32,14 +32,18 @@ public class AssoPersonProductService extends ServiceImpl<AssoPersonProductMappe
         PersonnelVO personnelVO = cacheUtil.getLoginUser(LoginUtils.getToken());
         AssoPersonFunction assoPersonFunction = vipService.getAssoPersonFunction("6");
         if (assoPersonFunction == null) {
-            return null;
+          return  -2;
         }
+        Integer totalNum = 5;
         FunctionConfig functionConfig = JSON.parseObject(assoPersonFunction.getFunctionParameter(), FunctionConfig.class);
+        totalNum = functionConfig.getCanGetNum();
+
         //查看关注的数量
         LambdaQueryWrapper<AssoPersonProduct> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(AssoPersonProduct::getPersonUuid, personnelVO.getUuid());
         Long total = this.count(queryWrapper);
-        if (total >= functionConfig.getCanGetNum()) {
+
+        if (total >= totalNum) {
             return null;
         }
         if (ToolUtil.isNotEmpty(personnelVO)) {

+ 75 - 0
src/main/java/com/example/xiaoshiweixinback/service/common/NoticeService.java

@@ -0,0 +1,75 @@
+package com.example.xiaoshiweixinback.service.common;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.aliyuncs.DefaultAcsClient;
+import com.aliyuncs.IAcsClient;
+import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
+import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
+import com.aliyuncs.exceptions.ClientException;
+import com.aliyuncs.profile.DefaultProfile;
+import com.example.xiaoshiweixinback.business.utils.RabbitMQUtils;
+import com.example.xiaoshiweixinback.entity.shortMessage.ShortMessageVO;
+import com.google.gson.Gson;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+@Service
+public class NoticeService {
+    @Autowired
+    private RabbitMQUtils rabbitMQUtils;
+
+
+    @Value("${SMS.regionId}")
+    private String regionId;
+
+    @Value("${SMS.accessKeyId}")
+    private String accessKeyId;
+
+    @Value("${SMS.secret}")
+    private String secret;
+    public String noticeAdminToHandle() {
+        Map<String, Object> map = new LinkedHashMap<>();
+        map.put("title", "任务通知");
+        String name = "";
+        //判断是否为内部人员
+
+
+            map.put("template", "mail/SyneryInside.html");
+            map.put("value1", "张三");
+            map.put("email", "2232623707@qq.com");
+            map.put("img", "/logo.png");
+            map.put("value2", "11");
+        rabbitMQUtils.sendEmailMessage(map);
+        return name;
+    }
+
+    public void sendShortMessage(ShortMessageVO shortMessageVO){
+        DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, secret);
+        IAcsClient client = new DefaultAcsClient(profile);
+        SendSmsRequest request = new SendSmsRequest();
+//        String templateParam = "{\"code\":\"" + random + "\",\"message\":\"" + "为您的登陆验证码" + "\",\"validTime\":\"" + "5分钟" + "\"}";
+        String templateParam =shortMessageVO.getTemplateParam();
+        request.setPhoneNumbers(shortMessageVO.getPhoneNum());//接收短信的手机号码
+        request.setSignName(shortMessageVO.getSignName());//短信签名名称
+        request.setTemplateCode(shortMessageVO.getTemplateCode());//短信模板CODE
+        request.setTemplateParam(templateParam);//短信模板变量对应的实际值
+        try {
+            SendSmsResponse response = client.getAcsResponse(request);
+            System.out.println(new Gson().toJson(response));
+        } catch (ClientException e) {
+            System.out.println("ErrCode:" + e.getErrCode());
+            System.out.println("ErrMsg:" + e.getErrMsg());
+            System.out.println("RequestId:" + e.getRequestId());
+        }
+    }
+
+}

+ 1 - 2
src/main/java/com/example/xiaoshiweixinback/service/importPatent/CommonService.java

@@ -38,7 +38,7 @@ public class CommonService {
             //获取 applicationHome 内的路径 ...\target\classes 到这一层级下
             File fileTem = ah.getSource();
             //获取 file的parentFile 即最后一级之前的所有层级路径(包括盘符) 这里能获得到的最终层级为  ...\target 后续用FILE_SEPARATOR(系统路径分割通配符 即 "\") 以及fileName拼接生成存放文件的目录层级 即为根目录 root
-            String rootPath = fileTem.getParentFile().toString() + FileUtils.FILE_SEPARATOR+"jsons/";
+            String rootPath = fileTem.getParentFile().toString() + FileUtils.FILE_SEPARATOR + "jsons/";
 //            String filePath = fileUtils.getPath("/11.docx");
             File file = new File(rootPath + fileName);
             Reader reader = new InputStreamReader(new FileInputStream(file), "utf-8");
@@ -57,5 +57,4 @@ public class CommonService {
     }
 
 
-
 }

+ 11 - 7
src/main/java/com/example/xiaoshiweixinback/service/importPatent/excel/GetPatentFromSzService.java

@@ -13,6 +13,7 @@ import com.example.xiaoshiweixinback.entity.dto.importTaskModel.ImportTaskText;
 import com.example.xiaoshiweixinback.entity.dto.patent.UploadPatentWebDTO;
 import com.example.xiaoshiweixinback.service.importPatent.GetPatentFromExcelService;
 import com.example.xiaoshiweixinback.service.importPatent.GetPatentPictureFromExcelService;
+import com.example.xiaoshiweixinback.service.importPatent.SavePatentToEsService;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.ss.usermodel.Drawing;
 import org.apache.poi.ss.usermodel.PictureData;
@@ -36,9 +37,11 @@ private ExcuteUploadSettingService excuteUploadSettingService;
 private GetPatentFromExcelService getPatentFromExcelService;
 @Autowired
 private GetPatentPictureFromExcelService getPatentPictureFromExcelService;
-    public void test(String path) {
-        try {
-            File tempFile = new File("D:\\usa_patent\\202101-2380\\"+path);
+@Autowired
+private SavePatentToEsService savePatentToEsService;
+    public void test(String path) throws  Exception {
+
+            File tempFile = new File(path);
 
             Sheet sheet = ReadExcelUtils.readExcel(tempFile);
             int total = sheet.getPhysicalNumberOfRows() - 1;
@@ -66,14 +69,15 @@ private GetPatentPictureFromExcelService getPatentPictureFromExcelService;
                         File file = FileUtils.getFileByBytes(data, picName, "." + ext);
                         getPatentPictureFromExcelService.tem(file, uploadParamsVO.getPatent(),i);
                     }
-
+                UploadPatentWebDTO uploadPatentWebDTO =new UploadPatentWebDTO();
+                uploadPatentWebDTO.setPatent(uploadParamsVO.getPatent());
+                savePatentToEsService.saveOrUpdate(uploadPatentWebDTO);
+                System.out.println(r);
             }
 
 
             //获得总列数
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
+
 
 
     }

+ 3 - 2
src/main/resources/application-dev.yml

@@ -67,7 +67,7 @@ PCSUrl: http://localhost:8871
 OPSUrl: http://139.224.24.90:5001
 PASUrl: http://localhost:8877
 FMSUrl: http://localhost:8802
-VectorUrl: http://192.168.1.19:8000
+VectorUrl: http://139.224.24.90:8000
 FileSource: 5
 
 ##################  短信 ####################
@@ -81,4 +81,5 @@ WeChat:
   appId: wxaefb842bd0b93ff0
   appSecret: 89fe0fb96472548d48f63b2f5c956537
 
-Keypath: C:\Users\admin\Desktop\小程序证书\1673179188_20240408_cert\apiclient_key.pem
+Keypath: C:\Users\admin\Desktop\小程序证书\1673179188_20240408_cert\apiclient_key.pem
+queueName: emailProd.queue

+ 1 - 1
src/main/resources/application.yml

@@ -20,7 +20,7 @@ spring:
       max-file-size: 1000MB
       max-request-size: 1000MB
   profiles:
-    active: dev
+    active: prodNetIn
   jackson:
     default-property-inclusion: non_null
     serialization:

+ 1 - 1
src/main/resources/mapper/ProductMapper.xml

@@ -21,7 +21,7 @@
                 </foreach>
             </if>
             <if test="getProductDTO.current!=null and getProductDTO.size!=null">
-                limit ${(getProductDTO.current -1)*getProductDTO.size},${getProductDTO.current*getProductDTO.size}
+                limit ${(getProductDTO.current -1)*getProductDTO.size},${getProductDTO.size}
             </if>
         </where>
 

+ 34 - 0
src/test/java/com/example/xiaoshiweixinback/NoticeServiceTest.java

@@ -0,0 +1,34 @@
+package com.example.xiaoshiweixinback;
+
+import com.example.xiaoshiweixinback.entity.shortMessage.ShortMessageVO;
+import com.example.xiaoshiweixinback.service.common.NoticeService;
+import com.example.xiaoshiweixinback.service.importPatent.excel.ImportProduct;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Lazy;
+
+@SpringBootTest
+public class NoticeServiceTest {
+    @Autowired
+    private NoticeService noticeService;
+
+
+    @Test
+    public void test1() {
+        System.out.println("a");
+    }
+
+
+    @Test
+    public void sendShortMessage() {
+        ShortMessageVO shortMessageVO =new ShortMessageVO();
+        shortMessageVO.setPhoneNum("17625547167");
+        shortMessageVO.setSignName("小世数字科技");
+        shortMessageVO.setTemplateCode("SMS_465645339");
+        String templateParam = "{\"code\":\"" + "123456" + "\"}";
+        shortMessageVO.setTemplateParam(templateParam);
+        noticeService.sendShortMessage(shortMessageVO);
+        System.out.println("a");
+    }
+}