| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- package cn.com.lzt.useroptions.service.impl;
- import java.io.Serializable;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.UUID;
- import org.jeecgframework.core.common.exception.BusinessException;
- import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
- import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
- import org.jeecgframework.core.util.ApplicationContextUtil;
- import org.jeecgframework.core.util.MyClassLoader;
- import org.jeecgframework.core.util.StringUtil;
- import org.jeecgframework.web.cgform.enhance.CgformEnhanceJavaInter;
- import org.jeecgframework.web.system.pojo.base.TSDepart;
- import org.jeecgframework.web.system.pojo.base.TSUserOrg;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import cn.com.lzt.useroptions.entity.TBusUserOptionsEntity;
- import cn.com.lzt.useroptions.service.TBusUserOptionsServiceI;
- @Service("tBusUserOptionsService")
- @Transactional
- public class TBusUserOptionsServiceImpl extends CommonServiceImpl implements TBusUserOptionsServiceI {
-
- public void delete(TBusUserOptionsEntity entity) throws Exception{
- super.delete(entity);
- //执行删除操作增强业务
- this.doDelBus(entity);
- }
-
- public Serializable save(TBusUserOptionsEntity entity) throws Exception{
- Serializable t = super.save(entity);
- //执行新增操作增强业务
- this.doAddBus(entity);
- return t;
- }
-
- public void saveOrUpdate(TBusUserOptionsEntity entity) throws Exception{
- super.saveOrUpdate(entity);
- //执行更新操作增强业务
- this.doUpdateBus(entity);
- }
- @Override
- public TBusUserOptionsEntity getOptionsByUserID(String userid, String optiontype, boolean isDefaultBelongUnit) throws Exception{
- CriteriaQuery cq = new CriteriaQuery(TBusUserOptionsEntity.class);
- cq.eq("userId", userid);
- cq.add();
- List<TBusUserOptionsEntity> result = new ArrayList<TBusUserOptionsEntity>();
-
- result = getListByCriteriaQuery(cq, false);
- if(result != null & result.size()>0) {
- return result.get(0);
- }else {
- if(!isDefaultBelongUnit) {
- return null;
- }
- 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();
- if(roleUser != null && roleUser.size()>0) {
- TSDepart depart = roleUser.get(0).getTsDepart();
- if(depart != null) {
- TBusUserOptionsEntity entit = new TBusUserOptionsEntity();
- entit.setUserId(userid);
- entit.setOptionType(optiontype);
- entit.setOptionName(depart.getDepartname());
- entit.setOptionId(depart.getId());
- String id = (String)save(entit);
- entit.setId(id);
- return entit;
- }
- }
- }
- return null;
- }
-
- @Override
- public void saveUserOptions(String userid, String optionid, String optionname, String optiontype) throws Exception{
- if(userid == null || optionid == null || optiontype == null) {
- throw new BusinessException("用户默认选项参数不能为空");
- }
- if(optionname == null) {
- TSDepart depart = get(TSDepart.class, optionid);
- if(depart != null) {
- optionname = depart.getDepartname();
- }
- if(optionname == null) {
- throw new BusinessException("用户默认选项参数名称获取失败,不能为空");
- }
- }
- TBusUserOptionsEntity result = getOptionsByUserID(userid, optiontype, false);
- if(result != null) {
- if(result.getOptionId().equals(optionid) && result.getOptionName().equals(optionname)) {
- return;
- }
- result.setOptionId(optionid);
- result.setOptionName(optionname);
- }else {
- result = new TBusUserOptionsEntity();
- result.setUserId(userid);
- result.setOptionType(optiontype);
- result.setOptionName(optionname);
- result.setOptionId(optionid);
- }
- this.saveOrUpdate(result);
- }
-
- @Override
- public void saveUserOptions(String userid, String optionid, String optiontype) throws Exception{
- saveUserOptions(userid, optionid, null, optiontype);
- }
-
- /**
- * 新增操作增强业务
- * @param t
- * @return
- */
- private void doAddBus(TBusUserOptionsEntity t) throws Exception{
- //-----------------sql增强 start----------------------------
- //-----------------sql增强 end------------------------------
-
- //-----------------java增强 start---------------------------
- //-----------------java增强 end-----------------------------
- }
- /**
- * 更新操作增强业务
- * @param t
- * @return
- */
- private void doUpdateBus(TBusUserOptionsEntity t) throws Exception{
- //-----------------sql增强 start----------------------------
- //-----------------sql增强 end------------------------------
-
- //-----------------java增强 start---------------------------
- //-----------------java增强 end-----------------------------
- }
- /**
- * 删除操作增强业务
- * @param id
- * @return
- */
- private void doDelBus(TBusUserOptionsEntity t) throws Exception{
- //-----------------sql增强 start----------------------------
- //-----------------sql增强 end------------------------------
-
- //-----------------java增强 start---------------------------
- //-----------------java增强 end-----------------------------
- }
-
- private Map<String,Object> populationMap(TBusUserOptionsEntity t){
- Map<String,Object> map = new HashMap<String,Object>();
- map.put("id", t.getId());
- map.put("create_name", t.getCreateName());
- map.put("create_by", t.getCreateBy());
- map.put("create_date", t.getCreateDate());
- map.put("update_name", t.getUpdateName());
- map.put("update_by", t.getUpdateBy());
- map.put("update_date", t.getUpdateDate());
- map.put("sys_org_code", t.getSysOrgCode());
- map.put("sys_company_code", t.getSysCompanyCode());
- map.put("bpm_status", t.getBpmStatus());
- map.put("user_id", t.getUserId());
- map.put("option_id", t.getOptionId());
- map.put("option_name", t.getOptionName());
- map.put("option_type", t.getOptionType());
- return map;
- }
-
- /**
- * 替换sql中的变量
- * @param sql
- * @param t
- * @return
- */
- public String replaceVal(String sql,TBusUserOptionsEntity t){
- sql = sql.replace("#{id}",String.valueOf(t.getId()));
- sql = sql.replace("#{create_name}",String.valueOf(t.getCreateName()));
- sql = sql.replace("#{create_by}",String.valueOf(t.getCreateBy()));
- sql = sql.replace("#{create_date}",String.valueOf(t.getCreateDate()));
- sql = sql.replace("#{update_name}",String.valueOf(t.getUpdateName()));
- sql = sql.replace("#{update_by}",String.valueOf(t.getUpdateBy()));
- sql = sql.replace("#{update_date}",String.valueOf(t.getUpdateDate()));
- sql = sql.replace("#{sys_org_code}",String.valueOf(t.getSysOrgCode()));
- sql = sql.replace("#{sys_company_code}",String.valueOf(t.getSysCompanyCode()));
- sql = sql.replace("#{bpm_status}",String.valueOf(t.getBpmStatus()));
- sql = sql.replace("#{user_id}",String.valueOf(t.getUserId()));
- sql = sql.replace("#{option_id}",String.valueOf(t.getOptionId()));
- sql = sql.replace("#{option_name}",String.valueOf(t.getOptionName()));
- sql = sql.replace("#{option_type}",String.valueOf(t.getOptionType()));
- sql = sql.replace("#{UUID}",UUID.randomUUID().toString());
- return sql;
- }
-
- /**
- * 执行JAVA增强
- */
- private void executeJavaExtend(String cgJavaType,String cgJavaValue,Map<String,Object> data) throws Exception {
- if(StringUtil.isNotEmpty(cgJavaValue)){
- Object obj = null;
- try {
- if("class".equals(cgJavaType)){
- //因新增时已经校验了实例化是否可以成功,所以这块就不需要再做一次判断
- obj = MyClassLoader.getClassByScn(cgJavaValue).newInstance();
- }else if("spring".equals(cgJavaType)){
- obj = ApplicationContextUtil.getContext().getBean(cgJavaValue);
- }
- if(obj instanceof CgformEnhanceJavaInter){
- CgformEnhanceJavaInter javaInter = (CgformEnhanceJavaInter) obj;
- javaInter.execute("t_bus_user_options",data);
- }
- } catch (Exception e) {
- e.printStackTrace();
- throw new Exception("执行JAVA增强出现异常!");
- }
- }
- }
- }
|