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.
 
 
 
 

182 lines
5.7 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.meeting.service;
  10. import java.util.List;
  11. import java.util.Map;
  12. import com.ffii.core.dao.JdbcDao;
  13. import com.ffii.core.utils.BooleanUtils;
  14. import com.ffii.core.utils.MapUtils;
  15. import com.ffii.core.utils.Params;
  16. import com.ffii.core.utils.SecurityUtils;
  17. import com.ffii.core.web.AbstractService;
  18. import com.ffii.tbms.meeting.Meeting;
  19. import com.ffii.tbms.meeting.dao.MeetingDao;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.stereotype.Service;
  22. import org.springframework.transaction.annotation.Isolation;
  23. import org.springframework.transaction.annotation.Transactional;
  24. /**
  25. * @author Patrick
  26. */
  27. @Service
  28. public class MeetingService extends AbstractService {
  29. @Autowired
  30. private JdbcDao jdbcDao;
  31. @Autowired
  32. private MeetingDao meetingDao;
  33. @Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class, readOnly = false)
  34. public Integer saveOrUpdate(Meeting instance) {
  35. return meetingDao.saveOrUpdate(instance);
  36. }
  37. @Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class, readOnly = true)
  38. public Meeting find(Integer id) {
  39. return meetingDao.find(id);
  40. }
  41. private String getSearchCriteriaString(Map<String, Object> args) {
  42. StringBuilder sql = new StringBuilder("");
  43. if (args != null) {
  44. if (args.containsKey("fromDate"))
  45. sql.append(" AND DATE(m.date) >= DATE(:fromDate) ");
  46. if (args.containsKey("toDate"))
  47. sql.append(" AND DATE(m.date) < :toDate ");
  48. if (args.containsKey("custId"))
  49. sql.append(" AND m.custId = :custId ");
  50. if (args.containsKey("orderId"))
  51. sql.append(" AND m.orderId = :orderId ");
  52. if (args.containsKey(Params.ID))
  53. sql.append(" AND m.id = :id");
  54. if(args.containsKey("sysGroupId")){
  55. sql.append(" AND m.sysGroupId = :sysGroupId ");
  56. }
  57. }
  58. return sql.toString();
  59. }
  60. @Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class, readOnly = true)
  61. public List<Map<String, Object>> search(Map<String, Object> args) {
  62. SecurityUtils.authArgs(args);
  63. StringBuilder sql = new StringBuilder(" SELECT "
  64. + " m.*, "
  65. + " concat_ws(' / ', c.phone1, c.phone2) AS phone, "
  66. + " c.email, "
  67. + " concat(o.type,' ',o.code) AS orderNo , "
  68. + " CONCAT(IF(c.firstName IS NULL, '', CONCAT(c.firstName, ' ')), "
  69. + " IF(c.surname IS NULL, '', CONCAT(c.surname, ' ')), "
  70. + " IF(c.nameCh IS NULL, '', c.nameCh)) AS customerName "
  71. + " FROM meeting m "
  72. + " LEFT JOIN customer c ON c.id = m.custId "
  73. + " LEFT JOIN orders o ON o.id = m.orderId "
  74. + " WHERE m.deleted = 0 ");
  75. sql.append(getSearchCriteriaString(args));
  76. if(args.containsKey("sysGroupId")){
  77. sql.append(" AND m.sysGroupId = :sysGroupId ");
  78. }
  79. if (args.containsKey("meetingDate")) {
  80. sql.append(" AND DATE(m.date) = :meetingDate");
  81. }
  82. if (args.containsKey("isDESC") && BooleanUtils.isTrue(args.get("isDESC"))) {
  83. sql.append(" ORDER BY m.date DESC, m.id DESC ");
  84. }else{
  85. sql.append(" ORDER BY m.date ASC, m.id ASC ");
  86. }
  87. if (args != null) {
  88. if (args.containsKey("start") && args.containsKey("limit"))
  89. sql.append(" LIMIT :start, :limit");
  90. }
  91. logger.info(sql.toString());
  92. return jdbcDao.queryForList(sql.toString(), args);
  93. }
  94. @Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class, readOnly = true)
  95. public Map<String, Object> countSearch(Map<String, Object> args) {
  96. SecurityUtils.authArgs(args);
  97. StringBuilder sql = new StringBuilder(" SELECT count(*) AS count FROM meeting m WHERE m.deleted = 0 ");
  98. sql.append(getSearchCriteriaString(args));
  99. if(args.containsKey("sysGroupId")){
  100. sql.append(" AND m.sysGroupId = :sysGroupId ");
  101. }
  102. if (args.containsKey("meetingDate")) {
  103. sql.append(" AND m.date = :meetingDate");
  104. }
  105. return jdbcDao.queryForMap(sql.toString(), args);
  106. }
  107. @Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class, readOnly = true)
  108. public Map<String, Object> queryForMap(Integer id) {
  109. Map<String, Object> args = MapUtils.toHashMap(Params.ID, id);
  110. SecurityUtils.authArgs(args);
  111. String sql = "SELECT * FROM meeting m WHERE m.id = :id";
  112. if(args.containsKey("sysGroupId")){
  113. sql+=" AND m.sysGroupId = :sysGroupId ";
  114. }
  115. return jdbcDao.queryForMap(sql, args);
  116. }
  117. @Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class, readOnly = true)
  118. public List<Map<String, Object>> searchForCalendar(Map<String, Object> args) {
  119. SecurityUtils.authArgs(args);
  120. StringBuilder sql = new StringBuilder("SELECT Date(m.date) as date, "
  121. + " SUM(IF(type = " + Meeting.TYPE_COMMISSION + ", 1, 0)) AS commission, "
  122. + " SUM(IF(type = " + Meeting.TYPE_FITTING + ", 1, 0)) AS fitting, "
  123. + " SUM(IF(type = " + Meeting.TYPE_PICKUP + ", 1, 0)) AS pickup, "
  124. + " SUM(IF(type = " + Meeting.TYPE_NEW + ", 1, 0)) AS new "
  125. + " FROM meeting m "
  126. + " WHERE m.deleted = 0 ");
  127. if(args.containsKey("sysGroupId")){
  128. sql.append(" AND m.sysGroupId = :sysGroupId ");
  129. }
  130. sql.append(getSearchCriteriaString(args));
  131. sql.append(" GROUP BY DATE(m.date) ORDER BY DATE(m.date) DESC ");
  132. logger.info("searchForCalendar:"+sql.toString());
  133. logger.info("args:"+args);
  134. return jdbcDao.queryForList(sql.toString(), args);
  135. }
  136. public void addActionLog(int refId, String table, String recordStr){
  137. }
  138. }