TBusUserOptionsServiceImpl.java 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. package cn.com.lzt.useroptions.service.impl;
  2. import java.io.Serializable;
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7. import java.util.UUID;
  8. import org.jeecgframework.core.common.exception.BusinessException;
  9. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  10. import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
  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. import org.jeecgframework.web.system.pojo.base.TSDepart;
  16. import org.jeecgframework.web.system.pojo.base.TSUserOrg;
  17. import org.springframework.stereotype.Service;
  18. import org.springframework.transaction.annotation.Transactional;
  19. import cn.com.lzt.useroptions.entity.TBusUserOptionsEntity;
  20. import cn.com.lzt.useroptions.service.TBusUserOptionsServiceI;
  21. @Service("tBusUserOptionsService")
  22. @Transactional
  23. public class TBusUserOptionsServiceImpl extends CommonServiceImpl implements TBusUserOptionsServiceI {
  24. public void delete(TBusUserOptionsEntity entity) throws Exception{
  25. super.delete(entity);
  26. //执行删除操作增强业务
  27. this.doDelBus(entity);
  28. }
  29. public Serializable save(TBusUserOptionsEntity entity) throws Exception{
  30. Serializable t = super.save(entity);
  31. //执行新增操作增强业务
  32. this.doAddBus(entity);
  33. return t;
  34. }
  35. public void saveOrUpdate(TBusUserOptionsEntity entity) throws Exception{
  36. super.saveOrUpdate(entity);
  37. //执行更新操作增强业务
  38. this.doUpdateBus(entity);
  39. }
  40. @Override
  41. public TBusUserOptionsEntity getOptionsByUserID(String userid, String optiontype, boolean isDefaultBelongUnit) throws Exception{
  42. CriteriaQuery cq = new CriteriaQuery(TBusUserOptionsEntity.class);
  43. cq.eq("userId", userid);
  44. cq.add();
  45. List<TBusUserOptionsEntity> result = new ArrayList<TBusUserOptionsEntity>();
  46. result = getListByCriteriaQuery(cq, false);
  47. if(result != null & result.size()>0) {
  48. return result.get(0);
  49. }else {
  50. if(!isDefaultBelongUnit) {
  51. return null;
  52. }
  53. List<TSUserOrg> roleUser = getSession().createSQLQuery("select * from t_s_user_org where user_id = '"+userid+"' and ifpluralism = 0 and status = 0 ").addEntity(TSUserOrg.class).list();
  54. if(roleUser != null && roleUser.size()>0) {
  55. TSDepart depart = roleUser.get(0).getTsDepart();
  56. if(depart != null) {
  57. TBusUserOptionsEntity entit = new TBusUserOptionsEntity();
  58. entit.setUserId(userid);
  59. entit.setOptionType(optiontype);
  60. entit.setOptionName(depart.getDepartname());
  61. entit.setOptionId(depart.getId());
  62. String id = (String)save(entit);
  63. entit.setId(id);
  64. return entit;
  65. }
  66. }
  67. }
  68. return null;
  69. }
  70. @Override
  71. public void saveUserOptions(String userid, String optionid, String optionname, String optiontype) throws Exception{
  72. if(userid == null || optionid == null || optiontype == null) {
  73. throw new BusinessException("用户默认选项参数不能为空");
  74. }
  75. if(optionname == null) {
  76. TSDepart depart = get(TSDepart.class, optionid);
  77. if(depart != null) {
  78. optionname = depart.getDepartname();
  79. }
  80. if(optionname == null) {
  81. throw new BusinessException("用户默认选项参数名称获取失败,不能为空");
  82. }
  83. }
  84. TBusUserOptionsEntity result = getOptionsByUserID(userid, optiontype, false);
  85. if(result != null) {
  86. if(result.getOptionId().equals(optionid) && result.getOptionName().equals(optionname)) {
  87. return;
  88. }
  89. result.setOptionId(optionid);
  90. result.setOptionName(optionname);
  91. }else {
  92. result = new TBusUserOptionsEntity();
  93. result.setUserId(userid);
  94. result.setOptionType(optiontype);
  95. result.setOptionName(optionname);
  96. result.setOptionId(optionid);
  97. }
  98. this.saveOrUpdate(result);
  99. }
  100. @Override
  101. public void saveUserOptions(String userid, String optionid, String optiontype) throws Exception{
  102. saveUserOptions(userid, optionid, null, optiontype);
  103. }
  104. /**
  105. * 新增操作增强业务
  106. * @param t
  107. * @return
  108. */
  109. private void doAddBus(TBusUserOptionsEntity t) throws Exception{
  110. //-----------------sql增强 start----------------------------
  111. //-----------------sql增强 end------------------------------
  112. //-----------------java增强 start---------------------------
  113. //-----------------java增强 end-----------------------------
  114. }
  115. /**
  116. * 更新操作增强业务
  117. * @param t
  118. * @return
  119. */
  120. private void doUpdateBus(TBusUserOptionsEntity t) throws Exception{
  121. //-----------------sql增强 start----------------------------
  122. //-----------------sql增强 end------------------------------
  123. //-----------------java增强 start---------------------------
  124. //-----------------java增强 end-----------------------------
  125. }
  126. /**
  127. * 删除操作增强业务
  128. * @param id
  129. * @return
  130. */
  131. private void doDelBus(TBusUserOptionsEntity t) throws Exception{
  132. //-----------------sql增强 start----------------------------
  133. //-----------------sql增强 end------------------------------
  134. //-----------------java增强 start---------------------------
  135. //-----------------java增强 end-----------------------------
  136. }
  137. private Map<String,Object> populationMap(TBusUserOptionsEntity t){
  138. Map<String,Object> map = new HashMap<String,Object>();
  139. map.put("id", t.getId());
  140. map.put("create_name", t.getCreateName());
  141. map.put("create_by", t.getCreateBy());
  142. map.put("create_date", t.getCreateDate());
  143. map.put("update_name", t.getUpdateName());
  144. map.put("update_by", t.getUpdateBy());
  145. map.put("update_date", t.getUpdateDate());
  146. map.put("sys_org_code", t.getSysOrgCode());
  147. map.put("sys_company_code", t.getSysCompanyCode());
  148. map.put("bpm_status", t.getBpmStatus());
  149. map.put("user_id", t.getUserId());
  150. map.put("option_id", t.getOptionId());
  151. map.put("option_name", t.getOptionName());
  152. map.put("option_type", t.getOptionType());
  153. return map;
  154. }
  155. /**
  156. * 替换sql中的变量
  157. * @param sql
  158. * @param t
  159. * @return
  160. */
  161. public String replaceVal(String sql,TBusUserOptionsEntity t){
  162. sql = sql.replace("#{id}",String.valueOf(t.getId()));
  163. sql = sql.replace("#{create_name}",String.valueOf(t.getCreateName()));
  164. sql = sql.replace("#{create_by}",String.valueOf(t.getCreateBy()));
  165. sql = sql.replace("#{create_date}",String.valueOf(t.getCreateDate()));
  166. sql = sql.replace("#{update_name}",String.valueOf(t.getUpdateName()));
  167. sql = sql.replace("#{update_by}",String.valueOf(t.getUpdateBy()));
  168. sql = sql.replace("#{update_date}",String.valueOf(t.getUpdateDate()));
  169. sql = sql.replace("#{sys_org_code}",String.valueOf(t.getSysOrgCode()));
  170. sql = sql.replace("#{sys_company_code}",String.valueOf(t.getSysCompanyCode()));
  171. sql = sql.replace("#{bpm_status}",String.valueOf(t.getBpmStatus()));
  172. sql = sql.replace("#{user_id}",String.valueOf(t.getUserId()));
  173. sql = sql.replace("#{option_id}",String.valueOf(t.getOptionId()));
  174. sql = sql.replace("#{option_name}",String.valueOf(t.getOptionName()));
  175. sql = sql.replace("#{option_type}",String.valueOf(t.getOptionType()));
  176. sql = sql.replace("#{UUID}",UUID.randomUUID().toString());
  177. return sql;
  178. }
  179. /**
  180. * 执行JAVA增强
  181. */
  182. private void executeJavaExtend(String cgJavaType,String cgJavaValue,Map<String,Object> data) throws Exception {
  183. if(StringUtil.isNotEmpty(cgJavaValue)){
  184. Object obj = null;
  185. try {
  186. if("class".equals(cgJavaType)){
  187. //因新增时已经校验了实例化是否可以成功,所以这块就不需要再做一次判断
  188. obj = MyClassLoader.getClassByScn(cgJavaValue).newInstance();
  189. }else if("spring".equals(cgJavaType)){
  190. obj = ApplicationContextUtil.getContext().getBean(cgJavaValue);
  191. }
  192. if(obj instanceof CgformEnhanceJavaInter){
  193. CgformEnhanceJavaInter javaInter = (CgformEnhanceJavaInter) obj;
  194. javaInter.execute("t_bus_user_options",data);
  195. }
  196. } catch (Exception e) {
  197. e.printStackTrace();
  198. throw new Exception("执行JAVA增强出现异常!");
  199. }
  200. }
  201. }
  202. }