cf1997c5a35a1dbb380a78c4f7f5a06d6b8946a6.svn-base 7.88 KB
/**
 * Copyright © 2015-2018 ODM All rights reserved.
 */
package com.thinkgem.jeesite.modules.reg.service.base;

import java.io.IOException;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.reg.dao.base.RegBaseZbinfoZrzDao;
import com.thinkgem.jeesite.modules.reg.dao.base.RegBaseZrzDao;
import com.thinkgem.jeesite.modules.reg.entity.base.RegBaseZbinfoZrz;
import com.thinkgem.jeesite.modules.reg.entity.base.RegBaseZrz;

/**
 * 自然幢信息维护Service
 * @author xuyg
 * @version 2015-10-28
 */
@Service
@Transactional(readOnly = true)
public class RegBaseZrzService extends CrudService<RegBaseZrzDao, RegBaseZrz> {
	
	@Autowired
	private RegBaseZbinfoZrzDao regBaseZbinfoDao;

	public RegBaseZrz get(String id) {
		RegBaseZrz regBaseZrz = super.get(id);
		return regBaseZrz;
	}
	
	public long getZrzMaxBsm(){
		if("oracle".equals(Global.getDbName())){
			return dao.getZrzMaxBsmofOracle();
		}else{
			return dao.getZrzMaxBsm();
		}
	}
	
	public String getczds(String bdcdyh){
		return dao.getczds(bdcdyh);
	}
	
	public List<String> findZddms(String xmid){
		return dao.findZddms(xmid);
	}
	
	public RegBaseZrz getRegBaseZrz(String bdcdyh) {
		return dao.getRegBaseZrz(bdcdyh);
	}
	
	public List<RegBaseZrz> getListByZddm(RegBaseZrz regBaseZrz) {
		return dao.getListByZddm(regBaseZrz);
	}
	
	public List<RegBaseZrz> findList(RegBaseZrz regBaseZrz) {
		return super.findList(regBaseZrz);
	}
	
	public List<RegBaseZrz> findJzwmcList(RegBaseZrz regBaseZrz) {
		return dao.findJzwmcList(regBaseZrz);
	}
	
	public List<RegBaseZrz> findzrzhsxhList(RegBaseZrz regBaseZrz) {
		return dao.findzrzhsxhList(regBaseZrz);
	}
	
	//界址点导入修改后生成楼栋不动产单元号
		public List<RegBaseZrz> findzrzhList(RegBaseZrz regBaseZrz) {
			return dao.findzrzhList(regBaseZrz);
		}
	public Page<RegBaseZrz> findPage(Page<RegBaseZrz> page, RegBaseZrz regBaseZrz) {
		return super.findPage(page, regBaseZrz);
	}
	
	@Transactional(readOnly = false)
	public void save(RegBaseZrz regBaseZrz) {
		super.save(regBaseZrz);
	}
	
	/*@Transactional(readOnly = false)
	public void zrzzbxxsave(RegBaseZrz regBaseZrz){
		for (RegBaseZbinfoZrz regBaseZbinfoZrz : regBaseZrz.getRegBaseZbinfoZrzList()){
			if (regBaseZbinfoZrz.getId() == null){
				continue;
			}
			if (RegBaseZbinfoZrz.DEL_FLAG_NORMAL.equals(regBaseZbinfoZrz.getDelFlag())){
				if (StringUtils.isBlank(regBaseZbinfoZrz.getId())){
					regBaseZbinfoZrz.setMainIdZrz(regBaseZrz);
					regBaseZbinfoZrz.preInsert();
					regBaseZbinfoZrzDao.insert(regBaseZbinfoZrz);
				}else{
					regBaseZbinfoZrz.preUpdate();
					regBaseZbinfoZrzDao.update(regBaseZbinfoZrz);
				}
			}else{
				regBaseZbinfoZrzDao.delete(regBaseZbinfoZrz);
			}
		}
	}*/
	
	@Transactional(readOnly = false)
	public void savebat(RegBaseZrz regBaseZrz) {
		super.savebat(regBaseZrz);
	}
	
	@Transactional(readOnly = false)
	public void delete(RegBaseZrz regBaseZrz) {
		super.delete(regBaseZrz);
	}
	@Transactional(readOnly = false)
	public void zrzdelete(RegBaseZrz regBaseZrz) {
		dao.zrzdelete(regBaseZrz);
	}
	
public List<RegBaseZrz> importRegBaseZrz(InputStream in) throws IOException  {
	    
	    List<RegBaseZrz> regBaseZrzs = readRegBaseZrzXls(in);
	    return regBaseZrzs;
	  }
	private List<RegBaseZrz> readRegBaseZrzXls(InputStream is) throws IOException{
		    HSSFWorkbook hssfWorkbook = new HSSFWorkbook(is);
		    List<RegBaseZrz> regBaseZrzs = new ArrayList<RegBaseZrz>();
		    RegBaseZrz regBaseZrz;
		    // 循环工作表Sheet
		      HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(1);
		      // 循环行Row
		      for (int rowNum = 1; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
		    	  regBaseZrz = new RegBaseZrz();
		        HSSFRow hssfRow = hssfSheet.getRow(rowNum);
		        for (int cellNum = 0; cellNum < hssfRow.getLastCellNum(); cellNum++){
		          HSSFCell hssfCell  = hssfRow.getCell(cellNum);
		          if(hssfCell==null){
		        	  continue;
		          }
		          String strCell = getValue(hssfCell);
		          if (cellNum == 0) {
		        	  regBaseZrz.setXmmc(strCell);
		          } else if (cellNum == 1) {
		        	  regBaseZrz.setZddm(strCell);
		          } else if (cellNum == 2) {
		        	  regBaseZrz.setGzwmc(strCell);
		          } else if (cellNum == 3) {
		        	  regBaseZrz.setZzdmj(Double.valueOf(strCell));
		          } else if (cellNum == 4) {
		        	  regBaseZrz.setScjzmj(Double.valueOf(strCell));
		          } else if (cellNum == 5) {
		        	  regBaseZrz.setZcs(Integer.valueOf(strCell));
		          } else if (cellNum == 6) {
		        	  regBaseZrz.setDscs(strCell);
		          } else if (cellNum == 7) {
		        	  regBaseZrz.setGhyt(strCell);
		          } else if (cellNum == 8) {
		        	  regBaseZrz.setFwjg(strCell);
		          } else if (cellNum == 9) {
		        	  regBaseZrz.setZdftfs(strCell);
		          } else if (cellNum == 10) {
		        	  regBaseZrz.setZrzh(strCell);
		          } else if (cellNum == 11) {
		        	  regBaseZrz.setDxcs(strCell);
		          } else if (cellNum == 12) {
		        	  SimpleDateFormat s1 = new SimpleDateFormat("yyyy.MM.dd");
		        	  try {
						regBaseZrz.setJgrq(s1.parse(strCell));
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
		          } else if (cellNum == 13) {
		        	  regBaseZrz.setJzwgd(Double.valueOf(strCell));
		          } else if (cellNum == 14) {
		        	  regBaseZrz.setZydmj(Double.valueOf(strCell));
		          } else if (cellNum == 15) {
		        	  regBaseZrz.setZts(Integer.valueOf(strCell));
		          } else if (cellNum == 16) {
		        	  regBaseZrz.setJzwjbyt(strCell);
		          } else if (cellNum == 17) {
		        	  regBaseZrz.setDah(strCell);
		          } else if (cellNum == 18) {
		        	  regBaseZrz.setBz(strCell);
		          } else if (cellNum == 19) {
		        	  regBaseZrz.setZt(strCell);
		          } else if (cellNum == 20) {
		        	  String nextZHSort = "0000";
		        	  nextZHSort = String.valueOf(Integer.valueOf(nextZHSort)+1);
		        	  regBaseZrz.setBdcdyh(regBaseZrz.getZddm()+"F"+ nextZHSort +"0000");
		        	  break;
		          }
		        }
		        regBaseZrzs.add(regBaseZrz);

		      }
		    return regBaseZrzs;
		  }


@SuppressWarnings("static-access")
private String getValue(HSSFCell hssfCell){  
	    if(hssfCell.getCellType() == hssfCell.CELL_TYPE_BOOLEAN){
	      return String.valueOf( hssfCell.getBooleanCellValue());
	    }else if(hssfCell.getCellType() == hssfCell.CELL_TYPE_NUMERIC){
	    	DecimalFormat df = new  DecimalFormat("###0.###");
	    	return df.format(hssfCell.getNumericCellValue()).toString();
	     // return String.valueOf( hssfCell.getNumericCellValue());
	    }else if (hssfCell.getCellType() ==hssfCell.CELL_TYPE_STRING){
	    	return String.valueOf(hssfCell.getStringCellValue());
	    }else{
	      return String.valueOf( hssfCell.getStringCellValue());
	    }
	  }

     public List<RegBaseZrz> findListZb(RegBaseZrz zrz) {
 	     return dao.findListZb(zrz);
}

	public RegBaseZrz getByZddmZrzh(String zddm, String zrzh) {
		// TODO Auto-generated method stub
		return dao.getByZddmZrzh(zddm, zrzh);
	}

	public RegBaseZrz getByZrzh(String zrzh) {
		// TODO Auto-generated method stub
		return dao.getByZrzh(zrzh);
	} 
	
}