| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- package cn.com.lzt.post.service.impl;
- import cn.com.lzt.post.entity.PostEntity;
- import cn.com.lzt.post.service.PostServiceI;
- 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.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.io.Serializable;
- import java.util.*;
- @Service("postService")
- @Transactional
- public class PostServiceImpl extends CommonServiceImpl implements PostServiceI {
-
- public void delete(PostEntity entity) throws Exception{
- super.delete(entity);
- //执行删除操作增强业务
- this.doDelBus(entity);
- }
-
- /**
- * 逻辑删除
- */
- public void logicDel(PostEntity entity) throws Exception{
- super.updateEntitie(entity);
- //执行更新操作增强业务
- this.doUpdateBus(entity);
- }
-
- /**
- * 批量更新操作
- *
- */
- public void batchUpdate(List<PostEntity> entityList) throws Exception{
- for(PostEntity entity : entityList){
- super.updateEntitie(entity);
- }
- }
-
- public Serializable save(PostEntity entity) throws Exception{
- Serializable t = super.save(entity);
- //执行新增操作增强业务
- this.doAddBus(entity);
- return t;
- }
-
- public void saveOrUpdate(PostEntity entity) throws Exception{
- super.saveOrUpdate(entity);
- //执行更新操作增强业务
- this.doUpdateBus(entity);
- }
-
- /**
- * 新增操作增强业务
- * @param t
- * @return
- */
- private void doAddBus(PostEntity t) throws Exception{
- //-----------------sql增强 start----------------------------
- //-----------------sql增强 end------------------------------
-
- //-----------------java增强 start---------------------------
- //-----------------java增强 end-----------------------------
- }
- /**
- * 更新操作增强业务
- * @param t
- * @return
- */
- private void doUpdateBus(PostEntity t) throws Exception{
- //-----------------sql增强 start----------------------------
- //-----------------sql增强 end------------------------------
-
- //-----------------java增强 start---------------------------
- //-----------------java增强 end-----------------------------
- }
- /**
- * 删除操作增强业务
- * @param id
- * @return
- */
- private void doDelBus(PostEntity t) throws Exception{
- //-----------------sql增强 start----------------------------
- //-----------------sql增强 end------------------------------
-
- //-----------------java增强 start---------------------------
- //-----------------java增强 end-----------------------------
- }
-
- private Map<String,Object> populationMap(PostEntity 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("post_code", t.getPostCode());
- map.put("post_name", t.getPostName());
- map.put("parent_postid", t.getParentPostid());
- map.put("post_desc", t.getPostDesc());
- map.put("status", t.getStatus());
- map.put("delete_flag", t.getDeleteFlag());
- return map;
- }
-
- /**
- * 替换sql中的变量
- * @param sql
- * @param t
- * @return
- */
- public String replaceVal(String sql,PostEntity 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("#{post_code}",String.valueOf(t.getPostCode()));
- sql = sql.replace("#{post_name}",String.valueOf(t.getPostName()));
- sql = sql.replace("#{parent_postid}",String.valueOf(t.getParentPostid()));
- sql = sql.replace("#{post_desc}",String.valueOf(t.getPostDesc()));
- sql = sql.replace("#{status}",String.valueOf(t.getStatus()));
- sql = sql.replace("#{delete_flag}",String.valueOf(t.getDeleteFlag()));
- 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_post",data);
- }
- } catch (Exception e) {
- e.printStackTrace();
- throw new Exception("执行JAVA增强出现异常!");
- }
- }
- }
- @Override
- public Boolean findPostByPostName(PostEntity post) {
- List<PostEntity> postobj = new ArrayList<PostEntity>();
- StringBuffer hql = new StringBuffer(" from PostEntity where postName= ? and parentPostid=? and deleteFlag=0");
- if(StringUtil.isEmpty(post.getParentPostid())){
- post.setParentPostid(null);
- if(StringUtil.isNotEmpty(post.getId())){
- hql = new StringBuffer(
- " from PostEntity where id!=? and postName= ? and parentPostid is null and deleteFlag=0");
- postobj = findHql(hql.toString(),post.getId(),post.getPostName());
- }else{
- hql = new StringBuffer(" from PostEntity where postName= ? and parentPostid is null and deleteFlag=0");
- postobj = findHql(hql.toString(),post.getPostName());
- }
-
- }else{
- if(StringUtil.isNotEmpty(post.getId())){
- hql = new StringBuffer(" from PostEntity where id!=? and postName= ? and parentPostid=? and deleteFlag=0");
- postobj = findHql(hql.toString(),post.getId(),post.getPostName(),post.getParentPostid());
- }else{
- postobj = findHql(hql.toString(),post.getPostName(),post.getParentPostid());
- }
-
- }
- Boolean flag = true;
- if(postobj.size() > 0){
- flag = false;
- }
- return flag;
- }
- }
|