From a335dae46e684c9d3a729d4d21629689e30402ba Mon Sep 17 00:00:00 2001
From: yujian <yujian>
Date: 星期三, 27 三月 2019 09:22:33 +0800
Subject: [PATCH] 系统参数Dao改造(config/clientParams/helpList等)

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/config/SystemClientParamsServiceImpl.java |  346 ++-------------------------------------------------------
 1 files changed, 14 insertions(+), 332 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/config/SystemClientParamsServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/config/SystemClientParamsServiceImpl.java
index 29ab3ea..a6b44ad 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/config/SystemClientParamsServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/config/SystemClientParamsServiceImpl.java
@@ -1,362 +1,50 @@
 package com.yeshi.fanli.service.impl.config;
 
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 
 import javax.annotation.Resource;
 
-import org.hibernate.HibernateException;
-import org.hibernate.Query;
-import org.hibernate.Session;
 import org.springframework.cache.annotation.Cacheable;
-import org.springframework.orm.hibernate4.HibernateCallback;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import com.yeshi.fanli.dao.config.SystemClientParamsDao;
-import com.yeshi.fanli.dao.config.SystemHelpListDao;
-import com.yeshi.fanli.dao.config.SystemSecondProblemDao;
 import com.yeshi.fanli.dao.mybatis.SystemClientParamsMapper;
-import com.yeshi.fanli.entity.admin.SystemClientParamsAdmin;
 import com.yeshi.fanli.entity.system.BusinessSystem;
-import com.yeshi.fanli.entity.system.CustomerContent;
-import com.yeshi.fanli.entity.system.CustomerName;
 import com.yeshi.fanli.entity.system.SystemClientParams;
-import com.yeshi.fanli.service.inter.config.BusinessSystemService;
 import com.yeshi.fanli.service.inter.config.SystemClientParamsService;
-import com.yeshi.fanli.util.Constant;
-import com.yeshi.fanli.util.StringUtil;
 
 @Service
 public class SystemClientParamsServiceImpl implements SystemClientParamsService {
 
 	@Resource
-	private SystemClientParamsDao systemClientParamsDao;
-	
-	@Resource
 	private SystemClientParamsMapper systemClientParamsMapper;
 	
-	@Resource
-	private SystemHelpListDao systemHelpListDao;
 	
-	@Resource
-	private BusinessSystemService businessSystemService;
-	
-	@Resource
-	private SystemSecondProblemDao systemSecondProblemDao;
-	@Cacheable(value = "clientParamCache", key = "#id")
-	public List<SystemClientParams> getSystemClientParamsBySystemId(long id) {
-
-		return systemClientParamsDao.list("from SystemClientParams scp where scp.system.id=?",
-				new Serializable[] { id });
-	}
-	
-	@Cacheable(value = "clientParamCache", key = "#id+'-'+#version")
-	public List<SystemClientParams> getSystemClientParamsBySystemId(long id,int version) {
-
-		return systemClientParamsDao.list("from SystemClientParams scp where scp.system.id=?",
-				new Serializable[] { id });
+	@Cacheable(value = "clientParamCache", key = "#systemId+'-'+#version")
+	public List<SystemClientParams> getSystemClientParamsBySystemId(long systemId, int version) {
+		return systemClientParamsMapper.listBySystemId(systemId);
 	}
 
-	public List<SystemClientParamsAdmin> getAdminList(BusinessSystem system, String key) {
-		List<SystemClientParams> list;
-		List<SystemClientParamsAdmin> adminList = new ArrayList<SystemClientParamsAdmin>();
-		if (system == null) {
-			list = systemClientParamsDao.list("from SystemClientParams scp where scp.name like ? ",
-					new Serializable[] { "%" + key + "%" });
-		} else {
-			list = systemClientParamsDao.list(
-					"from SystemClientParams scp where scp.system.id = ? and scp.name like ? ",
-					new Serializable[] { system.getId(), "%" + key + "%" });
-			StringBuffer hqlb = new StringBuffer("from SystemClientParams scp ");
-			int ii = 0;
-			if (list.size() > 0) {
-				for (SystemClientParams scp : list) {
-					if (ii == 0) {
-						hqlb.append(" where ( scp.name = '" + scp.getName() + "'  and scp.key = '" + scp.getKey()
-								+ "' and scp.value = '" + scp.getValue() + "' ) ");
-					} else {
-						hqlb.append(" or ( scp.name = '" + scp.getName() + "'  and scp.key = '" + scp.getKey()
-								+ "' and scp.value = '" + scp.getValue() + "' ) ");
-					}
-					ii++;
-				}
-				list = systemClientParamsDao.list(hqlb.toString());
-			}
-		}
-		
-		SystemClientParamsAdmin scpa = null;
-		for (SystemClientParams scp : list) {
-			scpa = new SystemClientParamsAdmin(scp);
-			if (adminList.contains(scpa)) {
-				int indexof = adminList.indexOf(scpa);
-				SystemClientParamsAdmin systemClientParamsAdmin = adminList.get(indexof);
-				systemClientParamsAdmin.getSystemList().add(scp.getSystem());
-			} else {
-				scpa.getSystemList().add(scp.getSystem());
-				adminList.add(scpa);
-			}
-		}
-
-		return adminList;
-	}
-
-	@Transactional
-	public void addSystemClientParamsList(SystemClientParams scp, List<BusinessSystem> list) throws Exception {
-		SystemClientParams nscp = null;
-		for (BusinessSystem system : list) {
-			nscp = new SystemClientParams();
-			nscp.setKey(scp.getKey());
-			nscp.setName(scp.getName());
-			nscp.setValue(scp.getValue());
-			nscp.setSystem(system);
-			nscp.setUpdatetime(java.lang.System.currentTimeMillis());
-			systemClientParamsDao.create(nscp);
-		}
-	}
-
-	@Transactional
-	public void deleteSystemClientParams(final SystemClientParams scp, final BusinessSystem system) {
-		systemClientParamsDao.excute(new HibernateCallback() {
-			public Object doInHibernate(Session session) throws HibernateException {
-				Query query = session.createQuery(
-						"delete from SystemClientParams scp where scp.name = ? and scp.key =? and scp.value = ? and scp.system.id = ?");
-				query.setParameter(0, scp.getName());
-				query.setParameter(1, scp.getKey());
-				query.setParameter(2, scp.getValue());
-				query.setParameter(3, system.getId());
-				return query.executeUpdate();
-			}
-		});
-	}
-
-	public void addSystemClientParams(SystemClientParams scp, BusinessSystem system) {
-		scp.setSystem(system);
-		systemClientParamsDao.create(scp);
-	}
-
-	@Transactional
-	public void deleteSystemClientParams(final SystemClientParams scp) {
-		systemClientParamsDao.excute(new HibernateCallback() {
-
-			public Object doInHibernate(Session session) throws HibernateException {
-				Query query = session.createQuery(
-						"delete from SystemClientParams scp where scp.name=? and scp.key = ?  and scp.value = ? ");
-				query.setParameter(0, scp.getName());
-				query.setParameter(1, scp.getKey());
-				query.setParameter(2, scp.getValue());
-				return query.executeUpdate();
-			}
-		});
-	}
-
-	public SystemClientParamsAdmin getSystemClientParamsAdmin(final SystemClientParams scp) {
-
-		return (SystemClientParamsAdmin) systemClientParamsDao.excute(new HibernateCallback<SystemClientParamsAdmin>() {
-			public SystemClientParamsAdmin doInHibernate(Session session) throws HibernateException {
-				Query query = session
-						.createQuery("from SystemClientParams s where s.key = ?");
-				query.setParameter(0, scp.getKey());
-				List<SystemClientParams> list = query.list();
-				SystemClientParamsAdmin scpa = new SystemClientParamsAdmin(scp);
-				for (SystemClientParams fscp : list) {
-					BusinessSystem system = fscp.getSystem();
-					if (scpa.getSystemList().contains(system)) {
-						continue;
-					}
-					scpa.getSystemList().add(fscp.getSystem());
-					scpa.setSystemClientParams(fscp);
-				}
-				return scpa;
-			}
-		});
-
-	}
-
-	@Transactional
-	public void update(final SystemClientParams oscp, final SystemClientParams nscp) {
-		systemClientParamsDao.excute(new HibernateCallback() {
-			public Object doInHibernate(Session session) throws HibernateException {
-				Query query = session.createQuery(
-						"update SystemClientParams s set s.name=? , s.key=? , s.value=? where s.name=? and s.key = ? ");
-				query.setParameter(0, nscp.getName());
-				query.setParameter(1, nscp.getKey());
-				query.setParameter(2, nscp.getValue());
-				query.setParameter(3, oscp.getName());
-				query.setParameter(4, oscp.getKey());
-				return query.executeUpdate();
-			}
-		});
-	}
 
 	@Override
 	public SystemClientParams getSystemClientParamsBySystemAndKey(BusinessSystem system, String key) {
-		List<SystemClientParams> list = systemClientParamsDao.list(
-				"from SystemClientParams scp where scp.system.id=? and scp.key=?",
-				new Serializable[] { system.getId(), key });
-		if (list == null || list.size() == 0)
+		if (system == null) {
 			return null;
-		else
-			return list.get(0);
-	}
-
-	@Override
-	public Integer getCount(int type) {
-		return systemClientParamsMapper.getCount(type);
-	}
-	
-	@Override
-	public List<CustomerName> customerNameList(int page, String key, int type) {
-		int start = page * Constant.PAGE_SIZE;
-		return systemHelpListDao.list(
-
-			"from CustomerName cn where cn.type = ? and cn.name like ? order by cn.createTime asc", start,
-			Constant.PAGE_SIZE, new Serializable[] {type, "%"+key+"%"});
-	}
-
-	@Override
-	public void deleteHelp(long id) {
-		systemHelpListDao.excute(new HibernateCallback() {
-			public Object doInHibernate(Session session) 
-								throws HibernateException {
-				Query query = session.createQuery("delete from CustomerName cn where cn.id = ?");
-				query.setParameter(0, id);
-				query.executeUpdate();
-				return null;
-			}
-		});
-	}
-	
-
-	@Override
-	public CustomerName getHelpCenter(int type) {
-		return systemClientParamsMapper.getHelpCenter(type);
-	}
-
-	@Override
-	public Integer getProblemCount(long id) {
-		return systemClientParamsMapper.getProblemCount(id);
-	}
-
-	@Override
-	public List<CustomerContent> getSecondProblemList(int index, String key, long id) {
-		int start = index * Constant.PAGE_SIZE;
-		return systemSecondProblemDao.list(
-				"from CustomerContent cc where cc.cnId = ? and cc.title like ? order by cc.createTime asc", start,
-				Constant.PAGE_SIZE, new Serializable[] {id, "%"+key+"%"});
-	}
-	
-	
-	@Override
-	public void deleteSecondProblem(long id) {
-		systemSecondProblemDao.excute(new HibernateCallback() {
-			public Object doInHibernate(Session session) 
-								throws HibernateException {
-				Query query = session.createQuery("delete from CustomerContent cc where cc.id = ?");
-				query.setParameter(0, id);
-				query.executeUpdate();
-				return null;
-			}
-		});
-	}
-
-	@Override
-	public CustomerContent getCustomerContent(long id) {
-		return systemSecondProblemDao.find(CustomerContent.class, id);
-	}
-
-	@Override
-	public void updateAnswerDetail(CustomerContent customerContent) {
-		CustomerContent find = systemSecondProblemDao.find(CustomerContent.class, customerContent.getId());
-		if(find == null ){
-			return;
 		}
-		find.setTitle(customerContent.getTitle());
-		find.setContent(customerContent.getContent());
-		systemSecondProblemDao.update(find);
+		return systemClientParamsMapper.getSystemClientParamsBySystemAndKey(system.getId(), key);
 	}
 
-	@Override
-	public void addFirstMenu(CustomerName customerName, int type) {
-		customerName.setName(customerName.getName());
-		customerName.setCreateTime(new Date());
-		customerName.setType(type);
-		systemHelpListDao.save(customerName);
-	}
-
-	@Override
-	public void addSecondMenu(CustomerContent customerContent, long cnId) {
-		customerContent.setCnId(cnId);
-		customerContent.setTitle(customerContent.getTitle());
-		customerContent.setContent(customerContent.getContent());
-		customerContent.setCreateTime(new Date());
-		systemSecondProblemDao.save(customerContent);
-	}
-
-	@Override
-	public List<CustomerContent> contactCustomerService(String title) {
-		return systemClientParamsMapper.contactCustomerService(title);
-	}
-
+	
 	
 	@Override
 	public List<SystemClientParams> listQuery(int start, int count, String key, Long systemId) {
-		
-		List<SystemClientParams> list = null;
-		
-		if (systemId == null) {
-			
-			if (StringUtil.isNullOrEmpty(key)) {
-				list = systemClientParamsDao.list("from SystemClientParams scp", start, count, null);
-			} else {
-				list = systemClientParamsDao.list("from SystemClientParams scp where (scp.name like ? or scp.key like ?) ",
-						start, count, new Serializable[] { "%" + key + "%" ,"%" + key + "%"});
-			}
-			
-		} else {
-			
-			if (StringUtil.isNullOrEmpty(key)) {
-				list = systemClientParamsDao.list("from SystemClientParams scp where scp.system.id = ? ",
-						start, count, new Serializable[] {systemId});
-				
-			} else {
-				list = systemClientParamsDao.list(
-						"from SystemClientParams scp where scp.system.id = ? and (scp.name like ? or scp.key like ?)",
-						start, count, new Serializable[] {systemId, "%" + key + "%" ,"%" + key + "%"});
-			}
-		}
-		
-		return list;
+		return systemClientParamsMapper.listQuery(start, count, systemId, key);
 	}
 
 	
 	@Override
 	public long countQuery(String key, Long systemId) {
-		
-		if (systemId == null) {
-			
-			if (StringUtil.isNullOrEmpty(key)) {
-				return systemClientParamsDao.getCount(" select count(id) from SystemClientParams scp");
-			} else {
-				return systemClientParamsDao.getCount(" select count(id) from SystemClientParams scp where (scp.name like ? or scp.key like ?) ",
-						new Serializable[] { "%" + key + "%" ,"%" + key + "%"});
-			}
-			
-		} else {
-			
-			if (StringUtil.isNullOrEmpty(key)) {
-				return systemClientParamsDao.getCount(" select count(id) from SystemClientParams scp where scp.system.id = ? ",
-						 new Serializable[] {systemId});
-				
-			} else {
-				return systemClientParamsDao.getCount(
-						" select count(id) from SystemClientParams scp where scp.system.id = ? and (scp.name like ? or scp.key like ?)",
-						new Serializable[] {systemId, "%" + key + "%" ,"%" + key + "%"});
-			}
-		}
-		
+		return systemClientParamsMapper.countQuery(systemId, key);
 	}
 	
 	
@@ -377,32 +65,26 @@
 			nscp.setValue(scp.getValue());
 			nscp.setSystem(system);
 			nscp.setUpdatetime(java.lang.System.currentTimeMillis());
-			systemClientParamsDao.create(nscp);
+			systemClientParamsMapper.insertSelective(nscp);
 		}
 	}
 	
 	@Override
 	public void update(SystemClientParams systemClientParams) {
-		systemClientParamsDao.update(systemClientParams);
+		systemClientParamsMapper.updateByPrimaryKeySelective(systemClientParams);
 	}
 	
 	@Override
-	public List<SystemClientParams> getById(long id) {
-		return systemClientParamsDao.list("from SystemClientParams scp where scp.id=?",
-				new Serializable[] { id });
+	public  SystemClientParams selectByPrimaryKey(long id) {
+		return systemClientParamsMapper.selectByPrimaryKey(id);
 	}
 	
 	@Transactional
 	@Override
 	public void deleteBatchByPrimaryKey(List<Long> ids) {
 		for (Long id: ids) {
-			systemClientParamsDao.excute(new HibernateCallback() {
-				public Object doInHibernate(Session session) throws HibernateException {
-					Query query = session.createQuery("delete from SystemClientParams scp where scp.id= ?");
-					query.setParameter(0, id);
-					return query.executeUpdate();
-				}
-			});
+			systemClientParamsMapper.deleteByPrimaryKey(id);
 		}
 	}
+
 }

--
Gitblit v1.8.0