| | |
| | | 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.mybatis.msg.MsgDeviceReadStateMapper;
|
| | | import com.yeshi.fanli.entity.bus.msg.MsgDeviceReadState;
|
| | | import com.yeshi.fanli.service.inter.msg.MsgDeviceReadStateService;
|
| | |
|
| | | @Service
|
| | | public class MsgDeviceReadStateServiceImpl implements MsgDeviceReadStateService {
|
| | |
|
| | | @Resource
|
| | | private MsgDeviceReadStateMapper msgDeviceReadStateMapper;
|
| | |
|
| | | @Override
|
| | | public void setDeviceMsgRead(String type, String device, int platform) {
|
| | | MsgDeviceReadState state = msgDeviceReadStateMapper.selectByDeviceAndPlatformAndType(device, platform, type);
|
| | | if (state != null) {
|
| | | MsgDeviceReadState update = new MsgDeviceReadState();
|
| | | update.setId(state.getId());
|
| | | update.setReadTime(new Date());
|
| | | update.setUnReadCount(0);
|
| | | update.setUpdateTime(new Date());
|
| | | msgDeviceReadStateMapper.updateByPrimaryKeySelective(update);
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void addUnreadDeviceMsg(String type, String device, int platform, int msgCount, String msg) {
|
| | | MsgDeviceReadState state = msgDeviceReadStateMapper.selectByDeviceAndPlatformAndType(device, platform, type);
|
| | | if (state != null) {
|
| | | MsgDeviceReadState update = new MsgDeviceReadState();
|
| | | update.setId(state.getId());
|
| | | update.setUnReadCount(state.getUnReadCount() + msgCount);
|
| | | update.setUpdateTime(new Date());
|
| | | update.setLatestContent(msg);
|
| | | msgDeviceReadStateMapper.updateByPrimaryKeySelective(update);
|
| | | } else {
|
| | | state = new MsgDeviceReadState();
|
| | | state.setCreateTime(new Date());
|
| | | state.setDevice(device);
|
| | | state.setPlatform(platform);
|
| | | state.setType(type);
|
| | | state.setUnReadCount(msgCount);
|
| | | state.setUpdateTime(new Date());
|
| | | state.setLatestContent(msg);
|
| | | msgDeviceReadStateMapper.insertSelective(state);
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public MsgDeviceReadState getByDeviceAndPlatformAndType(String type, String device, int platform) {
|
| | | MsgDeviceReadState state = msgDeviceReadStateMapper.selectByDeviceAndPlatformAndType(device, platform, type);
|
| | | if (state == null) {
|
| | | state = new MsgDeviceReadState();
|
| | | state.setCreateTime(new Date());
|
| | | state.setDevice(device);
|
| | | state.setPlatform(platform);
|
| | | state.setType(type);
|
| | | state.setUnReadCount(0);
|
| | | state.setUpdateTime(new Date());
|
| | | msgDeviceReadStateMapper.insertSelective(state);
|
| | | }
|
| | | return state;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void setAllMsgRead(String device, int platform) {
|
| | | msgDeviceReadStateMapper.setAllMsgRead(device, platform);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void initReadState(String device, int platform, String type) {
|
| | | MsgDeviceReadState state = getByDeviceAndPlatformAndType(type, device, platform);
|
| | | if (state == null) {
|
| | | state = new MsgDeviceReadState();
|
| | | state.setCreateTime(new Date());
|
| | | state.setDevice(device);
|
| | | state.setPlatform(platform);
|
| | | state.setReadTime(null);
|
| | | state.setType(type);
|
| | | state.setUnReadCount(0);
|
| | | msgDeviceReadStateMapper.insertSelective(state);
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int getUnReadCount(String device, int platform) {
|
| | | int totalCount = 0;
|
| | | List<MsgDeviceReadState> stateList = msgDeviceReadStateMapper.listByDeviceAndPlatform(device, platform);
|
| | | for (MsgDeviceReadState state : stateList) {
|
| | | totalCount += state.getUnReadCount();
|
| | | }
|
| | | return totalCount;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int getUnReadCount(String device, int platform, String type) {
|
| | | MsgDeviceReadState state = getByDeviceAndPlatformAndType(type, device, platform);
|
| | | if (state == null)
|
| | | return 0;
|
| | | return state.getUnReadCount() == null ? 0 : state.getUnReadCount();
|
| | | }
|
| | |
|
| | | }
|
| | | 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.msg.MsgDeviceReadStateMapper; |
| | | import com.yeshi.fanli.entity.bus.msg.MsgDeviceReadState; |
| | | import com.yeshi.fanli.service.inter.msg.MsgDeviceReadStateService; |
| | | |
| | | @Service |
| | | public class MsgDeviceReadStateServiceImpl implements MsgDeviceReadStateService { |
| | | |
| | | @Resource |
| | | private MsgDeviceReadStateMapper msgDeviceReadStateMapper; |
| | | |
| | | @Override |
| | | public void setDeviceMsgRead(String type, String device, int platform) { |
| | | MsgDeviceReadState state = msgDeviceReadStateMapper.selectByDeviceAndPlatformAndType(device, platform, type); |
| | | if (state != null) { |
| | | MsgDeviceReadState update = new MsgDeviceReadState(); |
| | | update.setId(state.getId()); |
| | | update.setReadTime(new Date()); |
| | | update.setUnReadCount(0); |
| | | update.setUpdateTime(new Date()); |
| | | msgDeviceReadStateMapper.updateByPrimaryKeySelective(update); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void addUnreadDeviceMsg(String type, String device, int platform, int msgCount, String msg, Date msgTime) { |
| | | MsgDeviceReadState state = msgDeviceReadStateMapper.selectByDeviceAndPlatformAndType(device, platform, type); |
| | | if (state != null) { |
| | | MsgDeviceReadState update = new MsgDeviceReadState(); |
| | | update.setId(state.getId()); |
| | | update.setUnReadCount(state.getUnReadCount() + msgCount); |
| | | update.setUpdateTime(new Date()); |
| | | update.setLatestContent(msg); |
| | | update.setLatestContentTime(msgTime); |
| | | msgDeviceReadStateMapper.updateByPrimaryKeySelective(update); |
| | | } else { |
| | | state = new MsgDeviceReadState(); |
| | | state.setCreateTime(new Date()); |
| | | state.setDevice(device); |
| | | state.setPlatform(platform); |
| | | state.setType(type); |
| | | state.setUnReadCount(msgCount); |
| | | state.setUpdateTime(new Date()); |
| | | state.setLatestContent(msg); |
| | | state.setLatestContentTime(msgTime); |
| | | msgDeviceReadStateMapper.insertSelective(state); |
| | | } |
| | | } |
| | | |
| | | @Transactional |
| | | @Override |
| | | public MsgDeviceReadState getByDeviceAndPlatformAndType(String type, String device, int platform) { |
| | | MsgDeviceReadState state = msgDeviceReadStateMapper.selectByDeviceAndPlatformAndTypeForUpdate(device, platform, |
| | | type); |
| | | if (state == null) { |
| | | state = new MsgDeviceReadState(); |
| | | state.setCreateTime(new Date()); |
| | | state.setDevice(device); |
| | | state.setPlatform(platform); |
| | | state.setType(type); |
| | | state.setUnReadCount(0); |
| | | state.setUpdateTime(new Date()); |
| | | msgDeviceReadStateMapper.insertSelective(state); |
| | | } |
| | | return state; |
| | | } |
| | | |
| | | @Override |
| | | public void setAllMsgRead(String device, int platform) { |
| | | msgDeviceReadStateMapper.setAllMsgRead(device, platform); |
| | | } |
| | | |
| | | @Override |
| | | public void initReadState(String device, int platform, String type) { |
| | | MsgDeviceReadState state = getByDeviceAndPlatformAndType(type, device, platform); |
| | | if (state == null) { |
| | | state = new MsgDeviceReadState(); |
| | | state.setCreateTime(new Date()); |
| | | state.setDevice(device); |
| | | state.setPlatform(platform); |
| | | state.setReadTime(null); |
| | | state.setType(type); |
| | | state.setUnReadCount(0); |
| | | msgDeviceReadStateMapper.insertSelective(state); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public int getUnReadCount(String device, int platform) { |
| | | int totalCount = 0; |
| | | List<MsgDeviceReadState> stateList = msgDeviceReadStateMapper.listByDeviceAndPlatform(device, platform); |
| | | for (MsgDeviceReadState state : stateList) { |
| | | totalCount += state.getUnReadCount(); |
| | | } |
| | | return totalCount; |
| | | } |
| | | |
| | | @Override |
| | | public int getUnReadCount(String device, int platform, String type) { |
| | | MsgDeviceReadState state = getByDeviceAndPlatformAndType(type, device, platform); |
| | | if (state == null) |
| | | return 0; |
| | | return state.getUnReadCount() == null ? 0 : state.getUnReadCount(); |
| | | } |
| | | |
| | | } |