TestxxServiceImpl.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package com.xcgl.test.service.impl;
  2. import com.xcgl.test.service.TestxxServiceI;
  3. import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
  4. import com.xcgl.test.entity.TestxxEntity;
  5. import org.springframework.stereotype.Service;
  6. import org.springframework.transaction.annotation.Transactional;
  7. import java.util.HashMap;
  8. import java.util.Map;
  9. import java.util.UUID;
  10. import java.io.Serializable;
  11. import org.jeecgframework.core.util.ApplicationContextUtil;
  12. import org.jeecgframework.core.util.MyClassLoader;
  13. import org.jeecgframework.core.util.StringUtil;
  14. import org.jeecgframework.web.cgform.enhance.CgformEnhanceJavaInter;
  15. @Service("testxxService")
  16. @Transactional
  17. public class TestxxServiceImpl extends CommonServiceImpl implements TestxxServiceI {
  18. public void delete(TestxxEntity entity) throws Exception{
  19. super.delete(entity);
  20. //执行删除操作增强业务
  21. this.doDelBus(entity);
  22. }
  23. public Serializable save(TestxxEntity entity) throws Exception{
  24. Serializable t = super.save(entity);
  25. //执行新增操作增强业务
  26. this.doAddBus(entity);
  27. return t;
  28. }
  29. public void saveOrUpdate(TestxxEntity entity) throws Exception{
  30. super.saveOrUpdate(entity);
  31. //执行更新操作增强业务
  32. this.doUpdateBus(entity);
  33. }
  34. /**
  35. * 自定义按钮-[激活]业务处理
  36. * @param id
  37. * @return
  38. */
  39. public void doActivateBus(TestxxEntity t) throws Exception{
  40. //-----------------sql增强 start----------------------------
  41. //-----------------sql增强 end------------------------------
  42. //-----------------java增强 start---------------------------
  43. //-----------------java增强 end-----------------------------
  44. }
  45. /**
  46. * 新增操作增强业务
  47. * @param t
  48. * @return
  49. */
  50. private void doAddBus(TestxxEntity t) throws Exception{
  51. //-----------------sql增强 start----------------------------
  52. //-----------------sql增强 end------------------------------
  53. //-----------------java增强 start---------------------------
  54. //-----------------java增强 end-----------------------------
  55. }
  56. /**
  57. * 更新操作增强业务
  58. * @param t
  59. * @return
  60. */
  61. private void doUpdateBus(TestxxEntity t) throws Exception{
  62. //-----------------sql增强 start----------------------------
  63. //-----------------sql增强 end------------------------------
  64. //-----------------java增强 start---------------------------
  65. //-----------------java增强 end-----------------------------
  66. }
  67. /**
  68. * 删除操作增强业务
  69. * @param id
  70. * @return
  71. */
  72. private void doDelBus(TestxxEntity t) throws Exception{
  73. //-----------------sql增强 start----------------------------
  74. //-----------------sql增强 end------------------------------
  75. //-----------------java增强 start---------------------------
  76. //-----------------java增强 end-----------------------------
  77. }
  78. private Map<String,Object> populationMap(TestxxEntity t){
  79. Map<String,Object> map = new HashMap<String,Object>();
  80. map.put("id", t.getId());
  81. map.put("create_name", t.getCreateName());
  82. map.put("create_by", t.getCreateBy());
  83. map.put("create_date", t.getCreateDate());
  84. map.put("update_name", t.getUpdateName());
  85. map.put("update_by", t.getUpdateBy());
  86. map.put("update_date", t.getUpdateDate());
  87. map.put("sys_org_code", t.getSysOrgCode());
  88. map.put("sys_company_code", t.getSysCompanyCode());
  89. map.put("bpm_status", t.getBpmStatus());
  90. map.put("name", t.getName());
  91. map.put("location", t.getLocation());
  92. map.put("room", t.getRoom());
  93. map.put("icon", t.getIcon());
  94. map.put("pid", t.getPid());
  95. return map;
  96. }
  97. /**
  98. * 替换sql中的变量
  99. * @param sql
  100. * @param t
  101. * @return
  102. */
  103. public String replaceVal(String sql,TestxxEntity t){
  104. sql = sql.replace("#{id}",String.valueOf(t.getId()));
  105. sql = sql.replace("#{create_name}",String.valueOf(t.getCreateName()));
  106. sql = sql.replace("#{create_by}",String.valueOf(t.getCreateBy()));
  107. sql = sql.replace("#{create_date}",String.valueOf(t.getCreateDate()));
  108. sql = sql.replace("#{update_name}",String.valueOf(t.getUpdateName()));
  109. sql = sql.replace("#{update_by}",String.valueOf(t.getUpdateBy()));
  110. sql = sql.replace("#{update_date}",String.valueOf(t.getUpdateDate()));
  111. sql = sql.replace("#{sys_org_code}",String.valueOf(t.getSysOrgCode()));
  112. sql = sql.replace("#{sys_company_code}",String.valueOf(t.getSysCompanyCode()));
  113. sql = sql.replace("#{bpm_status}",String.valueOf(t.getBpmStatus()));
  114. sql = sql.replace("#{name}",String.valueOf(t.getName()));
  115. sql = sql.replace("#{location}",String.valueOf(t.getLocation()));
  116. sql = sql.replace("#{room}",String.valueOf(t.getRoom()));
  117. sql = sql.replace("#{icon}",String.valueOf(t.getIcon()));
  118. sql = sql.replace("#{pid}",String.valueOf(t.getPid()));
  119. sql = sql.replace("#{UUID}",UUID.randomUUID().toString());
  120. return sql;
  121. }
  122. /**
  123. * 执行JAVA增强
  124. */
  125. private void executeJavaExtend(String cgJavaType,String cgJavaValue,Map<String,Object> data) throws Exception {
  126. if(StringUtil.isNotEmpty(cgJavaValue)){
  127. Object obj = null;
  128. try {
  129. if("class".equals(cgJavaType)){
  130. //因新增时已经校验了实例化是否可以成功,所以这块就不需要再做一次判断
  131. obj = MyClassLoader.getClassByScn(cgJavaValue).newInstance();
  132. }else if("spring".equals(cgJavaType)){
  133. obj = ApplicationContextUtil.getContext().getBean(cgJavaValue);
  134. }
  135. if(obj instanceof CgformEnhanceJavaInter){
  136. CgformEnhanceJavaInter javaInter = (CgformEnhanceJavaInter) obj;
  137. javaInter.execute("testxx",data);
  138. }
  139. } catch (Exception e) {
  140. e.printStackTrace();
  141. throw new Exception("执行JAVA增强出现异常!");
  142. }
  143. }
  144. }
  145. }