You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

87 lines
3.1 KiB

  1. /*******************************************************************************
  2. * Copyright 2Fi Business Solutions Ltd.
  3. *
  4. * This code is copyrighted. Under no circumstances should any party, people,
  5. * or organization should redistribute any portions of this code in any form,
  6. * either verbatim or through electronic media, to any third parties, unless
  7. * under explicit written permission by 2Fi Business Solutions Ltd.
  8. ******************************************************************************/
  9. package com.ffii.tbms.message.service;
  10. import java.util.List;
  11. import java.util.Map;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.stereotype.Service;
  14. import org.springframework.transaction.annotation.Isolation;
  15. import org.springframework.transaction.annotation.Transactional;
  16. import com.ffii.core.dao.JdbcDao;
  17. import com.ffii.core.utils.BooleanUtils;
  18. import com.ffii.core.utils.SecurityUtils;
  19. import com.ffii.core.web.AbstractService;
  20. import com.ffii.tbms.message.Message;
  21. import com.ffii.tbms.message.dao.MessageDao;
  22. @Service
  23. public class MessageService extends AbstractService {
  24. @Autowired
  25. private JdbcDao jdbcDao;
  26. @Autowired
  27. private MessageDao messageDao;
  28. @Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class, readOnly = true)
  29. public Message find(Integer id) {
  30. return messageDao.find(id);
  31. }
  32. @Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class, readOnly = false)
  33. public Integer saveOrUpdate(Message instance) {
  34. return messageDao.saveOrUpdate(instance);
  35. }
  36. @Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class, readOnly = true)
  37. public List<Map<String, Object>> search(Map<String, Object> args) {
  38. SecurityUtils.authArgs(args);
  39. StringBuilder sql = new StringBuilder(" SELECT m.* "
  40. +" FROM message m "
  41. +" WHERE m.deleted = 0 ");
  42. if (args != null) {
  43. if (args.containsKey("unRead") && BooleanUtils.isTrue(args.get("unRead")))
  44. sql.append(" AND readTime IS NULL ");
  45. if(args.containsKey("query")) sql.append(" AND m.content LIKE :query ");
  46. if(args.containsKey("sysGroupId")) sql.append(" AND m.sysGroupId = :sysGroupId ");
  47. }
  48. sql.append(" ORDER BY m.created DESC ");
  49. if (args != null) {
  50. if (args.containsKey("start") && args.containsKey("limit"))
  51. sql.append(" LIMIT :start, :limit ");
  52. }
  53. return jdbcDao.queryForList(sql.toString(), args);
  54. }
  55. @Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class, readOnly = true)
  56. public Map<String, Object> searchCount(Map<String, Object> args) {
  57. SecurityUtils.authArgs(args);
  58. StringBuilder sql = new StringBuilder(" SELECT count(m.id) AS count "
  59. +" FROM message m "
  60. +" WHERE m.deleted = 0 ");
  61. if (args != null) {
  62. if (args.containsKey("unRead") && BooleanUtils.isTrue(args.get("unRead")))
  63. sql.append(" AND readTime IS NULL ");
  64. if(args.containsKey("query")) sql.append(" AND m.content LIKE :query ");
  65. if(args.containsKey("sysGroupId")) sql.append(" AND m.sysGroupId = :sysGroupId ");
  66. }
  67. return jdbcDao.queryForMap(sql.toString(), args);
  68. }
  69. }