PostServiceImpl.java 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. package cn.com.lzt.post.service.impl;
  2. import cn.com.lzt.post.entity.PostEntity;
  3. import cn.com.lzt.post.service.PostServiceI;
  4. import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
  5. import org.jeecgframework.core.util.ApplicationContextUtil;
  6. import org.jeecgframework.core.util.MyClassLoader;
  7. import org.jeecgframework.core.util.StringUtil;
  8. import org.jeecgframework.web.cgform.enhance.CgformEnhanceJavaInter;
  9. import org.springframework.stereotype.Service;
  10. import org.springframework.transaction.annotation.Transactional;
  11. import java.io.Serializable;
  12. import java.util.*;
  13. @Service("postService")
  14. @Transactional
  15. public class PostServiceImpl extends CommonServiceImpl implements PostServiceI {
  16. public void delete(PostEntity entity) throws Exception{
  17. super.delete(entity);
  18. //执行删除操作增强业务
  19. this.doDelBus(entity);
  20. }
  21. /**
  22. * 逻辑删除
  23. */
  24. public void logicDel(PostEntity entity) throws Exception{
  25. super.updateEntitie(entity);
  26. //执行更新操作增强业务
  27. this.doUpdateBus(entity);
  28. }
  29. /**
  30. * 批量更新操作
  31. *
  32. */
  33. public void batchUpdate(List<PostEntity> entityList) throws Exception{
  34. for(PostEntity entity : entityList){
  35. super.updateEntitie(entity);
  36. }
  37. }
  38. public Serializable save(PostEntity entity) throws Exception{
  39. Serializable t = super.save(entity);
  40. //执行新增操作增强业务
  41. this.doAddBus(entity);
  42. return t;
  43. }
  44. public void saveOrUpdate(PostEntity entity) throws Exception{
  45. super.saveOrUpdate(entity);
  46. //执行更新操作增强业务
  47. this.doUpdateBus(entity);
  48. }
  49. /**
  50. * 新增操作增强业务
  51. * @param t
  52. * @return
  53. */
  54. private void doAddBus(PostEntity t) throws Exception{
  55. //-----------------sql增强 start----------------------------
  56. //-----------------sql增强 end------------------------------
  57. //-----------------java增强 start---------------------------
  58. //-----------------java增强 end-----------------------------
  59. }
  60. /**
  61. * 更新操作增强业务
  62. * @param t
  63. * @return
  64. */
  65. private void doUpdateBus(PostEntity t) throws Exception{
  66. //-----------------sql增强 start----------------------------
  67. //-----------------sql增强 end------------------------------
  68. //-----------------java增强 start---------------------------
  69. //-----------------java增强 end-----------------------------
  70. }
  71. /**
  72. * 删除操作增强业务
  73. * @param id
  74. * @return
  75. */
  76. private void doDelBus(PostEntity t) throws Exception{
  77. //-----------------sql增强 start----------------------------
  78. //-----------------sql增强 end------------------------------
  79. //-----------------java增强 start---------------------------
  80. //-----------------java增强 end-----------------------------
  81. }
  82. private Map<String,Object> populationMap(PostEntity t){
  83. Map<String,Object> map = new HashMap<String,Object>();
  84. map.put("id", t.getId());
  85. map.put("create_name", t.getCreateName());
  86. map.put("create_by", t.getCreateBy());
  87. map.put("create_date", t.getCreateDate());
  88. map.put("update_name", t.getUpdateName());
  89. map.put("update_by", t.getUpdateBy());
  90. map.put("update_date", t.getUpdateDate());
  91. map.put("sys_org_code", t.getSysOrgCode());
  92. map.put("sys_company_code", t.getSysCompanyCode());
  93. map.put("post_code", t.getPostCode());
  94. map.put("post_name", t.getPostName());
  95. map.put("parent_postid", t.getParentPostid());
  96. map.put("post_desc", t.getPostDesc());
  97. map.put("status", t.getStatus());
  98. map.put("delete_flag", t.getDeleteFlag());
  99. return map;
  100. }
  101. /**
  102. * 替换sql中的变量
  103. * @param sql
  104. * @param t
  105. * @return
  106. */
  107. public String replaceVal(String sql,PostEntity t){
  108. sql = sql.replace("#{id}",String.valueOf(t.getId()));
  109. sql = sql.replace("#{create_name}",String.valueOf(t.getCreateName()));
  110. sql = sql.replace("#{create_by}",String.valueOf(t.getCreateBy()));
  111. sql = sql.replace("#{create_date}",String.valueOf(t.getCreateDate()));
  112. sql = sql.replace("#{update_name}",String.valueOf(t.getUpdateName()));
  113. sql = sql.replace("#{update_by}",String.valueOf(t.getUpdateBy()));
  114. sql = sql.replace("#{update_date}",String.valueOf(t.getUpdateDate()));
  115. sql = sql.replace("#{sys_org_code}",String.valueOf(t.getSysOrgCode()));
  116. sql = sql.replace("#{sys_company_code}",String.valueOf(t.getSysCompanyCode()));
  117. sql = sql.replace("#{post_code}",String.valueOf(t.getPostCode()));
  118. sql = sql.replace("#{post_name}",String.valueOf(t.getPostName()));
  119. sql = sql.replace("#{parent_postid}",String.valueOf(t.getParentPostid()));
  120. sql = sql.replace("#{post_desc}",String.valueOf(t.getPostDesc()));
  121. sql = sql.replace("#{status}",String.valueOf(t.getStatus()));
  122. sql = sql.replace("#{delete_flag}",String.valueOf(t.getDeleteFlag()));
  123. sql = sql.replace("#{UUID}",UUID.randomUUID().toString());
  124. return sql;
  125. }
  126. /**
  127. * 执行JAVA增强
  128. */
  129. private void executeJavaExtend(String cgJavaType,String cgJavaValue,Map<String,Object> data) throws Exception {
  130. if(StringUtil.isNotEmpty(cgJavaValue)){
  131. Object obj = null;
  132. try {
  133. if("class".equals(cgJavaType)){
  134. //因新增时已经校验了实例化是否可以成功,所以这块就不需要再做一次判断
  135. obj = MyClassLoader.getClassByScn(cgJavaValue).newInstance();
  136. }else if("spring".equals(cgJavaType)){
  137. obj = ApplicationContextUtil.getContext().getBean(cgJavaValue);
  138. }
  139. if(obj instanceof CgformEnhanceJavaInter){
  140. CgformEnhanceJavaInter javaInter = (CgformEnhanceJavaInter) obj;
  141. javaInter.execute("t_bus_post",data);
  142. }
  143. } catch (Exception e) {
  144. e.printStackTrace();
  145. throw new Exception("执行JAVA增强出现异常!");
  146. }
  147. }
  148. }
  149. @Override
  150. public Boolean findPostByPostName(PostEntity post) {
  151. List<PostEntity> postobj = new ArrayList<PostEntity>();
  152. StringBuffer hql = new StringBuffer(" from PostEntity where postName= ? and parentPostid=? and deleteFlag=0");
  153. if(StringUtil.isEmpty(post.getParentPostid())){
  154. post.setParentPostid(null);
  155. if(StringUtil.isNotEmpty(post.getId())){
  156. hql = new StringBuffer(
  157. " from PostEntity where id!=? and postName= ? and parentPostid is null and deleteFlag=0");
  158. postobj = findHql(hql.toString(),post.getId(),post.getPostName());
  159. }else{
  160. hql = new StringBuffer(" from PostEntity where postName= ? and parentPostid is null and deleteFlag=0");
  161. postobj = findHql(hql.toString(),post.getPostName());
  162. }
  163. }else{
  164. if(StringUtil.isNotEmpty(post.getId())){
  165. hql = new StringBuffer(" from PostEntity where id!=? and postName= ? and parentPostid=? and deleteFlag=0");
  166. postobj = findHql(hql.toString(),post.getId(),post.getPostName(),post.getParentPostid());
  167. }else{
  168. postobj = findHql(hql.toString(),post.getPostName(),post.getParentPostid());
  169. }
  170. }
  171. Boolean flag = true;
  172. if(postobj.size() > 0){
  173. flag = false;
  174. }
  175. return flag;
  176. }
  177. }