Browse Source

更改素材尺寸为比例形式

Signed-off-by: jiapeng.dong <jiapeng.dong@cloudcross.com>
jiapeng.dong 9 years ago
parent
commit
7743970f88

+ 21 - 11
src/main/java/com/cloudcross/ssp/model/BannerTemplate.java

@@ -28,12 +28,14 @@ public class BannerTemplate {
 	private Long width;
 	//创意高度
 	private Long height;
+	//比率宽
+	private Long rwidth;
+	//比率高
+	private Long rheight;
 	//状态
 	private Integer status;
 	//上传时间
 	private Date updated;
-	//创建banner对象
-	AuditBanner banner;
 	public Long getId() {
 		return id;
 	}
@@ -94,6 +96,18 @@ public class BannerTemplate {
 	public void setHeight(Long height) {
 		this.height = height;
 	}
+	public Long getRwidth() {
+		return rwidth;
+	}
+	public void setRwidth(Long rwidth) {
+		this.rwidth = rwidth;
+	}
+	public Long getRheight() {
+		return rheight;
+	}
+	public void setRheight(Long rheight) {
+		this.rheight = rheight;
+	}
 	public Integer getStatus() {
 		return status;
 	}
@@ -106,20 +120,16 @@ public class BannerTemplate {
 	public void setUpdated(Date updated) {
 		this.updated = updated;
 	}
-	public AuditBanner getBanner() {
-		return banner;
-	}
-	public void setBanner(AuditBanner banner) {
-		this.banner = banner;
-	}
 	@Override
 	public String toString() {
 		return "BannerTemplate [id=" + id + ", agentId=" + agentId
 				+ ", advertiserId=" + advertiserId + ", operatorId="
 				+ operatorId + ", name=" + name + ", path=" + path
 				+ ", pathSmall=" + pathSmall + ", type=" + type + ", width="
-				+ width + ", height=" + height + ", status=" + status
-				+ ", updated=" + updated + ", banner=" + banner + "]";
+				+ width + ", height=" + height + ", rwidth=" + rwidth
+				+ ", rheight=" + rheight + ", status=" + status + ", updated="
+				+ updated + "]";
 	}
-
+	
+	
 }

+ 18 - 1
src/main/java/com/cloudcross/ssp/model/Size.java

@@ -12,6 +12,10 @@ public final class Size {
 	private Long width;
 	//模版尺寸的高度
 	private Long height;
+	//模板比率宽
+	private Long rwidth;
+	//模板比率宽
+	private Long rheight;
 	public Long getId() {
 		return id;
 	}
@@ -30,9 +34,22 @@ public final class Size {
 	public void setHeight(Long height) {
 		this.height = height;
 	}
+	public Long getRwidth() {
+		return rwidth;
+	}
+	public void setRwidth(Long rwidth) {
+		this.rwidth = rwidth;
+	}
+	public Long getRheight() {
+		return rheight;
+	}
+	public void setRheight(Long rheight) {
+		this.rheight = rheight;
+	}
 	@Override
 	public String toString() {
 		return "Size [id=" + id + ", width=" + width + ", height=" + height
-				+ "]";
+				+ ", rwidth=" + rwidth + ", rheight=" + rheight + "]";
 	}
+	
 }

+ 22 - 18
src/main/java/com/cloudcross/ssp/model/mapper/banner-template.sql.xml

@@ -12,6 +12,8 @@
 		type,
 		width,
 		height,
+		rwidth,
+		rheight,
 		t_banner_template.status,
 		t_banner_template.updated
 	</sql>
@@ -24,6 +26,8 @@
 		type,
 		width,
 		height,
+		rwidth,
+		rheight,
 		status,
 		updated
 	</sql>
@@ -67,11 +71,11 @@
 			<if test="type != null">
 				and type=#{type}
 			</if>
-			<if test="height != null">
-				and height=#{height}
+			<if test="rheight != null">
+				and rheight=#{rheight}
 			</if>
-			<if test="width != null">
-				and width=#{width}
+			<if test="rwidth != null">
+				and rwidth=#{rwidth}
 			</if>
 			<if test="value != null">
 				and name like #{value}
@@ -246,11 +250,11 @@ where banner_template_id in
 			<if test="type != null">
 				and type=#{type}
 			</if>
-			<if test="height != null">
-				and height=#{height}
+			<if test="rheight != null">
+				and rheight=#{rheight}
 			</if>
-			<if test="width != null">
-				and width=#{width}
+			<if test="rwidth != null">
+				and rwidth=#{rwidth}
 			</if>
 			<if test="advertiserId != null">
 				and advertiser_id = #{advertiserId}
@@ -306,11 +310,11 @@ where banner_template_id in
 			<if test="type != null">
 				and type=#{type}
 			</if>
-			<if test="height != null">
-				and height=#{height}
+			<if test="rheight != null">
+				and rheight=#{rheight}
 			</if>
-			<if test="width != null">
-				and width=#{width}
+			<if test="rwidth != null">
+				and rwidth=#{rwidth}
 			</if>
 			<if test="advertiserId != null">
 				and advertiser_id = #{advertiserId}
@@ -366,11 +370,11 @@ where banner_template_id in
 			<if test="type != null">
 				and type = #{type}
 			</if>
-			<if test="height != null">
-				and height = #{height}
+			<if test="rheight != null">
+				and rheight = #{rheight}
 			</if>
-			<if test="width != null">
-				and width = #{width}
+			<if test="rwidth != null">
+				and rwidth = #{rwidth}
 			</if>
 			<if test="value != null">
 				and name like #{value}
@@ -396,8 +400,8 @@ where banner_template_id in
 	</select>
 	<insert id="addBannerTemplate" parameterType="com.cloudcross.ssp.model.BannerTemplate" useGeneratedKeys="true"
         keyProperty="id">
-insert into t_banner_template (agent_id,advertiser_id,operator_id,name,path,path_small,type,width,height,status,updated) 
-values(#{agentId},#{advertiserId},#{operatorId},#{name},#{path},#{pathSmall},#{type},#{width},#{height},#{status},#{updated})	
+insert into t_banner_template (agent_id,advertiser_id,operator_id,name,path,path_small,type,width,height,rwidth,rheight,status,updated) 
+values(#{agentId},#{advertiserId},#{operatorId},#{name},#{path},#{pathSmall},#{type},#{width},#{height},#{rwidth},#{rheight},#{status},#{updated})	
 
 </insert>
 	

+ 5 - 1
src/main/java/com/cloudcross/ssp/model/mapper/banner.sql.xml

@@ -29,6 +29,8 @@
 		b.type as type,
 		b.width as width,
 		b.height as height,
+		b.rwidth as rwidth,
+		b.rheight as rheight,
 		b.status as status,
 		b.updated as updated	
 	</sql>
@@ -59,7 +61,9 @@
     <result property="pathSmall" column="pathSmall"/>
    <result property="type" column="type"/>
    <result property="width" column="width"/> 
-   <result property="height" column="height"/> 
+   <result property="height" column="height"/>
+   <result property="rwidth" column="rwidth"/> 
+   <result property="rheight" column="rheight"/> 
    <result property="status" column="status"/>   
    <result property="updated" column="updated"/>     
 </resultMap>  

+ 2 - 2
src/main/java/com/cloudcross/ssp/model/mapper/size.sql.xml

@@ -2,12 +2,12 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
 <mapper namespace="sizeSqlMapper">
 	<sql id="base_column">
-		id,width,height
+		id,width,height,rwidth,rheight
 	</sql>
 
 	<select id="findAllSize"  resultType="com.cloudcross.ssp.model.Size">
 		select <include refid="base_column"/> 
-		from t_size order by id desc
+		from t_size group by rwidth,rheight order by id desc
 	</select>
 
 	<select id="findSize" parameterType="int" resultType="com.cloudcross.ssp.model.Size">

+ 48 - 90
src/main/java/com/cloudcross/ssp/service/impl/BannerTemplateService.java

@@ -181,46 +181,42 @@ public class BannerTemplateService extends SimpleController implements IBannerTe
 		return true;
 	}
 	
-	//@wanfu
-		@Override
-		public int countByParams2(Map<String, Object> paramMap) {
+	
+	@Override
+	public int countByParams2(Map<String, Object> paramMap) {
 			//这里的搜索只是对名称进行搜索
 			String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
 			paramMap.put("key", paramMap.get("searchKey"));
 			paramMap.put("value", searchValue);
-			if(paramMap.get("width") == ""){ paramMap.put("width", null); }
-			if(paramMap.get("height") == ""){ paramMap.put("height", null); }
-			if(paramMap.get("type") == ""){ paramMap.put("type", null); }
-			if(paramMap.get("status") == ""){ paramMap.put("status", null); }
+			if(!paramMap.containsKey("rwidth")||(paramMap.get("rwidth")).equals("")){paramMap.put("rwidth", null); }
+			if(!paramMap.containsKey("rheight")||(paramMap.get("rheight")).equals("")){paramMap.put("rheight", null); }
+			if(!paramMap.containsKey("type")||(paramMap.get("type")).equals("")){ paramMap.put("type", null); }
+			if(!paramMap.containsKey("status")||(paramMap.get("status")).equals("")){ paramMap.put("status", null); }
+			if(!paramMap.containsKey("advertiserId")||(paramMap.get("advertiserId")).equals("")||(paramMap.get("advertiserId")).equals("-1")){
+				paramMap.put("advertiserId", null);
+			}
 			return myBatisDao.get("bannerTemplateSqlMapper.countByParams2advertiser", paramMap);
 		}
-		public int countByParams2Operator(Map<String, Object> paramMap) {
+		
+	public int countByParams2Operator(Map<String, Object> paramMap) {
 			//这里的搜索只是对名称进行搜索
 			String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
 			paramMap.put("key", paramMap.get("searchKey"));
 			paramMap.put("value", searchValue);
 			return myBatisDao.get("bannerTemplateSqlMapper.countByParams2operator", paramMap);
 		}
-		//@wanfu
-		@Override
-		public List<BannerTemplate> findByParams2(Map<String, Object> paramMap, Pager pager) {
+		
+	@Override
+	public List<BannerTemplate> findByParams2(Map<String, Object> paramMap, Pager pager) {
 			//这里的搜索只是对名称进行搜索
 			String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
 			paramMap.put("key", paramMap.get("searchKey"));
 			paramMap.put("value", searchValue);
 			paramMap.put("pager", pager);
-			if(paramMap.get("width") == ""){ paramMap.put("width", null); }
-			if(paramMap.get("height") == ""){ paramMap.put("height", null); }
-			if(paramMap.get("type") == ""){ paramMap.put("type", null); }
-			if(paramMap.get("status") == ""){ paramMap.put("status", null); }
-			if(paramMap.get("advertiserId") == ""){ paramMap.put("advertiserId", null); }
-//			if(paramMap.get("orderId") == ""){ paramMap.put("orderId", null); }
-//			if(paramMap.get("campaignId") == ""){ paramMap.put("campaignId", null); }
-//			if(paramMap.get("adgroupId") == ""){ paramMap.put("adgroupId", null); }
 			return myBatisDao.getList("bannerTemplateSqlMapper.findByParams2advertiser", paramMap);
 		}
 
-		public List<BannerTemplate> findByParams2Operator(Map<String, Object> paramMap, Pager pager) {
+	public List<BannerTemplate> findByParams2Operator(Map<String, Object> paramMap, Pager pager) {
 			//这里的搜索只是对名称进行搜索
 			String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
 			paramMap.put("key", paramMap.get("searchKey"));
@@ -230,60 +226,47 @@ public class BannerTemplateService extends SimpleController implements IBannerTe
 			return myBatisDao.getList("bannerTemplateSqlMapper.findByParams2Operator", paramMap);
 		}
 		
-		@Override
-		public int countByParams3(Map<String, Object> paramMap) {
-			String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
+	@Override
+	public int countByParams3(Map<String, Object> paramMap) {
+		String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
 			paramMap.put("key", paramMap.get("searchKey"));
 			paramMap.put("value", searchValue);
-			if(paramMap.get("height")==""||paramMap.get("width")==""){
-				paramMap.put("width", null);
-				paramMap.put("height",null);
-				
-			}else{
-				paramMap.put("width", paramMap.get("width"));
-				paramMap.put("height", paramMap.get("height"));
-				
-			}
-			if(paramMap.get("type")==""){
-					paramMap.put("type",null);
-			}else{
-				paramMap.put("type",paramMap.get("type"));
+			if(paramMap.get("rheight")==""||paramMap.get("rwidth")==""){
+				paramMap.put("rwidth", null);
+				paramMap.put("rheight",null);	
 			}
+			if(paramMap.get("type")==""){paramMap.put("type",null);}
 			return myBatisDao.get("bannerTemplateSqlMapper.countByParams3advertiser", paramMap);
 		}		
 		
-		public int countByParams3Operator(Map<String, Object> paramMap) {
-			return myBatisDao.get("operator.bannerTemplateSqlMapper.countByParams3operator", paramMap);
+	public int countByParams3Operator(Map<String, Object> paramMap) {
+			return myBatisDao.get("bannerTemplateSqlMapper.countByParams3operator", paramMap);
 		}
+		
 	@Override
-	public List<BannerTemplate> findByParams4(Map<String, Object> paramMap, Pager pager) {		paramMap.put("pager", pager);
+	public List<BannerTemplate> findByParams4(Map<String, Object> paramMap, Pager pager) {		
+		paramMap.put("pager", pager);
 	String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
 	paramMap.put("key", paramMap.get("searchKey"));
 	paramMap.put("value", searchValue);
 	paramMap.put("pager", pager);
-	if(paramMap.get("height")==""||paramMap.get("width")==""){
-		paramMap.put("width", null);
-		paramMap.put("height",null);
-		
-	}else{
-		paramMap.put("width", paramMap.get("width"));
-		paramMap.put("height", paramMap.get("height"));
-		
-	}
-	if(paramMap.get("type")==""){
-			paramMap.put("type",null);
-	}else{
-		paramMap.put("type",paramMap.get("type"));
+	if(paramMap.get("rheight")==""||paramMap.get("rwidth")==""){
+		paramMap.put("rwidth", null);
+		paramMap.put("rheight",null);	
 	}
-		return myBatisDao.getList("bannerTemplateSqlMapper.findByParams4advertiser", paramMap);
+	if(paramMap.get("type")==""){paramMap.put("type",null);}
+	
+	return myBatisDao.getList("bannerTemplateSqlMapper.findByParams4advertiser", paramMap);
 	}
+	
+	
 	public List<BannerTemplate> findByParams4Operator(Map<String, Object> paramMap, Pager pager) {
 //		//这里的搜索只是对名称进行搜索
 //		String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
 //		paramMap.put("key", paramMap.get("searchKey"));
 //		paramMap.put("value", searchValue);
 		paramMap.put("pager", pager);
-		return myBatisDao.getList("operator.bannerTemplateSqlMapper.findByParams4operator", paramMap);
+		return myBatisDao.getList("bannerTemplateSqlMapper.findByParams4operator", paramMap);
 	}
 
 	@Override
@@ -373,50 +356,25 @@ public class BannerTemplateService extends SimpleController implements IBannerTe
 			BannerTemplate bannerTemplate) {
 		//构造image图片
 
-				long max_width = 0;
-				long max_height = 0;
 				Size size = new Size();		
-				int i;
 				int n =0; 
 				//查找所有广告位
 				List<Size> sizeList = sizeService.findAllSize();
-				//取平方差
-				double suit[] = new double[sizeList.size()];
 				long _width[] = new long[sizeList.size()];
 				long _height[] = new long[sizeList.size()];
-				for ( i=0 ;i<sizeList.size();i++){
+				for ( int i=0 ;i<sizeList.size();i++){
 					size = sizeList.get(i); 
-					_width[i] = size.getWidth(); 
-					_height[i] = size.getHeight();
-					if(width<_width[i]&&height<_height[i]){
-						suit[i] =Math.sqrt(Math.abs(width-_width[i])*Math.abs(width-_width[i])+Math.abs(height-_height[i])*Math.abs(height-_height[i]));
-					}else{
-						if((width*_height[i])==(_width[i]*height)){
-							suit[i] =Math.sqrt(Math.abs(width-_width[i])*Math.abs(width-_width[i])+Math.abs(height-_height[i])*Math.abs(height-_height[i]));
-						}else{
-						suit[i]=0;
+					_width[i] = size.getRwidth(); 
+					_height[i] = size.getRheight();
+					if(width*_height[i]==height*_width[i]){
+						bannerTemplate.setWidth((long)width);
+						bannerTemplate.setHeight((long)height);
+						bannerTemplate.setRwidth(_width[i]);
+						bannerTemplate.setRheight(_height[i]);
+						return bannerTemplate;
 						}
-					}
-					
-					}
-				
-					//取最小值
-					double min=10000;
-					for (i=0;i<suit.length;i++){
-						if(suit[i]!=0){			
-							if (suit[i]<min){						
-								min = suit[i];
-								n=i;
-							}	
-						}	
-					}
-				if(min==10000){
-						bannerTemplate=null;
-					}else{
-			
-				bannerTemplate.setWidth(_width[n]);
-				bannerTemplate.setHeight(_height[n]);
-				}	
+					}				
+				bannerTemplate=null;
 				return bannerTemplate;
 	}
 	

+ 0 - 7
src/main/java/com/cloudcross/ssp/service/impl/CloneBanner.java

@@ -1,7 +0,0 @@
-package com.cloudcross.ssp.service.impl;
-
-
-
-public class CloneBanner {
-
-}

+ 28 - 73
src/main/java/com/cloudcross/ssp/web/advertiser/main/ad/BannerTemplateController.java

@@ -89,28 +89,6 @@ public class BannerTemplateController extends SimpleController {
 			noStuffixSet.add("png");
 		}
 
-	@RequestMapping
-	public String index(Model model, 
-			@RequestParam Map<String, Object> paramMap) {
-		// 查询符合条件的广告策略
-		Account loginUser = getLoginUser();
-		Long agentId = loginUser.getAgentId();
-		paramMap.put("agentId", agentId);
-		int totalRow = bannerTemplateService.countByParams2(paramMap);
-		Pager pager = new Pager();
-		pager.setPage(1);
-		pager.setTotalRow(totalRow);
-		//获取尺寸的列表
-		List<Size> sizeList = sizeService.findAllSize();
-		//获取创意的列表
-		List<BannerTemplate> bannerTemplateList = bannerTemplateService.findByParams2(paramMap, pager);
-		model.addAllAttributes(paramMap);
-		model.addAttribute("bannerTemplateList", bannerTemplateList);
-		model.addAttribute("sizeList", sizeList);
-		model.addAttribute("pager", pager);
-		return page("index");
-	}
-
 	/**
 	 * 显示list方法。
 	 * 根据创意尺寸,创意类型,状态显示相应的素材。
@@ -123,8 +101,8 @@ public class BannerTemplateController extends SimpleController {
 			//HttpServletRequest request
 			) {
 		//HttpSession session = request.getSession();
-		model.addAttribute("width", paramMap.get("width"));
-		model.addAttribute("height", paramMap.get("height"));
+		model.addAttribute("rwidth", paramMap.get("rwidth"));
+		model.addAttribute("rheight", paramMap.get("rheight"));
 		model.addAttribute("type", paramMap.get("type"));
 		model.addAttribute("status", paramMap.get("status"));
 		model.addAttribute("advertiserId",paramMap.get("advertiserId"));
@@ -218,7 +196,7 @@ public class BannerTemplateController extends SimpleController {
 	
 	@RequestMapping(value="/upload")  
 
-	public @ResponseBody String upload(Model model,HttpServletResponse response,HttpServletRequest request,Long advertiserId) throws IOException{  
+	public @ResponseBody String upload(Model model,HttpServletRequest request,Long advertiserId) throws IOException{  
 		String uploadName;
 		String resetName;
 		String fileType;
@@ -229,9 +207,6 @@ public class BannerTemplateController extends SimpleController {
 		String responseStr="null";
 		int width;
 		int height;
-		//广告位宽高
-		int _width;
-		int _height;
 		Account loginUser = getLoginUser();
 		Long agentId = loginUser.getAgentId();
 		Long operatorId = loginUser.getOperatorId();
@@ -249,7 +224,8 @@ public class BannerTemplateController extends SimpleController {
 		  for(Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) { 
 			MultipartFile file = entity.getValue();
 			BannerTemplate bannerTemplate = new BannerTemplate();
-			if(file != null){ 
+			if(file != null && file.getSize()<1024*2*1000){ 
+				System.out.println(file.getSize());
 				//取得当前上传文件的文件名称(不加路径)  
 				uploadName = file.getOriginalFilename();  
 				resetName = bannerTemplateService.resetName(uploadName);
@@ -264,16 +240,10 @@ public class BannerTemplateController extends SimpleController {
 				  
 				//如果名称不为“”,说明该文件存在,否则说明该文件不存在  
 				if(uploadName.trim() !=""){  
-
-//					//命名上传后的缩略图文件名  
-//					String fileName = "small_".concat(file.getOriginalFilename()); 
-					
-					
+		
 					//处理上传文件路径
 					path = bannerTemplateService.getLocalFilePath(resetName);
-					System.out.println(path);
-					System.out.println("qqqqqqq+==="+path);
-					
+
 					File localFile = new File(path); 
 					//上传目录不存在,则新建目录
 					if (!localFile.getParentFile().exists()){
@@ -292,8 +262,6 @@ public class BannerTemplateController extends SimpleController {
 						if(bannerTemplate==null){
 							return "图片尺寸错啦!!";
 						}
-					 _width =Integer.parseInt(bannerTemplate.getWidth().toString()) ;
-					 _height = Integer.parseInt(bannerTemplate.getHeight().toString());	
 					
 				//取上传文件父级目录
 				String absolutePath = localFile.getParentFile().getAbsolutePath();
@@ -301,19 +269,11 @@ public class BannerTemplateController extends SimpleController {
 				pathSmall = absolutePath.concat(File.separator).concat("small_").concat(resetName);
 				//生成缩略图
 				bannerTemplateService.compressPicture(localFile,pathSmall,150,60);
-				//判断是否需要缩放
-				if((width*_height)==(_width*height)){
-					//压缩文件上传路径
-					 String compressPath =absolutePath.concat(File.separator).concat("compress_").concat(resetName);
-					 //生成压缩图
-					 bannerTemplateService.compressPicture(localFile,compressPath, _width,_height);
-					//设置文件上传路径
-					 bannerTemplate.setPath(bannerTemplateService.replacePath(compressPath));
-				 }else{
-					 //设置文件上传路径
-					 bannerTemplate.setPath(bannerTemplateService.replacePath(path));
-				 }
-				responseStr="上传成功";
+				
+				 //设置文件上传路径
+				 bannerTemplate.setPath(bannerTemplateService.replacePath(path));
+				
+				
 				//设置缩略图文件路径
 				bannerTemplate.setPathSmall(bannerTemplateService.replacePath(pathSmall));
 				bannerTemplate.setName(uploadName);
@@ -325,14 +285,15 @@ public class BannerTemplateController extends SimpleController {
 			
 				//添加素材
 				bannerTemplateService.add(bannerTemplate);
-				
+				responseStr="上传成功";
 				}
+			  }else{
+				  return "图片尺寸超过2M啦";
 			  }
+			
 			}
 		 }catch(IOException e){
-						
-						responseStr="上传失败";
-						return responseStr;
+				 return "上传失败";
 			}	
 		}	
 		  return responseStr; 
@@ -341,7 +302,7 @@ public class BannerTemplateController extends SimpleController {
 	
 	@RequestMapping(value="/replace")  
 
-	public @ResponseBody String replace(Model model,HttpServletResponse response,HttpServletRequest request,Long bannerTemplateId) throws IOException{  
+	public @ResponseBody String replace(Model model,HttpServletRequest request,Long bannerTemplateId) throws IOException{  
 		String uploadName;
 		String resetName;
 		String fileType;
@@ -367,7 +328,7 @@ public class BannerTemplateController extends SimpleController {
 		//取得request中的所有文件名 
 		  for(Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) { 
 			MultipartFile file = entity.getValue();
-			if(file != null){ 
+			if(file != null && file.getSize()<1024*2*1000){ 
 				//取得当前上传文件的文件名称(不加路径)  
 				uploadName = file.getOriginalFilename();  
 				resetName = bannerTemplateService.resetName(uploadName);
@@ -397,8 +358,8 @@ public class BannerTemplateController extends SimpleController {
 					 BufferedImage image = ImageIO.read(new FileInputStream(path));
 					 width = image.getWidth();
 					 height = image.getHeight();
-					 _width =Integer.parseInt(bannerTemplate.getWidth().toString()) ;
-					 _height = Integer.parseInt(bannerTemplate.getHeight().toString());
+					 _width =Integer.parseInt(bannerTemplate.getRwidth().toString()) ;
+					 _height = Integer.parseInt(bannerTemplate.getRheight().toString());
 					//取上传文件父级目录
 					String absolutePath = localFile.getParentFile().getAbsolutePath();
 					//生成缩略图路径名
@@ -407,19 +368,13 @@ public class BannerTemplateController extends SimpleController {
 					bannerTemplateService.compressPicture(localFile,pathSmall,150,60);
 					
 					if((width*_height)==(_width*height)){
-						//压缩文件上传路径
-						 String compressPath =absolutePath.concat(File.separator).concat("compress_").concat(resetName);
-						 //生成压缩图
-						 bannerTemplateService.compressPicture(localFile,compressPath, _width,_height);
-						//设置文件上传路径
-						 bannerTemplate.setPath(bannerTemplateService.replacePath(compressPath));
+						bannerTemplate.setWidth((long)width);
+						bannerTemplate.setHeight((long)height);
 					 }else{
-						 if(width>_width||height>_height){
 							 return "图片尺寸错啦!!";
 						 }
-						 //设置文件上传路径
-						 bannerTemplate.setPath(bannerTemplateService.replacePath(path));
-					 }
+					//设置文件上传路径
+					bannerTemplate.setPath(bannerTemplateService.replacePath(path));					
 				
 					//设置缩略图文件路径
 					bannerTemplate.setPathSmall(bannerTemplateService.replacePath(pathSmall));
@@ -429,12 +384,12 @@ public class BannerTemplateController extends SimpleController {
 				bannerTemplateService.edit(bannerTemplate);
 				responseStr="上传成功";
 				}
+			  }else{
+				  return "图片尺寸超过2M啦";
 			  }
 			}
 		 }catch(IOException e){
-						
-						responseStr="上传失败";
-						return responseStr;
+				  return "上传失败";
 			}	
 		}	
 		  return responseStr; 

+ 18 - 38
src/main/java/com/cloudcross/ssp/web/advertiser/main/ad/target/AdController.java

@@ -430,9 +430,8 @@ public class AdController extends SimpleController {
 	 *文件上传
 	 * */
 	@RequestMapping("/upload")
-	public @ResponseBody String upload(HttpServletRequest request,HttpServletResponse response,Model model,Long bannerId) throws IOException{
+	public @ResponseBody String upload(HttpServletRequest request,Model model,Long bannerId) throws IOException{
 	
-	HttpSession session = request.getSession();	
 	String uploadName = null;
 	String resetName;
 	String path = null;
@@ -452,7 +451,7 @@ public class AdController extends SimpleController {
 				//获得请求文件
 				MultipartFile file = multiRequest.getFile(iter.next());
 				//判断文件是否为空
-				if(file != null){ 
+				if(file != null && file.getSize()<1024*2*1000){ 
 					
 					uploadName = file.getOriginalFilename();  
 					resetName = bannerTemplateService.resetName(uploadName);
@@ -482,19 +481,20 @@ public class AdController extends SimpleController {
 												
 						//复制文件到上传文件
 						file.transferTo(localFile);
-						if(checkPic(localFile,bannerTemplate)){
-							result = "~图片尺寸错啦!!";
-							return result;
+						if(!checkPic(localFile,bannerTemplate)){
+							//"~"为前段判定符
+							return "~图片尺寸错啦!!";
 						}
 												
 					}catch(IOException e){
 							e.printStackTrace();
-							result="~文件上传失败 ";
-							return result;
+							return "~文件上传失败 ";
 						}
 					  
 					}  			 
-				}  
+				}else{
+					  return "~图片尺寸超过2M啦";
+				  }  
 			} 
 		}
 
@@ -515,9 +515,6 @@ public class AdController extends SimpleController {
 			//图片宽高
 			int width;
 			int height;
-			//广告位宽高
-			int _width;
-			int _height;
 			//查找创意
 			Banner formerBanner = bannerService.findById(banner.getId());
 			//取模板素材
@@ -548,21 +545,12 @@ public class AdController extends SimpleController {
 				 BufferedImage image = ImageIO.read(new FileInputStream(filePath));
 				 width = image.getWidth();
 				 height = image.getHeight();
-				 _width =Integer.parseInt(bannerTemplate.getWidth().toString()) ;
-				 _height = Integer.parseInt(bannerTemplate.getHeight().toString());
+				 //设置宽高
+				 bannerTemplate.setWidth((long)width);
+				 bannerTemplate.setHeight((long)height);				 
 				 
-				 if(width>_width||height>_height){
-					//设置压缩文件上传路径
-					 String compressPath =absolutePath.concat(File.separator).concat("compress_").concat(uploadName);
-					 //生成压缩图
-					 bannerTemplateService.compressPicture(uploadFile,compressPath, _width,_height);
-					//设置文件上传路径
-					 bannerTemplate.setPath(bannerTemplateService.replacePath(compressPath));
-				 }else{
-				 
-					 //设置文件上传路径
-					 bannerTemplate.setPath(bannerTemplateService.replacePath(filePath));
-				 }
+				 //设置文件上传路径
+				 bannerTemplate.setPath(bannerTemplateService.replacePath(filePath));
 				//设置缩略图上传路径
 				bannerTemplate.setName(banner.getBannerTemplate().getName());
 				bannerTemplate.setPathSmall(bannerTemplateService.replacePath(pathSmall));
@@ -904,19 +892,11 @@ public class AdController extends SimpleController {
 		Image src = javax.imageio.ImageIO.read(localFile);	
 		long width = src.getWidth(null);
 		long height = src.getHeight(null);
-		long _width = bannerTemplate.getWidth();
-		long _height = bannerTemplate.getHeight();
-		if(width>0&&height>0){
-			if(width<=_width&&height<=_height){
-				return false;
-			}else{
-				if((width*_height)==(_width*height)){
-					return false;
-				}
-					return true;
+		long _width = bannerTemplate.getRwidth();
+		long _height = bannerTemplate.getRheight();
+		if(width*_height !=height*_width){
+			return false;
 			}	
-		
-		}
 			return true;
 	}
 	

+ 3 - 3
src/main/java/com/cloudcross/ssp/web/advertiser/main/ad/target/CloneBannerController.java

@@ -87,7 +87,7 @@ public class CloneBannerController extends SimpleController {
 
 		
 		List<Size> sizeList = sizeService.findAllSize();
-		System.out.println("size111=="+sizeList);
+		//System.out.println("size111=="+sizeList);
 		List<BannerTemplate> bannerTemplateList = bat.findByParams4(paramMap, pager);
 		LOG.debug("bannertemplate="+bannerTemplateList);
 
@@ -105,8 +105,8 @@ public class CloneBannerController extends SimpleController {
 			@RequestParam(defaultValue = "1") int page) {
 		LOG.debug("paramm111=="+paramMap);
 		Long adGroupId = Long.parseLong((String)paramMap.get("adGroupId"));
-		model.addAttribute("width",paramMap.get("width"));
-		model.addAttribute("height",paramMap.get("height"));
+		model.addAttribute("rwidth",paramMap.get("rwidth"));
+		model.addAttribute("rheight",paramMap.get("rheight"));
 		model.addAttribute("type",paramMap.get("type"));
 		// 根据广告策略名模糊统计符合条件的策略总数
 		AdGroup adGroup = adGroupService.findById(adGroupId);

+ 36 - 48
src/main/java/com/cloudcross/ssp/web/advertiser/main/ad/target/CreateBannerController.java

@@ -81,7 +81,7 @@ import com.cloudcross.ssp.common.utils.SWFHeader;
 /**
  * 创意创意列表。
  *
- * @author Dongjiapeng
+ * @author djp
  */
 @Controller
 @RequestMapping("/advertiser/main/ad/target/create-banner")
@@ -265,7 +265,7 @@ public class CreateBannerController extends SimpleController{
 	
 	@RequestMapping(value="/upload")  
 
-	public @ResponseBody String upload(Model model,HttpServletResponse response,HttpServletRequest request) throws IOException{  
+	public @ResponseBody String upload(Model model,HttpServletRequest request) throws IOException{  
 		String uploadName;
 		String resetName;
 		String fileType;
@@ -276,9 +276,6 @@ public class CreateBannerController extends SimpleController{
 		String responseStr="null";
 		int width;
 		int height;
-		//广告位宽高
-		int _width;
-		int _height;
 		Long adGroupId = 1l;
 		Account loginUser = getLoginUser();
 		Long operatorId = loginUser.getOperatorId();
@@ -296,7 +293,7 @@ public class CreateBannerController extends SimpleController{
 		  for(Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) { 
 			MultipartFile file = entity.getValue();
 			BannerTemplate bannerTemplate = new BannerTemplate();
-			if(file != null){ 
+			if(file != null && file.getSize()<1024*2*1000){ 
 				//取得当前上传文件的文件名称(不加路径)  
 				uploadName = file.getOriginalFilename();  
 				resetName = bannerTemplateService.resetName(uploadName);
@@ -331,8 +328,6 @@ public class CreateBannerController extends SimpleController{
 					if(bannerTemplate==null){
 						return "图片尺寸错啦!!";
 					}
-				 _width =Integer.parseInt(bannerTemplate.getWidth().toString()) ;
-				 _height = Integer.parseInt(bannerTemplate.getHeight().toString());	
 				 
 				//取上传文件父级目录
 				String absolutePath = localFile.getParentFile().getAbsolutePath();
@@ -341,19 +336,11 @@ public class CreateBannerController extends SimpleController{
 				//生成缩略图
 				bannerTemplateService.compressPicture(localFile,pathSmall,150,60);
 				//判断是否需要缩放
-				if((width*_height)==(_width*height)){
-					//压缩文件上传路径
-					 String compressPath =absolutePath.concat(File.separator).concat("compress_").concat(resetName);
-					 //生成压缩图
-					 bannerTemplateService.compressPicture(localFile,compressPath, _width,_height);
-					//设置文件上传路径
-					 bannerTemplate.setPath(bannerTemplateService.replacePath(compressPath));
-				 }else{
-					 //设置文件上传路径
-					 bannerTemplate.setPath(bannerTemplateService.replacePath(path));
-				 }
+				
+				 //设置文件上传路径
+				 bannerTemplate.setPath(bannerTemplateService.replacePath(path));
 
-				responseStr="文件上传成功";
+				
 				//保存缩略图路径
 				bannerTemplate.setPathSmall(bannerTemplateService.replacePath(pathSmall));	
 				adGroupId =Long.parseLong(ids[0]);
@@ -391,39 +378,40 @@ public class CreateBannerController extends SimpleController{
 				banner.setVisitAddress("visitAddress");
 				banner.setClickAddress("clickAddress");
 				banner.setImpressionAddress("impressionAddress");
-				//添加创意,如果添加成功则添加新增日志
-				if(bannerService.add(banner)) {
-					Log log = new Log();
-					//对应模块,这里应该是投放模块
-					log.setModule("Ad");
-					//对应的表名,这里是t_adgroup
-					log.setTableName("t_banner");
-					//对应的投放id
-					log.setRecordId(banner.getId());
-					//对应的操作类型
-					log.setActionType("新增");
-					//变更详情
-					log.setAction("新增了创意:" + bannerTemplate.getName());
-					log.setActionTime("100");
-					log.setAccountId(new Long(getLoginUser().getId()));
-					log.setUserIp(Common.toIpAddr(request));
-					log.setAccountName(getLoginUser().getAccountName());
-					logService.add(log);
-					
-				}
+				boolean judge = bannerService.add(banner); 
 				
-						}
+				//添加创意,如果添加成功则添加新增日志
+					if(judge) {
+						responseStr="文件上传成功";
+						Log log = new Log();
+						//对应模块,这里应该是投放模块
+						log.setModule("Ad");
+						//对应的表名,这里是t_adgroup
+						log.setTableName("t_banner");
+						//对应的投放id
+						log.setRecordId(banner.getId());
+						//对应的操作类型
+						log.setActionType("新增");
+						//变更详情
+						log.setAction("新增了创意:" + bannerTemplate.getName());
+						log.setActionTime("100");
+						log.setAccountId(new Long(getLoginUser().getId()));
+						log.setUserIp(Common.toIpAddr(request));
+						log.setAccountName(getLoginUser().getAccountName());
+						logService.add(log);		
 					}
 				}
-			}catch(IOException e){
-						
-						responseStr="上传失败";
-						return responseStr;
-			}
-			
+			}else{
+						  return "图片尺寸超过2M啦";
+				 }
 		}
-				return responseStr;  
+	}catch(IOException e){
+			return "上传失败";
+						}
+			
 	}
+			return responseStr;  
+}
 
 	
 }

+ 3 - 3
src/main/webapp/WEB-INF/pages/advertiser/main/ad/banner-template/list.ftl

@@ -24,8 +24,8 @@
  			</div>
  			<form id="myform" action="${ctx}/advertiser/main/ad/banner-template/list" method="post">
  				<input type="hidden" id="status" name="status" value="${status!}"/>
- 				<input type="hidden" id="width" name="width" value="${width!}"/>
-				<input type="hidden" id="height" name="height" value="${height!}"/>
+ 				<input type="hidden" id="rwidth" name="rwidth" value="${rwidth!}"/>
+				<input type="hidden" id="rheight" name="rheight" value="${rheight!}"/>
 				<input type="hidden" id="type" name="type" value="${type!}"/>
 				<input type="hidden" id="size" name="size" value="${size!}"/>
  				<div id="selectuls">
@@ -44,7 +44,7 @@
 						<a value="">全部</a>
 						<#if sizeList ??>
 						<#list sizeList as size>	
-	                	<a value="${size.width!}X${size.height!}">${size.width!}X${size.height!}</a>
+	                	<a value="${size.rwidth!}:${size.rheight!}">${size.rwidth!}:${size.rheight!}</a>
 						</#list>
 						</#if>
 					</div>

+ 3 - 3
src/main/webapp/WEB-INF/pages/advertiser/main/ad/target/clone-banner/index.ftl

@@ -10,8 +10,8 @@
    		<div id="content">
    			<p id="cloneListP">从创意中心选择</p>
  			<form id="myform" action="${ctx}/advertiser/main/ad/target/clone-banner?adGroupId=${adGroupId!}" method="post">
- 				<input type="hidden" id="width" name="width" value="${width!}"/>
-				<input type="hidden" id="height" name="height" value="${height!}"/>
+ 				<input type="hidden" id="rwidth" name="rwidth" value="${rwidth!}"/>
+				<input type="hidden" id="rheight" name="rheight" value="${rheight!}"/>
 				<input type="hidden" id="type" name="type" value="${type!}"/>
 				<input type="hidden" id="size" name="size" value="${size!}"/>
 				<input type="hidden" id="adGroupId" name="adGroupId" value="${adGroupId!}"/>
@@ -21,7 +21,7 @@
 						<a value="">全部</a>
 						<#if sizeList ??>
 						<#list sizeList as size>	
-	                	<a value="${size.width!}X${size.height!}">${size.width!}X${size.height!}</a>
+	                	<a value="${size.rwidth!}:${size.rheight!}">${size.rwidth!}:${size.rheight!}</a>
 						</#list>
 						</#if>
 					</div>

+ 6 - 6
src/main/webapp/assets/js/advertiser/adBanner.js

@@ -83,7 +83,7 @@ $(document).ready(function(){
 				if(path.indexOf("~") < 0){
 					var file_name = path.split("--")[path.split("--").length-1];
 					var file_path = path.split("--")[path.split("--").length-2];
-					alert(file_name);
+					//alert(file_name);
 					//alert(file_path);
 					$("#bannerTemplateName").val(file_name);
 					$("#bannerTemplateName1").val(file_name); 
@@ -135,12 +135,12 @@ $(document).ready(function(){
 	$("#selectBar_size a").click(function(){
 		$("#size").val($(this).attr("value"));
 		if($(this).attr("value") != ""){
-			var _size = $(this).attr("value").split('X',2);
-			$("#width").val(_size[0]);
-			$("#height").val(_size[1]);
+			var _size = $(this).attr("value").split(':',2);
+			$("#rwidth").val(_size[0]);
+			$("#rheight").val(_size[1]);
 		}else{
-			$("#width").val("");
-			$("#height").val("");
+			$("#rwidth").val("");
+			$("#rheight").val("");
 		}
  		refreshData();
  	});

+ 6 - 6
src/main/webapp/assets/js/advertiser/banner.js

@@ -1,7 +1,7 @@
 $(document).ready(function(){
 	var ctx = $("#ctx").val();//获取服务器地址
 	
-	/***************************    订单列表页    ***************************/
+	/***************************    创意列表页    ***************************/
 	
 	$("#all-btn-upload").click(function(){
 		if($("#advertiserId").val() == "" || $("#advertiserId").val() == -1){
@@ -32,12 +32,12 @@ $(document).ready(function(){
 	$("#selectBar_size a").click(function(){
 		$("#size").val($(this).attr("value"));
 		if($(this).attr("value") != ""){
-			var _size = $(this).attr("value").split('X',2);
-			$("#width").val(_size[0]);
-			$("#height").val(_size[1]);
+			var _size = $(this).attr("value").split(':',2);
+			$("#rwidth").val(_size[0]);
+			$("#rheight").val(_size[1]);
 		}else{
-			$("#width").val("");
-			$("#height").val("");
+			$("#rwidth").val("");
+			$("#rheight").val("");
 		}
  		refreshData();
  	});