|
|
@@ -0,0 +1,133 @@
|
|
|
+package com.tianhu.system.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
+import com.keao.tianhu.core.entity.R;
|
|
|
+import com.tianhu.common.core.utils.CommonUtil;
|
|
|
+import com.tianhu.common.redis.common.RedisUtils;
|
|
|
+import com.tianhu.system.api.domain.SysUser;
|
|
|
+import com.tianhu.system.common.impl.MessageUtilsServiceImpl;
|
|
|
+import com.tianhu.system.domain.SysNotice;
|
|
|
+import com.tianhu.system.domain.SysNoticeUserRel;
|
|
|
+import com.tianhu.system.service.IOwnNoticeService;
|
|
|
+import com.tianhu.system.service.ISysNoticeService;
|
|
|
+import com.tianhu.system.service.ISysNoticeUserRelService;
|
|
|
+import com.tianhu.system.service.ISysUserService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 通知Service业务层处理
|
|
|
+ *
|
|
|
+ * @author keao
|
|
|
+ * @date 2020-08-25
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class OwnNoticeServiceImpl implements IOwnNoticeService
|
|
|
+{
|
|
|
+ @Autowired
|
|
|
+ private ISysNoticeService iSysNoticeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysNoticeUserRelService iSysNoticeUserRelService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MessageUtilsServiceImpl messageUtilsService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysUserService iSysUserService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通知类型 00待办
|
|
|
+ */
|
|
|
+ static final String TYPE_WORK = "00";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通知类型 01消息
|
|
|
+ */
|
|
|
+ static final String TYPE_NOTICE = "01";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送短信 1发送
|
|
|
+ */
|
|
|
+ static final String SEND_MESSAGES = "1";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param companyId 企业id
|
|
|
+ * @param tableId 表主键
|
|
|
+ * @param title 标题
|
|
|
+ * @param type 类型 00待办 01消息
|
|
|
+ * @param noticeType 消息类型 00费用提醒 01发票寄出 02到期还款
|
|
|
+ * @param workType 待办类型 00待审批 01链属企业申请 02融信失效
|
|
|
+ * @param messageSend 是否发送短信 0不发送 1发送
|
|
|
+ * @param userIds 收到信息用户id集合
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public R sendNotice(String companyId, String tableId, String title, String type, String noticeType, String workType, String messageSend, List<Long> userIds)
|
|
|
+ {
|
|
|
+ //新增通知公告
|
|
|
+ SysNotice notice = new SysNotice();
|
|
|
+ //主键
|
|
|
+ String id = IdUtil.fastSimpleUUID();
|
|
|
+ notice.setNoticeId(id);
|
|
|
+ //企业id
|
|
|
+ notice.setCompanyId(companyId);
|
|
|
+ //表主键
|
|
|
+ notice.setTableId(tableId);
|
|
|
+ //标题
|
|
|
+ notice.setNoticeTitle(title);
|
|
|
+ //类型 00待办 01消息
|
|
|
+ notice.setType(type);
|
|
|
+ //消息类型 00费用提醒 01发票寄出 02到期还款
|
|
|
+ notice.setNoticeType(noticeType);
|
|
|
+ //待办类型 00待审批 01链属企业申请 02融信失效
|
|
|
+ notice.setWorkType(workType);
|
|
|
+ //是否发送短信 0不发送 1发送
|
|
|
+ notice.setMessageSend(messageSend);
|
|
|
+ //发送短信手机号
|
|
|
+ String phones = "";
|
|
|
+ //新增通知公告接收人
|
|
|
+ for (Long userId : userIds) {
|
|
|
+ SysNoticeUserRel sysNoticeUserRel = new SysNoticeUserRel();
|
|
|
+ sysNoticeUserRel.setSnyrNoticeId(id);
|
|
|
+ sysNoticeUserRel.setSnyrUserId(userId);
|
|
|
+ iSysNoticeUserRelService.insertSysNoticeUserRel(sysNoticeUserRel);
|
|
|
+ //查询发送人手机号
|
|
|
+ SysUser user = iSysUserService.selectUserById(userId);
|
|
|
+ if (CommonUtil.isEmpty(phones)){
|
|
|
+ phones = user.getUserName();
|
|
|
+ }else {
|
|
|
+ phones = phones.concat(",").concat(user.getUserName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //如果发送短信
|
|
|
+ if(SEND_MESSAGES.equals(messageSend)){
|
|
|
+ try {
|
|
|
+ //消息模版id
|
|
|
+ String templateCode = null;
|
|
|
+ if(TYPE_WORK.equals(type)){
|
|
|
+ //待办
|
|
|
+ templateCode = RedisUtils.getDictValue("sys_work_type", workType);
|
|
|
+ }else if (TYPE_NOTICE.equals(type)){
|
|
|
+ //消息
|
|
|
+ templateCode = RedisUtils.getDictValue("sys_notice_type", noticeType);
|
|
|
+ }
|
|
|
+ //消息模版参数
|
|
|
+ Map map = new HashMap();
|
|
|
+ //TODO 发送短信
|
|
|
+// messageUtilsService.sendMessageCode(phones, templateCode, map,null);
|
|
|
+ //发送短信成功
|
|
|
+ notice.setMessageStatus("1");
|
|
|
+ }catch(Exception e){
|
|
|
+ //发送短信失败
|
|
|
+ notice.setMessageStatus("0");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ iSysNoticeService.insertNotice(notice);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+}
|