| | |
| | | package com.yeshi.fanli.service.impl.user;
|
| | |
|
| | | import java.io.Serializable;
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.hibernate.HibernateException;
|
| | | import org.hibernate.Session;
|
| | | import org.springframework.orm.hibernate4.HibernateCallback;
|
| | | import org.springframework.stereotype.Service;
|
| | |
|
| | | import com.yeshi.fanli.dao.config.SystemZnxDao;
|
| | | import com.yeshi.fanli.dao.user.AccountMessageDao;
|
| | | import com.yeshi.fanli.dao.user.UserInfoDao;
|
| | | import com.yeshi.fanli.dao.mybatis.AccountMessageMapper;
|
| | | import com.yeshi.fanli.entity.bus.user.AccountMessage;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.system.SystemZnx;
|
| | | import com.yeshi.fanli.service.inter.user.AccountMessageService;
|
| | | import com.yeshi.fanli.service.inter.user.SystemZnxService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | |
|
| | | @Service
|
| | | public class AccountMessageServiceImpl implements AccountMessageService {
|
| | |
|
| | | @Resource
|
| | | private AccountMessageDao dao;
|
| | | private AccountMessageMapper accountMessageMapper;
|
| | | @Resource
|
| | | private UserInfoDao userInfoDao;
|
| | |
|
| | | private UserInfoService userInfoService;
|
| | | |
| | | @Resource
|
| | | private SystemZnxDao systemZnxDao;
|
| | |
|
| | | @Resource
|
| | | private AccountMessageService accountMessageService;
|
| | | private SystemZnxService systemZnxService;
|
| | |
|
| | | @Override
|
| | | public List<AccountMessage> findAccountMessageList(long uid, int page) {
|
| | | return dao.list("from AccountMessage am where am.userInfo.id=? order by id desc",
|
| | | (page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, new Serializable[] { uid });
|
| | | return accountMessageMapper.listByUidOrderByIdDesc(uid, (page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int getCount(long uid) {
|
| | | return (int) dao.getCount("select count(*) from AccountMessage am where am.userInfo.id=?",
|
| | | new Serializable[] { uid });
|
| | | return (int) accountMessageMapper.countByUidAndOpen(uid, null);
|
| | |
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void open(long id) {
|
| | | AccountMessage find = dao.find(AccountMessage.class, id);
|
| | | AccountMessage find = accountMessageMapper.selectByPrimaryKey(id);
|
| | | if (find != null) {
|
| | | find.setIsOpen(true);
|
| | | dao.update(find);
|
| | | AccountMessage update = new AccountMessage();
|
| | | update.setId(id);
|
| | | update.setIsOpen(true);
|
| | | accountMessageMapper.updateByPrimaryKeySelective(update);
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int getCanOpenCount(long uid) {
|
| | | return (int) dao.getCount("select count(*) from AccountMessage am where am.userInfo.id=? and am.isOpen=0",
|
| | | new Serializable[] { uid });
|
| | | return (int) accountMessageMapper.countByUidAndOpen(uid, false);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void save(AccountMessage accountMessage) {
|
| | | if (accountMessage != null)
|
| | | dao.save(accountMessage);
|
| | | accountMessageMapper.insertSelective(accountMessage);
|
| | | }
|
| | |
|
| | | @SuppressWarnings("unchecked")
|
| | | @Override
|
| | | public void syncSystemZnx(long uid) {
|
| | | UserInfo userInfo = userInfoDao.find(UserInfo.class, uid);
|
| | | UserInfo userInfo = userInfoService.selectByPKey(uid);
|
| | | if (userInfo == null)
|
| | | return;
|
| | | List<SystemZnx> list = (List<SystemZnx>) systemZnxDao.excute(new HibernateCallback<List<SystemZnx>>() {
|
| | | @SuppressWarnings("unchecked")
|
| | | @Override
|
| | | public List<SystemZnx> doInHibernate(Session session) throws HibernateException {
|
| | | List result = session
|
| | | .createSQLQuery(
|
| | | "SELECT sm.* FROM `yeshi_ec_system_msg` sm LEFT JOIN (SELECT * FROM `yeshi_ec_account_message` a WHERE a.`uid`=? AND a.`system_msg_id` IS NOT NULL) s ON s.`system_msg_id`=sm.`id` WHERE s.`system_msg_id` IS NULL and sm.createTime>="
|
| | | + userInfo.getCreatetime())
|
| | | .addEntity(SystemZnx.class).setParameter(0, uid).list();
|
| | | if (result != null) {
|
| | | List<SystemZnx> list = (List<SystemZnx>) result;
|
| | | return list;
|
| | | }
|
| | | return null;
|
| | | }
|
| | | });
|
| | | |
| | | List<SystemZnx> list = systemZnxService.listbyUidAndCreateTime(uid, userInfo.getCreatetime());
|
| | |
|
| | | if (list != null)
|
| | | for (SystemZnx systemZnx : list) {
|
| | | AccountMessage accountMessage = new AccountMessage();
|
| | |
| | | accountMessage.setIsOpen(false);
|
| | | accountMessage.setUserInfo(new UserInfo(uid));
|
| | | accountMessage.setSystemMsgId(systemZnx.getId());
|
| | | accountMessageService.save(accountMessage);
|
| | | save(accountMessage);
|
| | | }
|
| | | }
|
| | |
|