package cn.com.countrygarden.bi.main.service.dup.impl;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.*;
import java.util.regex.Pattern;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import com.github.pagehelper.PageRowBounds;
import cn.com.countrygarden.bi.main.core.Result;
import cn.com.countrygarden.bi.main.core.ResultCode;
import cn.com.countrygarden.bi.main.dao.dup.SiteResourcesMapper;
import cn.com.countrygarden.bi.main.dao.dup.TbHsprContractMapper;
import cn.com.countrygarden.bi.main.dao.sys.RoleMapper;
import cn.com.countrygarden.bi.main.dao.twerp.hm.TbHsprCommunityMapper;
import cn.com.countrygarden.bi.main.dao.twerp.hm.TbSysOrganMapper;
import cn.com.countrygarden.bi.main.dto.wcx.WcxRegionProjectDto;
import cn.com.countrygarden.bi.main.exception.ServiceCodeException;
import cn.com.countrygarden.bi.main.model.AccessToken;
import cn.com.countrygarden.bi.main.model.PageData;
import cn.com.countrygarden.bi.main.model.dup.SiteResources;
import cn.com.countrygarden.bi.main.model.mediaResource.AdvertisingFileDirectory;
import cn.com.countrygarden.bi.main.model.sys.Role;
import cn.com.countrygarden.bi.main.model.twerp.ErpCommunity;
import cn.com.countrygarden.bi.main.model.twerp.hm.TbSysOrgan;
import cn.com.countrygarden.bi.main.service.AccessTokenService;
import cn.com.countrygarden.bi.main.service.dup.CurrencyCommonService;
import cn.com.countrygarden.bi.main.service.dup.SiteResourcesService;
import cn.com.countrygarden.bi.main.service.twerp.hm.TbSysOrganService;
import cn.com.countrygarden.bi.main.util.OSSUtils;
import cn.com.countrygarden.bi.main.util.UploadUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * <pre>
 * 。场地资源ServiceImpl
 * </pre>
 *
 * @author developer developer@meicloud.com
 * @version 1.00.00
 *
 * <pre>
 * 修改记录
 *    修改后版本:     修改人：  修改日期:     修改内容:
 *          </pre>
 */
@Slf4j
@Service
@Transactional
public class SiteResourcesServiceImpl implements SiteResourcesService {

    @Autowired
    private CurrencyCommonService currencyCommonService;

    @Resource
    private SiteResourcesMapper siteResourcesMapper;

    @Autowired
    private OSSUtils ossUtils;

    @Autowired
    private AccessTokenService accessTokenService;

    @Autowired
    private RoleMapper roleMapper;

    @Autowired
    private TbSysOrganService tbSysOrganService;
    
/*    @Autowired
    private TbSysOrganMapper tbSysOrganMapper;*/

    @Autowired
    private TbHsprCommunityMapper tbHsprCommunityMapper;

    @Autowired
    private TbHsprContractMapper tbHsprContractMapper;


    @Override
    public PageData findAllSiteResourcesControllerLike(SiteResources siteResources, HttpServletRequest request) {
        PageRowBounds pageRowBounds = new PageRowBounds(siteResources.getPageIndex(), siteResources.getPageSize());

        checkPackagePermission(siteResources, request);

        List<SiteResources> list = siteResourcesMapper.findAllSiteResourcesControllerLike(siteResources, pageRowBounds);
        PageData PageData = new PageData(list, pageRowBounds);
        return PageData;
    }

    private void checkPackagePermission(SiteResources siteResources, HttpServletRequest request) {
        Map<String, List<String>> user = getUser(request, siteResources.getOrganCode(), siteResources.getCommId());
        if (user.size() != 0 || user != null) {
            if (user.get("organCode") != null) {
                siteResources.setOrganCodes(user.get("organCode"));
            }
            if (user.get("comid") != null) {
                siteResources.setCommIds(user.get("comid"));
            }
        }
    }

    @Override
    public List<SiteResources> findAllSiteResources(SiteResources siteResources, HttpServletRequest request) {
        checkPackagePermission(siteResources, request);

        List<SiteResources> list = siteResourcesMapper.findAllSiteResourcesControllerLike(siteResources);
        return list;
    }

	
	
	@Override
	   public Result insertResources(SiteResources dto,HttpServletRequest request){
	    Result rt=new Result();
	    
	    calibrationParameter(dto,new String[]{"name","location","organCode","commId","organName","commName",
                "area","areaDetail","commCityLevel",
                "resourcesId","image","forthputtingStatus","userCode"});

           if(!isInteger(dto.getArea().toString())){
               throw new ServiceCodeException("","面积只能是数字");
           }

           checkPackagePermission(dto, request);

        if (resourcesIsRepeat(dto)) {
            throw new ServiceCodeException("", "该资源已存在");
        }
        if (dto.getId() != null) {
            if (StringUtils.isEmpty(dto.getAddDate())) {
                throw new ServiceCodeException("", "该参数为必填项: " + "addDate");
            }
            updateResources(dto);
        } else {
            insertResources(dto);
        }
        return rt.setResultCode(ResultCode.OK).setResultMsg(AdvertisingFileDirectory.SUCESS);
    }


    public String uploadFile(MultipartFile file, HttpServletRequest request) throws IOException {

        if (file.getSize() > 2097152) {
            throw new ServiceCodeException("", "文件大小限制在2MB内");
        } else if (file.getSize() <= 0) {
            throw new ServiceCodeException("", "文件不能为空");
        }
        String[] suffixArr = {".JPG", ".JPEG", ".PNG", ".BMP", ".PSD"};
        String interim = file.getOriginalFilename();

        String suffix = interim.substring(interim.lastIndexOf("."), interim.length());
        boolean flag = false;
        for (String suffixs : suffixArr) {
            if (suffixs.equals(suffix.toUpperCase())) {
                flag = true;
                break;
            }
        }

        if (flag) {
            String fileRealName = UUID.randomUUID().toString().replaceAll("-", "") + suffix;
            String url = ossUtils.uploadFile(fileRealName, file.getInputStream());

            return url;
        } else {
            throw new ServiceCodeException("", "上传附件只能是 JPG 、PNG 、JPEG 、BMP、PSD格式!");
        }
    }



    private void calibrationParameter(SiteResources dto,String[] mandatoryField) {
        //必填项校验
	    Map<String, Boolean> stringBooleanMap =  currencyCommonService.checkFormAuth(dto, mandatoryField);
	    
        for (String key : stringBooleanMap.keySet()) {
            if (!stringBooleanMap.get(key)) {
                throw new ServiceCodeException("","该参数为必填项: " + key);
            }
        }
    }

    @Override
    public String generateId(SiteResources siteResources) {
        //新资源录入后生成编号；规则：区域编号+项目编号+资源名称序列号+新增序列号（顺位），形成资源铭牌做线下标记
        calibrationParameter(siteResources,new String[]{"name","organCode","commId"});
        
        StringBuilder stringBuilder=new StringBuilder();

            Integer maxNuber=siteResourcesMapper.selectMaxResourcesId();
   
            stringBuilder.append(siteResources.getOrganCode()).append(siteResources.getCommId()).
            append(siteResources.getName()).append(maxNuber==null?getRandom():maxNuber).append(getRandom()).append(siteResources.getRow()==null?0:siteResources.getRow());  

        return stringBuilder.toString();
    }

    public String getRandom(){
        String valueOf = String.valueOf(Math.random()*1000);
        int indexOf = valueOf.indexOf(".");
       return valueOf.substring(0,indexOf);
    }
    
/*    public Integer getDates() {
       BigDecimal setScale = new BigDecimal(System.currentTimeMillis()).divide(new BigDecimal(100000000)).setScale(0,BigDecimal.ROUND_HALF_UP);
        
        return setScale.intValue();
    }*/
    
    public List<Map<String, String>> findByDictCode(String code){
        return siteResourcesMapper.findByDictCode(code);
    }
	
	   public Boolean resourcesIsRepeat(SiteResources siteResources) {
	       String repeat = siteResourcesMapper.resourcesIsRepeat(siteResources);
	        return StringUtils.isNoneBlank(repeat);
	    }
	
	    public boolean insertResources(SiteResources siteResources) {
	        return siteResourcesMapper.insertResources(siteResources)== 1;
	    }

	public boolean updateResources(SiteResources siteResources) {
		return siteResourcesMapper.updateResources(siteResources) == 1;
	}
	


    public Map<String, List<String>> getUser(HttpServletRequest request, String code, Integer commID) {
        HashMap<String, List<String>> hashMap = new HashMap<>();
        List ls = new ArrayList<>();
        String accessToken = request.getParameter("AccessToken");

        AccessToken token = accessTokenService.findByToken(accessToken);

        List<Role> list = roleMapper.findByUserCode(token.getUserCode());

        String organCode = "false";
        for (Role userRoles : list) {

            if (userRoles.getCode().equals("site_organ")) {

                organCode ="";
                List<String> tbSysOrgan = tbHsprContractMapper.findArea(token.getUserCode());
                if (tbSysOrgan.isEmpty() && tbSysOrgan.size() == 0) {
                    throw new ServiceCodeException("", "查找不到用户所管辖的区域");
                }


                log.info("----管辖区域集合---" + JSONObject.toJSONString(tbSysOrgan));

/*                organCode = tbHsprContractMapper.getOrganName(wcxRegionProjectDto.getRegionName());

                if (organCode == null || "null".equals(organCode)) {
                    throw new ServiceCodeException("", "查找不到用户所在区域");
                }

                if (StringUtils.isNoneBlank(code) && !code.equals(organCode)) {
                    throw new ServiceCodeException("", "请选择所在区域!!");
                }*/

                if (StringUtils.isNoneBlank(code) && !tbSysOrgan.contains(code)) {
                    throw new ServiceCodeException("", "请选择所管辖区域!!");
                }
                
                hashMap.put("organCode", tbSysOrgan);
                break;
            } else if (userRoles.getCode().equals("site_admin") || userRoles.getCode().equals("admin")) {
                organCode = null;
                break;
            } else if (userRoles.getCode().equals("site_community")) {
                organCode ="";
                List<String> tbSysOrgan = tbHsprContractMapper.findProject(token.getUserCode());
                if (tbSysOrgan.isEmpty() && tbSysOrgan.size() == 0) {
                    throw new ServiceCodeException("", "查找不到用户所管辖项目");
                }
          /*      Map<String, Object> stringObjectMap = tbSysOrgan.get(0);
                String name = (String) stringObjectMap.get("commName");
                
                if (stringObjectMap.get("commId") == null || "null".equals(stringObjectMap.get("commId"))) {
                    throw new ServiceCodeException("", "查找不到用户所在项目");
                }
                Integer comid = (Integer) stringObjectMap.get("commId");
                */
                log.info("----管辖项目集合---" + JSONObject.toJSONString(tbSysOrgan));
                //organCode = tbHsprContractMapper.getOrganName(name);
          /*      Map<String, Object> community = tbHsprContractMapper.getCommunity(comid.toString());
                organCode = (String) community.get("OrganCode");
                if (StringUtils.isNoneBlank(code) && !organCode.equals(code)) {
                    throw new ServiceCodeException("", "请选择所在区域");
                }
                if (commID != null && !commID.equals(comid)) {
                    throw new ServiceCodeException("", "请选择所在项目");
                }*/
                //hashMap.put("organCode", organCode);
                List<String> areasByLists = tbHsprContractMapper.getAreasByLists(tbSysOrgan);
                if (StringUtils.isNoneBlank(code) && !areasByLists.contains(code)) {
                    throw new ServiceCodeException("", "请选择所管辖项目的区域!!");
                }

                if (commID != null && !tbSysOrgan.contains(commID.toString())) {
                    throw new ServiceCodeException("", "请选择所管辖项目");
                }

                hashMap.put("comid", tbSysOrgan);
                break;
            }
        }
        if ("false".equals(organCode)) {
            throw new ServiceCodeException("", "请为该账号赋予一个权限角色");
        }
        
        return hashMap;
    }
    

	@Override
	public Result deleteResources(SiteResources siteResources) {
	    return   new Result().setResultCode(ResultCode.OK).setResultMsg(AdvertisingFileDirectory.SUCESS).setData(siteResourcesMapper.deleteResources(siteResources) == 1);
	}

	@Override
	public Result excelToObject(MultipartFile multipartFile,HttpServletRequest request,String name) throws Exception{
	  
        String accessToken = request.getParameter("AccessToken");
        AccessToken token = accessTokenService.findByToken(accessToken);
        if (multipartFile == null) {
            throw new ServiceCodeException("","请选择需要上传的文件");
        }else if(name == null){
            throw new ServiceCodeException("","请输入文件名");
        }
        CommonsMultipartFile commonsMultipartFile = (CommonsMultipartFile) multipartFile;
        if (commonsMultipartFile.isEmpty()) {
            throw new ServiceCodeException("","上传文件为空文件");
        }
        String fileName = commonsMultipartFile.getOriginalFilename();
        
        if (fileName.indexOf(".xlsx") <= 0 && fileName.indexOf(".xls") <= 0) {
            throw new ServiceCodeException("","上传文件应为excel文件格式为：xlsx 或 xls");
        }

	    Workbook xwb = null;

		BufferedInputStream bf = new BufferedInputStream(commonsMultipartFile.getInputStream());
			
		if (fileName.endsWith("xls")) { // Excel&nbsp;2003
			xwb = new HSSFWorkbook(bf);
		} else if (fileName.endsWith("xlsx")) { // Excel 2007/2010
			xwb = new XSSFWorkbook(bf);
		}

		List<String> mList=new ArrayList<>();
		List<SiteResources> sList=new ArrayList<>();
		Boolean flag=true;
		
		
        List<Map<String, String>> resourceType = findByDictCode("RESOURCE_TYPE");
        List<Map<String, String>> resourceName = findByDictCode("RESOURCE_NAME");
        List<Map<String, String>> useStatus = findByDictCode("USE_STATUS");
        List<Map<String, String>> commCityLevels = findByDictCode("COMM_CITY_LEVEL");
        List<Map<String, String>> siteUnit = findByDictCode("SITE_UNIT");
        
        if(xwb!=null&&xwb.getSheetAt(0)!=null){
            Sheet   sheet = xwb.getSheetAt(0);//获取第几个页面0开始
            
            //校验表头
            if(sheet!=null){ 
                List<List<String>> basicInfoTitleList = UploadUtil.readOneSheetForList(sheet, 0, 0, 0, -1);
                List<String> transferTitles = this.getSiteExcelTitleList();
                if(!UploadUtil.isRightTemplet(basicInfoTitleList, transferTitles)){
                    throw new ServiceCodeException("","该模板与导入模板不匹配，请重新下载最新模板");
                }
            }
            //校验模板是否空模板
            List<List<String>> transferBasicInfoList = UploadUtil.readOneSheetForList(sheet, 1, -1, 0, -1);
            if(transferBasicInfoList.size() == 0){
                throw new ServiceCodeException("","不能上传空模板");
            }
            int length = transferBasicInfoList.size();
            for(int rowNum=0;rowNum<length;rowNum++){
                int rowErrorNum = rowNum + 2;
                SiteResources siteResources = new SiteResources();
                siteResources.setRow(rowNum);
                List<String> transferBasicInfo = transferBasicInfoList.get(rowNum);

                siteResources.setUserCode(token.getUserCode());

                String organId = transferBasicInfo.get(1);
                String str = transferBasicInfo.get(3);
                Integer commid = null;
                if (StringUtils.isNotEmpty(str)) {
                    commid = Integer.parseInt(transferBasicInfo.get(3));
                }
                siteResources.setOrganCode(organId);
                if (StringUtils.isNotEmpty(organId)) {
                    try {
                        getUser(request, organId, commid);
                     /*   TbSysOrgan tbOrgan = tbSysOrganMapper.findByOrganCode(organId);
                         if(tbOrgan!=null){
                             siteResources.setOrganName(tbOrgan.getOrganName());
                         }*/
                    } catch (ServiceCodeException e) {
                        flag = false;
                        mList.add("第【" + rowErrorNum + "】行的第2列或第4列{区域}或{项目} 权限不符合: " + e.getMessage());
                    }

                } else {
                    flag = false;
                    mList.add("第【" + rowErrorNum + "】行的第2列{区域} 是必填项不能为空");
                }
                
           
           //------------------资源名称----------------     
                String  resourcesname= transferBasicInfo.get(7);
                siteResources.setName(resourcesname);
                if(StringUtils.isNotEmpty(resourcesname)){
                    Optional<Map<String, String>> findFirstName= resourceName.stream().filter(m -> (m.get("value")+m.get("name")).equals(resourcesname)).findFirst();
                    if(findFirstName.isPresent()){
                        siteResources.setName(findFirstName.get().get("value"));
                    }else{
                        flag=false;
                        mList.add("第【"+rowErrorNum+"】行的第8列{资源名称} 查找不到此资源名称的字典值"); 
                    }
                }else{
                    flag=false;
                    mList.add("第【"+rowErrorNum+"】行的第8列{资源名称} 是必填项不能为空"); 
                }
              //------------------资源名称----------------       
                
                
                String commId = transferBasicInfo.get(3);
                
                if(StringUtils.isNotEmpty(commId)){
                    List<ErpCommunity> commByCommId = tbHsprCommunityMapper.findBaseCommByCommId(commId);

                    if(commByCommId!=null&&commByCommId.size()>0){
                        ErpCommunity erpCommunity = commByCommId.get(0);
          
                        if(!erpCommunity.getOrganCode().equals(organId)){

                                flag=false;
                                mList.add("第【"+rowErrorNum+"】行的第4列{项目} 通过项目Id查找到的区域Id与该行的(区域Id不匹配)");
                        }
                        if(flag){
                            siteResources.setCommId(Integer.parseInt(commId));
                            siteResources.setCommName(erpCommunity.getCommName());
                            siteResources.setOrganName(erpCommunity.getOrganName());
                            siteResources.setResourcesId(generateId(siteResources));
                        }
                    }else{
                        
                        flag=false;
                        mList.add("第【"+rowErrorNum+"】行的第4列{项目} 查找不到此项目Id");
                 
                    }
                }else{
                    flag=false;
                    mList.add("第【"+rowErrorNum+"】行的第4列{项目} 是必填项不能为空"); 
                }
             
                
                
                String  commCityLevel= transferBasicInfo.get(4);
                siteResources.setCommCityLevel(commCityLevel);
                if(StringUtils.isNotEmpty(commCityLevel)){
                    Optional<Map<String, String>> findFirstcommCityLevel = commCityLevels.stream().filter(m -> m.get("name").equals(commCityLevel)).findFirst();
                    if(findFirstcommCityLevel.isPresent()){
                        siteResources.setCommCityLevel(findFirstcommCityLevel.get().get("value"));
                    }else{
                        flag=false;
                        mList.add("第【"+rowErrorNum+"】行的第5列{项目城市级别} 查找不到此项目城市级别的字典值"); 
                    }
                    
                }else{
                    flag=false;
                    mList.add("第【"+rowErrorNum+"】行的第5列{项目城市级别} 是必填项不能为空"); 
                }
                
                String  area= transferBasicInfo.get(5);
                if(StringUtils.isNotEmpty(area)){
                    if(isInteger(area)){
                        BigDecimal setScale = new BigDecimal(area).setScale(2,BigDecimal.ROUND_HALF_UP);
                        siteResources.setArea(setScale.doubleValue());
                    }else{
                        flag=false;
                        mList.add("第【"+rowErrorNum+"】行的第6列{面积} 只能是数字"); 
                    }
                }else{
                    flag=false;
                    mList.add("第【"+rowErrorNum+"】行的第6列{面积} 是必填项不能为空"); 
                }
                
                
                String  areaDetail= transferBasicInfo.get(6);
                siteResources.setAreaDetail(areaDetail);
                if(StringUtils.isEmpty(areaDetail)){
                    flag=false;
                    mList.add("第【"+rowErrorNum+"】行的第7列{面积明细} 是必填项不能为空"); 
                }
                
                
       /*         String  publicResourcesType= transferBasicInfo.get(5);
                if(StringUtils.isNotEmpty(publicResourcesType)){
                    Optional<Map<String, String>> findFirst = resourceType.stream().filter(m -> m.get("name").equals(publicResourcesType)).findFirst();
                    if(findFirst.isPresent()){
                        siteResources.setPublicResourcesType(findFirst.get().get("value"));
                    }else{
                        flag=false;
                        mList.add("第【"+rowErrorNum+"】行的第6列{公共资源类型} 查找不到此公共资源类型的字典值"); 
                    }
                    
                }else{
                    flag=false;
                    mList.add("第【"+rowErrorNum+"】行的第6列{公共资源类型} 是必填项不能为空"); 
                }*/
                
                
                
                //-----------------------使用状态----------------------------
                String  forthputtingStatus= transferBasicInfo.get(9);
                if(StringUtils.isNotEmpty(forthputtingStatus)){
                    Optional<Map<String, String>> findFirstuseStatus= useStatus.stream().filter(m -> m.get("name").equals(forthputtingStatus)).findFirst();
                    if(findFirstuseStatus.isPresent()){
                        siteResources.setForthputtingStatus(findFirstuseStatus.get().get("value"));
                    }else{
                        flag=false;
                        mList.add("第【"+rowErrorNum+"】行的第10列{使用状态} 查找不到此使用状态的字典值"); 
                    }
                }else{
                    flag=false;
                    mList.add("第【"+rowErrorNum+"】行的第10列{使用状态} 是必填项不能为空"); 
                }
              //-----------------------使用状态----------------------------
 
                String  location= transferBasicInfo.get(8);
                siteResources.setLocation(location);
                if(StringUtils.isNotEmpty(location)){
                    if(flag){
                        Boolean boolean1=  resourcesIsRepeat(siteResources);

                        for (int i=0;i<length;i++) {
                           if(i==rowNum){
                               continue;
                           }
                           int errorNum=i+2;
                           List<String> string= transferBasicInfoList.get(i);
                            if(string!=null&&string.size()>0){
                                String oran = string.get(1);
                                String comm = string.get(3);
                                String loca = string.get(8);
                          /*      &&forthputtingStatus.equals(status)
                                String status = string.get(9);*/
                                String resoname = string.get(7);
                                String are = string.get(5);

                                if(organId.equals(oran)&&commId.equals(comm)&&location.equals(loca)
                                  &&resourcesname.equals(resoname)
                                  &&area.equals(are)){
                                    flag=false;
                                    mList.add("第【"+rowErrorNum+"】行的第9列{资源具体位置} 与第"+errorNum+"行的{资源具体位置}相同 !!"); 
                                }
                            }
                            
                        }
                        if(boolean1){
                            flag=false;
                            mList.add("第【"+rowErrorNum+"】行的第9列{资源具体位置} 该资源已经存在"); 
                        }
                    }
              
                    
                }else{
                    flag=false;
                    mList.add("第【"+rowErrorNum+"】行的第9列{资源具体位置} 是必填项不能为空"); 
                }
                

      /*          String  number= transferBasicInfo.get(9);
                if(StringUtils.isNotEmpty(number)){
                    if(isInteger(number)){
                        siteResources.setNumber(Integer.parseInt(number));
                    }else{
                        flag=false;
                        mList.add("第【"+rowErrorNum+"】行的第10列{数量} 只能是数字"); 
                    }
                }*/
                
                String  unit= transferBasicInfo.get(10);
                if(StringUtils.isNotEmpty(unit)){
                    Optional<Map<String, String>> findFirSiteUnit= siteUnit.stream().filter(m -> m.get("name").equals(unit)).findFirst();
                    if(findFirSiteUnit.isPresent()){
                        siteResources.setUnit(findFirSiteUnit.get().get("value"));
                    }else{
                        flag=false;
                        mList.add("第【"+rowErrorNum+"】行的第11列{单位} 查找不到此单位的字典值"); 
                    }
                }
                
                
/*                String  specification= transferBasicInfo.get(11);
                siteResources.setSpecification(specification);
               
                String  partner= transferBasicInfo.get(12);
                siteResources.setPartner(partner);
                
                String  price= transferBasicInfo.get(13);
                if(StringUtils.isNotEmpty(price)){
                    if(isInteger(price)){
                        siteResources.setPrice(new Double(price));
                    }else{
                        flag=false;
                        mList.add("第【"+rowErrorNum+"】行的第14列{价格} 只能是数字"); 
                    }
                }
                
                
                String  leaseTimeLimit= transferBasicInfo.get(14);
                if(StringUtils.isNotEmpty(leaseTimeLimit)){
                    if(isInteger(leaseTimeLimit)){
                        siteResources.setLeaseTimeLimit(Integer.parseInt(leaseTimeLimit));
                    }else{
                        flag=false;
                        mList.add("第【"+rowErrorNum+"】行的第15列{出租时限} 只能是数字"); 
                    }
                }

                String  idleResourcesDirections= transferBasicInfo.get(15);
                siteResources.setIdleResourcesDirections(idleResourcesDirections);
                */
                String  remark= transferBasicInfo.get(11);
                siteResources.setRemark(remark);
                sList.add(siteResources);
            }
            
        }
        if(!flag){
            return    new Result().setResultCode(ResultCode.FAIL).setResultMsg("校验不通过").setData(mList);
        }else{
  
            return new Result().setResultCode(ResultCode.OK).setResultMsg(AdvertisingFileDirectory.SUCESS).setData(batchInsert(sList));
        }


	}
	
	

     
     public int batchInsert(List<SiteResources> list){
         int j =0;
         if(null != list && list.size()>0){
             int limit = 500;
             int num = list.size() / limit;
             
             if(num > 0){
                 
                 for(int i=0;i<num;i++){
                     List<SiteResources> tempList = list.subList(0, limit);
                     j +=siteResourcesMapper.addSiteList(tempList);
                     list.subList(0, limit).clear();
                 }
                 if(list.size() > 0){
                     j += siteResourcesMapper.addSiteList(list);
                     list.clear();
                 }
             }else{
                 j = siteResourcesMapper.addSiteList(list);
                 list.clear();
             }
         }  
         return j;
     }

    /** 
     * 验证整数和浮点数（正负整数和正负浮点数） 
     * @param decimals 一位或多位0-9之间的浮点数，如：1.23，233.30 
     * @return 验证成功返回true，验证失败返回false 
     */   
    public static boolean isInteger(String decimals) {    
        //String regex = "\\-?[1-9]\\d+(\\.\\d+)?";   
        String regex ="-?[0-9]*(\\.?)[0-9]*";
        return Pattern.matches(regex,decimals);   
    }    

            @SuppressWarnings("resource")
            private List<String> getSiteExcelTitleList(){
                ClassLoader loader = getClass().getClassLoader();
                String fileName = "siteResources.xlsx";
                String path = (new StringBuilder())
                        .append("excel/sqfz/").append(fileName).toString();
                InputStream in = loader.getResourceAsStream(path);
                XSSFWorkbook wb = null;
                try {
                    wb = new XSSFWorkbook(in);
                } catch (IOException e) {
                    
                }
                Sheet transferSheet = wb.getSheetAt(0);
                List<List<String>> basicInfoTitleList = UploadUtil.readOneSheetForList(transferSheet, 0, 0, 0, -1);
                basicInfoTitleList.get(0).remove(basicInfoTitleList.get(0).size()-1);
                basicInfoTitleList.get(0).remove(basicInfoTitleList.get(0).size()-1);
                return basicInfoTitleList.get(0);
            }

	
	
}
