MemberService.java 2.95 KB
/**
 * Copyright © 2015-2018 ODM All rights reserved.
 */
package com.pudp.bae.service;
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.sql.Clob;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.pudp.bae.dao.redis.MemberDao;
import com.pudp.bae.model.Member;
import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.mapper.JsonMapper;
import com.thinkgem.jeesite.modules.reg.dao.base.BdcDao;
import com.thinkgem.jeesite.modules.reg.entity.base.DmlRecords;
 
@Service
@Transactional(readOnly = true)
public class MemberService {
	
     @Resource(name="memberDao")
     private MemberDao memberDao;
     @Autowired
     private BdcDao bdcDao;
      
     public void setMemberDao(MemberDao memberDao)
     {
        this.memberDao = memberDao;
     }
     
     @Transactional(readOnly = false)
     public void add(Member member){
         memberDao.add(member);
     }
     
     @Transactional(readOnly = false)
     public void delete(String id){
         memberDao.delete(id);
     }
      
     public Member get(String id)
     {
         return memberDao.get(id);
     }
     
     /**
 	 * 根据dml操作记录保存redis
 	 * @return 
 	 * @throws SQLException 
 	 * @throws IOException 
 	 */
 	@Transactional(readOnly = false)
 	public String selectDmlRecords(DmlRecords dmlRecords) throws SQLException, IOException {
 		String success = "";
 		Member member = new Member();
 		Map<String, Object> bdcmap = null;
 		if(!"DELETE".equals(dmlRecords.getDmllx())) {
 			bdcmap = bdcDao.selDate(dmlRecords.getTablename(),dmlRecords.getTableid());
 			//keySet获取map集合key的集合  然后在遍历key即可
 			for(String key : bdcmap.keySet()){
 				//判断map值是否为Clob
 				if(bdcmap.get(key) instanceof Clob) {
 					Clob clob = (Clob) bdcmap.get(key);
 					Reader is = clob.getCharacterStream();// 得到流
 					BufferedReader br = new BufferedReader(is);
 					String s = br.readLine();
 					StringBuffer sb = new StringBuffer();
 					// 执行循环将字符串全部取出付值给StringBuffer由StringBuffer转成STRING
 					while (s != null) {
 						sb.append(s);
 						s = br.readLine();
 					}
 					is.close();
 					br.close();
 					bdcmap.put(key, sb.toString());
 				}
 			}
 		}
 		member.setId(dmlRecords.getId());
 		Map<String, Object> map_new_sett = new HashMap<String, Object>();
 		map_new_sett.put("dmlRecords", dmlRecords);
 		map_new_sett.put("qxdm", Global.getAreaCode());
 		map_new_sett.put("data", bdcmap);
 		member.setNickname(JsonMapper.toJsonString(map_new_sett));
 		try {
 			add(member);
 			success = "success";
		} catch (Exception e) {
			e.printStackTrace();
			success = e.getMessage();
		}
 		return success;
 	}
}