AppServiceImpl.java 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. package com.pcitc.imp.bizlog.bll.itf.impl;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.regex.Matcher;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.stereotype.Component;
  7. import org.springframework.stereotype.Service;
  8. import com.pcitc.imp.bizlog.bll.itf.AppService;
  9. import com.pcitc.imp.bizlog.dal.dao.AppDao;
  10. import com.pcitc.imp.bizlog.dal.dao.LogDao;
  11. import com.pcitc.imp.bizlog.exception.BusiException;
  12. import com.pcitc.imp.bizlog.service.model.Condition;
  13. import com.pcitc.imp.bizlog.util.CheckPrompt;
  14. import com.pcitc.imp.bizlog.util.CheckUtil;
  15. import com.pcitc.imp.bizlog.util.EntityUtil;
  16. import com.pcitc.imp.bizlog.util.ErrorCodeEnum;
  17. import pcitc.imp.common.ettool.utils.ObjectConverter;
  18. /**
  19. * @ClassName: AppServiceImpl
  20. * @Description: 业务应用集合
  21. * @author
  22. * @date 2016年9月5日 上午8:49:30
  23. */
  24. @Service
  25. @Component
  26. public class AppServiceImpl implements AppService{
  27. @Autowired
  28. private AppDao appDao;
  29. @Autowired
  30. private LogDao logDao;
  31. /**
  32. * @Title: getAppByCode
  33. * @Description: app查询-条件查询code
  34. * @throws BusiException
  35. * @return List<App> 返回类型
  36. */
  37. @SuppressWarnings("unchecked")
  38. public List<com.pcitc.imp.bizlog.bll.entity.App> getAppByCode(String code) throws BusiException {
  39. List<com.pcitc.imp.bizlog.dal.pojo.App> appList = null;
  40. List<com.pcitc.imp.bizlog.bll.entity.App> applists = new ArrayList<>();
  41. try {
  42. appList = appDao.getAppByCode(code);
  43. applists = ObjectConverter.listConverter(appList, com.pcitc.imp.bizlog.dal.pojo.App.class);
  44. } catch (BusiException e) {
  45. throw new BusiException(ErrorCodeEnum.M001, CheckPrompt.QUERY, e);
  46. } catch (Exception e) {
  47. e.printStackTrace();
  48. }
  49. return applists;
  50. }
  51. /**
  52. * @Title: addApp
  53. * @Description: 日志操作记录-添加
  54. * @return void 返回类型
  55. * @param appEntitys
  56. * @throws Exception
  57. */
  58. public int addApp(List<com.pcitc.imp.bizlog.bll.entity.App> etAppList) throws BusiException {
  59. List<com.pcitc.imp.bizlog.dal.pojo.App> pojoList = new ArrayList<>();
  60. List<BusiException> errDatas = new ArrayList<>();
  61. int count = etAppList.size();
  62. for(com.pcitc.imp.bizlog.bll.entity.App appEntity : etAppList){
  63. // 校验appcode是否已经存在
  64. if (appDao.queryByParam(appEntity.getCode())) {
  65. throw new BusiException(ErrorCodeEnum.M000, CheckPrompt.APP_CODE_REPEAT);
  66. }
  67. if(etAppList != null && etAppList.size()>0){
  68. count--;
  69. checkInput(appEntity,count,errDatas);
  70. }
  71. // entity转换为pojo
  72. com.pcitc.imp.bizlog.dal.pojo.App appPojo;
  73. try {
  74. appPojo = EntityUtil.entity2Pojo(appEntity);
  75. pojoList.add(appPojo);
  76. } catch (Exception e) {
  77. e.printStackTrace();
  78. }
  79. }
  80. // 创建app
  81. return appDao.insertApp(pojoList);
  82. }
  83. /**
  84. * @Title: deleteApp @Description: 日志操作记录-删除-根据条件删除 @param code 唯一条件 @return
  85. * void 返回类型 @throws
  86. */
  87. public void deleteApp(String code) throws BusiException {
  88. List<com.pcitc.imp.bizlog.dal.pojo.Log> logPojoList = null;
  89. Condition condition = new Condition();
  90. boolean logIndexExist = true;
  91. try {
  92. logPojoList = logDao.getLogsByCon(code, condition);
  93. } catch (BusiException e) {
  94. logIndexExist = false;
  95. }
  96. if (logIndexExist && !logPojoList.isEmpty()) {
  97. throw new BusiException(ErrorCodeEnum.M000, CheckPrompt.APP_CODE_REPEAT_LOG);
  98. }
  99. if (logIndexExist && logPojoList.isEmpty()) {
  100. logDao.deleteLogs(code);
  101. }
  102. // 校验appcode是否已经存在
  103. if (!appDao.queryByParam(code)) {
  104. throw new BusiException(ErrorCodeEnum.M000, CheckPrompt.APP_CODE_NOT_REPEAT);
  105. }
  106. appDao.deleteApp(code);
  107. }
  108. /**
  109. * @Title: updateAppName
  110. * @Description: 日志操作记录-修改
  111. * @param code
  112. * @param appEntitys
  113. * @throws BusiException
  114. * @return String 返回类型
  115. * @throws BusiException
  116. */
  117. @SuppressWarnings({ "unchecked", "unused" })
  118. public void updateAppName(String code, List<com.pcitc.imp.bizlog.bll.entity.App> appEntitys) throws BusiException {
  119. // 校验appcode是否已经存在
  120. for (com.pcitc.imp.bizlog.bll.entity.App appEntity:appEntitys) {
  121. if (!appDao.queryByParam(code)) {
  122. throw new BusiException(ErrorCodeEnum.M000, CheckPrompt.APP_CODE_NOT_REPEAT);
  123. }
  124. }
  125. List<com.pcitc.imp.bizlog.dal.pojo.App> appPojoList = null;
  126. try {
  127. appPojoList = ObjectConverter.listConverter(appEntitys, com.pcitc.imp.bizlog.dal.pojo.App.class);
  128. } catch (Exception e) {
  129. throw new BusiException(ErrorCodeEnum.M001, e.getMessage());
  130. }
  131. appDao.updateAppName(code, appPojoList.get(0));
  132. }
  133. /**
  134. * @Title: getAppsByPage
  135. * @Description:分页查询 +codeList 查询
  136. * @param skip
  137. * @param top
  138. * @throws BusiException
  139. * @return List<App> 返回类型
  140. */
  141. @SuppressWarnings("unchecked")
  142. public List<com.pcitc.imp.bizlog.bll.entity.App> getAppsByPage(List<Integer> countList,String skip, String top, String codes) throws BusiException {
  143. List<com.pcitc.imp.bizlog.dal.pojo.App> appPojo = null;
  144. List<com.pcitc.imp.bizlog.bll.entity.App> appEntity = new ArrayList<>();
  145. try {
  146. appPojo = appDao.getAppsByPage(countList,skip, top, codes);
  147. appEntity = ObjectConverter.listConverter(appPojo, com.pcitc.imp.bizlog.bll.entity.App.class);
  148. } catch (Exception e) {
  149. throw new BusiException(ErrorCodeEnum.M001, e.getMessage());
  150. }
  151. return appEntity;
  152. }
  153. @SuppressWarnings("unchecked")
  154. public List<com.pcitc.imp.bizlog.bll.entity.App> getAppsByPage(String skip, String top, String codes) throws BusiException {
  155. List<com.pcitc.imp.bizlog.dal.pojo.App> appPojo = null;
  156. List<com.pcitc.imp.bizlog.bll.entity.App> appEntity = new ArrayList<>();
  157. try {
  158. appPojo = appDao.getAppsByPage(skip, top, codes);
  159. appEntity = ObjectConverter.listConverter(appPojo, com.pcitc.imp.bizlog.bll.entity.App.class);
  160. } catch (Exception e) {
  161. throw new BusiException(ErrorCodeEnum.M001, e.getMessage());
  162. }
  163. return appEntity;
  164. }
  165. /**
  166. * 创建appregister表
  167. */
  168. public void creatAppRegister() throws BusiException{
  169. appDao.creatAppRegister();
  170. }
  171. /**
  172. * @Title: checkInput
  173. * @Description: 应用批量验证新增返回信息
  174. * @param appEntity
  175. * @param integer
  176. * @param errList
  177. * @throws BusiException
  178. * @return void 返回类型
  179. * @throws BusiException
  180. */
  181. public void checkInput(com.pcitc.imp.bizlog.bll.entity.App appEntity,Integer integer,List<BusiException> errList) throws BusiException {
  182. if (CheckUtil.checkStringIsNull(appEntity.getCode())) {
  183. errList.add(new BusiException(ErrorCodeEnum.M000, appEntity.getCode()+":"+CheckPrompt.APP_CODE_NULL));
  184. }
  185. if (CheckUtil.checkStringIsNull(appEntity.getName())) {
  186. errList.add(new BusiException(ErrorCodeEnum.M000, appEntity.getName()+":"+CheckPrompt.APP_NAME_NULL));
  187. }
  188. Matcher checkMatcher = CheckUtil.checkMatcher(appEntity.getCode());
  189. if (checkMatcher.find() == false) {
  190. errList.add(new BusiException(ErrorCodeEnum.M000, appEntity.getCode()+":"+CheckPrompt.CHECKMATCHER));
  191. }
  192. if (CheckUtil.characterFilter(appEntity.getName())) {
  193. errList.add(new BusiException(ErrorCodeEnum.M000, appEntity.getName()+":"+CheckPrompt.APP_NAME_CHECKMATCHER));
  194. }
  195. if(integer ==0){
  196. StringBuffer sb = new StringBuffer();
  197. if(errList != null && errList.size()>0){
  198. for (BusiException busiException : errList) {
  199. sb.append(busiException.getMessage()+" ");
  200. }
  201. throw new BusiException(ErrorCodeEnum.M000,sb.toString());
  202. }
  203. }
  204. }
  205. }