ExtAttributeServiceImpl.java 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. package cn.com.lzt.extattribute.service.impl;
  2. import cn.com.lzt.extattribute.entity.ExtAttributeEntity;
  3. import cn.com.lzt.extattribute.service.ExtAttributeServiceI;
  4. import cn.com.lzt.extattributedefset.entity.ExtAttributeDefsetEntity;
  5. import org.apache.commons.lang3.StringUtils;
  6. import org.jeecgframework.core.common.exception.BusinessException;
  7. import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
  8. import org.jeecgframework.core.util.MyBeanUtils;
  9. import org.jeecgframework.core.util.StringUtil;
  10. import org.jeecgframework.core.util.oConvertUtils;
  11. import org.springframework.stereotype.Service;
  12. import org.springframework.transaction.annotation.Transactional;
  13. import java.util.ArrayList;
  14. import java.util.List;
  15. import java.util.UUID;
  16. @Service("extAttributeService")
  17. @Transactional
  18. public class ExtAttributeServiceImpl extends CommonServiceImpl implements ExtAttributeServiceI {
  19. public <T> void delete(T entity) {
  20. super.delete(entity);
  21. //执行删除操作配置的sql增强
  22. this.doDelSql((ExtAttributeEntity)entity);
  23. }
  24. public void addMain(ExtAttributeEntity extAttribute,
  25. List<ExtAttributeDefsetEntity> extAttributeDefsetList){
  26. //保存主信息
  27. this.save(extAttribute);
  28. /**保存-扩展属性设置明细*/
  29. for(ExtAttributeDefsetEntity extAttributeDefset:extAttributeDefsetList){
  30. if(StringUtils.isEmpty(extAttributeDefset.getExtname())) {
  31. extAttributeDefset.setBpmStatus("0");
  32. }
  33. //外键设置
  34. extAttributeDefset.setExtattributeid(extAttribute.getId());
  35. this.save(extAttributeDefset);
  36. }
  37. //执行新增操作配置的sql增强
  38. this.doAddSql(extAttribute);
  39. }
  40. public void updateMain(ExtAttributeEntity extAttribute,
  41. List<ExtAttributeDefsetEntity> extAttributeDefsetList) {
  42. //保存主表信息
  43. if(StringUtil.isNotEmpty(extAttribute.getId())){
  44. try {
  45. ExtAttributeEntity temp = findUniqueByProperty(ExtAttributeEntity.class, "id", extAttribute.getId());
  46. MyBeanUtils.copyBeanNotNull2Bean(extAttribute, temp);
  47. this.saveOrUpdate(temp);
  48. } catch (Exception e) {
  49. e.printStackTrace();
  50. }
  51. }else{
  52. this.saveOrUpdate(extAttribute);
  53. }
  54. //===================================================================================
  55. //获取参数
  56. Object id0 = extAttribute.getId();
  57. //===================================================================================
  58. //1.查询出数据库的明细数据-扩展属性设置明细
  59. String hql0 = "from ExtAttributeDefsetEntity where 1 = 1 AND eXTATTRIBUTEID =? ";
  60. List<ExtAttributeDefsetEntity> extAttributeDefsetOldList = this.findHql(hql0,id0);
  61. //2.筛选更新明细数据-扩展属性设置明细
  62. if(extAttributeDefsetList!=null&&extAttributeDefsetList.size()>0){
  63. for(ExtAttributeDefsetEntity oldE:extAttributeDefsetOldList){
  64. boolean isUpdate = false;
  65. for(ExtAttributeDefsetEntity sendE:extAttributeDefsetList){
  66. //需要更新的明细数据-扩展属性设置明细
  67. if(oldE.getId().equals(sendE.getId())){
  68. try {
  69. MyBeanUtils.copyBeanNotNull2Bean(sendE,oldE);
  70. if(StringUtils.isEmpty(oldE.getExtname())) {
  71. oldE.setBpmStatus("0");
  72. }else {
  73. oldE.setBpmStatus("1");
  74. }
  75. this.saveOrUpdate(oldE);
  76. } catch (Exception e) {
  77. e.printStackTrace();
  78. throw new BusinessException(e.getMessage());
  79. }
  80. isUpdate= true;
  81. break;
  82. }
  83. }
  84. if(!isUpdate){
  85. //如果数据库存在的明细,前台没有传递过来则是删除-扩展属性设置明细
  86. super.delete(oldE);
  87. }
  88. }
  89. //3.持久化新增的数据-扩展属性设置明细
  90. for(ExtAttributeDefsetEntity extAttributeDefset:extAttributeDefsetList){
  91. if(oConvertUtils.isEmpty(extAttributeDefset.getId())){
  92. //外键设置
  93. extAttributeDefset.setExtattributeid(extAttribute.getId());
  94. if(StringUtils.isEmpty(extAttributeDefset.getExtname())) {
  95. extAttributeDefset.setBpmStatus("0");
  96. }
  97. this.save(extAttributeDefset);
  98. }
  99. }
  100. }
  101. //执行更新操作配置的sql增强
  102. this.doUpdateSql(extAttribute);
  103. }
  104. public void delMain(ExtAttributeEntity extAttribute) {
  105. //删除主表信息
  106. this.delete(extAttribute);
  107. //===================================================================================
  108. //获取参数
  109. Object id0 = extAttribute.getId();
  110. //===================================================================================
  111. //删除-扩展属性设置明细
  112. String hql0 = "from ExtAttributeDefsetEntity where 1 = 1 AND eXTATTRIBUTEID =? ";
  113. List<ExtAttributeDefsetEntity> extAttributeDefsetOldList = this.findHql(hql0,id0);
  114. this.deleteAllEntitie(extAttributeDefsetOldList);
  115. }
  116. /**
  117. * 默认按钮-sql增强-新增操作
  118. * @param id
  119. * @return
  120. */
  121. public boolean doAddSql(ExtAttributeEntity t){
  122. return true;
  123. }
  124. /**
  125. * 默认按钮-sql增强-更新操作
  126. * @param id
  127. * @return
  128. */
  129. public boolean doUpdateSql(ExtAttributeEntity t){
  130. return true;
  131. }
  132. /**
  133. * 默认按钮-sql增强-删除操作
  134. * @param id
  135. * @return
  136. */
  137. public boolean doDelSql(ExtAttributeEntity t){
  138. return true;
  139. }
  140. /**
  141. * 替换sql中的变量
  142. * @param sql
  143. * @return
  144. */
  145. public String replaceVal(String sql,ExtAttributeEntity t){
  146. sql = sql.replace("#{id}",String.valueOf(t.getId()));
  147. sql = sql.replace("#{create_name}",String.valueOf(t.getCreateName()));
  148. sql = sql.replace("#{create_by}",String.valueOf(t.getCreateBy()));
  149. sql = sql.replace("#{create_date}",String.valueOf(t.getCreateDate()));
  150. sql = sql.replace("#{update_name}",String.valueOf(t.getUpdateName()));
  151. sql = sql.replace("#{update_by}",String.valueOf(t.getUpdateBy()));
  152. sql = sql.replace("#{update_date}",String.valueOf(t.getUpdateDate()));
  153. sql = sql.replace("#{sys_org_code}",String.valueOf(t.getSysOrgCode()));
  154. sql = sql.replace("#{sys_company_code}",String.valueOf(t.getSysCompanyCode()));
  155. sql = sql.replace("#{bpm_status}",String.valueOf(t.getBpmStatus()));
  156. sql = sql.replace("#{billtypecode}",String.valueOf(t.getBilltypecode()));
  157. sql = sql.replace("#{billtypename}",String.valueOf(t.getBilltypename()));
  158. sql = sql.replace("#{tablename}",String.valueOf(t.getTablename()));
  159. sql = sql.replace("#{UUID}",UUID.randomUUID().toString());
  160. return sql;
  161. }
  162. @Override
  163. public List<ExtAttributeDefsetEntity> getExtSetting(String tablename) {
  164. List<ExtAttributeDefsetEntity> extList = new ArrayList<ExtAttributeDefsetEntity>();
  165. ExtAttributeEntity t = findUniqueByProperty(ExtAttributeEntity.class, "tablename", tablename);
  166. if(t != null) {
  167. extList = findHql(" FROM ExtAttributeDefsetEntity where extattributeid =? and bpmStatus = ? ", t.getId(),"1");
  168. }
  169. return extList;
  170. }
  171. }