Bläddra i källkod

Merge tag 'refs/tags/jenkins-back-end-594' into release

develop
release_toaliyun_real
Stormeye Wu 7 år sedan
förälder
incheckning
000511b17b
5 ändrade filer med 127 tillägg och 68 borttagningar
  1. +22
    -16
      mallinkAdmin/src/main/java/com/iformall/controller/AsyncTask.java
  2. +1
    -1
      mallinkAdmin/src/main/java/com/iformall/controller/HomeController.java
  3. +72
    -10
      mallinkAdmin/src/main/java/com/iformall/controller/WxCUserBasicInfoController.java
  4. +30
    -41
      mallinkSchedule/src/main/java/com/iformall/schedule/MsgSendingSchedule.java
  5. +2
    -0
      mallinkService/src/main/java/com/iformall/service/impl/WxCUserBasicInfoServiceImpl.java

+ 22
- 16
mallinkAdmin/src/main/java/com/iformall/controller/AsyncTask.java Visa fil

@@ -19,9 +19,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.List;
import java.util.concurrent.TimeUnit;

@Component
public class AsyncTask {
@@ -48,8 +49,18 @@ public class AsyncTask {

}

private void set_redis_value(String importKey, String allCount, String allSuccessCount, String processCount, String failCount, boolean fail) {
stringRedisTemplate.opsForHash().put(importKey, "allCount", allCount);
stringRedisTemplate.opsForHash().put(importKey, "allSuccessCount", allSuccessCount);
stringRedisTemplate.opsForHash().put(importKey, "processCount", processCount);
stringRedisTemplate.opsForHash().put(importKey, "failCount", failCount);
if(fail) {
stringRedisTemplate.expire(importKey,10, TimeUnit.SECONDS);
}
}

@Async
public void importExcelData(MultipartFile file, MallUserInfo user, String importKey, String tenantId) {
public void importExcelData(File file, MallUserInfo user, String importKey, String tenantId) {
ImportParams params = new ImportParams();
// 需要验证
params.setImportFields(new String[]{"姓名", "性别", "手机号", "微信昵称", "学历", "生日", "地址", "上次活跃时间", "注册时间", "标签", "成长值"});
@@ -60,22 +71,20 @@ public class AsyncTask {
ExcelImportResult<CUserBaseInfoT> datalist = null;

try {
datalist = ExcelImportUtil.importExcelMore(file.getInputStream(), CUserBaseInfoT.class, params);
datalist = ExcelImportUtil.importExcelMore(file, CUserBaseInfoT.class, params);
} catch (Exception e) {
stringRedisTemplate.opsForHash().put(importKey, "allCount", "1");
stringRedisTemplate.opsForHash().put(importKey, "allSuccessCount", "0");
stringRedisTemplate.opsForHash().put(importKey, "processCount", "0");
stringRedisTemplate.opsForHash().put(importKey, "failCount", "1");
set_redis_value(importKey, "1", "0", "0", "1", true);
logger.error(e.getMessage());
// 删除缓存文件
file.delete();
return;
}
// 删除缓存文件
file.delete();

if(datalist == null) {
logger.error("导入模板失败: 模板数据解析失败");
stringRedisTemplate.opsForHash().put(importKey, "allCount", "1");
stringRedisTemplate.opsForHash().put(importKey, "allSuccessCount", "0");
stringRedisTemplate.opsForHash().put(importKey, "processCount", "0");
stringRedisTemplate.opsForHash().put(importKey, "failCount", "1");
set_redis_value(importKey, "1", "0", "0", "1", true);
return;
}

@@ -87,10 +96,7 @@ public class AsyncTask {
int all_fail = failList.size();

//添加到redis里
stringRedisTemplate.opsForHash().put(importKey, "allCount", "" + total);
stringRedisTemplate.opsForHash().put(importKey, "allSuccessCount", "" + all_success);
stringRedisTemplate.opsForHash().put(importKey, "processCount", "0");
stringRedisTemplate.opsForHash().put(importKey, "failCount", "" + all_fail);
set_redis_value(importKey, "" + total, "" + all_success, "0", "" + all_fail, false);

logger.info("验证通过的数量: " + successList.size());
logger.info("验证未通过的数量: " + failList.size());
@@ -109,7 +115,7 @@ public class AsyncTask {
wxCUserBasicInfoService.importOneMem(tenantId, importKey, tagList, uBase);
});
} catch (Exception e) {
stringRedisTemplate.opsForHash().put(importKey, "allCount", "" + all_fail);
set_redis_value(importKey, "1", "0", "0", "1", true);
e.printStackTrace();
logger.error("导入模板失败:"+e.getMessage());
}


+ 1
- 1
mallinkAdmin/src/main/java/com/iformall/controller/HomeController.java Visa fil

@@ -170,7 +170,7 @@ public class HomeController extends BaseController {
if(StringUtils.isNotBlank(user.getPhone())) {
// 领导登录
user = mallUserInfoService.getByPhone(user.getPhone());
if(!isInMobileAdmin(user)) {
if(user == null && !isInMobileAdmin(user)) {
return new ResultData(ErrorCode.USER_NOT_ADMIN);
}
} else if(StringUtils.isNotBlank(user.getOpenId())) {


+ 72
- 10
mallinkAdmin/src/main/java/com/iformall/controller/WxCUserBasicInfoController.java Visa fil

@@ -25,10 +25,13 @@ import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

@@ -258,12 +261,20 @@ public class WxCUserBasicInfoController extends BaseController {

}

private void set_redis_value(String importKey, String allCount, String allSuccessCount, String processCount, String failCount, boolean fail) {
stringRedisTemplate.opsForHash().put(importKey, "allCount", allCount);
stringRedisTemplate.opsForHash().put(importKey, "allSuccessCount", allSuccessCount);
stringRedisTemplate.opsForHash().put(importKey, "processCount", processCount);
stringRedisTemplate.opsForHash().put(importKey, "failCount", failCount);
if(fail) {
stringRedisTemplate.expire(importKey,10, TimeUnit.SECONDS);
}
}


@RequestMapping("/importTemplate")
public ResultData importTemplate(@RequestParam("file") MultipartFile file) {
@PostMapping(value = "/importTemplate", consumes = "multipart/*")
public ResultData importTemplate(@RequestParam("file") MultipartFile mFile) {
logger.debug("[" + getIpAddr() + "] WxCUserBasicInfoController::importTemplate");
if (file.isEmpty()) {
if (mFile.isEmpty()) {
throw new MallinkException(Result.ERROR, "上传文件不能为空");
}
//得到当前用户ID
@@ -279,20 +290,71 @@ public class WxCUserBasicInfoController extends BaseController {
}

stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allCount", 0 + "");
stringRedisTemplate.expire(importKey,30,TimeUnit.MINUTES);
stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allSuccessCount", 0 + "");
stringRedisTemplate.opsForHash().putIfAbsent(importKey, "processCount", "");
stringRedisTemplate.opsForHash().putIfAbsent(importKey, "failCount", "");

asyncTask.importExcelData(file, user, importKey, tenantId);
String fpath = "./upload/";
File targetFile = new File(fpath);
if (!targetFile.exists()) {
targetFile.mkdirs();
}
String fileName = "1.xls";
int dot = mFile.getOriginalFilename().lastIndexOf('.');
fileName = fileName + mFile.getOriginalFilename().substring(dot, mFile.getOriginalFilename().length());

File lFile = new File(fpath + File.separator + fileName);

FileOutputStream fos = null;
BufferedInputStream fs = null;
try {
fos = new FileOutputStream(lFile);
fs = (BufferedInputStream) mFile.getInputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = fs.read(buffer)) != -1) {
fos.write(buffer, 0, len);
}
fos.close();
fs.close();
} catch (Exception e) {
stringRedisTemplate.expire(importKey,3,TimeUnit.SECONDS);
stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allCount", "1");
stringRedisTemplate.opsForHash().putIfAbsent(importKey, "failCount", "1");
logger.error(e.getMessage());
return new ResultData(ErrorCode.MEM_IMPORT_ERR.getCode(), "模板上传失败");
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
stringRedisTemplate.expire(importKey,3,TimeUnit.SECONDS);
stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allCount", "1");
stringRedisTemplate.opsForHash().putIfAbsent(importKey, "failCount", "1");
logger.error(e.getMessage());
return new ResultData(ErrorCode.MEM_IMPORT_ERR.getCode(), "模板上传失败");
}
}
if (fs != null) {
try {
fs.close();
} catch (IOException e) {
stringRedisTemplate.expire(importKey,3,TimeUnit.SECONDS);
stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allCount", "1");
stringRedisTemplate.opsForHash().putIfAbsent(importKey, "failCount", "1");
logger.error(e.getMessage());
return new ResultData(ErrorCode.MEM_IMPORT_ERR.getCode(), "模板上传失败");
}
}
}

asyncTask.importExcelData(lFile, user, importKey, tenantId);

stringRedisTemplate.expire(importKey,30,TimeUnit.MINUTES);
return new ResultData(Result.SUCCESS, "模板正在导入");
}





@GetMapping("/queryTemplateCount")
public ResultData queryTemplateCount() {
String importKey = importMemPrev + getUser().getId();


+ 30
- 41
mallinkSchedule/src/main/java/com/iformall/schedule/MsgSendingSchedule.java Visa fil

@@ -1,22 +1,28 @@
package com.iformall.schedule;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.iformall.domain.po.WxMsg;
import com.iformall.domain.po.WxMsgConfig;
import com.iformall.enums.EnumMsgSendStatus;
import com.iformall.enums.EnumMsgStatus;
import com.iformall.enums.EnumVerifyCode;
import com.iformall.exception.MallinkException;
import com.iformall.mapper.WxMsgConfigMapper;
import com.iformall.mapper.WxMsgMapper;
import com.iformall.service.PushLimitService;
import com.iformall.utils.*;
import com.iformall.utils.DateUtils;
import com.iformall.utils.WiwideUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.*;
import java.util.List;

/**
* @author gongbiao
*/
@Component
public class MsgSendingSchedule {

@@ -28,79 +34,62 @@ public class MsgSendingSchedule {
@Autowired
private WxMsgConfigMapper wxMsgConfigMapper;

@Autowired
private PushLimitService pushLimitService;


@Scheduled(cron = "0 1 * * * ?") // 每小时第一分钟执行
/**
* 每小时第一分钟执行
*/
@Scheduled(cron = "0 1 * * * ?")
public void sendmsgschedule() {

logger.info("sendmsg定时任务启动");

String systemTime = DateUtils.getSystemTime("yyyy-MM-dd HH:00:00");
WxMsg wxMsg = new WxMsg();
wxMsg.setIsright(0);
wxMsg.setSendtime(systemTime);
List<WxMsg> list = wxMsgMapper.findList(wxMsg);

for(WxMsg msg:list){
boolean checkTime = false;
try {
checkTime = pushLimitService.checkSendTime(wxMsg.getTenantId());
} catch (MallinkException e) {
logger.error(e.getMessage());
}
if (checkTime) {
sendmsg(msg);
}
logger.info("将要发送的短信列表:" + JSONArray.toJSONString(list));
for (WxMsg msg : list) {
sendmsg(msg);
}

logger.info("sendmsg定时任务结束");
}

public void sendmsg(WxMsg wxMsg){



public void sendmsg(WxMsg wxMsg) {
logger.info("发送短信开始----------");
//从短信配置中查询密钥 bid 等信息
WxMsgConfig wxMsgConfig = new WxMsgConfig();
wxMsgConfig.setTenantId(wxMsg.getTenantId());
List<WxMsgConfig> wxMsgConfigs = wxMsgConfigMapper.findList(wxMsgConfig);
if (wxMsgConfigs.size() == 0) return;
if (wxMsgConfigs.size() == 0) {
logger.info("短信相关配置不存在");
return;
}
wxMsgConfig = wxMsgConfigs.get(0);

if(wxMsgConfig.getRemains()==0){
if (wxMsgConfig.getRemains() == 0) {
logger.info("短信数量为0");
return;
}

if(wxMsgConfig.getRemains()<wxMsg.getExpectSendNumber()){
if (wxMsgConfig.getRemains() < wxMsg.getExpectSendNumber()) {
logger.info("短信数量不足");
return;
}


String secret = wxMsgConfig.getSecret();
String bid = wxMsgConfig.getBid();
String publickey = wxMsgConfig.getPublickey();

String phone = wxMsg.getPhones();
String signature = wxMsg.getSignature();
String msg = wxMsg.getMsg();
String notifyUrl = wxMsgConfig.getNotifyurl();
String result = WiwideUtil.sendMsg(secret, bid, publickey, phone, signature, msg, notifyUrl,EnumVerifyCode.NO.getCode().toString());
String result = WiwideUtil.sendMsg(secret, bid, publickey, phone, signature, msg, notifyUrl, EnumVerifyCode.NO.getCode().toString());
logger.info("短信返回结果:" + result);
JSONObject jsonObjectResult = JSONObject.parseObject(result);
String ret = jsonObjectResult.get("ret").toString();

if (ret.equals("1")) {
wxMsg.setSendstatus(1);
wxMsg.setSendstatus(EnumMsgSendStatus.MSG_SEND_SUCCESS.getCode());
} else {
wxMsg.setSendstatus(0);
wxMsg.setSendstatus(EnumMsgSendStatus.MSG_SEND_FAIL.getCode());
}

wxMsg.setStatus(1);
wxMsg.setStatus(EnumMsgStatus.MSG_STATUS_SENDED.getCode());
wxMsgMapper.updateByPrimaryKeySelective(wxMsg);
logger.info("短信发送结束:" + jsonObjectResult.toJSONString());
}

}

+ 2
- 0
mallinkService/src/main/java/com/iformall/service/impl/WxCUserBasicInfoServiceImpl.java Visa fil

@@ -43,6 +43,7 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

@Service
public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService {
@@ -609,6 +610,7 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService {

//记数
stringRedisTemplate.opsForHash().increment(importKey,"processCount",1);
stringRedisTemplate.expire(importKey,10, TimeUnit.SECONDS);
}

@Override


Laddar…
Avbryt
Spara