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

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;

import com.github.pagehelper.PageRowBounds;

import cn.com.countrygarden.bi.main.constant.mediaResource.MediaResourceConstant;
import cn.com.countrygarden.bi.main.core.AbstractService;
import cn.com.countrygarden.bi.main.core.Result;
import cn.com.countrygarden.bi.main.core.ResultCode;
import cn.com.countrygarden.bi.main.core.ResultGenerator;
import cn.com.countrygarden.bi.main.dao.mediaResource.AdvertisingFileDirectoryMapper;
import cn.com.countrygarden.bi.main.dao.mediaResource.AdvertisingResourcesMapper;
import cn.com.countrygarden.bi.main.dao.mediaResource.AdvertistingReserveMapper;
import cn.com.countrygarden.bi.main.dao.mediaResource.BasicInfoMapper;
import cn.com.countrygarden.bi.main.dao.mediaResource.ScheduleBasicInfoMapper;
import cn.com.countrygarden.bi.main.dto.AdvertisingResourcesDto;
import cn.com.countrygarden.bi.main.dto.BasicInfoDto;
import cn.com.countrygarden.bi.main.dto.mediaResource.MediaUnit;
import cn.com.countrygarden.bi.main.exception.ServiceException;
import cn.com.countrygarden.bi.main.model.PageData;
import cn.com.countrygarden.bi.main.model.mediaResource.AdvertisingFileDirectory;
import cn.com.countrygarden.bi.main.model.mediaResource.AdvertisingResources;
import cn.com.countrygarden.bi.main.model.mediaResource.BasicInfo;
import cn.com.countrygarden.bi.main.model.twerp.hm.TbSysUser;
import cn.com.countrygarden.bi.main.service.mediaResource.AdvertisingResourcesService;
import cn.com.countrygarden.bi.main.service.mediaResource.BasicInfoService;
import cn.com.countrygarden.bi.main.util.ExcelUtil;
import cn.com.countrygarden.bi.main.util.OSSUtils;
import cn.com.countrygarden.bi.main.util.PageUtil;
import cn.com.countrygarden.bi.main.util.PinYinUtils;
import cn.com.countrygarden.bi.main.util.SnowflakeUtil;

@Service
@Transactional
public class AdvertisingResourcesServiceImpl extends AbstractService<AdvertisingResources> implements AdvertisingResourcesService{ 

	@Autowired
	private AdvertisingResourcesMapper mapper;
	
	@Autowired
	private AdvertisingFileDirectoryMapper directoryMapper;
	
	@Autowired
	private ScheduleBasicInfoMapper scheduleBasicInfoMapper;
	
	@Autowired
	private AdvertistingReserveMapper advertistingReserveMapper;
	
	@Autowired
	private  BasicInfoService  basicInfoService;
	
	@Autowired
	private BasicInfoMapper basicInfoMapper;
	
	@Autowired
	private OSSUtils ossUtils;
	
	

	@Override
	public Map<String, Object> findPage(String accessToken,AdvertisingResourcesDto dto) {
		dto.setPageIndex(dto.getPageIndex()==null?1:dto.getPageIndex());
		dto.setPageSize(dto.getPageSize()==null?10:dto.getPageSize());
		int pageOffset = PageUtil.getPageOffset(dto.getPageIndex(),dto.getPageSize());
		dto.setPageOffset(pageOffset);
		List<Map<String,Object>> list = mapper.findAdvertisingPage(dto);
		long total = mapper.findAdvertisingCount(dto);
		PageRowBounds pageRowBounds = new PageRowBounds(dto.getPageIndex(), dto.getPageSize());
	    pageRowBounds.setTotal(total);
	    pageRowBounds.setCount(true);
        PageData pageData = new PageData(list, pageRowBounds);
        
        TbSysUser user = basicInfoService.findErpUser(accessToken);
		int count = scheduleBasicInfoMapper.findUserRole(user.getUserCode(), MediaResourceConstant.roleCode);
		
        Map<String, Object> map = new HashMap<>();
        map.put("data", pageData);
        map.put("isAdmin",count==0?false:true);
        return map;
	}
	
	@Override
	public Map<String, Object> findOne(AdvertisingResources po) {
		Map<String, Object> map = new HashMap<>();
		map.put("data",mapper.selectByPrimaryKey(po.getMediaId()));
		map.put("fileList", directoryMapper.viewAdjunctByAdvertusubgId(String.valueOf(po.getMediaId())));
		return map;
	}

	@Override
	public Result saveOne(String accessToken,AdvertisingResources po,String fileDirectory,Result rt) {
		
		TbSysUser user = basicInfoService.findErpUser(accessToken);
		
		po.setCommName(po.getCommName().substring(0,(po.getCommName().indexOf("-")!=-1)?po.getCommName().indexOf("-"):po.getCommName().length()));
		BasicInfo dbModel = scheduleBasicInfoMapper.findCommIdAndOrganCode(po);
		
		String siteOne = StringUtils.isEmpty(po.getSiteOne())?"":po.getSiteOne();
		String siteTwo = StringUtils.isEmpty(po.getSiteTwo())?"":po.getSiteTwo();
		
		int count = mapper.verifyLocation2(po.getCommId(),siteOne,siteTwo,po.getMediaId());
		if (count!=0) {
			return rt.setResultCode(ResultCode.FAIL).setResultMsg("资源重复，保存失败！");
		}
		
		po.setCommId(dbModel.getCommId());
		po.setOrganCode(dbModel.getOrganCode());
		
		if (null!=po.getMediaId()) {
			count = scheduleBasicInfoMapper.findUserRole(user.getUserCode(),MediaResourceConstant.roleCode);
			if (count==0) {
				String organCode = basicInfoMapper.findErpUserOrgan(user.getUserCode()).get("organCode");
				if (!po.getOrganCode().equals(organCode)) {
					return ResultGenerator.genFailResult("不能跨区域修改！");
				}
			}
			
			
			List<String> cycleaList = advertistingReserveMapper.findCycleTimeOne(po.getMediaId());
			if (cycleaList.isEmpty()) {
				AdvertisingResources dbPo = mapper.selectByPrimaryKey(po.getMediaId());
				if (!dbPo.getMediaType().equals(po.getMediaType())) {
					Map<String, String> mediaType = getMediaType();
					String value = mediaType.entrySet().stream().filter(t->t.getKey().equals(po.getMediaType())).findFirst().get().getValue();
					String str = PinYinUtils.getHanziInitials(value.substring(0, 2));
					po.setMediaCode(po.getCommId()+"-"+str);
					str = mapper.findNextCode2(po.getMediaCode());
					count = str.length();
					if (count<3) {
						count = 3 - count;
						for (int k = 0; k < count; k++) {
							str="0"+str;
						}
					}
					po.setMediaCode(po.getMediaCode()+str);
				}
				po.setVersion(po.getVersion()+1);
				po.setModBy(user.getUserCode());
				po.setModByName(user.getUserName());
				po.setModTime(new Date());
				mapper.updateByPrimaryKeySelective(po);
				return rt.setResultCode(ResultCode.OK).setResultMsg("成功");
			}else {
				return rt.setResultCode(ResultCode.INTERNAL_SERVER_ERROR).setResultMsg("媒体资源被占用，不能修改！");
			}
		}
		
		if("3".equals(po.getMediaType())) {
			//到期广告
			if(!checkInputSiteTwo(1000,"号杆","r",siteTwo)) {
				return rt.setResultCode(ResultCode.INTERNAL_SERVER_ERROR).setResultMsg("媒体形式与媒体位置2不匹配！");
			}
		}else if("7".equals(po.getMediaType())) {
			if ("0".equals(po.getMediaForm()) || "1".equals(po.getMediaForm())) {
				if(!checkInputSiteTwo(100,"广告位","l",siteTwo)) {
					return rt.setResultCode(ResultCode.INTERNAL_SERVER_ERROR).setResultMsg("媒体形式与媒体位置2不匹配！");
				}
			}
		}
		
		String nextMdieaCode = nextMdieaCode(po.getCommId(),po.getMediaType());
		po.setMediaId(SnowflakeUtil.INSTANCE.getId());
		po.setMediaCode(nextMdieaCode);
		po.setCreateBy(user.getUserCode());
		po.setCreateByName(user.getUserName());
		po.setCreateTime(new Date());
		mapper.insertCallBack(po);
		if (StringUtils.isNotBlank(fileDirectory)) {
			String[] fileIds = fileDirectory.split(",");
			directoryMapper.saveRelation(fileIds,po.getMediaId());
		} 
		return rt.setResultCode(ResultCode.OK).setResultMsg("成功");
	}
	
	private boolean checkInputSiteTwo(int i, String input, String wz,String siteTwo) {
	
		boolean flag = false;
		if ("r".equals(wz)) {
			for (int j = 1; j <= i ; j++) {
				if ((j+input).equals(siteTwo)) {
					flag = true;
					break;
				}
			}
		}else {
			for (int j = 1; j <= i ; j++) {
				if ((input+j).equals(siteTwo)) {
					flag = true;
					break;
				}
			}
		}
		
		return flag;
	}

	private String nextMdieaCode(String commId,String t) {
		StringBuffer strb = new StringBuffer();
		Map<String, String> mediaType = getMediaType();
		String type = mediaType.entrySet().stream().filter((e)->e.getKey().equals(t)).findFirst().get().getValue();
		strb.append(commId).append("-").
		append(PinYinUtils.getHanziInitials(type.substring(0, 2)));
		strb.append(mapper.findNextMediaCode(strb.toString()));
		return strb.toString();
	}
	
	
	@Override
	public Result del(AdvertisingResourcesDto dto,String accessToken) {
		TbSysUser user = basicInfoService.findErpUser(accessToken);
		int count = scheduleBasicInfoMapper.findUserRole(user.getUserCode(), MediaResourceConstant.roleCode);
		if (count==0) {
			return ResultGenerator.genFailResult("权限不足，不能删除！");
		}
		String[] mediaIds = dto.getMediaIds();
		List<String> cycleaList = null;
		for (String mediaId : mediaIds) {
			cycleaList = advertistingReserveMapper.findCycleTimeOne(Long.valueOf(mediaId));
			if (!cycleaList.isEmpty()) {
				List<String> findMediaCode = mapper.findMediaCode(cycleaList);
				return ResultGenerator.genFailResult("媒体编号："+String.join(",", findMediaCode)+"被占用，不能删除。");
			}
		}
		mapper.dels(mediaIds);
		return ResultGenerator.genSuccessResult();
		
	}
	
	
	@Override
	public Object editState(AdvertisingResourcesDto dto) {
		String[] mediaIds = dto.getMediaIds();
		List<String> cycleaList = null;
		for (String mediaId : mediaIds) {
			cycleaList = advertistingReserveMapper.findCycleTimeOne(Long.valueOf(mediaId));
		}
		boolean empty = cycleaList.isEmpty();
		if (empty) {
			mapper.updateState(dto.getMediaStatus(),dto.getMediaIds());
		}else {
			List<String> findMediaCode = mapper.findMediaCode(cycleaList);
			return "媒体编号："+String.join(",", findMediaCode)+"被占用，不能删除。";
		}
		return empty?1:0;
	}
	
	
	@Override
	public List<Map<String, Object>> findAdvertising(String accessToken,AdvertisingResourcesDto dto) {
		/*TbSysUser user = basicInfoService.findErpUser(accessToken);
		int count = scheduleBasicInfoMapper.findUserRole(user.getUserCode(), MediaResourceConstant.roleCode);
		if (count==0) {
			String organCode = basicInfoMapper.findErpUserOrgan(user.getUserCode()).get("organCode");
			dto.setOrganCode(organCode);
			//StringUtils.isNotBlank(organCode)?"01".equals(organCode)?null:organCode:null
		}*/
		return mapper.findAdvertising(dto);
	}
	
	
	@Override
	public Result exportIn(String accessToken,Result rt,MultipartFile file) throws IOException {
		
		List<ArrayList<String>> data = ExcelUtil.importData(file,0);//这里还未定
		if (data.isEmpty()) {
			return rt.setResultCode(ResultCode.FAIL).setResultMsg("文件为空").setData(false);
		}
		String[] title = {"[区域编号","物业区域","项目编号","物业项目","媒体类型","媒体形式","地理位置","媒体位置2","媒体规格(宽mm)","媒体规格(高mm)","单位","使用状态]"};
		String[] split = data.get(0).toString().split(",");
		for (int i = 0; i < title.length; i++) {
			if (!title[i].equals(split[i].trim())) {
				/*System.out.println(title[i]);
				System.out.println(split[i]);*/
				return rt.setResultCode(ResultCode.FAIL).setResultMsg("标题错误，请下载模板文件。").setData(false);
			}
		}
		
		data.remove(0);
		if (data.isEmpty()) {
			return rt.setResultCode(ResultCode.FAIL).setResultMsg("文件为空").setData(false);
		}
		
		TbSysUser user = basicInfoService.findErpUser(accessToken);
		List<BasicInfoDto> dtoList = scheduleBasicInfoMapper.findAllCommId();
		List<String> commIdList = dtoList.stream().map(BasicInfoDto::getCommId).collect(Collectors.toList());
		Map<String, String> mediaType = getMediaType();
		Map<Integer, String> mediaForm = MediaResourceConstant.MEDIA_FORM.DES;

		StringBuffer overAllStr = new StringBuffer();
		
		Map<Integer, String> errorMsgMap = new HashMap<>();

		List<AdvertisingResources> successList = new ArrayList<>();
		
		for (int i = 0; i < data.size(); i++) {
			ArrayList<String> rows = data.get(i);
			
			String commId = rows.get(2).trim();	//项目编号
			String type = rows.get(4).trim();
			String from = rows.get(5).trim();
			String sietOne = rows.get(6).trim();
			String sietTwo = rows.get(7).trim();
			String width = rows.get(8).trim();
			String height = rows.get(9).trim();	
			String unit = rows.get(10).trim();	
			String status = rows.get(11).trim();	
			
			overAllStr.append(StringUtils.isNotBlank(commId)?"":"项目编号为空，");
			if (StringUtils.isEmpty(overAllStr)) {
				boolean verifyComm = commIdList.contains(commId);
				overAllStr.append(verifyComm?"":"项目编号不存在，");
			}
			overAllStr.append(StringUtils.isNotBlank(status)?"":"状态为空，");
			overAllStr.append(StringUtils.isNotBlank(sietOne)?"":"地理位置为空，");
			overAllStr.append(StringUtils.isNotBlank(type)?"":"媒体类型为空，");
			overAllStr.append(StringUtils.isNotBlank(from)?"":"媒体形式为空，");
			
			try {
				Integer.parseInt(width);
			} catch (Exception e) {
				overAllStr.append("媒体规格(宽mm)类型不正确，请填写数字且最大值不能超过:2147483647，");
			}
			
			try {
				Integer.parseInt(height);
			} catch (Exception e) {
				overAllStr.append("媒体规格(高mm)类型不正确，请填写数字且最大值不能超过:2147483647，");
			}
			
			AdvertisingResources po = new AdvertisingResources();
			try {
				po.setMediaType(mediaType.entrySet().stream().filter(t->t.getValue().equals(type)).findFirst().get().getKey());
			} catch (Exception e) {
				overAllStr.append("媒体类型不存在，");
			}
			
			try {
				po.setMediaForm(String.valueOf(mediaForm.entrySet().stream().filter(f->f.getValue().equals(from)).findAny().get().getKey()));
			} catch (Exception e) {
				overAllStr.append("媒体形式不存在，");
			}
			
			try {
				List<MediaUnit> list = findMediaForm(po.getMediaType());
				Map<String, MediaUnit> map = list.stream().collect(Collectors.toMap(MediaUnit::getFrom, MediaUnit->MediaUnit));
				MediaUnit mediaUnit = map.get(from);
				if (mediaUnit == null) {
					overAllStr.append("媒体类型与媒体形式不匹配，");
				}else {

					if("3".equals(po.getMediaType())) {
						//道旗广告
						overAllStr.append(checkInputSiteTwo(1000,"号杆","r",sietTwo)?"":"媒体形式与媒体位置2不匹配，");
					}else if("7".equals(po.getMediaType()) && ("0".equals(po.getMediaForm()) || "1".equals(po.getMediaForm()))) {
						overAllStr.append(checkInputSiteTwo(100,"广告位","l",sietTwo)?"":"媒体形式与媒体位置2不匹配，");
					}else {
						boolean contains = Stream.of(mediaUnit.getSiteTwoSelect()).collect(Collectors.toList()).contains(sietTwo);
						overAllStr.append(contains?"":"媒体形式与媒体位置2不匹配，");
					}
					overAllStr.append(mediaUnit.getUnit().equals(unit)?"":"媒体形式与单位不匹配，");
					
				}
				po.setMediaPriceUnit(mediaUnit.getMediaPriceUnit());
			} catch (Exception e) {
				overAllStr.append("媒体类型与媒体形式不匹配，");
			}
			
			
			if (StringUtils.isNotBlank(overAllStr)) {
				errorMsgMap.put(i+2, overAllStr.toString());
				overAllStr.setLength(0);
				continue;
			}
			
			
			BasicInfoDto dto = dtoList.stream().filter(c->c.getCommId().equals(commId)).findFirst().get();
			po.setMediaId(SnowflakeUtil.INSTANCE.getId());
			po.setCommId(commId);
			po.setCommName(dto.getCommName());
			po.setOrganCode(dto.getOrganCode());
			po.setOrganName(dto.getOrganName());
			
			String str = PinYinUtils.getHanziInitials(type.substring(0, 2));
			po.setMediaCode(commId+"-"+str);
			
			po.setSiteOne(sietOne);
			po.setSiteTwo(sietTwo);
			po.setMediaWidth(Integer.parseInt(width));
			po.setMediaHeight(Integer.parseInt(height));
			po.setMediaUnit(unit);
			po.setMediaStatus(status.equals("启用")?0:1);
			po.setCreateBy(user.getUserCode());
			po.setCreateByName(user.getUserName());
			po.setCreateTime(new Date());
			successList.add(po);
		}
		
		overAllStr.setLength(0);
		overAllStr.append("第");
		
		if (!CollectionUtils.isEmpty(errorMsgMap)) {
			List<String> resultErrorMsg = new ArrayList<>();
			errorMsgMap.forEach((i,v)->{
				resultErrorMsg.add(overAllStr.append(i+"行：").append(v.substring(0, v.length()-1)).toString());
				overAllStr.setLength(1);
			});
			return rt.setResultCode(ResultCode.FAIL).setResultMsg("导入失败").setData(resultErrorMsg);
		}
		
		List<String> insertFailList = new ArrayList<>();
		int accumulative = 1;
		String zero = "0";
		try {
			for (int j = 0; j < successList.size(); j++) {
				accumulative++;
				AdvertisingResources po = successList.get(j);
				//long strat = System.currentTimeMillis();
				int len = mapper.verifyLocation(po.getCommId(),po.getSiteOne(),po.getSiteTwo());
				if (len==0) {
					String str = mapper.findNextCode2(po.getMediaCode());
					len = str.length();
					if (len<3) {
						len = 3 - len;
						for (int k = 0; k < len; k++) {
							str=zero+str;
						}
					}
					po.setMediaCode(po.getMediaCode()+str);
					mapper.insertCallBack(po);
					/*long ends = System.currentTimeMillis();
					System.err.println(" ================================== "+(ends-strat)/1000);*/
				}else {
					insertFailList.add(overAllStr.append(accumulative).append("行资源资源重复，新增失败。").toString());
					overAllStr.setLength(1);
				}
			}
		} catch (Exception e) {
			insertFailList.add(overAllStr.append(accumulative).append("行新增失败").toString());
			overAllStr.setLength(1);
			e.printStackTrace();
		}
		
		return rt.setResultCode(ResultCode.OK).setResultMsg("导入"+(successList.size() - insertFailList.size())+"个数据成功")
				.setData(CollectionUtils.isEmpty(insertFailList)?null:insertFailList);
	}
	
	
  

	@Override
	public Result singleUpload(Result rt,AdvertisingResourcesDto dto,MultipartFile file) throws IOException {
		
		if (file.getSize() > 5242880) {
			return rt.setResultCode(ResultCode.FAIL).setResultMsg("文件大小限制在5MB内").setData(false);
		}
		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 = null;
			if (StringUtils.isNotBlank(dto.getMediaId())) {
				List<String> cycleaList = advertistingReserveMapper.findCycleTimeOne(Long.valueOf(dto.getMediaId()));
				if (!cycleaList.isEmpty()) {
					return rt.setResultCode(ResultCode.FAIL).setResultMsg("资源被占用，不能修改！");
				}
				boolean orNot = directoryMapper.findFileMeans(dto.getMediaId(),interim) == 0 ? true:false;
				AdvertisingFileDirectory directory = null;
				if (orNot) {
					url = ossUtils.uploadFile(fileRealName, file.getInputStream());
					directory = new AdvertisingFileDirectory(interim,fileRealName,url,dto.getMediaId());
					int callBack = directoryMapper.insertCallBack(directory);
					//System.err.println(callBack);
				}
				return rt.setResultCode(orNot?ResultCode.OK:ResultCode.FAIL).setResultMsg(orNot?AdvertisingFileDirectory.SUCESS:AdvertisingFileDirectory.ISEXIST).setData(orNot?directory:false);
			}else {//新增是无主键
				url = ossUtils.uploadFile(fileRealName, file.getInputStream());
				AdvertisingFileDirectory directory = new AdvertisingFileDirectory(interim, fileRealName, url, "0");
				directoryMapper.insertCallBack(directory);
				return rt.setResultCode(ResultCode.OK).setResultMsg(AdvertisingFileDirectory.SUCESS).setData(directory);
			}
		}
		
		return rt.setResultCode(ResultCode.FAIL).setResultMsg("上传附件只能是 JPG 、PNG 、JPEG 、BMP、PSD格式!").setData(false);
		
	}

	@Override
	public List<Map<String,Object>> viewAdjunct(AdvertisingResourcesDto dto) {
		return directoryMapper.viewAdjunctByAdvertusubgId(dto.getMediaId());
	}
	

	private Map<String, String> getMediaType(){
		Map<String, String> map = new HashMap<>();
		map.put("0","其他广告");
		map.put("1","电梯内广告");
		map.put("2","道闸广告");
		map.put("3","道旗广告");
		map.put("4","大牌广告");
		map.put("5","灯箱广告");
		map.put("6","电梯外广告");
		map.put("7","步梯楼广告");
		return map;
	}

	@Override
	public String getCommAddress(AdvertisingResourcesDto dto) {
		return scheduleBasicInfoMapper.getCommAddress(dto);
	}

	@Override
	public boolean delFile(Map<String, String> map) {
		String mediaId = map.get("mediaId");
		List<String> cycleaList = advertistingReserveMapper.findCycleTimeOne(Long.valueOf(mediaId));
		if (!cycleaList.isEmpty()) {
			return false;
		}
		String fileRealName = map.get("fileRealName");
		String ids = map.get("ids");
		if (StringUtils.isEmpty(fileRealName)) {
			throw new ServiceException("文件名称为空");
		}
		if (StringUtils.isEmpty(ids)) {
			throw new ServiceException("文件标识为空");
		}
		ossUtils.delFile(fileRealName);
		int delCallBack = directoryMapper.deleteByIds(ids);
		return delCallBack==1?true:false;
	}

	@Override
	public Map<Integer, String> findMediaType() {
		Map<Integer, String> map = MediaResourceConstant.MEDIA_TYPE.DES;
		return map;
	}

	@Override
	public List<MediaUnit> findMediaForm(String key) {
		List<MediaUnit> list = new ArrayList<>();
		if ("1".equals(key)) {//电梯内广告
			list.add(new MediaUnit("0","框架海报","幅","元/幅/月",new String[] {"左","中","右","左1","左2","中1","中2","右1","右2"},false));
			list.add(new MediaUnit("1","电子屏","台","元/台/月",new String[] {"左前门","右前门","左前门1","左前门2","右前门1","右前门2"},false));
			list.add(new MediaUnit("20","梯内门贴","门","元/门/月",new String[] {"中间","整门"},false));
			list.add(new MediaUnit("2","梯内投影","台","元/台/月",new String[] {"内门","地面"},false));
		}
		if ("6".equals(key)) {//电梯外广告
			list.add(new MediaUnit("3", "梯外门贴","门","元/门/月",new String[] {"中间","整门"},false));
			list.add(new MediaUnit("0", "框架海报","幅","元/幅/月",new String[] {"广告位1","广告位2","广告位3","广告位4","广告位5","广告位6","广告位7","广告位8","广告位9","广告位10"},false));
			list.add(new MediaUnit("4", "数码海报","台","元/台/月",new String[] {"广告位1","广告位2","广告位3","广告位4","广告位5","广告位6"},false));
			list.add(new MediaUnit("5", "LCD电视","台","元/台/月",new String[] {"广告位1","广告位2","广告位3","广告位4","广告位5","广告位6"},false));
			list.add(new MediaUnit("21","梯外投影","台","元/台/月",new String[] {"外门","地面"},false));
			list.add(new MediaUnit("31","立式广告机","台","元/台/月",new String[] {"广告位1","广告位2","广告位3","广告位4","广告位5","广告位6"},false));
			
		}
		if ("2".equals(key)) {//道闸广告
			list.add(new MediaUnit("6","翻页道闸","杆","元/杆/月",new String[] {"入口1","入口2","入口3","入口4","入口5","入口6","出口1","出口2","出口3","出口4","出口5","出口6"},false));
			list.add(new MediaUnit("7","横杆道闸","杆","元/杆/月",new String[] {"入口1","入口2","入口3","入口4","入口5","入口6","出口1","出口2","出口3","出口4","出口5","出口6"},false));
		}
		if ("3".equals(key)) {//道旗广告
			list.add(new MediaUnit("8","单边道旗","杆","元/杆/月",new String[] {"1号杆","2号杆","3号杆","4号杆","5号杆","6号杆","7号杆","8号杆","9号杆","10号杆"},true));//需要到1000杆
			list.add(new MediaUnit("9","双边道旗","杆","元/杆/月",new String[] {"1号杆","2号杆","3号杆","4号杆","5号杆","6号杆","7号杆","8号杆","9号杆","10号杆"},true));//需要到1000杆
		}
		if ("4".equals(key)) {//大牌广告
			list.add(new MediaUnit("10","地面大牌","块","元/平米/月",new String[] {""},false));
			list.add(new MediaUnit("11","墙体大牌","块","元/平米/月",new String[] {""},false));
			list.add(new MediaUnit("12","楼顶大牌","块","元/平米/月",new String[] {""},false));
			list.add(new MediaUnit("13","三面翻","块","元/平米/月",new String[] {"广告位1","广告位2","广告位3"},false));
			list.add(new MediaUnit("24","户外LED","块","元/平米/月",new String[] {""},false));
		}
		if ("5".equals(key)) {//灯箱广告
			list.add(new MediaUnit("14","户外滚动灯箱","面","元/面/月",new String[] {"广告位1","广告位2","广告位3","广告位4","广告位5","广告位6"},false));
			list.add(new MediaUnit("15","户外固定灯箱","台","元/平米/月",new String[] {""},false));
			list.add(new MediaUnit("16","室内固定灯箱","台","元/平米/月",new String[] {""},false));
			list.add(new MediaUnit("25","门禁灯箱","门","元/门/月",new String[] {"广告位1","广告位2"},false));
		}
		if ("0".equals(key)) {//其他广告
			list.add(new MediaUnit("17","公交亭海报","张","元/张/月",new String[] {"广告位1","广告位2","广告位3","广告位4","广告位5","广告位6","广告位7","广告位8","广告位9","广告位10"},false));
			list.add(new MediaUnit("23","公告栏海报","张","元/张/月",new String[] {"广告位1","广告位2","广告位3","广告位4","广告位5","广告位6","广告位7","广告位8","广告位9","广告位10"},false));
			list.add(new MediaUnit("32","门岗亭海报","张","元/张/月",new String[] {"广告位1","广告位2","广告位3","广告位4","广告位5","广告位6","广告位7","广告位8","广告位9","广告位10"},false));
			list.add(new MediaUnit("26","横幅","条","元/条/月",new String[] {""},false));
			list.add(new MediaUnit("27","X展架","个","元/个/月",new String[] {""},false));
			list.add(new MediaUnit("18","易拉宝","个","元/个/月",new String[] {""},false));
			list.add(new MediaUnit("28","快递柜广告","台","元/台/月",new String[] {""},false));
			list.add(new MediaUnit("33","饮水机体广告","台","元/台/月",new String[] {""},false));
			list.add(new MediaUnit("29","地贴/墙贴/玻璃贴","张","元/平米/月",new String[] {""},false));
			
			
			
		}
		if ("7".equals(key)) {//步梯楼广告
			list.add(new MediaUnit("0","框架海报","幅","元/幅/月",new String[] {"广告位1","广告位2","广告位3","广告位4","广告位5","广告位6","广告位7","广告位8","广告位9","广告位10"},true));//广告位100
			list.add(new MediaUnit("1","电子屏","台","元/台/月",new String[] {"广告位1","广告位2","广告位3","广告位4","广告位5","广告位6","广告位7","广告位8","广告位9","广告位10"},true));//广告位100
			list.add(new MediaUnit("16","室内固定灯箱","台","元/平米/月",new String[] {"广告位1","广告位2","广告位3","广告位4","广告位5"},false));
			list.add(new MediaUnit("30","地贴/墙贴/玻璃贴","张","元/平米/月",new String[] {""},false));
		}
		return list;
	}

	
}
