From 7f9eaaec74f3b36e8973a3f225aad06166b4964b Mon Sep 17 00:00:00 2001 From: gongbiao Date: Fri, 11 Jan 2019 15:49:12 +0800 Subject: [PATCH 1/5] =?UTF-8?q?[=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1][?= =?UTF-8?q?=E4=BF=AE=E6=94=B9][=E7=9F=AD=E4=BF=A1=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E5=8F=91=E9=80=81=E5=8A=A0=E5=85=A5=E6=97=A5=E5=BF=97=E4=BF=A1?= =?UTF-8?q?=E6=81=AF]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iformall/schedule/MsgSendingSchedule.java | 53 +++++++------------ 1 file changed, 20 insertions(+), 33 deletions(-) diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/MsgSendingSchedule.java b/mallinkSchedule/src/main/java/com/iformall/schedule/MsgSendingSchedule.java index ef745c1c2..b5f52bacd 100644 --- a/mallinkSchedule/src/main/java/com/iformall/schedule/MsgSendingSchedule.java +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/MsgSendingSchedule.java @@ -1,21 +1,24 @@ 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; @Component public class MsgSendingSchedule { @@ -32,75 +35,59 @@ public class MsgSendingSchedule { private PushLimitService pushLimitService; - @Scheduled(cron = "0 1 * * * ?") // 每小时第一分钟执行 + @Scheduled(cron = "0 46 * * * ?") // 每小时第一分钟执行 public void sendmsgschedule() { - logger.info("sendmsg定时任务启动"); - - String systemTime = DateUtils.getSystemTime("yyyy-MM-dd HH:00:00"); + String systemTime = DateUtils.getSystemTime("yyyy-MM-dd 14:00:00"); WxMsg wxMsg = new WxMsg(); wxMsg.setIsright(0); wxMsg.setSendtime(systemTime); List list = wxMsgMapper.findList(wxMsg); - + logger.info("将要发送的短信列表:" + JSONArray.toJSONString(list)); for(WxMsg msg:list){ - boolean checkTime = false; - try { - checkTime = pushLimitService.checkSendTime(wxMsg.getTenantId()); - } catch (MallinkException e) { - logger.error(e.getMessage()); - } - if (checkTime) { - sendmsg(msg); - } + sendmsg(msg); } - logger.info("sendmsg定时任务结束"); } public void sendmsg(WxMsg wxMsg){ - - - + logger.info("发送短信开始----------"); //从短信配置中查询密钥 bid 等信息 WxMsgConfig wxMsgConfig = new WxMsgConfig(); wxMsgConfig.setTenantId(wxMsg.getTenantId()); List wxMsgConfigs = wxMsgConfigMapper.findList(wxMsgConfig); - if (wxMsgConfigs.size() == 0) return; + if (wxMsgConfigs.size() == 0) { + logger.info("短信相关配置不存在"); + return; + } wxMsgConfig = wxMsgConfigs.get(0); - if(wxMsgConfig.getRemains()==0){ logger.info("短信数量为0"); return; } - if(wxMsgConfig.getRemains() Date: Fri, 11 Jan 2019 15:52:11 +0800 Subject: [PATCH 2/5] =?UTF-8?q?[=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1][?= =?UTF-8?q?=E4=BF=AE=E6=94=B9][=E7=9F=AD=E4=BF=A1=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E5=8F=91=E9=80=81=E5=8A=A0=E5=85=A5=E6=97=A5=E5=BF=97=E4=BF=A1?= =?UTF-8?q?=E6=81=AF]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iformall/schedule/MsgSendingSchedule.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/MsgSendingSchedule.java b/mallinkSchedule/src/main/java/com/iformall/schedule/MsgSendingSchedule.java index b5f52bacd..d01adca38 100644 --- a/mallinkSchedule/src/main/java/com/iformall/schedule/MsgSendingSchedule.java +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/MsgSendingSchedule.java @@ -20,6 +20,9 @@ import org.springframework.stereotype.Component; import java.util.List; +/** + * @author gongbiao + */ @Component public class MsgSendingSchedule { @@ -31,26 +34,25 @@ public class MsgSendingSchedule { @Autowired private WxMsgConfigMapper wxMsgConfigMapper; - @Autowired - private PushLimitService pushLimitService; - - - @Scheduled(cron = "0 46 * * * ?") // 每小时第一分钟执行 + /** + * 每小时第一分钟执行 + */ + @Scheduled(cron = "0 1 * * * ?") public void sendmsgschedule() { logger.info("sendmsg定时任务启动"); - String systemTime = DateUtils.getSystemTime("yyyy-MM-dd 14:00:00"); + String systemTime = DateUtils.getSystemTime("yyyy-MM-dd HH:00:00"); WxMsg wxMsg = new WxMsg(); wxMsg.setIsright(0); wxMsg.setSendtime(systemTime); List list = wxMsgMapper.findList(wxMsg); logger.info("将要发送的短信列表:" + JSONArray.toJSONString(list)); - for(WxMsg msg: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(); @@ -61,11 +63,11 @@ public class MsgSendingSchedule { return; } wxMsgConfig = wxMsgConfigs.get(0); - if(wxMsgConfig.getRemains()==0){ + if (wxMsgConfig.getRemains() == 0) { logger.info("短信数量为0"); return; } - if(wxMsgConfig.getRemains() Date: Fri, 11 Jan 2019 17:53:18 +0800 Subject: [PATCH 3/5] =?UTF-8?q?[=E4=B8=8A=E4=BC=A0=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E5=BC=82=E5=B8=B8][=E4=BF=AE=E6=94=B9]:redis=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/iformall/controller/AsyncTask.java | 38 +++++---- .../WxCUserBasicInfoController.java | 82 ++++++++++++++++--- 2 files changed, 94 insertions(+), 26 deletions(-) diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/AsyncTask.java b/mallinkAdmin/src/main/java/com/iformall/controller/AsyncTask.java index d9c84b3cd..e7598f780 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/AsyncTask.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/AsyncTask.java @@ -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 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()); } diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/WxCUserBasicInfoController.java b/mallinkAdmin/src/main/java/com/iformall/controller/WxCUserBasicInfoController.java index 799c0dd29..888179273 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/WxCUserBasicInfoController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/WxCUserBasicInfoController.java @@ -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(); From 628c9ce3f4cdb727b62f82393e4f10abe5bc7eb3 Mon Sep 17 00:00:00 2001 From: Stormeye Wu Date: Fri, 11 Jan 2019 18:10:02 +0800 Subject: [PATCH 4/5] =?UTF-8?q?[=E4=B8=8A=E4=BC=A0=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E5=BC=82=E5=B8=B8][=E4=BF=AE=E6=94=B9]:=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E9=87=8D=E8=AE=BE=E8=BF=87=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/iformall/service/impl/WxCUserBasicInfoServiceImpl.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCUserBasicInfoServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCUserBasicInfoServiceImpl.java index 726f650ed..a1dd83c00 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCUserBasicInfoServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCUserBasicInfoServiceImpl.java @@ -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 From 53ff8d4cb8dee84d484b7b5c6abe263a37933b59 Mon Sep 17 00:00:00 2001 From: Stormeye Wu Date: Fri, 11 Jan 2019 18:33:35 +0800 Subject: [PATCH 5/5] =?UTF-8?q?[=E5=85=8D=E5=AF=86=E7=99=BB=E5=BD=95][?= =?UTF-8?q?=E4=BF=AE=E6=94=B9]:=E7=94=A8=E6=88=B7=E4=B8=BAnull=E6=97=B6?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/iformall/controller/HomeController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/HomeController.java b/mallinkAdmin/src/main/java/com/iformall/controller/HomeController.java index cc50f105a..41aaed291 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/HomeController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/HomeController.java @@ -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())) {