yaozhixue 2 years ago
parent
commit
2564eb6f05

+ 76 - 0
src/main/java/com/zfire/jiasm/syncdata/sendmessage/MarketingSMSSelfTask.java

@@ -0,0 +1,76 @@
+package com.zfire.jiasm.syncdata.sendmessage;
+
+
+import com.zfire.jiasm.syncdata.service.SMSService;
+import com.zfire.jiasm.syncdata.utils.SMSSelfManager;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 自建短信发送类
+ * 数据源: fa_marketing_sms
+ * 需排除禁发营销短信的手机号 fa_exception_mobile
+ * yaozx 
+ */
+@Component
+@Slf4j
+public class MarketingSMSSelfTask {
+	@Autowired
+	private SMSSelfManager smsSelfManager;
+	@Autowired
+	private SMSService smsService;
+	@Value("${SMSSelf_marketing_templateId}")
+	private String templateId;
+
+	@Scheduled(fixedRateString = "${SMSSelf_marketing_Rate}")
+	private void process() {
+		try {
+			log.info("营销短信发送.....................开始");
+			List<String> mobiles = new ArrayList<>();
+			List<Map<String, Object>> result = smsService.getTaskMarkeginData4Self();
+
+			List<Map<String, Object>> exception = smsService.getTaskExceptionData();
+			for (Map<String, Object> row : exception) {
+				mobiles.add((String) row.get("mobile"));
+			}
+
+			for (Map<String, Object> row : result) {
+				String synTaskNo = (String) row.get("syn_task_no");
+				Integer synTimes = (Integer) row.get("syn_times");
+				Long yhlb = (Long) row.get("yhlb");
+				String phoneNo = (String) row.get("sjid");
+
+				// 禁发送处理
+				if (mobiles.contains(phoneNo)){
+					smsService.stopSendUpdate("fa_marketing_sms", 99, synTaskNo, "该用户已屏蔽此类短信");
+					continue;
+				}
+
+				// 不需要控制发送时间段判断 (!smsSelfManager.checkCanSend())
+
+				try {
+					String[] datas = new String[1];
+					datas[0] = (String) row.get("fsnr");
+					smsSelfManager.templateSMS(phoneNo, templateId, (String) row.get("syn_task_no"),
+							(String) row.get("fsma"), datas);
+					smsService.successUpdate("fa_marketing_sms", synTaskNo);
+				} catch (Exception ex) {
+					log.error("营销短信发送失败[syn_task_no=" + synTaskNo + "]", ex);
+					synTimes++;
+					smsService.errorUpdate("fa_marketing_sms", synTimes, synTaskNo, ex.getMessage());
+				}
+			}
+			log.info("营销短信发送.....................结束");
+		} catch (Exception ex) {
+			log.error("营销短信发送失败", ex);
+		}
+	}
+
+}

+ 4 - 0
src/main/java/com/zfire/jiasm/syncdata/service/SMSService.java

@@ -13,4 +13,8 @@ public interface SMSService {
 	
 	public void errorUpdate(String tabName,int synTimes,String synTaskNo,String errorMessage);
 
+	public List<Map<String, Object>> getTaskMarkeginData4Self();
+	public List<Map<String, Object>> getTaskExceptionData();
+	public void stopSendUpdate(String tabName,int synTimes,String synTaskNo,String errorMessage);
+
 }

+ 21 - 0
src/main/java/com/zfire/jiasm/syncdata/service/impl/SMSServiceImpl.java

@@ -40,6 +40,27 @@ public class SMSServiceImpl implements SMSService {
 	public void errorUpdate(String tabName, int synTimes, String synTaskNo, String errorMessage) {
 		jdbcTemplate.update("update " + tabName + " set syn_times=?,syn_time=?,syn_err_msg=? where syn_task_no=?",
 				new Object[] { synTimes, new Date(), errorMessage, synTaskNo });
+	}
+
+	@Override
+	public List<Map<String, Object>> getTaskMarkeginData4Self(){
+		List<Map<String, Object>> result = jdbcTemplate
+				.queryForList("SELECT * FROM fa_marketing_sms where syn_status=0 and "
+						+ "(syn_times is null  or syn_times<3) order by syn_req_time ");
+		return result;
+	}
+
+	@Override
+	public List<Map<String, Object>> getTaskExceptionData(){
+		List<Map<String, Object>> result = jdbcTemplate
+				.queryForList("SELECT * FROM fa_exception_mobile ");
+		return result;
+	}
+
+	@Override
+	public void stopSendUpdate(String tabName,int synStatus,String synTaskNo,String errorMessage){
+		jdbcTemplate.update("update " + tabName + " set syn_status=?,syn_time=?,syn_err_msg=? where syn_task_no=?",
+				new Object[] { synStatus, new Date(), errorMessage, synTaskNo });
 
 	}