From bf73a9cbd896d616bcb11ecc1eb0c8becf5c19bf Mon Sep 17 00:00:00 2001 From: 3y Date: Fri, 23 Dec 2022 10:00:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=9C=8D=E5=8A=A1=E5=8F=B7?= =?UTF-8?q?=E6=89=AB=E7=A0=81=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/constant/AustinConstant.java | 10 ++++ .../common/constant/CommonConstant.java | 10 ++++ .../austin/common/enums/RespStatusEnum.java | 2 +- .../austin/support/dao/ChannelAccountDao.java | 23 ++++++-- .../austin/support/domain/ChannelAccount.java | 5 ++ .../austin/support/utils/AccountUtils.java | 14 ----- .../controller/ChannelAccountController.java | 37 ++++++++---- .../controller/MessageTemplateController.java | 12 +++- .../controller/OfficialAccountController.java | 8 +-- .../web/service/ChannelAccountService.java | 7 ++- .../impl/ChannelAccountServiceImpl.java | 12 ++-- .../impl/MessageTemplateServiceImpl.java | 13 +++-- .../java3y/austin/web/utils/Convert4Amis.java | 17 ++++++ .../java3y/austin/web/utils/LoginUtils.java | 57 +++++++++++++++++++ .../austin/web/vo/MessageTemplateParam.java | 5 ++ .../resources/application-test.properties | 6 +- sql/austin.sql | 1 + 17 files changed, 185 insertions(+), 54 deletions(-) create mode 100644 austin-web/src/main/java/com/java3y/austin/web/utils/LoginUtils.java diff --git a/austin-common/src/main/java/com/java3y/austin/common/constant/AustinConstant.java b/austin-common/src/main/java/com/java3y/austin/common/constant/AustinConstant.java index 026887a..eb8a5df 100644 --- a/austin-common/src/main/java/com/java3y/austin/common/constant/AustinConstant.java +++ b/austin-common/src/main/java/com/java3y/austin/common/constant/AustinConstant.java @@ -33,5 +33,15 @@ public class AustinConstant { public static final String SEND_ALL = "@all"; + /** + * 默认的常量,如果新建模板/账号时,没传入则用该常量 + */ + public static final String DEFAULT_CREATOR = "Java3y"; + public static final String DEFAULT_UPDATOR = "Java3y"; + public static final String DEFAULT_TEAM = "Java3y公众号"; + public static final String DEFAULT_AUDITOR = "Java3y"; + + + } diff --git a/austin-common/src/main/java/com/java3y/austin/common/constant/CommonConstant.java b/austin-common/src/main/java/com/java3y/austin/common/constant/CommonConstant.java index 1502b41..5e9cde5 100644 --- a/austin-common/src/main/java/com/java3y/austin/common/constant/CommonConstant.java +++ b/austin-common/src/main/java/com/java3y/austin/common/constant/CommonConstant.java @@ -72,4 +72,14 @@ public class CommonConstant { */ public final static String CRON_FORMAT = "ss mm HH dd MM ? yyyy-yyyy"; + /** + * 环境常量 + */ + public final static String ENV_DEV = "dev"; + public final static String ENV_TEST = "test"; + + + + + } \ No newline at end of file diff --git a/austin-common/src/main/java/com/java3y/austin/common/enums/RespStatusEnum.java b/austin-common/src/main/java/com/java3y/austin/common/enums/RespStatusEnum.java index c30424e..51d0085 100644 --- a/austin-common/src/main/java/com/java3y/austin/common/enums/RespStatusEnum.java +++ b/austin-common/src/main/java/com/java3y/austin/common/enums/RespStatusEnum.java @@ -28,7 +28,7 @@ public enum RespStatusEnum { TEMPLATE_NOT_FOUND("A0002", "找不到模板或模板已被删除"), TOO_MANY_RECEIVER("A0003", "传入的接收者大于100个"), DO_NOT_NEED_LOGIN("A0004", "非测试环境,无须登录"), - NO_LOGIN("A0005", "还未登录"), + NO_LOGIN("A0005", "还未登录,请先登录"), /** * 系统 diff --git a/austin-support/src/main/java/com/java3y/austin/support/dao/ChannelAccountDao.java b/austin-support/src/main/java/com/java3y/austin/support/dao/ChannelAccountDao.java index 42b3bb6..112083e 100644 --- a/austin-support/src/main/java/com/java3y/austin/support/dao/ChannelAccountDao.java +++ b/austin-support/src/main/java/com/java3y/austin/support/dao/ChannelAccountDao.java @@ -2,11 +2,7 @@ package com.java3y.austin.support.dao; import com.java3y.austin.support.domain.ChannelAccount; -import com.java3y.austin.support.domain.MessageTemplate; -import com.java3y.austin.support.domain.SmsRecord; -import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.repository.CrudRepository; import java.util.List; @@ -19,7 +15,17 @@ public interface ChannelAccountDao extends JpaRepository { /** - * 查询 列表(分页) + * 查询 列表 + * + * @param deleted 0:未删除 1:删除 + * @param channelType 渠道值 + * @param creator 创建者 + * @return + */ + List findAllByIsDeletedEqualsAndCreatorEqualsAndSendChannelEquals(Integer deleted, String creator, Integer channelType); + + /** + * 查询 列表 * * @param deleted 0:未删除 1:删除 * @param channelType 渠道值 @@ -27,6 +33,13 @@ public interface ChannelAccountDao extends JpaRepository { */ List findAllByIsDeletedEqualsAndSendChannelEquals(Integer deleted, Integer channelType); + /** + * 根据创建者检索相关的记录 + * + * @param creator + * @return + */ + List findAllByCreatorEquals(String creator); /** * 统计未删除的条数 diff --git a/austin-support/src/main/java/com/java3y/austin/support/domain/ChannelAccount.java b/austin-support/src/main/java/com/java3y/austin/support/domain/ChannelAccount.java index 74fb731..9f92d0e 100644 --- a/austin-support/src/main/java/com/java3y/austin/support/domain/ChannelAccount.java +++ b/austin-support/src/main/java/com/java3y/austin/support/domain/ChannelAccount.java @@ -48,6 +48,11 @@ public class ChannelAccount { */ private Integer isDeleted; + /** + * 账号拥有者 + */ + private String creator; + /** * 创建时间 单位 s */ diff --git a/austin-support/src/main/java/com/java3y/austin/support/utils/AccountUtils.java b/austin-support/src/main/java/com/java3y/austin/support/utils/AccountUtils.java index 3085942..9d51a43 100644 --- a/austin-support/src/main/java/com/java3y/austin/support/utils/AccountUtils.java +++ b/austin-support/src/main/java/com/java3y/austin/support/utils/AccountUtils.java @@ -27,19 +27,7 @@ public class AccountUtils { private ChannelAccountDao channelAccountDao; - /** - * local.properties配置格式 - * (key:smsAccount)短信参数示例:[{"sms_10":{"url":"sms.tencentcloudapi.com","region":"ap-guangzhou","secretId":"AKIDhDxxxxxxxx1WljQq","secretKey":"B4hwww39yxxxrrrrgxyi","smsSdkAppId":"1423123125","templateId":"1182097","signName":"Java3y公众号","supplierId":10,"supplierName":"腾讯云"}},{"sms_20":{"url":"https://sms.yunpian.com/v2/sms/tpl_batch_send.json","apikey":"caffff8234234231b5cd7","tpl_id":"523333332","supplierId":20,"supplierName":"云片"}}] - * (key:emailAccount)邮件参数示例:[{"email_10":{"host":"smtp.qq.com","port":465,"user":"23423423@qq.com","pass":"23423432432423423","from":"234@qq.com","starttlsEnable":true,"auth":true,"sslEnable":true}},{"email_20":{"host":"smtp.163.com","port":465,"user":"22222@163.com","pass":"23432423","from":"234324324234@163.com","starttlsEnable":false,"auth":true,"sslEnable":true}}] - * (key:enterpriseWechatAccount)企业微信参数示例:[{"enterprise_wechat_10":{"corpId":"wwf87603333e00069c","corpSecret":"-IFWxS2222QxzPIorNV11144D915DM","agentId":10044442,"token":"rXROB3333Kf6i","aesKey":"MKZtoFxHIM44444M7ieag3r9ZPUsl"}}] - * (key:dingDingRobotAccount) 钉钉自定义机器人参数示例:[{"ding_ding_robot_10":{"secret":"SEC9222d4768aded74114faae92229de422222fedf","webhook":"https://oapi.dingtalk.com/robot/send?access_token=8d03b6442222203d87333367328b0c3003d164715d2c6c6e56"}}] - * (key:dingDingWorkNoticeAccount) 钉钉工作消息参数示例:[{"ding_ding_work_notice_10":{"appKey":"dingh6yyyyyyycrlbx","appSecret":"tQpvmkR863333yyyyyHP3QHyyyymy9Ao1yoL1oQX5NsdfsWHvWKbTu","agentId":"1523123123183622"}}] - * (key:officialAccount) 微信服务号模板消息参数示例:[{"official_10":{"appId":"wxecb4693d2eef1ea7","secret":"624asdfsa1640d769ba20120821","templateId":"JHUk6eE9T5Ts7asdfsadfiKNDQsk-Q","url":"http://weixin.qq.com/download","miniProgramId":"xiaochengxuappid12345","path":"index?foo=bar"}}] - * (key:miniProgramAccount) 微信小程序订阅消息参数示例:[{"mini_program_10":{"appId":"wxecb4693d2eef1ea7","appSecret":"6240870f4d91701640d769ba20120821","templateId":"JHUk6eE9T5TasdfCrQsk-Q","grantType":"client_credential","miniProgramState":"trial","page":"index?foo=bar"}}] - * (key:alipayMiniProgramAccount) 支付宝小程序订阅消息参数实例:[{"alipay_mini_program_10":{"privateKey":"MIIEvQIBADANB......","alipayPublicKey":"MIIBIjANBg...","appId":"2014********7148","userTemplateId":"MDI4YzIxMDE2M2I5YTQzYjUxNWE4MjA4NmU1MTIyYmM=","page":"page/component/index"}}] - */ public T getAccountById(Integer sendAccountId, Class clazz) { - try { Optional optionalChannelAccount = channelAccountDao.findById(Long.valueOf(sendAccountId)); if (optionalChannelAccount.isPresent()) { @@ -49,8 +37,6 @@ public class AccountUtils { } catch (Exception e) { log.error("AccountUtils#getAccount fail!", Throwables.getStackTraceAsString(e)); } - - log.error("AccountUtils#getAccount not found!:{}", sendAccountId); return null; } diff --git a/austin-web/src/main/java/com/java3y/austin/web/controller/ChannelAccountController.java b/austin-web/src/main/java/com/java3y/austin/web/controller/ChannelAccountController.java index b2fd3a7..2a7f038 100644 --- a/austin-web/src/main/java/com/java3y/austin/web/controller/ChannelAccountController.java +++ b/austin-web/src/main/java/com/java3y/austin/web/controller/ChannelAccountController.java @@ -2,17 +2,19 @@ package com.java3y.austin.web.controller; import cn.hutool.core.util.StrUtil; +import com.java3y.austin.common.constant.AustinConstant; +import com.java3y.austin.common.enums.RespStatusEnum; import com.java3y.austin.common.vo.BasicResultVO; import com.java3y.austin.support.domain.ChannelAccount; import com.java3y.austin.web.service.ChannelAccountService; -import com.java3y.austin.web.vo.amis.CommonAmisVo; +import com.java3y.austin.web.utils.Convert4Amis; +import com.java3y.austin.web.utils.LoginUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; @@ -31,6 +33,8 @@ public class ChannelAccountController { @Autowired private ChannelAccountService channelAccountService; + @Autowired + private LoginUtils loginUtils; /** * 如果Id存在,则修改 @@ -39,6 +43,11 @@ public class ChannelAccountController { @PostMapping("/save") @ApiOperation("/保存数据") public BasicResultVO saveOrUpdate(@RequestBody ChannelAccount channelAccount) { + if (loginUtils.needLogin() && StrUtil.isBlank(channelAccount.getCreator())) { + return BasicResultVO.fail(RespStatusEnum.NO_LOGIN); + } + channelAccount.setCreator(StrUtil.isBlank(channelAccount.getCreator()) ? AustinConstant.DEFAULT_CREATOR : channelAccount.getCreator()); + return BasicResultVO.success(channelAccountService.save(channelAccount)); } @@ -47,15 +56,14 @@ public class ChannelAccountController { */ @GetMapping("/queryByChannelType") @ApiOperation("/根据渠道标识查询相关的记录") - public BasicResultVO query(Integer channelType) { - List result = new ArrayList<>(); - - List channelAccounts = channelAccountService.queryByChannelType(channelType); - for (ChannelAccount channelAccount : channelAccounts) { - CommonAmisVo commonAmisVo = CommonAmisVo.builder().label(channelAccount.getName()).value(String.valueOf(channelAccount.getId())).build(); - result.add(commonAmisVo); + public BasicResultVO query(Integer channelType, String creator) { + if (loginUtils.needLogin() && StrUtil.isBlank(creator)) { + return BasicResultVO.fail(RespStatusEnum.NO_LOGIN); } - return BasicResultVO.success(result); + creator = StrUtil.isBlank(creator) ? AustinConstant.DEFAULT_CREATOR : creator; + + List channelAccounts = channelAccountService.queryByChannelType(channelType, creator); + return BasicResultVO.success(Convert4Amis.getChannelAccountVo(channelAccounts)); } /** @@ -63,8 +71,13 @@ public class ChannelAccountController { */ @GetMapping("/list") @ApiOperation("/渠道账号列表信息") - public BasicResultVO list() { - return BasicResultVO.success(channelAccountService.list()); + public BasicResultVO list(String creator) { + if (loginUtils.needLogin() && StrUtil.isBlank(creator)) { + return BasicResultVO.fail(RespStatusEnum.NO_LOGIN); + } + creator = StrUtil.isBlank(creator) ? AustinConstant.DEFAULT_CREATOR : creator; + + return BasicResultVO.success(channelAccountService.list(creator)); } /** diff --git a/austin-web/src/main/java/com/java3y/austin/web/controller/MessageTemplateController.java b/austin-web/src/main/java/com/java3y/austin/web/controller/MessageTemplateController.java index b864648..9a300b9 100644 --- a/austin-web/src/main/java/com/java3y/austin/web/controller/MessageTemplateController.java +++ b/austin-web/src/main/java/com/java3y/austin/web/controller/MessageTemplateController.java @@ -16,6 +16,7 @@ import com.java3y.austin.service.api.service.SendService; import com.java3y.austin.support.domain.MessageTemplate; import com.java3y.austin.web.service.MessageTemplateService; import com.java3y.austin.web.utils.Convert4Amis; +import com.java3y.austin.web.utils.LoginUtils; import com.java3y.austin.web.vo.MessageTemplateParam; import com.java3y.austin.web.vo.MessageTemplateVo; import com.java3y.austin.web.vo.amis.CommonAmisVo; @@ -56,6 +57,9 @@ public class MessageTemplateController { @Autowired private RecallService recallService; + @Autowired + private LoginUtils loginUtils; + @Value("${austin.business.upload.crowd.path}") private String dataPath; @@ -66,6 +70,9 @@ public class MessageTemplateController { @PostMapping("/save") @ApiOperation("/保存数据") public BasicResultVO saveOrUpdate(@RequestBody MessageTemplate messageTemplate) { + if (loginUtils.needLogin() && StrUtil.isBlank(messageTemplate.getCreator())) { + return BasicResultVO.fail(RespStatusEnum.NO_LOGIN); + } MessageTemplate info = messageTemplateService.saveOrUpdate(messageTemplate); return BasicResultVO.success(info); } @@ -76,6 +83,9 @@ public class MessageTemplateController { @GetMapping("/list") @ApiOperation("/列表页") public BasicResultVO queryList(@Validated MessageTemplateParam messageTemplateParam) { + if (loginUtils.needLogin() && StrUtil.isBlank(messageTemplateParam.getCreator())) { + return BasicResultVO.fail(RespStatusEnum.NO_LOGIN); + } Page messageTemplates = messageTemplateService.queryList(messageTemplateParam); List> result = Convert4Amis.flatListMap(messageTemplates.toList()); MessageTemplateVo messageTemplateVo = MessageTemplateVo.builder().count(messageTemplates.getTotalElements()).rows(result).build(); @@ -202,8 +212,6 @@ public class MessageTemplateController { localFile.mkdirs(); } file.transferTo(localFile); - - } catch (Exception e) { log.error("MessageTemplateController#upload fail! e:{},params{}", Throwables.getStackTraceAsString(e), JSON.toJSONString(file)); return BasicResultVO.fail(RespStatusEnum.SERVICE_ERROR); diff --git a/austin-web/src/main/java/com/java3y/austin/web/controller/OfficialAccountController.java b/austin-web/src/main/java/com/java3y/austin/web/controller/OfficialAccountController.java index 6c1784b..9c11c86 100644 --- a/austin-web/src/main/java/com/java3y/austin/web/controller/OfficialAccountController.java +++ b/austin-web/src/main/java/com/java3y/austin/web/controller/OfficialAccountController.java @@ -12,6 +12,7 @@ import com.java3y.austin.common.vo.BasicResultVO; import com.java3y.austin.support.utils.WxServiceUtils; import com.java3y.austin.web.config.WeChatLoginConfig; import com.java3y.austin.web.utils.Convert4Amis; +import com.java3y.austin.web.utils.LoginUtils; import com.java3y.austin.web.vo.amis.CommonAmisVo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -23,7 +24,6 @@ import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; import me.chanjar.weixin.mp.bean.result.WxMpUser; import me.chanjar.weixin.mp.bean.template.WxMpTemplate; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -49,7 +49,7 @@ public class OfficialAccountController { private WxServiceUtils wxServiceUtils; @Autowired - private ApplicationContext applicationContext; + private LoginUtils loginUtils; @Autowired private StringRedisTemplate redisTemplate; @@ -112,7 +112,7 @@ public class OfficialAccountController { @ApiOperation("/接收微信的事件消息") public String receiptMessage(HttpServletRequest request) { try { - WeChatLoginConfig configService = applicationContext.getBean(OfficialAccountParamConstant.WE_CHAT_LOGIN_CONFIG, WeChatLoginConfig.class); + WeChatLoginConfig configService = loginUtils.getLoginConfig(); if (configService == null) { return RespStatusEnum.DO_NOT_NEED_LOGIN.getMsg(); } @@ -163,7 +163,7 @@ public class OfficialAccountController { @ApiOperation("/生成 服务号 二维码") public BasicResultVO getQrCode() { try { - WeChatLoginConfig configService = applicationContext.getBean(OfficialAccountParamConstant.WE_CHAT_LOGIN_CONFIG, WeChatLoginConfig.class); + WeChatLoginConfig configService = loginUtils.getLoginConfig(); if (configService == null) { return BasicResultVO.fail(RespStatusEnum.DO_NOT_NEED_LOGIN); } diff --git a/austin-web/src/main/java/com/java3y/austin/web/service/ChannelAccountService.java b/austin-web/src/main/java/com/java3y/austin/web/service/ChannelAccountService.java index 7e9300a..7667c2e 100644 --- a/austin-web/src/main/java/com/java3y/austin/web/service/ChannelAccountService.java +++ b/austin-web/src/main/java/com/java3y/austin/web/service/ChannelAccountService.java @@ -25,17 +25,18 @@ public interface ChannelAccountService { * 根据渠道标识查询账号信息 * * @param channelType 渠道标识 + * @param creator 创建者 * @return */ - List queryByChannelType(Integer channelType); + List queryByChannelType(Integer channelType,String creator); /** - * 列表信息 无条件 + * 列表信息 * * @return */ - List list(); + List list(String creator); /** * 软删除(deleted=1) diff --git a/austin-web/src/main/java/com/java3y/austin/web/service/impl/ChannelAccountServiceImpl.java b/austin-web/src/main/java/com/java3y/austin/web/service/impl/ChannelAccountServiceImpl.java index 5338b36..a55eab7 100644 --- a/austin-web/src/main/java/com/java3y/austin/web/service/impl/ChannelAccountServiceImpl.java +++ b/austin-web/src/main/java/com/java3y/austin/web/service/impl/ChannelAccountServiceImpl.java @@ -1,6 +1,8 @@ package com.java3y.austin.web.service.impl; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.StrUtil; +import com.java3y.austin.common.constant.AustinConstant; import com.java3y.austin.common.constant.CommonConstant; import com.java3y.austin.support.dao.ChannelAccountDao; import com.java3y.austin.support.domain.ChannelAccount; @@ -21,12 +23,14 @@ public class ChannelAccountServiceImpl implements ChannelAccountService { private ChannelAccountDao channelAccountDao; @Autowired private WxServiceUtils wxServiceUtils; + @Override public ChannelAccount save(ChannelAccount channelAccount) { if (channelAccount.getId() == null) { channelAccount.setCreated(Math.toIntExact(DateUtil.currentSeconds())); channelAccount.setIsDeleted(CommonConstant.FALSE); } + channelAccount.setCreator(StrUtil.isBlank(channelAccount.getCreator()) ? AustinConstant.DEFAULT_CREATOR : channelAccount.getCreator()); channelAccount.setUpdated(Math.toIntExact(DateUtil.currentSeconds())); ChannelAccount result = channelAccountDao.save(channelAccount); wxServiceUtils.fresh(); @@ -34,13 +38,13 @@ public class ChannelAccountServiceImpl implements ChannelAccountService { } @Override - public List queryByChannelType(Integer channelType) { - return channelAccountDao.findAllByIsDeletedEqualsAndSendChannelEquals(CommonConstant.FALSE, channelType); + public List queryByChannelType(Integer channelType, String creator) { + return channelAccountDao.findAllByIsDeletedEqualsAndCreatorEqualsAndSendChannelEquals(CommonConstant.FALSE, creator, channelType); } @Override - public List list() { - return channelAccountDao.findAll(); + public List list(String creator) { + return channelAccountDao.findAllByCreatorEquals(creator); } @Override diff --git a/austin-web/src/main/java/com/java3y/austin/web/service/impl/MessageTemplateServiceImpl.java b/austin-web/src/main/java/com/java3y/austin/web/service/impl/MessageTemplateServiceImpl.java index d29817a..da38fb7 100644 --- a/austin-web/src/main/java/com/java3y/austin/web/service/impl/MessageTemplateServiceImpl.java +++ b/austin-web/src/main/java/com/java3y/austin/web/service/impl/MessageTemplateServiceImpl.java @@ -23,10 +23,7 @@ import org.springframework.data.domain.PageRequest; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Predicate; -import javax.persistence.criteria.Root; import java.util.ArrayList; import java.util.List; @@ -52,6 +49,7 @@ public class MessageTemplateServiceImpl implements MessageTemplateService { @Override public Page queryList(MessageTemplateParam param) { PageRequest pageRequest = PageRequest.of(param.getPage() - 1, param.getPerPage()); + String creator = StrUtil.isBlank(param.getCreator()) ? AustinConstant.DEFAULT_CREATOR : param.getCreator(); return messageTemplateDao.findAll((Specification) (root, query, cb) -> { List predicateList = new ArrayList<>(); // 加搜索条件 @@ -59,6 +57,7 @@ public class MessageTemplateServiceImpl implements MessageTemplateService { predicateList.add(cb.like(root.get("name").as(String.class), "%" + param.getKeywords() + "%")); } predicateList.add(cb.equal(root.get("isDeleted").as(Integer.class), CommonConstant.FALSE)); + predicateList.add(cb.equal(root.get("creator").as(String.class), creator)); Predicate[] p = new Predicate[predicateList.size()]; // 查询 query.where(cb.and(predicateList.toArray(p))); @@ -91,7 +90,7 @@ public class MessageTemplateServiceImpl implements MessageTemplateService { Iterable messageTemplates = messageTemplateDao.findAllById(ids); messageTemplates.forEach(messageTemplate -> messageTemplate.setIsDeleted(CommonConstant.TRUE)); for (MessageTemplate messageTemplate : messageTemplates) { - if (messageTemplate.getCronTaskId()!=null && messageTemplate.getCronTaskId() > 0) { + if (messageTemplate.getCronTaskId() != null && messageTemplate.getCronTaskId() > 0) { cronTaskService.deleteCronTask(messageTemplate.getCronTaskId()); } } @@ -149,14 +148,16 @@ public class MessageTemplateServiceImpl implements MessageTemplateService { /** * 初始化状态信息 - * TODO 创建者 修改者 团队 * * @param messageTemplate */ private void initStatus(MessageTemplate messageTemplate) { messageTemplate.setFlowId(StrUtil.EMPTY) .setMsgStatus(MessageStatus.INIT.getCode()).setAuditStatus(AuditStatus.WAIT_AUDIT.getCode()) - .setCreator("Java3y").setUpdator("Java3y").setTeam("公众号Java3y").setAuditor("3y") + .setCreator(StrUtil.isBlank(messageTemplate.getCreator()) ? AustinConstant.DEFAULT_CREATOR : messageTemplate.getCreator()) + .setUpdator(StrUtil.isBlank(messageTemplate.getUpdator()) ? AustinConstant.DEFAULT_UPDATOR : messageTemplate.getUpdator()) + .setTeam(StrUtil.isBlank(messageTemplate.getTeam()) ? AustinConstant.DEFAULT_TEAM : messageTemplate.getTeam()) + .setAuditor(StrUtil.isBlank(messageTemplate.getAuditor()) ? AustinConstant.DEFAULT_AUDITOR : messageTemplate.getAuditor()) .setCreated(Math.toIntExact(DateUtil.currentSeconds())) .setIsDeleted(CommonConstant.FALSE); diff --git a/austin-web/src/main/java/com/java3y/austin/web/utils/Convert4Amis.java b/austin-web/src/main/java/com/java3y/austin/web/utils/Convert4Amis.java index 5fb0d2c..3e866cb 100644 --- a/austin-web/src/main/java/com/java3y/austin/web/utils/Convert4Amis.java +++ b/austin-web/src/main/java/com/java3y/austin/web/utils/Convert4Amis.java @@ -6,6 +6,7 @@ import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.java3y.austin.support.domain.ChannelAccount; import com.java3y.austin.web.vo.amis.CommonAmisVo; import lombok.extern.slf4j.Slf4j; import me.chanjar.weixin.common.bean.subscribemsg.TemplateInfo; @@ -343,4 +344,20 @@ public class Convert4Amis { return CommonAmisVo.builder().type("form").title("登录").mode("horizontal").body(Arrays.asList(image, service)).build(); } + /** + * 【这个方法不用看】,纯粹为了适配amis前端 + *

+ * 得到渠道账号信息,返回给前端做展示 + * + * @return + */ + public static List getChannelAccountVo(List channelAccounts) { + List result = new ArrayList<>(); + for (ChannelAccount channelAccount : channelAccounts) { + CommonAmisVo commonAmisVo = CommonAmisVo.builder().label(channelAccount.getName()).value(String.valueOf(channelAccount.getId())).build(); + result.add(commonAmisVo); + } + return result; + } + } diff --git a/austin-web/src/main/java/com/java3y/austin/web/utils/LoginUtils.java b/austin-web/src/main/java/com/java3y/austin/web/utils/LoginUtils.java new file mode 100644 index 0000000..512e473 --- /dev/null +++ b/austin-web/src/main/java/com/java3y/austin/web/utils/LoginUtils.java @@ -0,0 +1,57 @@ +package com.java3y.austin.web.utils; + +import com.java3y.austin.common.constant.CommonConstant; +import com.java3y.austin.common.constant.OfficialAccountParamConstant; +import com.java3y.austin.web.config.WeChatLoginConfig; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.ApplicationContext; +import org.springframework.stereotype.Component; + +/** + * @author 3y + * @date 2022/12/22 + * 微信服务号登录的Utils + */ +@Component +@Slf4j +public class LoginUtils { + + @Autowired + private ApplicationContext applicationContext; + + @Value("${spring.profiles.active}") + private String env; + + /** + * 测试环境 使用 + * 获取 WeChatLoginConfig 对象 + * + * @return + */ + public WeChatLoginConfig getLoginConfig() { + try { + return applicationContext.getBean(OfficialAccountParamConstant.WE_CHAT_LOGIN_CONFIG, WeChatLoginConfig.class); + } catch (Exception e) { + return null; + } + } + + /** + * 测试环境使用 + * 判断是否需要登录 + * + * @return + */ + public boolean needLogin() { + try { + WeChatLoginConfig bean = applicationContext.getBean(OfficialAccountParamConstant.WE_CHAT_LOGIN_CONFIG, WeChatLoginConfig.class); + if (CommonConstant.ENV_TEST.equals(env) && bean != null) { + return true; + } + } catch (Exception e) { + } + return false; + } +} diff --git a/austin-web/src/main/java/com/java3y/austin/web/vo/MessageTemplateParam.java b/austin-web/src/main/java/com/java3y/austin/web/vo/MessageTemplateParam.java index 3ea7713..847c54c 100644 --- a/austin-web/src/main/java/com/java3y/austin/web/vo/MessageTemplateParam.java +++ b/austin-web/src/main/java/com/java3y/austin/web/vo/MessageTemplateParam.java @@ -37,6 +37,11 @@ public class MessageTemplateParam { */ private Long id; + /** + * 当前用户 + */ + private String creator; + /** * 消息接收者(测试发送时使用) */ diff --git a/austin-web/src/main/resources/application-test.properties b/austin-web/src/main/resources/application-test.properties index 4ecc180..ce2781f 100644 --- a/austin-web/src/main/resources/application-test.properties +++ b/austin-web/src/main/resources/application-test.properties @@ -45,7 +45,7 @@ austin.grayLog.ip=austin.graylog austin.business.upload.crowd.path=/Users/3y/temp # TODO if [login use officialAccount] switch 【optional】, if austin.login.official.account.enable=true 【must】 -austin.login.official.account.enable=false -austin.login.official.account.appId=wx22222b325 -austin.login.official.account.secret=203233fa99 +austin.login.official.account.enable=true +austin.login.official.account.appId=wx27f83ca10e06b325 +austin.login.official.account.secret=203299484df873a18621d076db46fa99 austin.login.official.account.token=austin123 \ No newline at end of file diff --git a/sql/austin.sql b/sql/austin.sql index f23e2ec..69cf9f9 100644 --- a/sql/austin.sql +++ b/sql/austin.sql @@ -68,6 +68,7 @@ CREATE TABLE `channel_account` `name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '账号名称', `send_channel` tinyint(4) NOT NULL DEFAULT '0' COMMENT '消息发送渠道:10.IM 20.Push 30.短信 40.Email 50.公众号 60.小程序 70.企业微信 80.钉钉机器人 90.钉钉工作通知 100.企业微信机器人 110.飞书机器人 110. 飞书应用消息 ', `account_config` varchar(1024) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '账号配置', + `creator` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'Java3y' COMMENT '拥有者', `created` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `updated` int(11) NOT NULL DEFAULT '0' COMMENT '更新时间', `is_deleted` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否删除:0.不删除 1.删除',