From d1f26741bddf6f512d62c0100d42c52be8d37e76 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期六, 06 二月 2021 15:35:40 +0800
Subject: [PATCH] 工具类优化

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/user/msg/MsgAccountDetailServiceImpl.java |  177 ++++++++++++++++++++++++++++++++--------------------------
 1 files changed, 98 insertions(+), 79 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/msg/MsgAccountDetailServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/msg/MsgAccountDetailServiceImpl.java
index 6993d12..f86a966 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/msg/MsgAccountDetailServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/msg/MsgAccountDetailServiceImpl.java
@@ -1,79 +1,98 @@
-package com.yeshi.fanli.service.impl.user.msg;
-
-import java.util.Date;
-import java.util.List;
-
-import javax.annotation.Resource;
-
-import org.springframework.stereotype.Service;
-
-import com.google.gson.Gson;
-import com.yeshi.fanli.dao.mybatis.msg.MsgAccountDetailMapper;
-import com.yeshi.fanli.dto.msg.MsgAccountVipDTO;
-import com.yeshi.fanli.entity.bus.msg.MsgAccountDetail;
-import com.yeshi.fanli.entity.bus.msg.MsgAccountDetail.MsgTypeAccountTypeEnum;
-import com.yeshi.fanli.entity.bus.msg.MsgOtherDetail.MsgTypeOtherTypeEnum;
-import com.yeshi.fanli.entity.bus.user.UserInfo;
-import com.yeshi.fanli.exception.msg.MsgAccountDetailException;
-import com.yeshi.fanli.exception.msg.MsgOtherDetailException;
-import com.yeshi.fanli.service.inter.msg.UserMsgReadStateService;
-import com.yeshi.fanli.service.inter.user.msg.MsgAccountDetailService;
-import com.yeshi.fanli.util.Constant;
-import com.yeshi.fanli.util.StringUtil;
-
-@Service
-public class MsgAccountDetailServiceImpl implements MsgAccountDetailService {
-
-	@Resource
-	private MsgAccountDetailMapper msgAccountDetailMapper;
-
-	@Resource
-	private UserMsgReadStateService userMsgReadStateService;
-
-	@Override
-	public void addMsgAccountDetail(MsgAccountDetail detail) throws MsgAccountDetailException {
-		if (detail == null)
-			throw new MsgAccountDetailException(1, "娑堟伅涓虹┖");
-		if (StringUtil.isNullOrEmpty(detail.getTitle()) || StringUtil.isNullOrEmpty(detail.getContent())
-				|| detail.getType() == null || detail.getUser() == null)
-			throw new MsgAccountDetailException(2, "娑堟伅鍐呭涓嶅畬鏁�");
-		// 鎸佷箙鍖栧埌鏁版嵁搴�
-		detail.setCreateTime(new Date());
-		detail.setUpdateTime(new Date());
-		detail.setRead(false);
-		msgAccountDetailMapper.insertSelective(detail);
-		userMsgReadStateService.addAccountMsgUnReadCount(detail.getUser().getId(), 1);
-	}
-
-	@Override
-	public List<MsgAccountDetail> listMsgAccountDetail(Long uid, int page) {
-		return msgAccountDetailMapper.listByUid(uid, (page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE);
-	}
-
-	@Override
-	public long countMsgAccountDetail(Long uid) {
-		return msgAccountDetailMapper.countByUid(uid);
-	}
-
-	@Override
-	public void readMsgByUid(Long uid) {
-		msgAccountDetailMapper.setMsgReadByUid(uid);
-	}
-
-	
-	@Override
-	public void addMsgVIP(Long uid, String title, String beiZhu, MsgAccountVipDTO dto) {
-		MsgAccountDetail detail = new MsgAccountDetail();
-		detail.setTitle(title);
-		detail.setBeiZhu(beiZhu);
-		detail.setCreateTime(new Date());
-		detail.setUpdateTime(new Date());
-		detail.setRead(false);
-		detail.setUser(new UserInfo(uid));
-		detail.setContent(new Gson().toJson(dto));
-		detail.setType(MsgTypeAccountTypeEnum.vipPgrade);
-		msgAccountDetailMapper.insertSelective(detail);
-		
-		userMsgReadStateService.addAccountMsgUnReadCount(detail.getUser().getId(), 1);
-	}
-}
+package com.yeshi.fanli.service.impl.user.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.google.gson.Gson;
+import com.yeshi.fanli.dao.mybatis.msg.MsgAccountDetailMapper;
+import com.yeshi.fanli.dto.msg.MsgAccountVipDTO;
+import com.yeshi.fanli.entity.bus.msg.MsgAccountDetail;
+import com.yeshi.fanli.entity.bus.msg.MsgAccountDetail.MsgTypeAccountTypeEnum;
+import com.yeshi.fanli.entity.bus.msg.MsgExtra;
+import com.yeshi.fanli.entity.bus.user.UserInfo;
+import com.yeshi.fanli.exception.msg.MsgAccountDetailException;
+import com.yeshi.fanli.service.inter.msg.MsgExtraService;
+import com.yeshi.fanli.service.inter.msg.UserMsgReadStateService;
+import com.yeshi.fanli.service.inter.user.msg.MsgAccountDetailService;
+import com.yeshi.fanli.util.Constant;
+import com.yeshi.fanli.util.StringUtil;
+
+@Service
+public class MsgAccountDetailServiceImpl implements MsgAccountDetailService {
+
+	@Resource
+	private MsgAccountDetailMapper msgAccountDetailMapper;
+
+	@Resource
+	private UserMsgReadStateService userMsgReadStateService;
+	
+	@Resource
+	private MsgExtraService msgExtraService;
+
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+	public void addMsgAccountDetail(MsgAccountDetail detail) throws MsgAccountDetailException {
+		if (detail == null || detail.getUser() == null || detail.getType() == null
+				|| StringUtil.isNullOrEmpty(detail.getExtraInfo()))
+			throw new MsgAccountDetailException(1, "娑堟伅淇℃伅涓嶅叏");
+		// 鎸佷箙鍖栧埌鏁版嵁搴�
+		detail.setCreateTime(new Date());
+		detail.setUpdateTime(new Date());
+		detail.setRead(false);
+		msgAccountDetailMapper.insertSelective(detail);
+		// 娑堟伅鍐呭
+		msgExtraService.addMsgExtra(detail.getId(), detail.getExtraInfo(), MsgExtra.MSG_TYPE_ACCOUNT);
+		// 绾㈢偣
+		userMsgReadStateService.addAccountMsgUnReadCount(detail.getUser().getId(), 1);
+	}
+
+	@Override
+	public List<MsgAccountDetail> listMsgAccountDetail(Long uid, int page) {
+		return msgAccountDetailMapper.listByUid(uid, (page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE);
+	}
+
+	@Override
+	public long countMsgAccountDetail(Long uid) {
+		return msgAccountDetailMapper.countByUid(uid);
+	}
+
+	@Override
+	public void readMsgByUid(Long uid) {
+		msgAccountDetailMapper.setMsgReadByUid(uid);
+	}
+
+	
+	@Override
+	public void addMsgVIP(Long uid, String title, String beiZhu, MsgAccountVipDTO dto) {
+		MsgAccountDetail detail = new MsgAccountDetail();
+		detail.setTitle(title);
+		detail.setBeiZhu(beiZhu);
+		detail.setCreateTime(new Date());
+		detail.setUpdateTime(new Date());
+		detail.setRead(false);
+		detail.setUser(new UserInfo(uid));
+		detail.setContent(new Gson().toJson(dto));
+		detail.setType(MsgTypeAccountTypeEnum.vipPgrade);
+		msgAccountDetailMapper.insertSelective(detail);
+		
+		userMsgReadStateService.addAccountMsgUnReadCount(detail.getUser().getId(), 1);
+	}
+	
+	
+	@Override
+	public MsgAccountDetail selectByPrimaryKey(Long id) {
+		return msgAccountDetailMapper.selectByPrimaryKey(id);
+	}
+	
+	@Override
+	public void deleteByPrimaryKey(Long id) {
+		msgAccountDetailMapper.deleteByPrimaryKey(id);
+		msgExtraService.deleteByPidAndType(id, MsgExtra.MSG_TYPE_ACCOUNT);
+	}
+	
+}

--
Gitblit v1.8.0