From a1be6075c6b1365a7abc66bf559d6058039248ab Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 19 五月 2021 18:13:29 +0800
Subject: [PATCH] 淘礼金兼容
---
fanli/src/main/java/com/yeshi/fanli/service/impl/msg/UserSystemMsgServiceImpl.java | 277 ++++++++++++++++++++++++++++---------------------------
1 files changed, 141 insertions(+), 136 deletions(-)
diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/msg/UserSystemMsgServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/msg/UserSystemMsgServiceImpl.java
index 0745cb3..30789c1 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/msg/UserSystemMsgServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/msg/UserSystemMsgServiceImpl.java
@@ -1,136 +1,141 @@
-package com.yeshi.fanli.service.impl.msg;
-
-import java.util.Date;
-import java.util.List;
-
-import javax.annotation.Resource;
-
-import org.springframework.stereotype.Service;
-
-import com.yeshi.fanli.dao.config.SystemZnxDao;
-import com.yeshi.fanli.dao.mybatis.UserInfoMapper;
-import com.yeshi.fanli.dao.mybatis.msg.UserSystemMsgMapper;
-import com.yeshi.fanli.entity.bus.msg.UserSystemMsg;
-import com.yeshi.fanli.entity.bus.msg.UserSystemMsgTypeEnum;
-import com.yeshi.fanli.entity.bus.user.UserInfo;
-import com.yeshi.fanli.entity.system.SystemZnx;
-import com.yeshi.fanli.exception.msg.UserSystemMsgException;
-import com.yeshi.fanli.service.inter.msg.UserMsgReadStateService;
-import com.yeshi.fanli.service.inter.msg.UserSystemMsgService;
-import com.yeshi.fanli.util.StringUtil;
-
-@Service
-public class UserSystemMsgServiceImpl implements UserSystemMsgService {
-
- @Resource
- private UserSystemMsgMapper userSystemMsgMapper;
-
- @Resource
- private UserMsgReadStateService userMsgReadStateService;
-
- @Resource
- private UserInfoMapper userInfoMapper;
-
- @Resource
- private SystemZnxDao systemZnxDao;
-
- @Override
- public void addUserSystemMsg(Long uid, UserSystemMsgTypeEnum type, String title, String content, int timeTag,
- SystemZnx sz) throws UserSystemMsgException {
- if (sz == null && (StringUtil.isNullOrEmpty(title) || StringUtil.isNullOrEmpty(content) || uid == null))
- throw new UserSystemMsgException(1, "淇℃伅涓嶅畬鏁�");
- UserSystemMsg msg = new UserSystemMsg();
- if (sz != null) {
- if (userSystemMsgMapper.selectBySystemZNXId(sz.getId()) == null) {
- msg.setCreateTime(new Date(sz.getCreateTime()));
- msg.setRead(false);
- msg.setSolved(false);
- msg.setSystemZNX(sz);
- msg.setUser(new UserInfo(uid));
- msg.setType(type);
- msg.setTimeTag(timeTag);
- } else
- throw new UserSystemMsgException(1, "娑堟伅宸插瓨鍦�");
- } else {
- msg.setCreateTime(new Date());
- msg.setRead(false);
- msg.setSolved(false);
- msg.setContent(content);
- msg.setTitle(title);
- msg.setUser(new UserInfo(uid));
- msg.setType(type);
- msg.setTimeTag(timeTag);
- }
- userSystemMsgMapper.insertSelective(msg);
- userMsgReadStateService.addSystemMsgUnReadCount(uid, 1);
- }
-
- @Override
- public UserSystemMsg getLatestUserSystemMsg(Long uid) {
- UserSystemMsg msg = userSystemMsgMapper.selectLatestUserSystemMsg(uid);
- if (msg != null)
- if (msg.getSystemZNX() != null) {
- msg.setTitle(msg.getSystemZNX().getTitle());
- msg.setContent(msg.getSystemZNX().getContent());
- }
- return msg;
- }
-
- @Override
- public List<UserSystemMsg> listUserSystemMsg(Long uid, int page, int pageSize) {
- List<UserSystemMsg> list = userSystemMsgMapper.listByUid(uid, (page - 1) * pageSize, pageSize);
- if (list != null)
- for (UserSystemMsg msg : list) {
- if (msg.getSystemZNX() != null) {
- msg.setTitle(msg.getSystemZNX().getTitle());
- msg.setContent(msg.getSystemZNX().getContent());
- }
- }
-
- return list;
- }
-
- @Override
- public long countUserSystemMsg(Long uid) {
- return userSystemMsgMapper.countByUid(uid);
- }
-
- @Override
- public void setSystemMsgSolved(Long uid, Long id) throws UserSystemMsgException {
- UserSystemMsg msg = userSystemMsgMapper.selectByPrimaryKey(id);
- if (msg.getUser().getId() != uid.longValue())
- throw new UserSystemMsgException(2, "涓嶆槸鑷繁鐨勬秷鎭�");
- UserSystemMsg update = new UserSystemMsg();
- update.setId(id);
- update.setSolved(true);
- update.setUpdateTime(new Date());
- userSystemMsgMapper.updateByPrimaryKeySelective(update);
- }
-
- @Override
- public void readMsgByUid(Long uid) {
- userSystemMsgMapper.setMsgReadByUid(uid);
- }
-
- @Override
- public void syncSystemZNX(Long uid) {
- UserInfo user = userInfoMapper.selectByPrimaryKey(uid);
- if (user == null)
- return;
- long createtTime = user.getCreatetime();
- List<SystemZnx> list = systemZnxDao.list("from SystemZnx s where s.createTime>=" + createtTime);
- if (list != null && list.size() > 0) {
- for (SystemZnx znx : list) {
- UserSystemMsg msg = userSystemMsgMapper.selectBySystemZNXId(znx.getId());
- if (msg == null)
- try {
- addUserSystemMsg(uid, UserSystemMsgTypeEnum.common, null, null, UserSystemMsg.TIME_TAG_COMMON, znx);
- } catch (UserSystemMsgException e) {
- e.printStackTrace();
- }
- }
-
- }
- }
-
-}
+package com.yeshi.fanli.service.impl.msg;
+
+import java.util.Date;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import com.yeshi.fanli.dao.mybatis.UserInfoMapper;
+import com.yeshi.fanli.dao.mybatis.msg.UserSystemMsgMapper;
+import com.yeshi.fanli.entity.bus.msg.UserSystemMsg;
+import com.yeshi.fanli.entity.bus.msg.UserSystemMsgTypeEnum;
+import com.yeshi.fanli.entity.bus.user.UserInfo;
+import com.yeshi.fanli.entity.system.SystemZnx;
+import com.yeshi.fanli.exception.msg.UserSystemMsgException;
+import com.yeshi.fanli.service.inter.msg.UserMsgReadStateService;
+import com.yeshi.fanli.service.inter.msg.UserSystemMsgService;
+import com.yeshi.fanli.service.inter.user.SystemZnxService;
+import com.yeshi.fanli.util.StringUtil;
+
+@Service
+public class UserSystemMsgServiceImpl implements UserSystemMsgService {
+
+ @Resource
+ private UserSystemMsgMapper userSystemMsgMapper;
+
+ @Resource
+ private UserMsgReadStateService userMsgReadStateService;
+
+ @Resource
+ private UserInfoMapper userInfoMapper;
+
+ @Resource
+ private SystemZnxService systemZnxService;
+
+ @Transactional(rollbackFor=Exception.class)
+ @Override
+ public void addUserSystemMsg(Long uid, UserSystemMsgTypeEnum type, String title, String content, int timeTag,
+ SystemZnx sz) throws UserSystemMsgException {
+ if (sz == null && (StringUtil.isNullOrEmpty(title) || StringUtil.isNullOrEmpty(content) || uid == null))
+ throw new UserSystemMsgException(1, "淇℃伅涓嶅畬鏁�");
+ UserSystemMsg msg = new UserSystemMsg();
+ if (sz != null) {
+ if (userSystemMsgMapper.selectBySystemZNXId(sz.getId(), uid) == null) {
+ msg.setCreateTime(new Date(sz.getCreateTime()));
+ msg.setRead(false);
+ msg.setSolved(false);
+ msg.setSystemZNX(sz);
+ msg.setUser(new UserInfo(uid));
+ msg.setType(type);
+ msg.setTimeTag(timeTag);
+ msg.setTitle(sz.getTitle());
+ msg.setContent(sz.getContent());
+ } else
+ throw new UserSystemMsgException(1, "娑堟伅宸插瓨鍦�");
+ } else {
+ msg.setCreateTime(new Date());
+ msg.setRead(false);
+ msg.setSolved(false);
+ msg.setContent(content);
+ msg.setTitle(title);
+ msg.setUser(new UserInfo(uid));
+ msg.setType(type);
+ msg.setTimeTag(timeTag);
+ }
+ userSystemMsgMapper.insertSelective(msg);
+ userMsgReadStateService.addSystemMsgUnReadCount(uid, 1);
+ }
+
+ @Override
+ public UserSystemMsg getLatestUserSystemMsg(Long uid) {
+ UserSystemMsg msg = userSystemMsgMapper.selectLatestUserSystemMsg(uid);
+ if (msg != null)
+ if (msg.getSystemZNX() != null) {
+ msg.setTitle(msg.getSystemZNX().getTitle());
+ msg.setContent(msg.getSystemZNX().getContent());
+ }
+ return msg;
+ }
+
+ @Override
+ public List<UserSystemMsg> listUserSystemMsg(Long uid, int page, int pageSize) {
+ List<UserSystemMsg> list = userSystemMsgMapper.listByUid(uid, (page - 1) * pageSize, pageSize);
+ if (list != null)
+ for (UserSystemMsg msg : list) {
+ if (msg.getSystemZNX() != null) {
+ msg.setTitle(msg.getSystemZNX().getTitle());
+ msg.setContent(msg.getSystemZNX().getContent());
+ }
+ }
+
+ return list;
+ }
+
+ @Override
+ public long countUserSystemMsg(Long uid) {
+ return userSystemMsgMapper.countByUid(uid);
+ }
+
+ @Override
+ public void setSystemMsgSolved(Long uid, Long id) throws UserSystemMsgException {
+ UserSystemMsg msg = userSystemMsgMapper.selectByPrimaryKey(id);
+ if (msg.getUser().getId() != uid.longValue())
+ throw new UserSystemMsgException(2, "涓嶆槸鑷繁鐨勬秷鎭�");
+ UserSystemMsg update = new UserSystemMsg();
+ update.setId(id);
+ update.setSolved(true);
+ update.setUpdateTime(new Date());
+ userSystemMsgMapper.updateByPrimaryKeySelective(update);
+ }
+
+ @Override
+ public void readMsgByUid(Long uid) {
+ userSystemMsgMapper.setMsgReadByUid(uid);
+ }
+
+ @Override
+ public void syncSystemZNX(Long uid) {
+ UserInfo user = userInfoMapper.selectAvailableByPrimaryKey(uid);
+ if (user == null)
+ return;
+ long createTime = user.getCreatetime();
+ List<SystemZnx> list = systemZnxService.listbyCreateTime(createTime);
+ if (list != null && list.size() > 0) {
+ for (SystemZnx znx : list) {
+ UserSystemMsg msg = userSystemMsgMapper.selectBySystemZNXId(znx.getId(), uid);
+ if (msg == null)
+ try {
+ addUserSystemMsg(uid, UserSystemMsgTypeEnum.common, null, null, UserSystemMsg.TIME_TAG_COMMON,
+ znx);
+ } catch (UserSystemMsgException e) {
+ e.printStackTrace();
+ }
+ }
+
+ }
+ }
+
+}
--
Gitblit v1.8.0