diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/AsyncTask.java b/mallinkAdmin/src/main/java/com/iformall/controller/AsyncTask.java new file mode 100644 index 000000000..e7598f780 --- /dev/null +++ b/mallinkAdmin/src/main/java/com/iformall/controller/AsyncTask.java @@ -0,0 +1,123 @@ +package com.iformall.controller; + +import cn.afterturn.easypoi.excel.ExcelImportUtil; +import cn.afterturn.easypoi.excel.entity.ImportParams; +import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult; +import cn.afterturn.easypoi.handler.impl.ExcelDataHandlerDefaultImpl; +import cn.afterturn.easypoi.handler.inter.IExcelDataHandler; +import com.iformall.domain.po.MallUserInfo; +import com.iformall.domain.po.WxTags; +import com.iformall.domain.vo.CUserBaseInfoT; +import com.iformall.service.WxCUserBasicInfoService; +import com.iformall.service.WxTagsService; +import com.iformall.shiro.UserSession; +import org.apache.shiro.SecurityUtils; +import org.apache.shiro.session.Session; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +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 java.io.File; +import java.util.List; +import java.util.concurrent.TimeUnit; + +@Component +public class AsyncTask { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private WxCUserBasicInfoService wxCUserBasicInfoService; + + @Autowired + private WxTagsService wxTagsService; + + @Autowired + StringRedisTemplate stringRedisTemplate; + + private class UserExcelHandler extends ExcelDataHandlerDefaultImpl { + @Override + public Object importHandler(CUserBaseInfoT obj, String name, Object value) { + if (value == null) { + value = ""; + } + System.out.println(name + " + " + value.toString()); + return super.importHandler(obj, name, value); + } + + } + + 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(File file, MallUserInfo user, String importKey, String tenantId) { + ImportParams params = new ImportParams(); + // 需要验证 + params.setImportFields(new String[]{"姓名", "性别", "手机号", "微信昵称", "学历", "生日", "地址", "上次活跃时间", "注册时间", "标签", "成长值"}); + IExcelDataHandler handler = new AsyncTask.UserExcelHandler(); + handler.setNeedHandlerFields(new String[] { "手机号" }); + params.setNeedVerify(true); + + ExcelImportResult datalist = null; + + try { + datalist = ExcelImportUtil.importExcelMore(file, CUserBaseInfoT.class, params); + } catch (Exception e) { + set_redis_value(importKey, "1", "0", "0", "1", true); + logger.error(e.getMessage()); + // 删除缓存文件 + file.delete(); + return; + } + // 删除缓存文件 + file.delete(); + + if(datalist == null) { + logger.error("导入模板失败: 模板数据解析失败"); + set_redis_value(importKey, "1", "0", "0", "1", true); + return; + } + + List successList = datalist.getList(); + List failList = datalist.getFailList(); + + int total = successList.size() + failList.size(); + int all_success = successList.size(); + int all_fail = failList.size(); + + //添加到redis里 + set_redis_value(importKey, "" + total, "" + all_success, "0", "" + all_fail, false); + + logger.info("验证通过的数量: " + successList.size()); + logger.info("验证未通过的数量: " + failList.size()); + + WxTags wxTagsQ = new WxTags(); + List tagList = wxTagsService.findList(wxTagsQ); + + try { + successList.parallelStream().forEach(uBase -> { + // 异步无法获取到原有的session,所以再注入一下session + Session session = SecurityUtils.getSubject().getSession(); + session.setAttribute(UserSession.userInfo, user); + session.setAttribute(UserSession.userId, user.getId()); + session.setAttribute(UserSession.tenantId, tenantId); + + wxCUserBasicInfoService.importOneMem(tenantId, importKey, tagList, uBase); + }); + } catch (Exception e) { + 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/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())) { diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/WxCUserBasicInfoController.java b/mallinkAdmin/src/main/java/com/iformall/controller/WxCUserBasicInfoController.java index 4fa95b145..888179273 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/WxCUserBasicInfoController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/WxCUserBasicInfoController.java @@ -1,10 +1,5 @@ package com.iformall.controller; -import cn.afterturn.easypoi.excel.ExcelImportUtil; -import cn.afterturn.easypoi.excel.entity.ImportParams; -import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult; -import cn.afterturn.easypoi.handler.impl.ExcelDataHandlerDefaultImpl; -import cn.afterturn.easypoi.handler.inter.IExcelDataHandler; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @@ -13,19 +8,14 @@ import com.iformall.common.ErrorCode; import com.iformall.common.Result; import com.iformall.common.ResultData; import com.iformall.domain.po.*; -import com.iformall.domain.vo.CUserBaseInfoT; import com.iformall.enums.EnumAssignTagsTrigger; import com.iformall.exception.MallinkException; import com.iformall.service.*; -import com.iformall.service.impl.WxCUserBasicInfoServiceImpl; -import com.iformall.shiro.UserSession; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; -import org.apache.shiro.SecurityUtils; -import org.apache.shiro.session.Session; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -35,6 +25,10 @@ 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; @@ -69,12 +63,14 @@ public class WxCUserBasicInfoController extends BaseController { @Autowired private WxLevelConfigService wxLevelConfigService; - @Autowired - private WxTagsService wxTagsService; + @Autowired StringRedisTemplate stringRedisTemplate; + @Autowired + private AsyncTask asyncTask; + private void setUserInfoLevel(WxCUserBasicInfo info) { if (info.getPoins() == null || info.getPoins() == 0) { @@ -265,103 +261,100 @@ public class WxCUserBasicInfoController extends BaseController { } - private class UserExcelHandler extends ExcelDataHandlerDefaultImpl { - @Override - public Object importHandler(CUserBaseInfoT obj, String name, Object value) { - if (value == null) { - value = ""; - } - System.out.println(name + " + " + value.toString()); - return super.importHandler(obj, name, value); + 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 final MallUserInfo user = getUser(); String userId = "" + user.getId(); String importKey = importMemPrev + userId; + final String tenantId = getTenantId(); + //查询当前用户得到的值是否为空,为空继续,不为空,返回模板正在导入 Boolean allCount = stringRedisTemplate.opsForHash().hasKey(importKey, "allCount"); if (allCount) { return new ResultData(Result.SUCCESS, "模板正在导入"); } + 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", ""); + 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()); - ImportParams params = new ImportParams(); - // 需要验证 - params.setImportFields(new String[]{"姓名", "性别", "手机号", "微信昵称", "学历", "生日", "地址", "上次活跃时间", "注册时间", "标签", "成长值"}); - IExcelDataHandler handler = new UserExcelHandler(); - handler.setNeedHandlerFields(new String[] { "手机号" }); - params.setNeedVerify(true); + File lFile = new File(fpath + File.separator + fileName); - ExcelImportResult datalist = null; + FileOutputStream fos = null; + BufferedInputStream fs = null; try { - datalist = ExcelImportUtil.importExcelMore(file.getInputStream(), CUserBaseInfoT.class, params); + 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.opsForHash().put(importKey, "allCount", "1"); - stringRedisTemplate.opsForHash().put(importKey, "allSuccessCount", "0"); - stringRedisTemplate.opsForHash().put(importKey, "processCount", "0"); - stringRedisTemplate.opsForHash().put(importKey, "failCount", "1"); + 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); - } - - if(datalist == null) { - logger.error("导入模板失败: 模板数据解析失败"); - return new ResultData(ErrorCode.MEM_IMPORT_ERR); + 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(), "模板上传失败"); + } + } } - List successList = datalist.getList(); - List failList = datalist.getFailList(); - - int total = successList.size() + failList.size(); - int all_success = successList.size(); - 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); - - logger.info("验证通过的数量: " + successList.size()); - logger.info("验证未通过的数量: " + failList.size()); - - WxTags wxTagsQ = new WxTags(); - List tagList = wxTagsService.findList(wxTagsQ); + asyncTask.importExcelData(lFile, user, importKey, tenantId); - final String tenantId = getTenantId(); - - try { - successList.parallelStream().forEach(uBase -> { - // 异步无法获取到原有的session,所以再注入一下session - Session session = SecurityUtils.getSubject().getSession(); - session.setAttribute(UserSession.userInfo, user); - session.setAttribute(UserSession.userId, user.getId()); - session.setAttribute(UserSession.tenantId, tenantId); - - wxCUserBasicInfoService.importOneMem(tenantId, importKey, tagList, uBase); - }); - } catch (Exception e) { - stringRedisTemplate.opsForHash().put(importKey, "allCount", "" + all_fail); - e.printStackTrace(); - logger.error("导入模板失败:"+e.getMessage()); - } - stringRedisTemplate.expire(importKey,30,TimeUnit.MINUTES); return new ResultData(Result.SUCCESS, "模板正在导入"); } + @GetMapping("/queryTemplateCount") public ResultData queryTemplateCount() { String importKey = importMemPrev + getUser().getId(); diff --git a/mallinkAdmin/src/main/resources/application-prod.yml b/mallinkAdmin/src/main/resources/application-prod.yml index 207f65b06..bb30ace8c 100644 --- a/mallinkAdmin/src/main/resources/application-prod.yml +++ b/mallinkAdmin/src/main/resources/application-prod.yml @@ -2,8 +2,8 @@ spring: # JDBC datasource: url: jdbc:mysql://formalldb.cfqyqflkdlit.rds.cn-northwest-1.amazonaws.com.cn:3306/mallink?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false - username: ENC(BDv01/sQdBGEhFEXuw+8tw==) - password: ENC(0wvpX49+RMUpGP2tb9PY4ta/yCwAmLLhbKG9ndvifPI=) + username: ENC(NUzgQOdJnCbVLKT6BaX0aw==) + password: ENC(mvuoDRiu0jqYaKNRwwTuXZ6U7aoIaqsjdiPqTLgi/nY=) type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.cj.jdbc.Driver filters: stat @@ -24,16 +24,56 @@ spring: redis: host: 127.0.0.1 port: 6379 - password: ENC(4Z6xTEJOw04DYyhur0mTwlveexVEX9YRfNTY78MyKgU=) + password: ENC(8gYU47Fu93NUJPhwPCiPbAT+6VFA1YDx1egK4Z0Nl6w=) timeout: 3600 expire: 1800 #30分钟 database: 1 + defaultExpiration: 2592000 # 默认生命周期30天 jedis: pool: - max-active: 8 - max-idle: 8 + max-active: 100 + max-idle: 20 max-wait: -1 min-idle: 0 + # EMAIL + mail: + host: smtp.exmail.qq.com + username: ENC(I2YKxnRVPY7J1r/bwzwHOhQCjj3nVqCWEbVTJvBq7y0=) + password: ENC(APQMO9XQRzMKd0eap+oSSOYH9MQe/r5K0YFF9A9mizU=) # 授权密码 + properties: + mail: + smtp: + auth: true + starttls: + enable: true + +aws: + clientRegion: cn-northwest-1 + bucketName: iformall-net + access: ENC(a6SN1sZ1enNL49ypiOXkg/pPPAnZD8H4buQFTTKN08s=) + secret: ENC(5P5ff4bTMJUbXVR4ZsM03UHzOKZ4+Zg5Iutcdkyp/Quny/oXg+A4KpfwEyGarlLu3vQMJahGP5M=) + + +wechat: + open: + componentAppId: "wx897e4673286c915d" + componentSecret: "cdfdfda65c45689beb6766c4c427eed2" + componentToken: "formall2018" + componentAesKey: "htKq8EjBMPNndfZQK9JiFojFaqFwFpw42VfeWFtx7HN" + redis: + host: 127.0.0.1 + port: 6379 + password: ENC(8gYU47Fu93NUJPhwPCiPbAT+6VFA1YDx1egK4Z0Nl6w=) + timeout: 3600 + expire: 1800 #30分钟 + database: 1 + defaultExpiration: 2592000 # 默认生命周期30天 + jedis: + pool: + max-active: 100 + max-idle: 100 + max-wait: -1 + min-idle: 10 fm: @@ -50,5 +90,3 @@ logging: tk.mybatis: debug com.iformall.mapper: debug path: ./logs/admin - - admin-page: http://admin.malls.iformall.com \ No newline at end of file diff --git a/mallinkAdmin/src/main/resources/application-test.yml b/mallinkAdmin/src/main/resources/application-test.yml index 4a66f892f..e4dabdfa1 100644 --- a/mallinkAdmin/src/main/resources/application-test.yml +++ b/mallinkAdmin/src/main/resources/application-test.yml @@ -2,8 +2,8 @@ spring: # JDBC datasource: url: jdbc:mysql://formalldb.cfqyqflkdlit.rds.cn-northwest-1.amazonaws.com.cn:3306/mallinkTest?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false - username: ENC(BDv01/sQdBGEhFEXuw+8tw==) - password: ENC(0wvpX49+RMUpGP2tb9PY4ta/yCwAmLLhbKG9ndvifPI=) + username: ENC(Uc0AjgkytxHHCwZrmDASWg==) + password: ENC(nV4Mi3bEbBx0Fj7uUyYH55eTaqsFMjKvmNzagicH4pc=) type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.cj.jdbc.Driver filters: stat @@ -24,17 +24,56 @@ spring: redis: host: 127.0.0.1 port: 6379 - password: ENC(4Z6xTEJOw04DYyhur0mTwlveexVEX9YRfNTY78MyKgU=) + password: ENC(QFwqv3NshvvGhFPiP8rwhvbnxk+rFSqhJi8Pw6TogSg=) timeout: 3600 expire: 1800 #30分钟 database: 1 defaultExpiration: 2592000 # 默认生命周期30天 jedis: pool: - max-active: 8 - max-idle: 8 + max-active: 100 + max-idle: 20 max-wait: -1 min-idle: 0 + # EMAIL + mail: + host: smtp.exmail.qq.com + username: ENC(HFbRXtAFVxU36Hk0yT3reyvRuLrw3RhMlbxFj9Ev/VY=) + password: ENC(pk4+/3C5n2hMYmgi+VTqI4P1m77DllW8y4KElMXXmIo=) # 授权密码 + properties: + mail: + smtp: + auth: true + starttls: + enable: true + +aws: + clientRegion: cn-northwest-1 + bucketName: iformall-net + access: ENC(NCLcmjwKpAWdn/abD17OKIY7yKepVLWzEpqRYUlURCw=) + secret: ENC(TRcZqql0Rq5PExlMeH/4WiZ/i02b8FXKmLTBChJmbluTa1uoLS9LrHyNEMrqe1DK+QgOAdvqGBo=) + +wechat: + open: + componentAppId: "wx897e4673286c915d" + componentSecret: "cdfdfda65c45689beb6766c4c427eed2" + componentToken: "formall2018" + componentAesKey: "htKq8EjBMPNndfZQK9JiFojFaqFwFpw42VfeWFtx7HN" + redis: + host: 127.0.0.1 + port: 6379 + password: ENC(QFwqv3NshvvGhFPiP8rwhvbnxk+rFSqhJi8Pw6TogSg=) + timeout: 3600 + expire: 1800 #30分钟 + database: 1 + defaultExpiration: 2592000 # 默认生命周期30天 + jedis: + pool: + max-active: 100 + max-idle: 100 + max-wait: -1 + min-idle: 10 + fm: exception: true diff --git a/mallinkBApi/src/main/resources/application-prod.yml b/mallinkBApi/src/main/resources/application-prod.yml index 88041cb26..12e579a99 100644 --- a/mallinkBApi/src/main/resources/application-prod.yml +++ b/mallinkBApi/src/main/resources/application-prod.yml @@ -2,8 +2,8 @@ spring: # JDBC datasource: url: jdbc:mysql://formalldb.cfqyqflkdlit.rds.cn-northwest-1.amazonaws.com.cn:3306/mallink?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false - username: ENC(BDv01/sQdBGEhFEXuw+8tw==) - password: ENC(0wvpX49+RMUpGP2tb9PY4ta/yCwAmLLhbKG9ndvifPI=) + username: ENC(NUzgQOdJnCbVLKT6BaX0aw==) + password: ENC(mvuoDRiu0jqYaKNRwwTuXZ6U7aoIaqsjdiPqTLgi/nY=) type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.cj.jdbc.Driver filters: stat @@ -23,17 +23,34 @@ spring: redis: host: 127.0.0.1 port: 6379 - password: ENC(4Z6xTEJOw04DYyhur0mTwlveexVEX9YRfNTY78MyKgU=) + password: ENC(8gYU47Fu93NUJPhwPCiPbAT+6VFA1YDx1egK4Z0Nl6w=) timeout: 3600 expire: 1800 #30分钟 database: 1 defaultExpiration: 2592000 # 默认生命周期30天 jedis: pool: - max-active: 8 - max-idle: 8 + max-active: 100 + max-idle: 20 max-wait: -1 min-idle: 0 + # EMAIL + mail: + host: smtp.exmail.qq.com + username: ENC(I2YKxnRVPY7J1r/bwzwHOhQCjj3nVqCWEbVTJvBq7y0=) + password: ENC(APQMO9XQRzMKd0eap+oSSOYH9MQe/r5K0YFF9A9mizU=) # 授权密码 + properties: + mail: + smtp: + auth: true + starttls: + enable: true + +aws: + clientRegion: cn-northwest-1 + bucketName: iformall-net + access: ENC(a6SN1sZ1enNL49ypiOXkg/pPPAnZD8H4buQFTTKN08s=) + secret: ENC(5P5ff4bTMJUbXVR4ZsM03UHzOKZ4+Zg5Iutcdkyp/Quny/oXg+A4KpfwEyGarlLu3vQMJahGP5M=) fm: exception: true diff --git a/mallinkBApi/src/main/resources/application-test.yml b/mallinkBApi/src/main/resources/application-test.yml index fcb5cb922..13c973402 100644 --- a/mallinkBApi/src/main/resources/application-test.yml +++ b/mallinkBApi/src/main/resources/application-test.yml @@ -2,8 +2,8 @@ spring: # JDBC datasource: url: jdbc:mysql://formalldb.cfqyqflkdlit.rds.cn-northwest-1.amazonaws.com.cn:3306/mallinkTest?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false - username: ENC(BDv01/sQdBGEhFEXuw+8tw==) - password: ENC(0wvpX49+RMUpGP2tb9PY4ta/yCwAmLLhbKG9ndvifPI=) + username: ENC(Uc0AjgkytxHHCwZrmDASWg==) + password: ENC(nV4Mi3bEbBx0Fj7uUyYH55eTaqsFMjKvmNzagicH4pc=) type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.cj.jdbc.Driver filters: stat @@ -23,17 +23,34 @@ spring: redis: host: 127.0.0.1 port: 6379 - password: ENC(4Z6xTEJOw04DYyhur0mTwlveexVEX9YRfNTY78MyKgU=) + password: ENC(QFwqv3NshvvGhFPiP8rwhvbnxk+rFSqhJi8Pw6TogSg=) timeout: 3600 expire: 1800 #30分钟 database: 1 defaultExpiration: 2592000 # 默认生命周期30天 jedis: pool: - max-active: 8 - max-idle: 8 + max-active: 50 + max-idle: 30 max-wait: -1 min-idle: 0 + # EMAIL + mail: + host: smtp.exmail.qq.com + username: ENC(HFbRXtAFVxU36Hk0yT3reyvRuLrw3RhMlbxFj9Ev/VY=) + password: ENC(pk4+/3C5n2hMYmgi+VTqI4P1m77DllW8y4KElMXXmIo=) # 授权密码 + properties: + mail: + smtp: + auth: true + starttls: + enable: true + +aws: + clientRegion: cn-northwest-1 + bucketName: iformall-net + access: ENC(NCLcmjwKpAWdn/abD17OKIY7yKepVLWzEpqRYUlURCw=) + secret: ENC(TRcZqql0Rq5PExlMeH/4WiZ/i02b8FXKmLTBChJmbluTa1uoLS9LrHyNEMrqe1DK+QgOAdvqGBo=) fm: exception: true diff --git a/mallinkCApi/src/main/resources/application-prod.yml b/mallinkCApi/src/main/resources/application-prod.yml index 0c1eba6d1..d93753e5d 100644 --- a/mallinkCApi/src/main/resources/application-prod.yml +++ b/mallinkCApi/src/main/resources/application-prod.yml @@ -2,8 +2,8 @@ spring: # JDBC datasource: url: jdbc:mysql://formalldb.cfqyqflkdlit.rds.cn-northwest-1.amazonaws.com.cn:3306/mallink?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false - username: ENC(BDv01/sQdBGEhFEXuw+8tw==) - password: ENC(0wvpX49+RMUpGP2tb9PY4ta/yCwAmLLhbKG9ndvifPI=) + username: ENC(NUzgQOdJnCbVLKT6BaX0aw==) + password: ENC(mvuoDRiu0jqYaKNRwwTuXZ6U7aoIaqsjdiPqTLgi/nY=) type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.cj.jdbc.Driver filters: stat @@ -23,17 +23,36 @@ spring: redis: host: 127.0.0.1 port: 6379 - password: ENC(4Z6xTEJOw04DYyhur0mTwlveexVEX9YRfNTY78MyKgU=) + password: ENC(8gYU47Fu93NUJPhwPCiPbAT+6VFA1YDx1egK4Z0Nl6w=) timeout: 3600 expire: 1800 #30分钟 database: 1 defaultExpiration: 2592000 # 默认生命周期30天 jedis: pool: - max-active: 8 - max-idle: 8 + max-active: 100 + max-idle: 20 max-wait: -1 min-idle: 0 + # EMAIL + mail: + host: smtp.exmail.qq.com + username: ENC(I2YKxnRVPY7J1r/bwzwHOhQCjj3nVqCWEbVTJvBq7y0=) + password: ENC(APQMO9XQRzMKd0eap+oSSOYH9MQe/r5K0YFF9A9mizU=) # 授权密码 + properties: + mail: + smtp: + auth: true + starttls: + enable: true + +aws: + clientRegion: cn-northwest-1 + bucketName: iformall-net + access: ENC(a6SN1sZ1enNL49ypiOXkg/pPPAnZD8H4buQFTTKN08s=) + secret: ENC(5P5ff4bTMJUbXVR4ZsM03UHzOKZ4+Zg5Iutcdkyp/Quny/oXg+A4KpfwEyGarlLu3vQMJahGP5M=) + + fm: exception: true diff --git a/mallinkCApi/src/main/resources/application-test.yml b/mallinkCApi/src/main/resources/application-test.yml index 7a6f7141f..7121e560b 100644 --- a/mallinkCApi/src/main/resources/application-test.yml +++ b/mallinkCApi/src/main/resources/application-test.yml @@ -2,8 +2,8 @@ spring: # JDBC datasource: url: jdbc:mysql://formalldb.cfqyqflkdlit.rds.cn-northwest-1.amazonaws.com.cn:3306/mallinkTest?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false - username: ENC(BDv01/sQdBGEhFEXuw+8tw==) - password: ENC(0wvpX49+RMUpGP2tb9PY4ta/yCwAmLLhbKG9ndvifPI=) + username: ENC(Uc0AjgkytxHHCwZrmDASWg==) + password: ENC(nV4Mi3bEbBx0Fj7uUyYH55eTaqsFMjKvmNzagicH4pc=) type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.cj.jdbc.Driver filters: stat @@ -23,7 +23,7 @@ spring: redis: host: 127.0.0.1 port: 6379 - password: ENC(4Z6xTEJOw04DYyhur0mTwlveexVEX9YRfNTY78MyKgU=) + password: ENC(QFwqv3NshvvGhFPiP8rwhvbnxk+rFSqhJi8Pw6TogSg=) timeout: 3600 expire: 1800 #30分钟 database: 1 @@ -34,6 +34,23 @@ spring: max-idle: 8 max-wait: -1 min-idle: 0 + # EMAIL + mail: + host: smtp.exmail.qq.com + username: ENC(HFbRXtAFVxU36Hk0yT3reyvRuLrw3RhMlbxFj9Ev/VY=) + password: ENC(pk4+/3C5n2hMYmgi+VTqI4P1m77DllW8y4KElMXXmIo=) # 授权密码 + properties: + mail: + smtp: + auth: true + starttls: + enable: true + +aws: + clientRegion: cn-northwest-1 + bucketName: iformall-net + access: ENC(NCLcmjwKpAWdn/abD17OKIY7yKepVLWzEpqRYUlURCw=) + secret: ENC(TRcZqql0Rq5PExlMeH/4WiZ/i02b8FXKmLTBChJmbluTa1uoLS9LrHyNEMrqe1DK+QgOAdvqGBo=) fm: exception: true diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/MsgSendingSchedule.java b/mallinkSchedule/src/main/java/com/iformall/schedule/MsgSendingSchedule.java index ef745c1c2..d01adca38 100644 --- a/mallinkSchedule/src/main/java/com/iformall/schedule/MsgSendingSchedule.java +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/MsgSendingSchedule.java @@ -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 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 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() 1) { - throw new MallinkException(ErrorCode.ORDER_IS_FAIL); - } + wxOrderService.couponOrderSuccess(order); } catch (Exception e) { logger.error(e.getMessage()); throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "订单更新");