From 52def9be0666c493c63dfe24e1c9ac71699d10a7 Mon Sep 17 00:00:00 2001 From: smartLRB Date: Fri, 21 Nov 2014 11:32:31 +0800 Subject: [PATCH] single jbpm6 done --- .../com/datalook/action/base/BaseAction.java | 14 +- .../com/datalook/action/base/TestAction.java | 5 +- .../datalook/action/sys/SysDictAction.java | 10 +- .../action/sys/SysFunctionAction.java | 8 +- .../datalook/action/sys/SysRoleAction.java | 10 +- .../datalook/action/sys/SysUserAction.java | 11 +- .../datalook/aop/base/ExceptionAspect.java | 4 +- .../filter/{ => base}/FastjsonFilter.java | 2 +- .../filter/base/web/EntityManagerFilter.java | 14 + .../filter/{ => base/web}/StrutsFilter.java | 2 +- .../web/UserSessionFilter.java} | 11 +- .../interceptor/base/SecurityInterceptor.java | 2 +- .../interceptor/base/SessionInterceptor.java | 2 +- .../datalook/service/base/BaseService.java | 451 ++++++++---------- .../service/base/BaseServiceImpl.java | 299 ++++++++++++ .../datalook/service/base/IBaseService.java | 252 ---------- .../service/sys/ISysFunctionService.java | 11 - .../datalook/service/sys/SysDictService.java | 76 +-- .../service/sys/SysFunctionService.java | 52 +- .../datalook/service/sys/SysRoleService.java | 22 +- .../datalook/service/sys/SysUserService.java | 46 +- .../sys/implement/SysDictServiceImpl.java | 73 +++ .../sys/implement/SysFunctionServiceImpl.java | 51 ++ .../sys/implement/SysRoleServiceImpl.java | 23 + .../sys/implement/SysUserServiceImpl.java | 44 ++ .../sys/interfaces/ISysDictService.java | 17 - .../sys/interfaces/ISysRoleService.java | 11 - .../sys/interfaces/ISysUserService.java | 24 - .../webservice/server/HelloWorldImpl.java | 1 + .../src/main/resources/applicationContext.xml | 4 +- blank/src/main/resources/struts.xml | 3 +- blank/src/main/webapp/WEB-INF/web.xml | 26 +- .../java/com/datalook/dao/base/BaseDaot.java | 4 +- .../test/java/com/datalook/dao/base/Daot.java | 4 +- 34 files changed, 793 insertions(+), 796 deletions(-) rename blank/src/main/java/com/datalook/filter/{ => base}/FastjsonFilter.java (93%) create mode 100644 blank/src/main/java/com/datalook/filter/base/web/EntityManagerFilter.java rename blank/src/main/java/com/datalook/filter/{ => base/web}/StrutsFilter.java (94%) rename blank/src/main/java/com/datalook/filter/{SessionFilter.java => base/web/UserSessionFilter.java} (85%) create mode 100644 blank/src/main/java/com/datalook/service/base/BaseServiceImpl.java delete mode 100644 blank/src/main/java/com/datalook/service/base/IBaseService.java delete mode 100644 blank/src/main/java/com/datalook/service/sys/ISysFunctionService.java create mode 100644 blank/src/main/java/com/datalook/service/sys/implement/SysDictServiceImpl.java create mode 100644 blank/src/main/java/com/datalook/service/sys/implement/SysFunctionServiceImpl.java create mode 100644 blank/src/main/java/com/datalook/service/sys/implement/SysRoleServiceImpl.java create mode 100644 blank/src/main/java/com/datalook/service/sys/implement/SysUserServiceImpl.java delete mode 100644 blank/src/main/java/com/datalook/service/sys/interfaces/ISysDictService.java delete mode 100644 blank/src/main/java/com/datalook/service/sys/interfaces/ISysRoleService.java delete mode 100644 blank/src/main/java/com/datalook/service/sys/interfaces/ISysUserService.java diff --git a/blank/src/main/java/com/datalook/action/base/BaseAction.java b/blank/src/main/java/com/datalook/action/base/BaseAction.java index e95e3bf..c13977f 100644 --- a/blank/src/main/java/com/datalook/action/base/BaseAction.java +++ b/blank/src/main/java/com/datalook/action/base/BaseAction.java @@ -21,12 +21,12 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.serializer.SerializerFeature; import com.datalook.dao.base.HqlFilter; -import com.datalook.filter.FastjsonFilter; +import com.datalook.filter.base.FastjsonFilter; import com.datalook.model.sys.easyui.ComboTree; import com.datalook.model.sys.easyui.Grid; import com.datalook.model.sys.easyui.Json; import com.datalook.model.sys.web.SessionInfo; -import com.datalook.service.base.IBaseService; +import com.datalook.service.base.BaseService; import com.datalook.util.base.BeanUtils; import com.datalook.util.base.GenericsUtils; import com.datalook.util.base.LogUtil; @@ -62,10 +62,10 @@ public class BaseAction extends ActionSupport{ protected Boolean closed= false;//下拉列表树子节点折叠属性,设置true后,展开所有节点 protected List comboTrees = new ArrayList();//通用下拉列表对象 - protected IBaseService service;// 业务逻辑 + protected BaseService service;// 业务逻辑 /** - * @see com.datalook.action.base.IBaseAction#setService(com.datalook.service.base.IBaseService) + * @see com.datalook.action.base.IBaseAction#setService(com.datalook.service.base.BaseService) * * 功能描述: * 时间:2014年9月29日 @@ -73,7 +73,7 @@ public class BaseAction extends ActionSupport{ * @param service */ - public void setService(IBaseService service) { + public void setService(BaseService service) { this.service = service; } @@ -331,7 +331,7 @@ public void writeJsonByFilter(Object object, String[] includesProperties, String if (includesProperties != null && includesProperties.length > 0) { filter.getIncludes().addAll(Arrays. asList(includesProperties)); } - LogUtil.trace("对象转JSON:要排除的属性[" + excludesProperties + "]要包含的属性[" + includesProperties + "]"); + LogUtil.trace("[JSON准备]:(+)[" + excludesProperties + "] (-)[" + includesProperties + "]"); String json; String User_Agent = getRequest().getHeader("User-Agent"); if (StringUtils.indexOfIgnoreCase(User_Agent, "MSIE 6") > -1) { @@ -342,7 +342,7 @@ public void writeJsonByFilter(Object object, String[] includesProperties, String // 使用SerializerFeature.DisableCircularReferenceDetect特性关闭引用检测和生成 json = JSON.toJSONString(object, filter,SerializerFeature.WriteDateUseDateFormat, SerializerFeature.DisableCircularReferenceDetect);// } - LogUtil.trace("转换后的JSON字符串:" + json); + LogUtil.trace("[JSON数据]:" + json); getResponse().setContentType("text/html;charset=utf-8"); getResponse().getWriter().write(json); getResponse().getWriter().flush(); diff --git a/blank/src/main/java/com/datalook/action/base/TestAction.java b/blank/src/main/java/com/datalook/action/base/TestAction.java index 7a336b1..9cba291 100644 --- a/blank/src/main/java/com/datalook/action/base/TestAction.java +++ b/blank/src/main/java/com/datalook/action/base/TestAction.java @@ -60,13 +60,10 @@ public void noSySn_upload(){ public void noSySn_ueditor(){ System.out.println(content); } - public void noSySn_jbpm(){ + public void noSySn_noSe_jbpm(){ RuntimeEngine engine = runtimeManager.getRuntimeEngine(null); KieSession ksession = engine.getKieSession(); ProcessInstance processInstance = ksession.startProcess("com.sample.bpmn.hello"); - - runtimeManager.disposeRuntimeEngine(engine); - runtimeManager.close(); } } diff --git a/blank/src/main/java/com/datalook/action/sys/SysDictAction.java b/blank/src/main/java/com/datalook/action/sys/SysDictAction.java index 8730a89..e792a60 100644 --- a/blank/src/main/java/com/datalook/action/sys/SysDictAction.java +++ b/blank/src/main/java/com/datalook/action/sys/SysDictAction.java @@ -8,23 +8,23 @@ import com.datalook.action.base.BaseAction; import com.datalook.dao.base.HqlFilter; import com.datalook.model.sys.SysDict; -import com.datalook.service.base.IBaseService; -import com.datalook.service.sys.interfaces.ISysDictService; +import com.datalook.service.base.BaseService; +import com.datalook.service.sys.SysDictService; @Action("sysDict") public class SysDictAction extends BaseAction{ @Resource(name="sysDictService") - public void setService(IBaseService service) { + public void setService(BaseService service) { this.service = service; } public void noSy_find(){ HqlFilter hqlFilter = new HqlFilter(getRequest()); if(!StringUtils.isBlank(hqlFilter.getSqltable())){ - writeJson(((ISysDictService)service).findValus(hqlFilter)); + writeJson(((SysDictService)service).findValus(hqlFilter)); }else{ - writeJson(((ISysDictService)service).findValus(hqlFilter)); + writeJson(((SysDictService)service).findValus(hqlFilter)); } } diff --git a/blank/src/main/java/com/datalook/action/sys/SysFunctionAction.java b/blank/src/main/java/com/datalook/action/sys/SysFunctionAction.java index 69569c0..fb8bac8 100644 --- a/blank/src/main/java/com/datalook/action/sys/SysFunctionAction.java +++ b/blank/src/main/java/com/datalook/action/sys/SysFunctionAction.java @@ -14,8 +14,8 @@ import com.datalook.exception.base.ToWebException; import com.datalook.model.sys.SysFunction; import com.datalook.model.sys.web.SessionInfo; -import com.datalook.service.base.IBaseService; -import com.datalook.service.sys.ISysFunctionService; +import com.datalook.service.base.BaseService; +import com.datalook.service.sys.SysFunctionService; /** * @@ -36,7 +36,7 @@ public class SysFunctionAction extends BaseAction{ List functions=new ArrayList(); @Resource(name="sysFunctionService") - public void setService(IBaseService service) { + public void setService(BaseService service) { this.service = service; } @@ -71,6 +71,6 @@ public void noSy_getAllMenuWithRoot(){ } public void noSySn_test() throws ToWebException{ - ((ISysFunctionService)service).test("params"); + ((SysFunctionService)service).test("params"); } } diff --git a/blank/src/main/java/com/datalook/action/sys/SysRoleAction.java b/blank/src/main/java/com/datalook/action/sys/SysRoleAction.java index e9502c2..6d5098c 100644 --- a/blank/src/main/java/com/datalook/action/sys/SysRoleAction.java +++ b/blank/src/main/java/com/datalook/action/sys/SysRoleAction.java @@ -14,18 +14,18 @@ import com.datalook.model.sys.SysFunction; import com.datalook.model.sys.SysRole; import com.datalook.model.sys.easyui.Json; -import com.datalook.service.base.IBaseService; -import com.datalook.service.sys.interfaces.ISysRoleService; +import com.datalook.service.base.BaseService; +import com.datalook.service.sys.SysRoleService; @Action("sysRole") public class SysRoleAction extends BaseAction{ private static final long serialVersionUID = 1L; @Resource(name="sysFunctionService") - IBaseService sysFunctionService; + BaseService sysFunctionService; @Resource(name="sysRoleService") - public void setService(IBaseService service) { + public void setService(BaseService service) { this.service = service; } @@ -56,7 +56,7 @@ public void grant(){ } re.setSuccess(true); try { - ((ISysRoleService)service).grant(id.toString(), grantids, inSomeSysFunctionIds); + ((SysRoleService)service).grant(id.toString(), grantids, inSomeSysFunctionIds); } catch (Exception e) { e.printStackTrace(); diff --git a/blank/src/main/java/com/datalook/action/sys/SysUserAction.java b/blank/src/main/java/com/datalook/action/sys/SysUserAction.java index 9be5ca6..64486e8 100644 --- a/blank/src/main/java/com/datalook/action/sys/SysUserAction.java +++ b/blank/src/main/java/com/datalook/action/sys/SysUserAction.java @@ -17,7 +17,7 @@ import com.datalook.model.sys.SysUser; import com.datalook.model.sys.easyui.Json; import com.datalook.model.sys.web.SessionInfo; -import com.datalook.service.sys.interfaces.ISysUserService; +import com.datalook.service.sys.SysUserService; import com.datalook.util.base.CookieUtil; import com.datalook.util.base.MD5Util; @@ -33,8 +33,6 @@ public class SysUserAction extends BaseAction { private static final long serialVersionUID = 1L; - private static final Logger logger = Logger.getLogger(SysUserAction.class); - private File image; private String imageFileName; private String imageContentType; @@ -70,7 +68,7 @@ public void setImageContentType(String imageContentType) { @Resource(name="sysUserService") - public void setService(ISysUserService service) { + public void setService(SysUserService service) { this.service = service; } @@ -99,14 +97,11 @@ public void noSnSy_logout() { * @author: lirenbo */ public void noSnSy_login() { - System.out.println(data); data.setPassword(MD5Util.md5(data.getPassword())); SysUser sysUser = service.getByProperties(data); - logger.info("用户登陆"+sysUser); Json json = new Json(); if (sysUser != null&&"1".equals(sysUser.getStatus())) { json.setSuccess(true); - logger.info("用户登陆成功"+sysUser); SessionInfo sessionInfo = new SessionInfo(); Hibernate.initialize(sysUser.getSysRoles()); for (SysRole role : sysUser.getSysRoles()) { @@ -165,7 +160,7 @@ public void noSy_checkCurrentUserPassword() { */ public void grantSysRole() { Json json = new Json(); - ((ISysUserService) service).grantSysRole(id, ids); + ((SysUserService) service).grantSysRole(id, ids); json.setSuccess(true); writeJson(json); } diff --git a/blank/src/main/java/com/datalook/aop/base/ExceptionAspect.java b/blank/src/main/java/com/datalook/aop/base/ExceptionAspect.java index da35077..c5f83ca 100644 --- a/blank/src/main/java/com/datalook/aop/base/ExceptionAspect.java +++ b/blank/src/main/java/com/datalook/aop/base/ExceptionAspect.java @@ -16,7 +16,7 @@ import com.datalook.exception.base.ToWebException; import com.datalook.model.sys.SysDict; import com.datalook.model.sys.easyui.Json; -import com.datalook.service.sys.interfaces.ISysDictService; +import com.datalook.service.sys.SysDictService; import com.datalook.util.base.LogUtil; @Aspect @@ -24,7 +24,7 @@ public class ExceptionAspect { @Resource(name="sysDictService") - private ISysDictService sysDictService; + private SysDictService sysDictService; @Order(2000) @AfterThrowing(value = "com.datalook.aop.base.SystemArchitecture.inActionLayer()", throwing = "t") diff --git a/blank/src/main/java/com/datalook/filter/FastjsonFilter.java b/blank/src/main/java/com/datalook/filter/base/FastjsonFilter.java similarity index 93% rename from blank/src/main/java/com/datalook/filter/FastjsonFilter.java rename to blank/src/main/java/com/datalook/filter/base/FastjsonFilter.java index 8f059dc..789cfed 100644 --- a/blank/src/main/java/com/datalook/filter/FastjsonFilter.java +++ b/blank/src/main/java/com/datalook/filter/base/FastjsonFilter.java @@ -1,4 +1,4 @@ -package com.datalook.filter; +package com.datalook.filter.base; import java.util.HashSet; import java.util.Set; diff --git a/blank/src/main/java/com/datalook/filter/base/web/EntityManagerFilter.java b/blank/src/main/java/com/datalook/filter/base/web/EntityManagerFilter.java new file mode 100644 index 0000000..1222691 --- /dev/null +++ b/blank/src/main/java/com/datalook/filter/base/web/EntityManagerFilter.java @@ -0,0 +1,14 @@ +package com.datalook.filter.base.web; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; + +import org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter; + +public class EntityManagerFilter extends OpenEntityManagerInViewFilter{ + + @Override + protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException { + return request.getRequestURI().contains("_noSe_"); + } +} diff --git a/blank/src/main/java/com/datalook/filter/StrutsFilter.java b/blank/src/main/java/com/datalook/filter/base/web/StrutsFilter.java similarity index 94% rename from blank/src/main/java/com/datalook/filter/StrutsFilter.java rename to blank/src/main/java/com/datalook/filter/base/web/StrutsFilter.java index d42be20..fa93bc1 100644 --- a/blank/src/main/java/com/datalook/filter/StrutsFilter.java +++ b/blank/src/main/java/com/datalook/filter/base/web/StrutsFilter.java @@ -1,4 +1,4 @@ -package com.datalook.filter; +package com.datalook.filter.base.web; import java.io.IOException; import java.util.ArrayList; diff --git a/blank/src/main/java/com/datalook/filter/SessionFilter.java b/blank/src/main/java/com/datalook/filter/base/web/UserSessionFilter.java similarity index 85% rename from blank/src/main/java/com/datalook/filter/SessionFilter.java rename to blank/src/main/java/com/datalook/filter/base/web/UserSessionFilter.java index 1dbdbbd..b6245e7 100644 --- a/blank/src/main/java/com/datalook/filter/SessionFilter.java +++ b/blank/src/main/java/com/datalook/filter/base/web/UserSessionFilter.java @@ -1,4 +1,4 @@ -package com.datalook.filter; +package com.datalook.filter.base.web; import java.io.IOException; import java.util.ArrayList; @@ -17,6 +17,8 @@ import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; +import com.datalook.util.base.LogUtil; + /** * * 功能描述:用于过滤需要拦截的JSP文件 @@ -24,9 +26,7 @@ * @author :lirenbo * */ -public class SessionFilter implements Filter { - - private static final Logger logger = Logger.getLogger(SessionFilter.class); +public class UserSessionFilter implements Filter { private List list = new ArrayList(); @@ -38,8 +38,7 @@ public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) for (String url : list) { if (servletPath.indexOf(url) > -1) {// 需要过滤 - logger.info("进入session过滤器->访问路径为[" + servletPath + "]"); - + LogUtil.trace("[Filter] UserSession -> [" + servletPath + "]"); if (request.getSession().getAttribute("sessionInfo") == null) {// session不存在需要拦截 request.setAttribute("msg", "您还没有登录或登录已超时,请重新登录,然后再刷新本功能!"); request.getRequestDispatcher("/error/noSession.jsp").forward(request, response); diff --git a/blank/src/main/java/com/datalook/interceptor/base/SecurityInterceptor.java b/blank/src/main/java/com/datalook/interceptor/base/SecurityInterceptor.java index bb7dc6b..5bde3af 100644 --- a/blank/src/main/java/com/datalook/interceptor/base/SecurityInterceptor.java +++ b/blank/src/main/java/com/datalook/interceptor/base/SecurityInterceptor.java @@ -25,7 +25,7 @@ public class SecurityInterceptor extends MethodFilterInterceptor { protected String doIntercept(ActionInvocation actionInvocation) throws Exception { SessionInfo sessionInfo = (SessionInfo) ServletActionContext.getRequest().getSession().getAttribute("sessionInfo"); String servletPath = ServletActionContext.getRequest().getServletPath(); - LogUtil.trace("进入权限拦截器->访问的资源为:[" + servletPath + "]"); + LogUtil.trace("[Interceptor] Security -> [" + servletPath + "]"); servletPath = StringUtils.substringBeforeLast(servletPath, ".");// 去掉后面的后缀*.action之类的 diff --git a/blank/src/main/java/com/datalook/interceptor/base/SessionInterceptor.java b/blank/src/main/java/com/datalook/interceptor/base/SessionInterceptor.java index cfaa3cc..80941cd 100644 --- a/blank/src/main/java/com/datalook/interceptor/base/SessionInterceptor.java +++ b/blank/src/main/java/com/datalook/interceptor/base/SessionInterceptor.java @@ -21,7 +21,7 @@ public class SessionInterceptor extends MethodFilterInterceptor { protected String doIntercept(ActionInvocation actionInvocation) throws Exception { SessionInfo sessionInfo = (SessionInfo) ServletActionContext.getRequest().getSession().getAttribute("sessionInfo"); - LogUtil.trace("进入session拦截器->访问路径为[" + ServletActionContext.getRequest().getServletPath() + "]"); + LogUtil.trace("[Interceptor] Session -> [" + ServletActionContext.getRequest().getServletPath() + "]"); if (sessionInfo == null) { String errMsg = "您还没有登录或登录已超时,请重新登录,然后再刷新本功能!"; LogUtil.trace(errMsg); diff --git a/blank/src/main/java/com/datalook/service/base/BaseService.java b/blank/src/main/java/com/datalook/service/base/BaseService.java index e5c9d40..dd09717 100644 --- a/blank/src/main/java/com/datalook/service/base/BaseService.java +++ b/blank/src/main/java/com/datalook/service/base/BaseService.java @@ -1,299 +1,252 @@ package com.datalook.service.base; -import java.io.IOException; -import java.lang.reflect.ParameterizedType; -import java.util.ArrayList; import java.util.List; import java.util.Map; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.lang3.StringUtils; -import org.apache.struts2.ServletActionContext; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import com.alibaba.fastjson.JSON; import com.datalook.dao.base.HqlFilter; import com.datalook.dao.base.IBaseDao; -import com.datalook.dao.base.SqlBeanGenerater; -import com.datalook.util.base.GenericsUtils; -import com.datalook.util.base.LogUtil; /** + * 基础业务逻辑类,其他service继承此service获得基本的业务 * - * 功能描述:基础业务逻辑 时间:2014年9月12日 - * - * @author :lirenbo + * @author * + * @param */ -@Service("baseService") -public class BaseService implements IBaseService { +public interface BaseService { + + public Long countByHQLFilter(HqlFilter hqlFilter); + + public Long countBySQLFilter(HqlFilter hqlFilter); - @Autowired - private IBaseDao baseDao; /** + * 删除一个对象 * - * @see com.datalook.service.base.IBaseService#countByHQLFilter(com.datalook.dao.base.HqlFilter) + * @param o + * 对象 + */ + public void delete(T o); + + /** + * 执行一条HQL语句 * - * 功能描述:根据过滤器查询,如果没有hqltable表则反射获取泛型为表 时间:2014年9月12日 - * @author: lirenbo - * @param hqlFilter - * @return + * @param hql + * HQL语句 + * @return 响应结果数目 + */ + public int executeHql(String hql); + /** + * 执行一条HQL语句 + * + * @param hql + * HQL语句 + * @param params + * 参数 + * @return 响应结果数目 + */ + public int executeHql(String hql, Map params); + + /** + * 执行SQL语句 + * + * @param sql + * SQL语句 + * @return 响应行数 + */ + public int executeSql(String sql); + + /** + * 执行SQL语句 + * + * @param sql + * SQL语句 + * @param params + * 参数 + * @return 响应行数 */ - @Override - public Long countByHQLFilter(HqlFilter hqlFilter) { - if (!StringUtils.isBlank(hqlFilter.getHqltable())) { - String hql = hqlFilter.getHql(); - hql = StringUtils.substringAfter(hql, "from"); - hql = StringUtils.substringBeforeLast(hql, "order"); - return baseDao.getLong("select count(*) from " + hql, hqlFilter.getParams()); - - } else { - String className = ((Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]).getName(); - String hql = hqlFilter.getHql(); - - hql = StringUtils.substringAfter(hql, "from").equals("") ? hql : StringUtils.substringAfter(hql, "from"); - hql = StringUtils.substringBeforeLast(hql, "order"); - - hql = "select count(*) from " + className + " " + hql; - return baseDao.getLong(hql, hqlFilter.getParams()); - } - } - - public Long countBySQLFilter(HqlFilter hqlFilter) { - if (!StringUtils.isBlank(hqlFilter.getSqltable())) { - String sql = hqlFilter.getSql(); - sql = StringUtils.substringAfter(sql, "from").equals("") ? sql : StringUtils.substringAfter(sql, "from"); - sql = StringUtils.substringBeforeLast(sql, "order"); - sql = "select count(*) from " + sql; - return Long.valueOf(baseDao.getIntegerBySql(sql, hqlFilter.getParams()).toString()); - } - return null; - } - - @Override - public void delete(T o) { - baseDao.delete(o); - } - - @Override - public int executeHql(String hql) { - return baseDao.executeHql(hql); - } - - @Override - public int executeHql(String hql, Map params) { - return baseDao.executeHql(hql, params); - } - - @Override - public int executeSql(String sql) { - return baseDao.executeSql(sql); - } - - @Override - public int executeSql(String sql, Map params) { - return baseDao.executeSql(sql, params); - } - - @Override - public List find(String hql) { - return baseDao.find(hql); - } - - @Override - public List find(String hql, int page, int rows) { - return baseDao.find(hql, page, rows); - } - - @Override - public List find(String hql, Map params) { - return baseDao.find(hql, params); - } - - @Override - public List find(String hql, Map params, int page, int rows) { - return baseDao.find(hql, params, page, rows); - } - - @Override - public List findAll() { - return findByHQLFilter(new HqlFilter()); - } - - @Override - public List findByHQLFilter(HqlFilter hqlFilter) { - if (!StringUtils.isBlank(hqlFilter.getHqltable())) { - return baseDao.find(hqlFilter.getHqlwithOrder(), hqlFilter.getParams()); - } else { - String className = ((Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]).getName(); - String hql = "from " + className + " " + hqlFilter.getHqlwithOrder(); - return baseDao.find(hql, hqlFilter.getParams()); - } - } + public int executeSql(String sql, Map params); + /** + * 获得对象列表 * - * @see com.datalook.service.base.IBaseService#findByHQLFilter(com.datalook.dao.base.HqlFilter, int, int) + * @param hql + * HQL语句 + * @return List + */ + public List find(String hql); + + /** + * 获得分页后的对象列表 * - * 功能描述:根据分页信息,与过滤器查询,如果没有hqltable表则反射获取泛型为表 时间:2014年9月12日 - * @author: lirenbo - * @param hqlFilter + * @param hql + * HQL语句 * @param page + * 要显示第几页 * @param rows - * @return + * 每页显示多少条 + * @return List + */ + public List find(String hql, int page, int rows); + + /** + * 获得对象列表 + * + * @param hql + * HQL语句 + * @param params + * 参数 + * @return List */ - @Override - public List findByHQLFilter(HqlFilter hqlFilter, int page, int rows) { - if (!StringUtils.isBlank(hqlFilter.getHqltable())) { - return baseDao.find(hqlFilter.getHqlwithOrder(), hqlFilter.getParams(), page, rows); - } else { - String className = ((Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]).getName(); - String hql = "from " + className + " " + hqlFilter.getHqlwithOrder(); - return baseDao.find(hql, hqlFilter.getParams(), page, rows); - } - } - - @Override - public List findByProperties(T properties) { - return baseDao.findByProperties(properties); - } - - @Override - public List findBySql(String sql) { - return baseDao.findBySql(sql); - } - - @Override - public List findBySql(String sql, int page, int rows) { - return baseDao.findBySql(sql, page, rows); - } - - @Override - public List findBySql(String sql, Map params) { - return baseDao.findBySql(sql, params); - } - - @Override - public List findBySql(String sql, Map params, int page, int rows) { - return baseDao.findBySql(sql, params, page, rows); - } - - public List findBySQLFilter(HqlFilter hqlFilter) { - if (!StringUtils.isBlank(hqlFilter.getSqltable())) { - List los = baseDao.findBySql(hqlFilter.getSqlwithOrder(), hqlFilter.getParams()); - return SqlBeanGenerater.generateBySqlList(hqlFilter.getSqlwithOrder(), los); - } - return new ArrayList(); - } - - public List findBySQLFilter(HqlFilter hqlFilter, int page, int rows) { - if (!StringUtils.isBlank(hqlFilter.getSqltable())) { - List los = baseDao.findBySql(hqlFilter.getSqlwithOrder(), hqlFilter.getParams(), page, rows); - return SqlBeanGenerater.generateBySqlList(hqlFilter.getSqlwithOrder(), los); - } - return new ArrayList(); - } - - public IBaseDao getBaseDao() { - return baseDao; - } - - @Override - public T getByHql(String hql) { - return baseDao.getByHql(hql); - } - - @Override - public T getByHql(String hql, Map params) { - return baseDao.getByHql(hql, params); - } - - @Override - public T getById(Class c, Object id) { - return (T) baseDao.getById(c, id); - } + public List find(String hql, Map params); + /** + * 获得分页后的对象列表 * - * @see com.datalook.service.base.IBaseService#getById(java.lang.Object) + * @param hql + * HQL语句 + * @param params + * 参数 + * @param page + * 要显示第几页 + * @param rows + * 每页显示多少条 + * @return List + */ + public List find(String hql, Map params, int page, int rows); + + /** + * 获得对象列表 * - * 功能描述:获取确定泛型class,根据主键直接查找对象 时间:2014年9月12日 - * @author: lirenbo - * @param id * @return */ - @Override - public T getById(Object id) { - Class c = GenericsUtils.getSuperClassGenricType(getClass()); - return (T) baseDao.getById(c, id); - } + public List findAll(); + + public List findByHQLFilter(HqlFilter hqlFilter); + + public List findByHQLFilter(HqlFilter hqlFilter, int page, int rows); + + + public List findByProperties(T properties); /** + * 获得结果集 * - * @see com.datalook.service.base.IBaseService#getByProperties(java.lang.Object) + * @param sql + * SQL语句 + * @return 结果集 + */ + public List findBySql(String sql); + + /** + * 获得结果集 * - * 功能描述:根据对象含有的属性查找对象,集合无效 时间:2014年9月12日 - * @author: lirenbo - * @param properties - * @return + * @param sql + * SQL语句 + * @param page + * 要显示第几页 + * @param rows + * 每页显示多少条 + * @return 结果集 + */ + public List findBySql(String sql, int page, int rows); + + /** + * 获得结果集 + * + * @param sql + * SQL语句 + * @param params + * 参数 + * @return 结果集 */ - @Override - public T getByProperties(T properties) { - List list = findByProperties(properties); - if (list.size() == 1) { - return list.get(0); - } - return null; - } + public List findBySql(String sql, Map params); /** + * 获得结果集 * - * 功能描述:调用存储过程获得对应表序列 时间:2014年9月4日 下午4:13:08 + * @param sql + * SQL语句 + * @param params + * 参数 + * @param page + * 要显示第几页 + * @param rows + * 每页显示多少条 + * @return 结果集 + */ + public List findBySql(String sql, Map params, int page, int rows); + + public List findBySQLFilter(HqlFilter hqlFilter); + + public List findBySQLFilter(HqlFilter hqlFilter, int page, int rows); + + public IBaseDao getBaseDao(); + + /** + * 通过HQL语句获取一个对象 * + * @param hql + * HQL语句 + * @return 对象 + */ + public T getByHql(String hql); + + /** + * 通过HQL语句获取一个对象 + * + * @param hql + * HQL语句 + * @param params + * 参数 + * @return 对象 + */ + public T getByHql(String hql, Map params); + + public T getById(Class c, Object id); + + /** + * 通过主键获得对象 + * + * @param c + * 类名.class + * @param id + * 主键 + * @return 对象 + */ + public T getById(Object id); + + public T getByProperties(T properties); + /** + * + * 功能描述:调用存储过程获得对应表序列 + * 时间:2014年9月4日 下午4:13:08 * @author :songxia * @param callName * @return */ - @Override - public Integer getSeqValueSQLServer(T o) { - if (o != null) { - String callName = o.getClass().getSimpleName() + "_GetSeqvalue"; - return baseDao.getSeqValueSQLServer(callName); - } - return null; - } - - @Override - public String getString(String hql) { - return baseDao.getString(hql); - } - - @Override - public Object save(T o) { - return baseDao.save(o); - } - + public Integer getSeqValueSQLServer(T o); + + String getString(String hql); + /** + * 保存一个对象 * - * @see com.datalook.service.base.IBaseService#saveoDeleteOld(java.lang.Object, java.lang.Object) + * @param o + * 对象 + * @return 对象的ID + */ + public Object save(T o); + + void saveoDeleteOld(T o, T oldo); + + /** + * 保存或更新一个对象 * - * 功能描述:删除oldo,保存o 时间:2014年9月12日 - * @author: lirenbo * @param o - * @param oldo + * 对象 */ - @Override - public void saveoDeleteOld(T o, T oldo) { - oldo = getByProperties(oldo); - delete(oldo); - save(o); - } - - @Override - public void saveOrUpdate(T o) { - baseDao.saveOrUpdate(o); - } + public void saveOrUpdate(T o); } diff --git a/blank/src/main/java/com/datalook/service/base/BaseServiceImpl.java b/blank/src/main/java/com/datalook/service/base/BaseServiceImpl.java new file mode 100644 index 0000000..ebadc33 --- /dev/null +++ b/blank/src/main/java/com/datalook/service/base/BaseServiceImpl.java @@ -0,0 +1,299 @@ +package com.datalook.service.base; + +import java.io.IOException; +import java.lang.reflect.ParameterizedType; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang3.StringUtils; +import org.apache.struts2.ServletActionContext; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.alibaba.fastjson.JSON; +import com.datalook.dao.base.HqlFilter; +import com.datalook.dao.base.IBaseDao; +import com.datalook.dao.base.SqlBeanGenerater; +import com.datalook.util.base.GenericsUtils; +import com.datalook.util.base.LogUtil; + +/** + * + * 功能描述:基础业务逻辑 时间:2014年9月12日 + * + * @author :lirenbo + * + */ +@Service("baseService") +public class BaseServiceImpl implements BaseService { + + @Autowired + private IBaseDao baseDao; + + /** + * + * @see com.datalook.service.base.BaseService#countByHQLFilter(com.datalook.dao.base.HqlFilter) + * + * 功能描述:根据过滤器查询,如果没有hqltable表则反射获取泛型为表 时间:2014年9月12日 + * @author: lirenbo + * @param hqlFilter + * @return + */ + @Override + public Long countByHQLFilter(HqlFilter hqlFilter) { + if (!StringUtils.isBlank(hqlFilter.getHqltable())) { + String hql = hqlFilter.getHql(); + hql = StringUtils.substringAfter(hql, "from"); + hql = StringUtils.substringBeforeLast(hql, "order"); + return baseDao.getLong("select count(*) from " + hql, hqlFilter.getParams()); + + } else { + String className = ((Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]).getName(); + String hql = hqlFilter.getHql(); + + hql = StringUtils.substringAfter(hql, "from").equals("") ? hql : StringUtils.substringAfter(hql, "from"); + hql = StringUtils.substringBeforeLast(hql, "order"); + + hql = "select count(*) from " + className + " " + hql; + return baseDao.getLong(hql, hqlFilter.getParams()); + } + } + + public Long countBySQLFilter(HqlFilter hqlFilter) { + if (!StringUtils.isBlank(hqlFilter.getSqltable())) { + String sql = hqlFilter.getSql(); + sql = StringUtils.substringAfter(sql, "from").equals("") ? sql : StringUtils.substringAfter(sql, "from"); + sql = StringUtils.substringBeforeLast(sql, "order"); + sql = "select count(*) from " + sql; + return Long.valueOf(baseDao.getIntegerBySql(sql, hqlFilter.getParams()).toString()); + } + return null; + } + + @Override + public void delete(T o) { + baseDao.delete(o); + } + + @Override + public int executeHql(String hql) { + return baseDao.executeHql(hql); + } + + @Override + public int executeHql(String hql, Map params) { + return baseDao.executeHql(hql, params); + } + + @Override + public int executeSql(String sql) { + return baseDao.executeSql(sql); + } + + @Override + public int executeSql(String sql, Map params) { + return baseDao.executeSql(sql, params); + } + + @Override + public List find(String hql) { + return baseDao.find(hql); + } + + @Override + public List find(String hql, int page, int rows) { + return baseDao.find(hql, page, rows); + } + + @Override + public List find(String hql, Map params) { + return baseDao.find(hql, params); + } + + @Override + public List find(String hql, Map params, int page, int rows) { + return baseDao.find(hql, params, page, rows); + } + + @Override + public List findAll() { + return findByHQLFilter(new HqlFilter()); + } + + @Override + public List findByHQLFilter(HqlFilter hqlFilter) { + if (!StringUtils.isBlank(hqlFilter.getHqltable())) { + return baseDao.find(hqlFilter.getHqlwithOrder(), hqlFilter.getParams()); + } else { + String className = ((Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]).getName(); + String hql = "from " + className + " " + hqlFilter.getHqlwithOrder(); + return baseDao.find(hql, hqlFilter.getParams()); + } + } + + /** + * + * @see com.datalook.service.base.BaseService#findByHQLFilter(com.datalook.dao.base.HqlFilter, int, int) + * + * 功能描述:根据分页信息,与过滤器查询,如果没有hqltable表则反射获取泛型为表 时间:2014年9月12日 + * @author: lirenbo + * @param hqlFilter + * @param page + * @param rows + * @return + */ + @Override + public List findByHQLFilter(HqlFilter hqlFilter, int page, int rows) { + if (!StringUtils.isBlank(hqlFilter.getHqltable())) { + return baseDao.find(hqlFilter.getHqlwithOrder(), hqlFilter.getParams(), page, rows); + } else { + String className = ((Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]).getName(); + String hql = "from " + className + " " + hqlFilter.getHqlwithOrder(); + return baseDao.find(hql, hqlFilter.getParams(), page, rows); + } + } + + @Override + public List findByProperties(T properties) { + return baseDao.findByProperties(properties); + } + + @Override + public List findBySql(String sql) { + return baseDao.findBySql(sql); + } + + @Override + public List findBySql(String sql, int page, int rows) { + return baseDao.findBySql(sql, page, rows); + } + + @Override + public List findBySql(String sql, Map params) { + return baseDao.findBySql(sql, params); + } + + @Override + public List findBySql(String sql, Map params, int page, int rows) { + return baseDao.findBySql(sql, params, page, rows); + } + + public List findBySQLFilter(HqlFilter hqlFilter) { + if (!StringUtils.isBlank(hqlFilter.getSqltable())) { + List los = baseDao.findBySql(hqlFilter.getSqlwithOrder(), hqlFilter.getParams()); + return SqlBeanGenerater.generateBySqlList(hqlFilter.getSqlwithOrder(), los); + } + return new ArrayList(); + } + + public List findBySQLFilter(HqlFilter hqlFilter, int page, int rows) { + if (!StringUtils.isBlank(hqlFilter.getSqltable())) { + List los = baseDao.findBySql(hqlFilter.getSqlwithOrder(), hqlFilter.getParams(), page, rows); + return SqlBeanGenerater.generateBySqlList(hqlFilter.getSqlwithOrder(), los); + } + return new ArrayList(); + } + + public IBaseDao getBaseDao() { + return baseDao; + } + + @Override + public T getByHql(String hql) { + return baseDao.getByHql(hql); + } + + @Override + public T getByHql(String hql, Map params) { + return baseDao.getByHql(hql, params); + } + + @Override + public T getById(Class c, Object id) { + return (T) baseDao.getById(c, id); + } + + /** + * + * @see com.datalook.service.base.BaseService#getById(java.lang.Object) + * + * 功能描述:获取确定泛型class,根据主键直接查找对象 时间:2014年9月12日 + * @author: lirenbo + * @param id + * @return + */ + @Override + public T getById(Object id) { + Class c = GenericsUtils.getSuperClassGenricType(getClass()); + return (T) baseDao.getById(c, id); + } + + /** + * + * @see com.datalook.service.base.BaseService#getByProperties(java.lang.Object) + * + * 功能描述:根据对象含有的属性查找对象,集合无效 时间:2014年9月12日 + * @author: lirenbo + * @param properties + * @return + */ + @Override + public T getByProperties(T properties) { + List list = findByProperties(properties); + if (list.size() == 1) { + return list.get(0); + } + return null; + } + + /** + * + * 功能描述:调用存储过程获得对应表序列 时间:2014年9月4日 下午4:13:08 + * + * @author :songxia + * @param callName + * @return + */ + @Override + public Integer getSeqValueSQLServer(T o) { + if (o != null) { + String callName = o.getClass().getSimpleName() + "_GetSeqvalue"; + return baseDao.getSeqValueSQLServer(callName); + } + return null; + } + + @Override + public String getString(String hql) { + return baseDao.getString(hql); + } + + @Override + public Object save(T o) { + return baseDao.save(o); + } + + /** + * + * @see com.datalook.service.base.BaseService#saveoDeleteOld(java.lang.Object, java.lang.Object) + * + * 功能描述:删除oldo,保存o 时间:2014年9月12日 + * @author: lirenbo + * @param o + * @param oldo + */ + @Override + public void saveoDeleteOld(T o, T oldo) { + oldo = getByProperties(oldo); + delete(oldo); + save(o); + } + + @Override + public void saveOrUpdate(T o) { + baseDao.saveOrUpdate(o); + } +} diff --git a/blank/src/main/java/com/datalook/service/base/IBaseService.java b/blank/src/main/java/com/datalook/service/base/IBaseService.java deleted file mode 100644 index e5f6d1c..0000000 --- a/blank/src/main/java/com/datalook/service/base/IBaseService.java +++ /dev/null @@ -1,252 +0,0 @@ -package com.datalook.service.base; - -import java.util.List; -import java.util.Map; - -import com.datalook.dao.base.HqlFilter; -import com.datalook.dao.base.IBaseDao; - -/** - * 基础业务逻辑类,其他service继承此service获得基本的业务 - * - * @author - * - * @param - */ -public interface IBaseService { - - public Long countByHQLFilter(HqlFilter hqlFilter); - - public Long countBySQLFilter(HqlFilter hqlFilter); - - - /** - * 删除一个对象 - * - * @param o - * 对象 - */ - public void delete(T o); - - /** - * 执行一条HQL语句 - * - * @param hql - * HQL语句 - * @return 响应结果数目 - */ - public int executeHql(String hql); - /** - * 执行一条HQL语句 - * - * @param hql - * HQL语句 - * @param params - * 参数 - * @return 响应结果数目 - */ - public int executeHql(String hql, Map params); - - /** - * 执行SQL语句 - * - * @param sql - * SQL语句 - * @return 响应行数 - */ - public int executeSql(String sql); - - /** - * 执行SQL语句 - * - * @param sql - * SQL语句 - * @param params - * 参数 - * @return 响应行数 - */ - public int executeSql(String sql, Map params); - - - /** - * 获得对象列表 - * - * @param hql - * HQL语句 - * @return List - */ - public List find(String hql); - - /** - * 获得分页后的对象列表 - * - * @param hql - * HQL语句 - * @param page - * 要显示第几页 - * @param rows - * 每页显示多少条 - * @return List - */ - public List find(String hql, int page, int rows); - - /** - * 获得对象列表 - * - * @param hql - * HQL语句 - * @param params - * 参数 - * @return List - */ - public List find(String hql, Map params); - - - /** - * 获得分页后的对象列表 - * - * @param hql - * HQL语句 - * @param params - * 参数 - * @param page - * 要显示第几页 - * @param rows - * 每页显示多少条 - * @return List - */ - public List find(String hql, Map params, int page, int rows); - - /** - * 获得对象列表 - * - * @return - */ - public List findAll(); - - public List findByHQLFilter(HqlFilter hqlFilter); - - public List findByHQLFilter(HqlFilter hqlFilter, int page, int rows); - - - public List findByProperties(T properties); - - /** - * 获得结果集 - * - * @param sql - * SQL语句 - * @return 结果集 - */ - public List findBySql(String sql); - - /** - * 获得结果集 - * - * @param sql - * SQL语句 - * @param page - * 要显示第几页 - * @param rows - * 每页显示多少条 - * @return 结果集 - */ - public List findBySql(String sql, int page, int rows); - - /** - * 获得结果集 - * - * @param sql - * SQL语句 - * @param params - * 参数 - * @return 结果集 - */ - public List findBySql(String sql, Map params); - - /** - * 获得结果集 - * - * @param sql - * SQL语句 - * @param params - * 参数 - * @param page - * 要显示第几页 - * @param rows - * 每页显示多少条 - * @return 结果集 - */ - public List findBySql(String sql, Map params, int page, int rows); - - public List findBySQLFilter(HqlFilter hqlFilter); - - public List findBySQLFilter(HqlFilter hqlFilter, int page, int rows); - - public IBaseDao getBaseDao(); - - /** - * 通过HQL语句获取一个对象 - * - * @param hql - * HQL语句 - * @return 对象 - */ - public T getByHql(String hql); - - /** - * 通过HQL语句获取一个对象 - * - * @param hql - * HQL语句 - * @param params - * 参数 - * @return 对象 - */ - public T getByHql(String hql, Map params); - - public T getById(Class c, Object id); - - /** - * 通过主键获得对象 - * - * @param c - * 类名.class - * @param id - * 主键 - * @return 对象 - */ - public T getById(Object id); - - public T getByProperties(T properties); - /** - * - * 功能描述:调用存储过程获得对应表序列 - * 时间:2014年9月4日 下午4:13:08 - * @author :songxia - * @param callName - * @return - */ - public Integer getSeqValueSQLServer(T o); - - String getString(String hql); - - /** - * 保存一个对象 - * - * @param o - * 对象 - * @return 对象的ID - */ - public Object save(T o); - - void saveoDeleteOld(T o, T oldo); - - /** - * 保存或更新一个对象 - * - * @param o - * 对象 - */ - public void saveOrUpdate(T o); -} diff --git a/blank/src/main/java/com/datalook/service/sys/ISysFunctionService.java b/blank/src/main/java/com/datalook/service/sys/ISysFunctionService.java deleted file mode 100644 index 5ce6fa7..0000000 --- a/blank/src/main/java/com/datalook/service/sys/ISysFunctionService.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.datalook.service.sys; - -import javax.transaction.Transactional; - -import com.datalook.exception.base.ToWebException; - -public interface ISysFunctionService { - - public abstract void test(String test) throws ToWebException; - -} \ No newline at end of file diff --git a/blank/src/main/java/com/datalook/service/sys/SysDictService.java b/blank/src/main/java/com/datalook/service/sys/SysDictService.java index c7ea155..5522c13 100644 --- a/blank/src/main/java/com/datalook/service/sys/SysDictService.java +++ b/blank/src/main/java/com/datalook/service/sys/SysDictService.java @@ -2,72 +2,16 @@ import java.util.List; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cache.annotation.Cacheable; -import org.springframework.stereotype.Service; - import com.datalook.dao.base.HqlFilter; -import com.datalook.dao.base.IBaseDao; import com.datalook.model.sys.SysDict; import com.datalook.service.base.BaseService; -import com.datalook.service.sys.interfaces.ISysDictService; -@Service("sysDictService") -public class SysDictService extends BaseService implements ISysDictService{ - @Autowired - IBaseDao sysDictDao; - - /** - * @see com.datalook.service.sys.interfaces.ISysDictService#getValue(java.lang.String, java.lang.String) - * - * 功能描述: - * 时间:2014年10月16日 - * @author: lirenbo - * @param location - * @param code - * @return - */ - @Override - @Cacheable({"SysDictValue"}) - public SysDict getValue(String location,String code){ - List sysDicts=sysDictDao.find("from SysDict where location ='"+location+"' and code ='"+code+"'"); - if(sysDicts.size()==0){ - return null; - }else{ - return sysDicts.get(0); - } - } - - - /** - * @see com.datalook.service.sys.interfaces.ISysDictService#findValus(java.lang.String) - * - * 功能描述: - * 时间:2014年10月16日 - * @author: lirenbo - * @param location - * @return - */ - @Override - @Cacheable({"SysDictValues"}) - public List findValus(String location){ - List sysDicts=sysDictDao.find("from SysDict where location ='"+location+"'"); - return sysDicts; - } - - - /** - * @see com.datalook.service.sys.interfaces.ISysDictService#findValus(com.datalook.dao.base.HqlFilter) - * - * 功能描述: - * 时间:2014年10月16日 - * @author: lirenbo - * @param hqlFilter - * @return - */ - @Override - @Cacheable({"SysDictValuesHqlFilter"}) - public List findValus(HqlFilter hqlFilter){ - List sysDicts=findByHQLFilter(hqlFilter); - return sysDicts; - } -} + +public interface SysDictService extends BaseService{ + + public abstract SysDict getValue(String location, String code); + + public abstract List findValus(String location); + + public abstract List findValus(HqlFilter hqlFilter); + +} \ No newline at end of file diff --git a/blank/src/main/java/com/datalook/service/sys/SysFunctionService.java b/blank/src/main/java/com/datalook/service/sys/SysFunctionService.java index b4767d9..11e24dd 100644 --- a/blank/src/main/java/com/datalook/service/sys/SysFunctionService.java +++ b/blank/src/main/java/com/datalook/service/sys/SysFunctionService.java @@ -1,57 +1,11 @@ package com.datalook.service.sys; -import java.util.List; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.Query; - -import org.springframework.stereotype.Service; - import com.datalook.exception.base.ToWebException; -import com.datalook.exception.base.ToWebExceptionFactory; import com.datalook.model.sys.SysFunction; import com.datalook.service.base.BaseService; -import com.datalook.service.base.IBaseService; - - -@Service("sysFunctionService") -public class SysFunctionService extends BaseService implements IBaseService, ISysFunctionService { - public SysFunctionService() { - super(); - } +public interface SysFunctionService extends BaseService{ - @Override - public synchronized Object save(SysFunction o) { - Integer i=getBaseDao().getInteger("select max(sf.id) from SysFunction sf"); - o.setSysFunction(getById(o.getPid())); - o.setId(i+1); - getBaseDao().save(o); - return o; - } + public abstract void test(String test) throws ToWebException; - @Override - public void saveOrUpdate(SysFunction o) { - o.setSysFunction(getById(o.getPid())); - getBaseDao().saveOrUpdate(o); - return ; - } - - - /** - * @see com.datalook.service.sys.ISysFunctionService#test(java.lang.String) - * - * 功能描述: - * 时间:2014年10月15日 - * @author: lirenbo - * @param test - * @throws ToWebException - */ - @Override - @org.springframework.transaction.annotation.Transactional - public void test(String test) throws ToWebException{ - getBaseDao().save(new SysFunction(99868, null, test, null, null, null, null, null, null, null, null)); - throw ToWebExceptionFactory.createCodeRollbackInstance("1"); - } -} +} \ No newline at end of file diff --git a/blank/src/main/java/com/datalook/service/sys/SysRoleService.java b/blank/src/main/java/com/datalook/service/sys/SysRoleService.java index e75d91e..868c163 100644 --- a/blank/src/main/java/com/datalook/service/sys/SysRoleService.java +++ b/blank/src/main/java/com/datalook/service/sys/SysRoleService.java @@ -1,23 +1,11 @@ package com.datalook.service.sys; -import org.springframework.stereotype.Service; - import com.datalook.model.sys.SysRole; import com.datalook.service.base.BaseService; -import com.datalook.service.sys.interfaces.ISysRoleService; -import com.datalook.util.base.StringUtil; -@Service("sysRoleService") -public class SysRoleService extends BaseService implements ISysRoleService{ +public interface SysRoleService extends BaseService{ + + public abstract void grant(String sysRoleId, String grantSysFunctionIds[], + String inSomeSysFunctionIds[]); - /* (non-Javadoc) - * @see com.datalook.service.sys.ISysRoleService#grant(java.lang.String, java.lang.String[], java.lang.String[]) - */ - @Override - public synchronized void grant(String sysRoleId,String grantSysFunctionIds[],String inSomeSysFunctionIds[]){ - getBaseDao().executeSql(StringUtil.formateString("delete SYS_ROLE_FUNCTION_RELATION where ROLEID = {0} and SYSFUNCTIONID in {1} ",sysRoleId,StringUtil.toVarcharsSqlInString(inSomeSysFunctionIds))); - for (String eachgrantSysFunctionId : grantSysFunctionIds) { - getBaseDao().executeSql(StringUtil.formateString("insert into SYS_ROLE_FUNCTION_RELATION values({0},{1})", sysRoleId,eachgrantSysFunctionId)); - } - } -} +} \ No newline at end of file diff --git a/blank/src/main/java/com/datalook/service/sys/SysUserService.java b/blank/src/main/java/com/datalook/service/sys/SysUserService.java index 3f26232..4f7a04e 100644 --- a/blank/src/main/java/com/datalook/service/sys/SysUserService.java +++ b/blank/src/main/java/com/datalook/service/sys/SysUserService.java @@ -1,48 +1,22 @@ package com.datalook.service.sys; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; - -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import com.datalook.dao.base.IBaseDao; -import com.datalook.model.sys.SysRole; import com.datalook.model.sys.SysUser; import com.datalook.service.base.BaseService; -import com.datalook.service.sys.interfaces.ISysUserService; /** - * 用户业务逻辑 + * 用户业务 * * */ -@Service -public class SysUserService extends BaseService implements ISysUserService { +public interface SysUserService extends BaseService { - @Autowired - private IBaseDao roleDao; - - /* (non-Javadoc) - * @see com.datalook.service.sys.ISysUserService#grantSysRole(java.lang.String, java.lang.String) + /** + * 修改用户角色 + * @param id + * 用户ID + * @param roleIds + * 角色IDS */ - @Override - public void grantSysRole(Integer id, String roleIds) { - SysUser user = getById(id); - if (user != null) { - user.setSysRoles(new HashSet()); - for (String roleId : roleIds.split(",")) { - if (!StringUtils.isBlank(roleId)) { - SysRole role = roleDao.getById(SysRole.class, Integer.valueOf(roleId)); - if (role != null) { - user.getSysRoles().add(role); - } - } - } - } - } + public void grantSysRole(Integer id, String roleIds); + } diff --git a/blank/src/main/java/com/datalook/service/sys/implement/SysDictServiceImpl.java b/blank/src/main/java/com/datalook/service/sys/implement/SysDictServiceImpl.java new file mode 100644 index 0000000..8483d6c --- /dev/null +++ b/blank/src/main/java/com/datalook/service/sys/implement/SysDictServiceImpl.java @@ -0,0 +1,73 @@ +package com.datalook.service.sys.implement; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Service; + +import com.datalook.dao.base.HqlFilter; +import com.datalook.dao.base.IBaseDao; +import com.datalook.model.sys.SysDict; +import com.datalook.service.base.BaseServiceImpl; +import com.datalook.service.sys.SysDictService; +@Service("sysDictService") +public class SysDictServiceImpl extends BaseServiceImpl implements SysDictService{ + @Autowired + IBaseDao sysDictDao; + + /** + * @see com.datalook.service.sys.SysDictService#getValue(java.lang.String, java.lang.String) + * + * 功能描述: + * 时间:2014年10月16日 + * @author: lirenbo + * @param location + * @param code + * @return + */ + @Override + @Cacheable({"SysDictValue"}) + public SysDict getValue(String location,String code){ + List sysDicts=sysDictDao.find("from SysDict where location ='"+location+"' and code ='"+code+"'"); + if(sysDicts.size()==0){ + return null; + }else{ + return sysDicts.get(0); + } + } + + + /** + * @see com.datalook.service.sys.SysDictService#findValus(java.lang.String) + * + * 功能描述: + * 时间:2014年10月16日 + * @author: lirenbo + * @param location + * @return + */ + @Override + @Cacheable({"SysDictValues"}) + public List findValus(String location){ + List sysDicts=sysDictDao.find("from SysDict where location ='"+location+"'"); + return sysDicts; + } + + + /** + * @see com.datalook.service.sys.SysDictService#findValus(com.datalook.dao.base.HqlFilter) + * + * 功能描述: + * 时间:2014年10月16日 + * @author: lirenbo + * @param hqlFilter + * @return + */ + @Override + @Cacheable({"SysDictValuesHqlFilter"}) + public List findValus(HqlFilter hqlFilter){ + List sysDicts=findByHQLFilter(hqlFilter); + return sysDicts; + } +} diff --git a/blank/src/main/java/com/datalook/service/sys/implement/SysFunctionServiceImpl.java b/blank/src/main/java/com/datalook/service/sys/implement/SysFunctionServiceImpl.java new file mode 100644 index 0000000..311c37b --- /dev/null +++ b/blank/src/main/java/com/datalook/service/sys/implement/SysFunctionServiceImpl.java @@ -0,0 +1,51 @@ +package com.datalook.service.sys.implement; + +import org.springframework.stereotype.Service; + +import com.datalook.exception.base.ToWebException; +import com.datalook.exception.base.ToWebExceptionFactory; +import com.datalook.model.sys.SysFunction; +import com.datalook.service.base.BaseServiceImpl; +import com.datalook.service.sys.SysFunctionService; + + +@Service("sysFunctionService") +public class SysFunctionServiceImpl extends BaseServiceImpl implements SysFunctionService { + + public SysFunctionServiceImpl() { + super(); + } + + @Override + public synchronized Object save(SysFunction o) { + Integer i=getBaseDao().getInteger("select max(sf.id) from SysFunction sf"); + o.setSysFunction(getById(o.getPid())); + o.setId(i+1); + getBaseDao().save(o); + return o; + } + + @Override + public void saveOrUpdate(SysFunction o) { + o.setSysFunction(getById(o.getPid())); + getBaseDao().saveOrUpdate(o); + return ; + } + + + /** + * @see com.datalook.service.sys.SysFunctionService#test(java.lang.String) + * + * 功能描述: + * 时间:2014年10月15日 + * @author: lirenbo + * @param test + * @throws ToWebException + */ + @Override + @org.springframework.transaction.annotation.Transactional + public void test(String test) throws ToWebException{ + getBaseDao().save(new SysFunction(99868, null, test, null, null, null, null, null, null, null, null)); + throw ToWebExceptionFactory.createCodeRollbackInstance("1"); + } +} diff --git a/blank/src/main/java/com/datalook/service/sys/implement/SysRoleServiceImpl.java b/blank/src/main/java/com/datalook/service/sys/implement/SysRoleServiceImpl.java new file mode 100644 index 0000000..ab4a2b8 --- /dev/null +++ b/blank/src/main/java/com/datalook/service/sys/implement/SysRoleServiceImpl.java @@ -0,0 +1,23 @@ +package com.datalook.service.sys.implement; + +import org.springframework.stereotype.Service; + +import com.datalook.model.sys.SysRole; +import com.datalook.service.base.BaseServiceImpl; +import com.datalook.service.sys.SysRoleService; +import com.datalook.util.base.StringUtil; + +@Service("sysRoleService") +public class SysRoleServiceImpl extends BaseServiceImpl implements SysRoleService{ + + /* (non-Javadoc) + * @see com.datalook.service.sys.ISysRoleService#grant(java.lang.String, java.lang.String[], java.lang.String[]) + */ + @Override + public synchronized void grant(String sysRoleId,String grantSysFunctionIds[],String inSomeSysFunctionIds[]){ + getBaseDao().executeSql(StringUtil.formateString("delete SYS_ROLE_FUNCTION_RELATION where ROLEID = {0} and SYSFUNCTIONID in {1} ",sysRoleId,StringUtil.toVarcharsSqlInString(inSomeSysFunctionIds))); + for (String eachgrantSysFunctionId : grantSysFunctionIds) { + getBaseDao().executeSql(StringUtil.formateString("insert into SYS_ROLE_FUNCTION_RELATION values({0},{1})", sysRoleId,eachgrantSysFunctionId)); + } + } +} diff --git a/blank/src/main/java/com/datalook/service/sys/implement/SysUserServiceImpl.java b/blank/src/main/java/com/datalook/service/sys/implement/SysUserServiceImpl.java new file mode 100644 index 0000000..37ebb7f --- /dev/null +++ b/blank/src/main/java/com/datalook/service/sys/implement/SysUserServiceImpl.java @@ -0,0 +1,44 @@ +package com.datalook.service.sys.implement; + +import java.util.HashSet; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.datalook.dao.base.IBaseDao; +import com.datalook.model.sys.SysRole; +import com.datalook.model.sys.SysUser; +import com.datalook.service.base.BaseServiceImpl; +import com.datalook.service.sys.SysUserService; + +/** + * 用户业务逻辑 + * + * + */ +@Service("sysUserService") +public class SysUserServiceImpl extends BaseServiceImpl implements SysUserService { + + @Autowired + private IBaseDao roleDao; + + /* (non-Javadoc) + * @see com.datalook.service.sys.ISysUserService#grantSysRole(java.lang.String, java.lang.String) + */ + @Override + public void grantSysRole(Integer id, String roleIds) { + SysUser user = getById(id); + if (user != null) { + user.setSysRoles(new HashSet()); + for (String roleId : roleIds.split(",")) { + if (!StringUtils.isBlank(roleId)) { + SysRole role = roleDao.getById(SysRole.class, Integer.valueOf(roleId)); + if (role != null) { + user.getSysRoles().add(role); + } + } + } + } + } +} diff --git a/blank/src/main/java/com/datalook/service/sys/interfaces/ISysDictService.java b/blank/src/main/java/com/datalook/service/sys/interfaces/ISysDictService.java deleted file mode 100644 index f5ec734..0000000 --- a/blank/src/main/java/com/datalook/service/sys/interfaces/ISysDictService.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.datalook.service.sys.interfaces; - -import java.util.List; - -import com.datalook.dao.base.HqlFilter; -import com.datalook.model.sys.SysDict; -import com.datalook.service.base.IBaseService; - -public interface ISysDictService extends IBaseService{ - - public abstract SysDict getValue(String location, String code); - - public abstract List findValus(String location); - - public abstract List findValus(HqlFilter hqlFilter); - -} \ No newline at end of file diff --git a/blank/src/main/java/com/datalook/service/sys/interfaces/ISysRoleService.java b/blank/src/main/java/com/datalook/service/sys/interfaces/ISysRoleService.java deleted file mode 100644 index fd95183..0000000 --- a/blank/src/main/java/com/datalook/service/sys/interfaces/ISysRoleService.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.datalook.service.sys.interfaces; - -import com.datalook.model.sys.SysRole; -import com.datalook.service.base.IBaseService; - -public interface ISysRoleService extends IBaseService{ - - public abstract void grant(String sysRoleId, String grantSysFunctionIds[], - String inSomeSysFunctionIds[]); - -} \ No newline at end of file diff --git a/blank/src/main/java/com/datalook/service/sys/interfaces/ISysUserService.java b/blank/src/main/java/com/datalook/service/sys/interfaces/ISysUserService.java deleted file mode 100644 index 4a5884a..0000000 --- a/blank/src/main/java/com/datalook/service/sys/interfaces/ISysUserService.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.datalook.service.sys.interfaces; - -import java.util.List; - -import com.datalook.model.sys.SysUser; -import com.datalook.service.base.IBaseService; - -/** - * 用户业务 - * - * - */ -public interface ISysUserService extends IBaseService { - - /** - * 修改用户角色 - * @param id - * 用户ID - * @param roleIds - * 角色IDS - */ - public void grantSysRole(Integer id, String roleIds); - -} diff --git a/blank/src/main/java/com/datalook/webservice/server/HelloWorldImpl.java b/blank/src/main/java/com/datalook/webservice/server/HelloWorldImpl.java index 624b293..223741c 100644 --- a/blank/src/main/java/com/datalook/webservice/server/HelloWorldImpl.java +++ b/blank/src/main/java/com/datalook/webservice/server/HelloWorldImpl.java @@ -5,6 +5,7 @@ import com.datalook.webservice.HelloWorld; @WebService(endpointInterface = "com.datalook.webservice.HelloWorld") +@org.springframework.stereotype.Component public class HelloWorldImpl implements HelloWorld { public String sayHi(String text,Integer i) { System.out.println("sayHi called"+text+i); diff --git a/blank/src/main/resources/applicationContext.xml b/blank/src/main/resources/applicationContext.xml index 4724c94..43a9578 100644 --- a/blank/src/main/resources/applicationContext.xml +++ b/blank/src/main/resources/applicationContext.xml @@ -80,7 +80,7 @@ - + @@ -91,7 +91,7 @@ - + diff --git a/blank/src/main/resources/struts.xml b/blank/src/main/resources/struts.xml index 4e82344..f5ca211 100644 --- a/blank/src/main/resources/struts.xml +++ b/blank/src/main/resources/struts.xml @@ -50,8 +50,7 @@ - - + diff --git a/blank/src/main/webapp/WEB-INF/web.xml b/blank/src/main/webapp/WEB-INF/web.xml index f1bd492..7d4c191 100644 --- a/blank/src/main/webapp/WEB-INF/web.xml +++ b/blank/src/main/webapp/WEB-INF/web.xml @@ -40,7 +40,7 @@ /* - + - + openSessionInViewFilter - org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter + com.datalook.filter.base.web.EntityManagerFilter openSessionInViewFilter *.action - + struts2 - com.datalook.filter.StrutsFilter + com.datalook.filter.base.web.StrutsFilter exclude - ueditor/jsp/controller.jsp,.json,.html + ueditor/jsp/controller.jsp struts2 - /* + *.action + + + struts2 + *.jsp - sessionFilter - com.datalook.filter.SessionFilter + userSessionFilter + com.datalook.filter.base.web.UserSessionFilter include @@ -95,7 +99,7 @@ - sessionFilter + userSessionFilter *.jsp diff --git a/blank/src/test/java/com/datalook/dao/base/BaseDaot.java b/blank/src/test/java/com/datalook/dao/base/BaseDaot.java index b136e95..aabd3db 100644 --- a/blank/src/test/java/com/datalook/dao/base/BaseDaot.java +++ b/blank/src/test/java/com/datalook/dao/base/BaseDaot.java @@ -16,7 +16,7 @@ import com.datalook.model.sys.SysFunction; import com.datalook.model.sys.SysRole; import com.datalook.model.sys.SysUser; -import com.datalook.service.base.IBaseService; +import com.datalook.service.base.BaseService; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={"classpath:/applicationContext.xml"}) public class BaseDaot extends AbstractTransactionalJUnit4SpringContextTests{ @@ -27,7 +27,7 @@ public class BaseDaot extends AbstractTransactionalJUnit4SpringContextTests{ @Autowired IBaseDao userDao; @Resource(name="sysUserService") - IBaseService userService; + BaseService userService; SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd"); diff --git a/blank/src/test/java/com/datalook/dao/base/Daot.java b/blank/src/test/java/com/datalook/dao/base/Daot.java index d5744f6..e688b1f 100644 --- a/blank/src/test/java/com/datalook/dao/base/Daot.java +++ b/blank/src/test/java/com/datalook/dao/base/Daot.java @@ -13,7 +13,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.datalook.model.sys.SysUser; -import com.datalook.service.base.IBaseService; +import com.datalook.service.base.BaseService; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={"classpath:/applicationContext.xml"}) @@ -26,7 +26,7 @@ public class Daot extends AbstractTransactionalJUnit4SpringContextTests { IBaseDao locationDao; @Resource(name="sysUserService") - IBaseService sysUserService; + BaseService sysUserService; @Autowired