Pārlūkot izejas kodu

修改分页问题

Administrator 1 gadu atpakaļ
vecāks
revīzija
c12e561ab6

+ 35 - 3
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/SendSmsController.java

@@ -11,6 +11,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.List;
+
 /**
  * @Author: tjf
  * @Date: 2023/10/13 17:15
@@ -22,15 +24,45 @@ public class SendSmsController {
 
     @Autowired
     private IInvestigateUserService investigateUserService;
+    @Autowired
+    private IInvestigateTableService iInvestigateTableService;
 
     /**
      * 给对应考察团发送密码短信
+     *
      * @param investigateUser
      * @return
      */
     @PostMapping("/investigateTable")
-    public AjaxResult sendSmsInvestigateTable(@RequestBody InvestigateUser investigateUser)
-    {
-        return  investigateUserService.sendSmsInvestigateTable(investigateUser);
+    public AjaxResult sendSmsInvestigateTable(@RequestBody InvestigateUser investigateUser) {
+        return investigateUserService.sendSmsInvestigateTable(investigateUser);
+    }
+
+    /**
+     * 给对应考察团发送通知短信
+     *
+     * @param
+     * @return
+     */
+    @PostMapping("/sendBatchSmsTable")
+    public AjaxResult investigateTableNotice(InvestigateTable investigateTable) {
+        Long investigateTableId = investigateTable.getInvestigateTableId();
+        List<InvestigateUser> investigateUserList = investigateTable.getInvestigateUserList();
+        iInvestigateTableService.sendBatchSmsTable(investigateTableId, investigateUserList);
+        return AjaxResult.success();
+    }
+
+    /**
+     * 给对应考察团发送更新通知短信
+     *
+     * @param
+     * @return
+     */
+    @PostMapping("/sendBatchSmsTableUpdate")
+    public AjaxResult sendBatchSmsTableUpdate(InvestigateTable investigateTable) {
+        Long investigateTableId = investigateTable.getInvestigateTableId();
+        List<InvestigateUser> investigateUserList = investigateTable.getInvestigateUserList();
+        iInvestigateTableService.sendBatchSmsTableUpdate(investigateTableId, investigateUserList);
+        return AjaxResult.success();
     }
 }

+ 15 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/IInvestigateTableService.java

@@ -65,4 +65,19 @@ public interface IInvestigateTableService
      * @return 结果
      */
     public int deleteInvestigateTableById(Long id);
+
+    /**
+     *发送考察团新增短信
+     * @param investigateTableId
+     * @param investigateUserList
+     * @return
+     */
+    void sendBatchSmsTable(Long investigateTableId, List<InvestigateUser> investigateUserList);
+
+    /**
+     * 发送考察团更新短信
+     * @param investigateTableId
+     * @param investigateUserList
+     */
+    void sendBatchSmsTableUpdate(Long investigateTableId, List<InvestigateUser> investigateUserList);
 }

+ 55 - 6
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/InvestigateTableServiceImpl.java

@@ -33,9 +33,6 @@ import com.ruoyi.system.mapper.InvestigateTableMapper;
 import com.ruoyi.system.domain.InvestigateTable;
 import com.ruoyi.system.service.IInvestigateTableService;
 import org.springframework.web.multipart.MultipartFile;
-
-import javax.annotation.Resource;
-
 import static com.ruoyi.common.config.RuoYiConfig.getProfile;
 
 /**
@@ -147,7 +144,7 @@ public class InvestigateTableServiceImpl implements IInvestigateTableService {
                 investigateUser.setInvestigateId(investigateTable.getInvestigateTableId());
             }
             investigateUserMapper.batchDispositionUser(investigateUserList);
-            //发送短信
+            //发送短信 新增不能立刻发送短信
             sendBatchSmsTable(investigateTableId, investigateUserList);
         }
 
@@ -222,7 +219,60 @@ public class InvestigateTableServiceImpl implements IInvestigateTableService {
         investigateDispositionTableMapper.batchDispositionTable(investigateDispositionTableList);
     }
 
-    public static void sendBatchSmsTable(Long investigateTableId, List<InvestigateUser> investigateUserList) {
+    @Override
+    public  void sendBatchSmsTable(Long investigateTableId, List<InvestigateUser> investigateUserList) {
+        for (InvestigateUser investigateUser : investigateUserList) {
+            StringBuffer phoneNumberJson = new StringBuffer();
+            StringBuffer templateParamJson = new StringBuffer();
+            StringBuffer signNameJson = new StringBuffer();
+            phoneNumberJson.append("[");
+            templateParamJson.append("[");
+            signNameJson.append("[");
+
+            // 防止有空行,手机号是必须要有的
+            String phone = investigateUser.getPhonenumber();
+            if (StringUtils.isEmpty(phone)) {
+                continue;
+            }
+            phoneNumberJson.append("\"" + phone + "\",");
+            signNameJson.append("\"中新云\",");
+            //发送短信
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.put("number", investigateTableId);
+            templateParamJson.append(jsonObject).append(",");
+
+
+            phoneNumberJson.deleteCharAt(phoneNumberJson.length() - 1);//移除最后一个逗号字符,
+            templateParamJson.deleteCharAt(templateParamJson.length() - 1);//移除最后一个逗号字符
+            signNameJson.deleteCharAt(signNameJson.length() - 1);
+            phoneNumberJson.append("]");
+            templateParamJson.append("]");
+            signNameJson.append("]");
+
+            SendBatchSmsRequest sendBatchSmsRequest = new SendBatchSmsRequest();
+            //组装电话号码
+            sendBatchSmsRequest.setPhoneNumberJson(phoneNumberJson.toString());
+            //签名名称
+            sendBatchSmsRequest.setSignNameJson(signNameJson.toString());
+            //替换参数
+            sendBatchSmsRequest.setTemplateParamJson(templateParamJson.toString());
+            //固定的模板名称
+            sendBatchSmsRequest.setTemplateCode("SMS_463622836");
+            long startTimeSend = System.currentTimeMillis();
+            SendBatchSmsResponse sendBatchSmsResponse = SendSmsUtils.sendBatchSms(sendBatchSmsRequest);
+            long endTimeSend = System.currentTimeMillis() - startTimeSend;
+            System.out.println("执行批量下发短信接口请求:" + endTimeSend + "ms");
+            String code = sendBatchSmsResponse.getBody().getCode();
+            if (sendBatchSmsResponse.getBody().getCode() != null && "OK".equals(code)) {
+                System.out.println("批量短信发送成功");
+            } else {
+                System.out.println("批量短信发送失败");
+            }
+        }
+    }
+
+    @Override
+    public  void sendBatchSmsTableUpdate(Long investigateTableId, List<InvestigateUser> investigateUserList) {
         for (InvestigateUser investigateUser : investigateUserList) {
             StringBuffer phoneNumberJson = new StringBuffer();
             StringBuffer templateParamJson = new StringBuffer();
@@ -251,7 +301,6 @@ public class InvestigateTableServiceImpl implements IInvestigateTableService {
             templateParamJson.append("]");
             signNameJson.append("]");
 
-            long startTimeSql = System.currentTimeMillis();
             SendBatchSmsRequest sendBatchSmsRequest = new SendBatchSmsRequest();
             //组装电话号码
             sendBatchSmsRequest.setPhoneNumberJson(phoneNumberJson.toString());