1
2
3
4
5 package gboat2.attachment.business.impl;
6
7 import gboat2.base.core.dao.QuerySupport;
8 import gboat2.base.core.service.BaseService;
9 import gboat2.attachment.business.IAttachConfigBusiness;
10 import gboat2.attachment.model.AttachConfig;
11
12 import java.math.BigInteger;
13 import java.util.HashMap;
14 import java.util.List;
15 import java.util.Map;
16
17 import org.apache.commons.lang3.StringUtils;
18 import org.springframework.stereotype.Service;
19 import org.springframework.transaction.annotation.Transactional;
20
21
22
23
24
25
26
27 @Transactional
28 @Service
29 public class AttachConfigBusinessImpl extends BaseService implements IAttachConfigBusiness {
30
31 @SuppressWarnings("unchecked")
32 @Override
33 public List<AttachConfig> getAvailableAttachTypesByCode(String attachCode) {
34 if (StringUtils.isEmpty(attachCode)) {
35 return null;
36 }
37 Map<String, Object> params = new HashMap<String, Object>();
38 params.put(QuerySupport.PARAM_TABLENAME, AttachConfig.class);
39 params.put("_attachCode", attachCode);
40 params.put("_avaliable", "true");
41 params.put(QuerySupport.PARAM_ORDERBY, "attachOrder");
42 return (List<AttachConfig>) super.query(params);
43 }
44
45 @Deprecated
46 public String[][] getAvailableAttachTypeByCode(String attachCode) {
47 List<AttachConfig> list = getAvailableAttachTypesByCode(attachCode);
48 String[][] configs = null;
49 if (list != null && list.size() > 0) {
50 configs = new String[list.size()][5];
51 int i = 0;
52 for (AttachConfig config : list) {
53 if (config == null)
54 continue;
55 if (StringUtils.isEmpty(config.getAttachType()))
56 continue;
57 if (StringUtils.isEmpty(config.getRequired()))
58 continue;
59 configs[i][0] = config.getConfigId();
60 configs[i][1] = config.getAttachType();
61 configs[i][2] = config.getRequired();
62 configs[i][3] = null == config.getMaxFileCount() ? "-1" : config.getMaxFileCount().toString();
63 configs[i][4] = config.getFileFilters();
64 i++;
65 }
66 }
67 return configs;
68 }
69
70 @Override
71 public boolean isAttachTypeUsedInAttachment(String attachType) {
72 String hql = "select count(ATTACHMENT_ID) as num from gb_t_attachment where ATTACH_NAME='" + attachType + "'";
73 List<?> list = super.baseDAO.queryListBySql(hql, null);
74 if (list != null) {
75 BigInteger num = (BigInteger) list.get(0);
76 if (num.compareTo(BigInteger.ZERO) > 0) {
77 return true;
78 }
79 }
80 return false;
81 }
82
83 @Override
84 public boolean isAttachTypeUsedInConfig(String moduleName, String attachType) {
85 String hql = "select count(CONFIG_ID) as num from GB_T_ATTACH_CONFIG where ATTACH_TYPE='" + attachType + "' and MODULE_NAME='" + moduleName
86 + "'";
87 List<?> list = super.baseDAO.queryListBySql(hql, null);
88 if (list != null) {
89 BigInteger num = (BigInteger) list.get(0);
90 if (num.compareTo(BigInteger.ZERO) > 0) {
91 return true;
92 }
93 }
94 return false;
95 }
96
97
98
99
100 @SuppressWarnings("unchecked")
101 @Override
102 public AttachConfig getAttachConfigBy(String attachCode, String attachType) {
103 if (StringUtils.isEmpty(attachCode) && StringUtils.isEmpty(attachType)) {
104 return null;
105 }
106 Map<String, Object> params = new HashMap<String, Object>();
107 params.put(QuerySupport.PARAM_TABLENAME, AttachConfig.class);
108 if (StringUtils.isNotEmpty(attachCode)) {
109 params.put("_attachCode", attachCode);
110 }
111 if (StringUtils.isNotEmpty(attachType)) {
112 params.put("_attachType", attachType);
113 }
114 params.put(QuerySupport.PARAM_ORDERBY, "attachOrder");
115 AttachConfig config = null;
116 List<AttachConfig> confList = (List<AttachConfig>) super.query(params);
117 if (confList != null && confList.size() > 0) {
118 config = (AttachConfig) confList.get(0);
119 }
120 return config;
121 }
122
123 @Override
124 public String getAttachConfigIdBy(String attachCode, String attachType) {
125 String configId = null;
126 AttachConfig config = (AttachConfig) this.getAttachConfigBy(attachCode, attachType);
127 if (null != config) {
128 configId = config.getConfigId();
129 }
130 return configId;
131 }
132
133 }