| | |
| | | package com.yeshi.fanli.service.impl.config;
|
| | |
|
| | | import java.io.Serializable;
|
| | | import java.util.HashSet;
|
| | | import java.util.List;
|
| | | import java.util.Set;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.cache.annotation.Cacheable;
|
| | | import org.springframework.stereotype.Service;
|
| | |
|
| | | import com.yeshi.fanli.dao.config.SystemConfigDao;
|
| | | import com.yeshi.fanli.entity.system.System;
|
| | | import com.yeshi.fanli.entity.system.SystemConfig;
|
| | | import com.yeshi.fanli.exception.NotExistObjectException;
|
| | | import com.yeshi.fanli.service.inter.config.SystemConfigService;
|
| | | import com.yeshi.fanli.service.inter.config.SystemService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.Utils;
|
| | |
|
| | | @Service
|
| | | public class SystemConfigServiceImpl implements SystemConfigService{
|
| | |
|
| | | @Resource
|
| | | private SystemConfigDao systemConfigDao;
|
| | | |
| | | @Resource
|
| | | private SystemService systemService;
|
| | | |
| | | public int getCount(System system,String key) {
|
| | | Long lcount;
|
| | | if(system!=null){
|
| | | lcount = systemConfigDao.getCount("select count(sc.id) from SystemConfig sc left join sc.systems s where s.id=? and sc.name like ?",new Serializable[]{system.getId(),"%"+key+"%"});
|
| | | }else{
|
| | | lcount = systemConfigDao.getCount("select count(sc.id) from SystemConfig sc where sc.name like ?",new Serializable[]{"%"+key+"%"});
|
| | | }
|
| | | return lcount.intValue();
|
| | | }
|
| | |
|
| | | public List<SystemConfig> getSystemConfigList(int index,System system, String key) {
|
| | | |
| | | int start =index * Constant.PAGE_SIZE;
|
| | | List<SystemConfig> list;
|
| | | if(system != null){
|
| | | list = systemConfigDao.list("from SystemConfig sc left outer join fetch sc.systems s where s.id = ? and sc.name like ?",start,Constant.PAGE_SIZE,new Serializable[]{system.getId(),"%"+key+"%"});
|
| | | StringBuffer hql=new StringBuffer("from SystemConfig sc ");
|
| | | Serializable[] params = new Serializable[list.size()];
|
| | | int ii=0;
|
| | | for (SystemConfig sc : list) {
|
| | | if(ii==0){
|
| | | hql.append(" where sc. id = ? "); |
| | | }else{
|
| | | hql.append(" or sc. id = ? ");
|
| | | }
|
| | | params[ii]=sc.getId();
|
| | | ii++;
|
| | | }
|
| | | list=systemConfigDao.list(hql.toString(),params);
|
| | | }else{
|
| | | list = systemConfigDao.list("from SystemConfig sc where sc.name like ?",start,Constant.PAGE_SIZE,new Serializable[]{"%"+key+"%"});
|
| | | }
|
| | | |
| | | return list;
|
| | | }
|
| | |
|
| | | public void addSystemConfig(SystemConfig sc) {
|
| | | Set<System> systems = sc.getSystems();
|
| | | Set<System> newSystems=new HashSet<System>();
|
| | | for (System system : systems) {
|
| | | String platform = Utils.getMap().get(String.valueOf(system.getPlatform()));
|
| | | String packages = system.getPackageName();
|
| | | System find = systemService.getSystem(platform, packages);
|
| | | if(find != null){
|
| | | newSystems.add(find);
|
| | | }
|
| | | }
|
| | | sc.setSystems(newSystems);
|
| | | sc.setUpdatetime(java.lang.System.currentTimeMillis());
|
| | | systemConfigDao.save(sc);
|
| | | }
|
| | |
|
| | | public void deleteSystem(long id, System system) throws NotExistObjectException {
|
| | | SystemConfig find = systemConfigDao.find(SystemConfig.class, id);
|
| | | if(find==null){
|
| | | throw new NotExistObjectException("不存在该子系统");
|
| | | }
|
| | | find.getSystems().remove(system);
|
| | | find.setUpdatetime(java.lang.System.currentTimeMillis());
|
| | | systemConfigDao.update(find);
|
| | | }
|
| | |
|
| | | public void addSystem(long id, System system) throws NotExistObjectException {
|
| | | SystemConfig find = systemConfigDao.find(SystemConfig.class, id);
|
| | | if(find==null){
|
| | | throw new NotExistObjectException("不存在该子系统");
|
| | | }
|
| | | find.getSystems().add(system);
|
| | | find.setUpdatetime(java.lang.System.currentTimeMillis());
|
| | | systemConfigDao.update(find);
|
| | | }
|
| | |
|
| | | public SystemConfig getSystemConfig(long id) {
|
| | | |
| | | return systemConfigDao.find(SystemConfig.class, id);
|
| | | }
|
| | |
|
| | | public void updateSystemConfig(SystemConfig sc) throws NotExistObjectException {
|
| | | SystemConfig find = systemConfigDao.find(SystemConfig.class, sc.getId());
|
| | | if(find==null){
|
| | | throw new NotExistObjectException("不存在该对象");
|
| | | }
|
| | | sc.setUpdatetime(java.lang.System.currentTimeMillis());
|
| | | Set<System> newSystems=new HashSet<System>();
|
| | | Set<System> systems = sc.getSystems();
|
| | | for (System system : systems) {
|
| | | String platform = Utils.getMap().get(String.valueOf(system.getPlatform()));
|
| | | String packages = system.getPackageName();
|
| | | System sfind = systemService.getSystem(platform, packages);
|
| | | if(sfind != null){
|
| | | newSystems.add(sfind);
|
| | | }
|
| | | }
|
| | | sc.setSystems(newSystems);
|
| | | systemConfigDao.update(sc);
|
| | | }
|
| | |
|
| | | public void deleteSystemConfig(long id) {
|
| | | systemConfigDao.delete(new SystemConfig(id));
|
| | | }
|
| | | @Cacheable(value={"childSystemCache"}, key="#p0")
|
| | | public String get(String sigkey) throws NotExistObjectException {
|
| | | List<SystemConfig> list = systemConfigDao.list("from SystemConfig sc where sc.key = ?", new Serializable[]{sigkey});
|
| | | if(list.size() ==0 ){
|
| | | throw new NotExistObjectException("不存在该参数"); |
| | | }
|
| | | return list.get(0).getValue();
|
| | | }
|
| | | @Cacheable(value={"childSystemCache"}, key="#p0+#system.id")
|
| | | public String get(String key, System system) {
|
| | | if(system==null || system.getId()==0){
|
| | | return "";
|
| | | }
|
| | | List<SystemConfig> list = systemConfigDao.list("select sc from SystemConfig sc join sc.systems syss where sc.key = ? and syss.id=?", new Serializable[]{key,system.getId()});
|
| | | if(list.size() != 0){
|
| | | return list.get(0).getValue();
|
| | | }
|
| | | return "";
|
| | | }
|
| | | |
| | |
|
| | | }
|
| | | package com.yeshi.fanli.service.impl.config; |
| | | |
| | | import com.ks.lib.common.exception.ParamsException; |
| | | import com.yeshi.fanli.dao.mybatis.SystemConfigMapper; |
| | | import com.yeshi.fanli.entity.SystemEnum; |
| | | import com.yeshi.fanli.entity.config.SystemConfigKeyEnum; |
| | | import com.yeshi.fanli.entity.system.SystemConfig; |
| | | import com.yeshi.fanli.service.inter.config.SystemConfigService; |
| | | import org.springframework.cache.annotation.Cacheable; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | @Service |
| | | public class SystemConfigServiceImpl implements SystemConfigService { |
| | | |
| | | @Resource |
| | | private SystemConfigMapper systemConfigMapper; |
| | | |
| | | |
| | | @Override |
| | | public void save(SystemConfig systemConfig) throws ParamsException { |
| | | |
| | | if (systemConfig == null || systemConfig.getSystem() == null || systemConfig.getKey() == null) { |
| | | throw new ParamsException(1, "参数不完整"); |
| | | } |
| | | |
| | | |
| | | SystemConfig old = getConfig(SystemConfigKeyEnum.valueOf(systemConfig.getKey()), systemConfig.getSystem()); |
| | | if (old != null) { |
| | | SystemConfig update = new SystemConfig(); |
| | | update.setId(old.getId()); |
| | | update.setValue(systemConfig.getValue()); |
| | | update.setUpdatetime(System.currentTimeMillis()); |
| | | systemConfigMapper.updateByPrimaryKeySelective(update); |
| | | } else { |
| | | if (systemConfig.getUpdatetime() == null) { |
| | | systemConfig.setUpdatetime(System.currentTimeMillis()); |
| | | } |
| | | systemConfigMapper.insertSelective(systemConfig); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public SystemConfig getConfig(SystemConfigKeyEnum key, SystemEnum system) { |
| | | return systemConfigMapper.selectByKeyAndSystem(key.name(), system); |
| | | } |
| | | |
| | | |
| | | @Cacheable(value = "systemConfig", key = "'getConfig-'+#key+'-'+#system") |
| | | @Override |
| | | public SystemConfig getConfigCache(SystemConfigKeyEnum key, SystemEnum system) { |
| | | return getConfig(key, system); |
| | | } |
| | | |
| | | @Cacheable(value = "systemConfig", key = "'getValue-'+#key+'-'+#system") |
| | | @Override |
| | | public String getValueCache(SystemConfigKeyEnum key, SystemEnum system) { |
| | | SystemConfig config = getConfig(key, system); |
| | | if (config == null) { |
| | | return null; |
| | | } |
| | | return config.getValue(); |
| | | } |
| | | } |