OtherSubsidyServiceImpl.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. package cn.com.lzt.othersubsidy.service.impl;
  2. import cn.com.lzt.othersubsidy.entity.OtherSubsidyEntity;
  3. import cn.com.lzt.othersubsidy.service.OtherSubsidyServiceI;
  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("otherSubsidyService")
  14. @Transactional
  15. public class OtherSubsidyServiceImpl extends CommonServiceImpl implements OtherSubsidyServiceI {
  16. public void delete(OtherSubsidyEntity entity) throws Exception{
  17. super.delete(entity);
  18. //执行删除操作增强业务
  19. this.doDelBus(entity);
  20. }
  21. public Serializable save(OtherSubsidyEntity entity) throws Exception{
  22. Serializable t = super.save(entity);
  23. //执行新增操作增强业务
  24. this.doAddBus(entity);
  25. return t;
  26. }
  27. public void saveOrUpdate(OtherSubsidyEntity entity) throws Exception{
  28. super.saveOrUpdate(entity);
  29. //执行更新操作增强业务
  30. this.doUpdateBus(entity);
  31. }
  32. /**
  33. * 批量更新操作
  34. *
  35. */
  36. public void batchUpdate(List<OtherSubsidyEntity> entityList) throws Exception{
  37. for(OtherSubsidyEntity entity : entityList){
  38. super.updateEntitie(entity);
  39. }
  40. }
  41. /**
  42. * 新增操作增强业务
  43. * @param t
  44. * @return
  45. */
  46. private void doAddBus(OtherSubsidyEntity t) throws Exception{
  47. //-----------------sql增强 start----------------------------
  48. //-----------------sql增强 end------------------------------
  49. //-----------------java增强 start---------------------------
  50. //-----------------java增强 end-----------------------------
  51. }
  52. /**
  53. * 更新操作增强业务
  54. * @param t
  55. * @return
  56. */
  57. private void doUpdateBus(OtherSubsidyEntity t) throws Exception{
  58. //-----------------sql增强 start----------------------------
  59. //-----------------sql增强 end------------------------------
  60. //-----------------java增强 start---------------------------
  61. //-----------------java增强 end-----------------------------
  62. }
  63. /**
  64. * 删除操作增强业务
  65. * @param id
  66. * @return
  67. */
  68. private void doDelBus(OtherSubsidyEntity t) throws Exception{
  69. //-----------------sql增强 start----------------------------
  70. //-----------------sql增强 end------------------------------
  71. //-----------------java增强 start---------------------------
  72. //-----------------java增强 end-----------------------------
  73. }
  74. private Map<String,Object> populationMap(OtherSubsidyEntity t){
  75. Map<String,Object> map = new HashMap<String,Object>();
  76. map.put("id", t.getId());
  77. map.put("create_name", t.getCreateName());
  78. map.put("create_by", t.getCreateBy());
  79. map.put("create_date", t.getCreateDate());
  80. map.put("update_name", t.getUpdateName());
  81. map.put("update_by", t.getUpdateBy());
  82. map.put("update_date", t.getUpdateDate());
  83. map.put("sys_org_code", t.getSysOrgCode());
  84. map.put("sys_company_code", t.getSysCompanyCode());
  85. map.put("subsidy_name", t.getSubsidyName());
  86. map.put("subsidy_money", t.getSubsidyMoney());
  87. map.put("status", t.getStatus());
  88. map.put("delete_flag", t.getDeleteFlag());
  89. return map;
  90. }
  91. /**
  92. * 替换sql中的变量
  93. * @param sql
  94. * @param t
  95. * @return
  96. */
  97. public String replaceVal(String sql,OtherSubsidyEntity t){
  98. sql = sql.replace("#{id}",String.valueOf(t.getId()));
  99. sql = sql.replace("#{create_name}",String.valueOf(t.getCreateName()));
  100. sql = sql.replace("#{create_by}",String.valueOf(t.getCreateBy()));
  101. sql = sql.replace("#{create_date}",String.valueOf(t.getCreateDate()));
  102. sql = sql.replace("#{update_name}",String.valueOf(t.getUpdateName()));
  103. sql = sql.replace("#{update_by}",String.valueOf(t.getUpdateBy()));
  104. sql = sql.replace("#{update_date}",String.valueOf(t.getUpdateDate()));
  105. sql = sql.replace("#{sys_org_code}",String.valueOf(t.getSysOrgCode()));
  106. sql = sql.replace("#{sys_company_code}",String.valueOf(t.getSysCompanyCode()));
  107. sql = sql.replace("#{subsidy_name}",String.valueOf(t.getSubsidyName()));
  108. sql = sql.replace("#{subsidy_money}",String.valueOf(t.getSubsidyMoney()));
  109. sql = sql.replace("#{status}",String.valueOf(t.getStatus()));
  110. sql = sql.replace("#{delete_flag}",String.valueOf(t.getDeleteFlag()));
  111. sql = sql.replace("#{UUID}",UUID.randomUUID().toString());
  112. return sql;
  113. }
  114. /**
  115. * 执行JAVA增强
  116. */
  117. private void executeJavaExtend(String cgJavaType,String cgJavaValue,Map<String,Object> data) throws Exception {
  118. if(StringUtil.isNotEmpty(cgJavaValue)){
  119. Object obj = null;
  120. try {
  121. if("class".equals(cgJavaType)){
  122. //因新增时已经校验了实例化是否可以成功,所以这块就不需要再做一次判断
  123. obj = MyClassLoader.getClassByScn(cgJavaValue).newInstance();
  124. }else if("spring".equals(cgJavaType)){
  125. obj = ApplicationContextUtil.getContext().getBean(cgJavaValue);
  126. }
  127. if(obj instanceof CgformEnhanceJavaInter){
  128. CgformEnhanceJavaInter javaInter = (CgformEnhanceJavaInter) obj;
  129. javaInter.execute("t_bus_other_subsidy",data);
  130. }
  131. } catch (Exception e) {
  132. e.printStackTrace();
  133. throw new Exception("执行JAVA增强出现异常!");
  134. }
  135. }
  136. }
  137. @Override
  138. public Boolean findByName(OtherSubsidyEntity otherSubsidy) {
  139. List<OtherSubsidyEntity> postobj = new ArrayList<OtherSubsidyEntity>();
  140. StringBuffer hql = new StringBuffer(" from OtherSubsidyEntity where subsidyName=? and deleteFlag=0");
  141. if(StringUtil.isNotEmpty(otherSubsidy.getId())){
  142. hql = new StringBuffer(" from OtherSubsidyEntity where id!=? and subsidyName=? and deleteFlag=0");
  143. postobj = findHql(hql.toString(),otherSubsidy.getId(),otherSubsidy.getSubsidyName());
  144. }else{
  145. postobj = findHql(hql.toString(),otherSubsidy.getSubsidyName());
  146. }
  147. Boolean flag = true;
  148. if(postobj.size() > 0){
  149. flag = false;
  150. }
  151. return flag;
  152. }
  153. }