UserChangesLogServiceImpl.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package cn.com.lzt.userchangeslog.service.impl;
  2. import cn.com.lzt.userchangeslog.service.UserChangesLogServiceI;
  3. import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
  4. import cn.com.lzt.userchangeslog.entity.UserChangesLogEntity;
  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("userChangesLogService")
  16. @Transactional
  17. public class UserChangesLogServiceImpl extends CommonServiceImpl implements UserChangesLogServiceI {
  18. public void delete(UserChangesLogEntity entity) throws Exception{
  19. super.delete(entity);
  20. //执行删除操作增强业务
  21. this.doDelBus(entity);
  22. }
  23. public Serializable save(UserChangesLogEntity entity) throws Exception{
  24. Serializable t = super.save(entity);
  25. //执行新增操作增强业务
  26. this.doAddBus(entity);
  27. return t;
  28. }
  29. public void saveOrUpdate(UserChangesLogEntity entity) throws Exception{
  30. super.saveOrUpdate(entity);
  31. //执行更新操作增强业务
  32. this.doUpdateBus(entity);
  33. }
  34. /**
  35. * 新增操作增强业务
  36. * @param t
  37. * @return
  38. */
  39. private void doAddBus(UserChangesLogEntity 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 doUpdateBus(UserChangesLogEntity t) throws Exception{
  51. //-----------------sql增强 start----------------------------
  52. //-----------------sql增强 end------------------------------
  53. //-----------------java增强 start---------------------------
  54. //-----------------java增强 end-----------------------------
  55. }
  56. /**
  57. * 删除操作增强业务
  58. * @param id
  59. * @return
  60. */
  61. private void doDelBus(UserChangesLogEntity t) throws Exception{
  62. //-----------------sql增强 start----------------------------
  63. //-----------------sql增强 end------------------------------
  64. //-----------------java增强 start---------------------------
  65. //-----------------java增强 end-----------------------------
  66. }
  67. private Map<String,Object> populationMap(UserChangesLogEntity t){
  68. Map<String,Object> map = new HashMap<String,Object>();
  69. map.put("id", t.getId());
  70. map.put("change_time", t.getChangeTime());
  71. map.put("user_code", t.getUserCode());
  72. map.put("user_name", t.getUserName());
  73. map.put("belong_unitid", t.getBelongUnitid());
  74. map.put("in_unitid", t.getInUnitid());
  75. map.put("change_type", t.getChangeType());
  76. map.put("applicant", t.getApplicant());
  77. map.put("pay_remind_status", t.getPayRemindStatus());
  78. map.put("pay_unit", t.getPayUnit());
  79. return map;
  80. }
  81. /**
  82. * 替换sql中的变量
  83. * @param sql
  84. * @param t
  85. * @return
  86. */
  87. public String replaceVal(String sql,UserChangesLogEntity t){
  88. sql = sql.replace("#{id}",String.valueOf(t.getId()));
  89. sql = sql.replace("#{change_time}",String.valueOf(t.getChangeTime()));
  90. sql = sql.replace("#{user_code}",String.valueOf(t.getUserCode()));
  91. sql = sql.replace("#{user_name}",String.valueOf(t.getUserName()));
  92. sql = sql.replace("#{belong_unitid}",String.valueOf(t.getBelongUnitid()));
  93. sql = sql.replace("#{in_unitid}",String.valueOf(t.getInUnitid()));
  94. sql = sql.replace("#{change_type}",String.valueOf(t.getChangeType()));
  95. sql = sql.replace("#{applicant}",String.valueOf(t.getApplicant()));
  96. sql = sql.replace("#{pay_remind_status}",String.valueOf(t.getPayRemindStatus()));
  97. sql = sql.replace("#{pay_unit}",String.valueOf(t.getPayUnit()));
  98. sql = sql.replace("#{UUID}",UUID.randomUUID().toString());
  99. return sql;
  100. }
  101. /**
  102. * 执行JAVA增强
  103. */
  104. private void executeJavaExtend(String cgJavaType,String cgJavaValue,Map<String,Object> data) throws Exception {
  105. if(StringUtil.isNotEmpty(cgJavaValue)){
  106. Object obj = null;
  107. try {
  108. if("class".equals(cgJavaType)){
  109. //因新增时已经校验了实例化是否可以成功,所以这块就不需要再做一次判断
  110. obj = MyClassLoader.getClassByScn(cgJavaValue).newInstance();
  111. }else if("spring".equals(cgJavaType)){
  112. obj = ApplicationContextUtil.getContext().getBean(cgJavaValue);
  113. }
  114. if(obj instanceof CgformEnhanceJavaInter){
  115. CgformEnhanceJavaInter javaInter = (CgformEnhanceJavaInter) obj;
  116. javaInter.execute("t_bus_user_changes_log",data);
  117. }
  118. } catch (Exception e) {
  119. e.printStackTrace();
  120. throw new Exception("执行JAVA增强出现异常!");
  121. }
  122. }
  123. }
  124. }