PageRenderTime 51ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/org/jeecgframework/core/common/service/impl/CommonServiceImpl.java

https://gitlab.com/spiderworts/ab_weixin_cms
Java | 459 lines | 211 code | 75 blank | 173 comment | 1 complexity | fed28ff4318c8d55aefd6a1ea761f2ed MD5 | raw file
  1. package org.jeecgframework.core.common.service.impl;
  2. import java.io.Serializable;
  3. import java.util.Collection;
  4. import java.util.List;
  5. import java.util.Map;
  6. import javax.annotation.Resource;
  7. import javax.servlet.http.HttpServletResponse;
  8. import org.jeecgframework.web.system.pojo.base.TSDepart;
  9. import org.hibernate.Session;
  10. import org.hibernate.criterion.DetachedCriteria;
  11. import org.jeecgframework.core.common.dao.ICommonDao;
  12. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  13. import org.jeecgframework.core.common.hibernate.qbc.HqlQuery;
  14. import org.jeecgframework.core.common.hibernate.qbc.PageList;
  15. import org.jeecgframework.core.common.model.common.DBTable;
  16. import org.jeecgframework.core.common.model.common.UploadFile;
  17. import org.jeecgframework.core.common.model.json.ComboTree;
  18. import org.jeecgframework.core.common.model.json.DataGridReturn;
  19. import org.jeecgframework.core.common.model.json.ImportFile;
  20. import org.jeecgframework.core.common.model.json.TreeGrid;
  21. import org.jeecgframework.core.common.service.CommonService;
  22. import org.jeecgframework.tag.vo.datatable.DataTableReturn;
  23. import org.jeecgframework.tag.vo.easyui.Autocomplete;
  24. import org.jeecgframework.tag.vo.easyui.ComboTreeModel;
  25. import org.jeecgframework.tag.vo.easyui.TreeGridModel;
  26. import org.springframework.stereotype.Service;
  27. import org.springframework.transaction.annotation.Transactional;
  28. @Service("commonService")
  29. @Transactional
  30. public class CommonServiceImpl implements CommonService {
  31. public ICommonDao commonDao = null;
  32. /**
  33. * 获取所有数据库表
  34. *
  35. * @return
  36. */
  37. public List<DBTable> getAllDbTableName() {
  38. return commonDao.getAllDbTableName();
  39. }
  40. public Integer getAllDbTableSize() {
  41. return commonDao.getAllDbTableSize();
  42. }
  43. @Resource
  44. public void setCommonDao(ICommonDao commonDao) {
  45. this.commonDao = commonDao;
  46. }
  47. public <T> Serializable save(T entity) {
  48. return commonDao.save(entity);
  49. }
  50. public <T> void saveOrUpdate(T entity) {
  51. commonDao.saveOrUpdate(entity);
  52. }
  53. public <T> void delete(T entity) {
  54. commonDao.delete(entity);
  55. }
  56. /**
  57. * 删除实体集合
  58. *
  59. * @param <T>
  60. * @param entities
  61. */
  62. public <T> void deleteAllEntitie(Collection<T> entities) {
  63. commonDao.deleteAllEntitie(entities);
  64. }
  65. /**
  66. * 根据实体名获取对象
  67. */
  68. public <T> T get(Class<T> class1, Serializable id) {
  69. return commonDao.get(class1, id);
  70. }
  71. /**
  72. * 根据实体名返回全部对象
  73. *
  74. * @param <T>
  75. * @param hql
  76. * @param size
  77. * @return
  78. */
  79. public <T> List<T> getList(Class clas) {
  80. return commonDao.loadAll(clas);
  81. }
  82. /**
  83. * 根据实体名获取对象
  84. */
  85. public <T> T getEntity(Class entityName, Serializable id) {
  86. return commonDao.getEntity(entityName, id);
  87. }
  88. /**
  89. * 根据实体名称和字段名称和字段值获取唯一记录
  90. *
  91. * @param <T>
  92. * @param entityClass
  93. * @param propertyName
  94. * @param value
  95. * @return
  96. */
  97. public <T> T findUniqueByProperty(Class<T> entityClass,
  98. String propertyName, Object value) {
  99. return commonDao.findUniqueByProperty(entityClass, propertyName, value);
  100. }
  101. /**
  102. * 按属性查找对象列表.
  103. */
  104. public <T> List<T> findByProperty(Class<T> entityClass,
  105. String propertyName, Object value) {
  106. return commonDao.findByProperty(entityClass, propertyName, value);
  107. }
  108. /**
  109. * 加载全部实体
  110. *
  111. * @param <T>
  112. * @param entityClass
  113. * @return
  114. */
  115. public <T> List<T> loadAll(final Class<T> entityClass) {
  116. return commonDao.loadAll(entityClass);
  117. }
  118. public <T> T singleResult(String hql) {
  119. return commonDao.singleResult(hql);
  120. }
  121. /**
  122. * 删除实体主键ID删除对象
  123. *
  124. * @param <T>
  125. * @param entities
  126. */
  127. public <T> void deleteEntityById(Class entityName, Serializable id) {
  128. commonDao.deleteEntityById(entityName, id);
  129. }
  130. /**
  131. * 更新指定的实体
  132. *
  133. * @param <T>
  134. * @param pojo
  135. */
  136. public <T> void updateEntitie(T pojo) {
  137. commonDao.updateEntitie(pojo);
  138. }
  139. /**
  140. * 通过hql 查询语句查找对象
  141. *
  142. * @param <T>
  143. * @param query
  144. * @return
  145. */
  146. public <T> List<T> findByQueryString(String hql) {
  147. return commonDao.findByQueryString(hql);
  148. }
  149. /**
  150. * 根据sql更新
  151. *
  152. * @param query
  153. * @return
  154. */
  155. public int updateBySqlString(String sql) {
  156. return commonDao.updateBySqlString(sql);
  157. }
  158. /**
  159. * 根据sql查找List
  160. *
  161. * @param <T>
  162. * @param query
  163. * @return
  164. */
  165. public <T> List<T> findListbySql(String query) {
  166. return commonDao.findListbySql(query);
  167. }
  168. /**
  169. * 通过属性称获取实体带排序
  170. *
  171. * @param <T>
  172. * @param clas
  173. * @return
  174. */
  175. public <T> List<T> findByPropertyisOrder(Class<T> entityClass,
  176. String propertyName, Object value, boolean isAsc) {
  177. return commonDao.findByPropertyisOrder(entityClass, propertyName,
  178. value, isAsc);
  179. }
  180. /**
  181. *
  182. * cq方式分页
  183. *
  184. * @param cq
  185. * @param isOffset
  186. * @return
  187. */
  188. public PageList getPageList(final CriteriaQuery cq, final boolean isOffset) {
  189. return commonDao.getPageList(cq, isOffset);
  190. }
  191. /**
  192. * 返回DataTableReturn模型
  193. *
  194. * @param cq
  195. * @param isOffset
  196. * @return
  197. */
  198. public DataTableReturn getDataTableReturn(final CriteriaQuery cq,
  199. final boolean isOffset) {
  200. return commonDao.getDataTableReturn(cq, isOffset);
  201. }
  202. /**
  203. * 返回easyui datagrid模型
  204. *
  205. * @param cq
  206. * @param isOffset
  207. * @return
  208. */
  209. public DataGridReturn getDataGridReturn(final CriteriaQuery cq,
  210. final boolean isOffset) {
  211. return commonDao.getDataGridReturn(cq, isOffset);
  212. }
  213. /**
  214. *
  215. * hqlQuery方式分页
  216. *
  217. * @param cq
  218. * @param isOffset
  219. * @return
  220. */
  221. public PageList getPageList(final HqlQuery hqlQuery,
  222. final boolean needParameter) {
  223. return commonDao.getPageList(hqlQuery, needParameter);
  224. }
  225. /**
  226. *
  227. * sqlQuery方式分页
  228. *
  229. * @param cq
  230. * @param isOffset
  231. * @return
  232. */
  233. public PageList getPageListBySql(final HqlQuery hqlQuery,
  234. final boolean isToEntity) {
  235. return commonDao.getPageListBySql(hqlQuery, isToEntity);
  236. }
  237. public Session getSession()
  238. {
  239. return commonDao.getSession();
  240. }
  241. public List findByExample(final String entityName,
  242. final Object exampleEntity) {
  243. return commonDao.findByExample(entityName, exampleEntity);
  244. }
  245. /**
  246. * 通过cq获取全部实体
  247. *
  248. * @param <T>
  249. * @param cq
  250. * @return
  251. */
  252. public <T> List<T> getListByCriteriaQuery(final CriteriaQuery cq,
  253. Boolean ispage) {
  254. return commonDao.getListByCriteriaQuery(cq, ispage);
  255. }
  256. /**
  257. * 文件上传
  258. *
  259. * @param request
  260. */
  261. public <T> T uploadFile(UploadFile uploadFile) {
  262. return commonDao.uploadFile(uploadFile);
  263. }
  264. public HttpServletResponse viewOrDownloadFile(UploadFile uploadFile)
  265. {
  266. return commonDao.viewOrDownloadFile(uploadFile);
  267. }
  268. /**
  269. * 生成XML文件
  270. *
  271. * @param fileName
  272. * XML全路径
  273. * @return
  274. */
  275. public HttpServletResponse createXml(ImportFile importFile) {
  276. return commonDao.createXml(importFile);
  277. }
  278. /**
  279. * 解析XML文件
  280. *
  281. * @param fileName
  282. * XML全路径
  283. */
  284. public void parserXml(String fileName) {
  285. commonDao.parserXml(fileName);
  286. }
  287. public List<ComboTree> comTree(List<TSDepart> all, ComboTree comboTree) {
  288. return commonDao.comTree(all, comboTree);
  289. }
  290. /**
  291. * 根据模型生成JSON
  292. *
  293. * @param all
  294. * 全部对象
  295. * @param in
  296. * 已拥有的对象
  297. * @param comboBox
  298. * 模型
  299. * @return
  300. */
  301. public List<ComboTree> ComboTree(List all, ComboTreeModel comboTreeModel,
  302. List in) {
  303. return commonDao.ComboTree(all, comboTreeModel, in);
  304. }
  305. /**
  306. * 构建树形数据表
  307. */
  308. public List<TreeGrid> treegrid(List all, TreeGridModel treeGridModel) {
  309. return commonDao.treegrid(all, treeGridModel);
  310. }
  311. /**
  312. * 获取自动完成列表
  313. *
  314. * @param <T>
  315. * @return
  316. */
  317. public <T> List<T> getAutoList(Autocomplete autocomplete) {
  318. StringBuffer sb = new StringBuffer("");
  319. for (String searchField : autocomplete.getSearchField().split(",")) {
  320. sb.append(" or " + searchField + " like '%"
  321. + autocomplete.getTrem() + "%' ");
  322. }
  323. String hql = "from " + autocomplete.getEntityName() + " where 1!=1 "
  324. + sb.toString();
  325. return commonDao.getSession().createQuery(hql)
  326. .setFirstResult(autocomplete.getCurPage() - 1)
  327. .setMaxResults(autocomplete.getMaxRows()).list();
  328. }
  329. public Integer executeSql(String sql, List<Object> param) {
  330. return commonDao.executeSql(sql, param);
  331. }
  332. public Integer executeSql(String sql, Object... param) {
  333. return commonDao.executeSql(sql, param);
  334. }
  335. public Integer executeSql(String sql, Map<String, Object> param) {
  336. return commonDao.executeSql(sql, param);
  337. }
  338. public Object executeSqlReturnKey(String sql, Map<String, Object> param) {
  339. return commonDao.executeSqlReturnKey(sql, param);
  340. }
  341. public List<Map<String, Object>> findForJdbc(String sql, int page, int rows) {
  342. return commonDao.findForJdbc(sql, page, rows);
  343. }
  344. public List<Map<String, Object>> findForJdbc(String sql, Object... objs) {
  345. return commonDao.findForJdbc(sql, objs);
  346. }
  347. public List<Map<String, Object>> findForJdbcParam(String sql, int page,
  348. int rows, Object... objs) {
  349. return commonDao.findForJdbcParam(sql, page, rows, objs);
  350. }
  351. public <T> List<T> findObjForJdbc(String sql, int page, int rows,
  352. Class<T> clazz) {
  353. return commonDao.findObjForJdbc(sql, page, rows, clazz);
  354. }
  355. public Map<String, Object> findOneForJdbc(String sql, Object... objs) {
  356. return commonDao.findOneForJdbc(sql, objs);
  357. }
  358. public Long getCountForJdbc(String sql) {
  359. return commonDao.getCountForJdbc(sql);
  360. }
  361. public Long getCountForJdbcParam(String sql, Object[] objs) {
  362. return commonDao.getCountForJdbcParam(sql,objs);
  363. }
  364. public <T> void batchSave(List<T> entitys) {
  365. this.commonDao.batchSave(entitys);
  366. }
  367. /**
  368. * 通过hql 查询语句查找对象
  369. *
  370. * @param <T>
  371. * @param query
  372. * @return
  373. */
  374. public <T> List<T> findHql(String hql, Object... param) {
  375. return this.commonDao.findHql(hql, param);
  376. }
  377. public <T> List<T> pageList(DetachedCriteria dc, int firstResult,
  378. int maxResult) {
  379. return this.commonDao.pageList(dc, firstResult, maxResult);
  380. }
  381. public <T> List<T> findByDetached(DetachedCriteria dc) {
  382. return this.commonDao.findByDetached(dc);
  383. }
  384. }