|
@@ -117,6 +117,7 @@ public class CreateBannerController extends SimpleController{
|
|
static {
|
|
static {
|
|
noStuffixSet.add("jpg");
|
|
noStuffixSet.add("jpg");
|
|
noStuffixSet.add("gif");
|
|
noStuffixSet.add("gif");
|
|
|
|
+ noStuffixSet.add("png");
|
|
}
|
|
}
|
|
|
|
|
|
@RequestMapping("/list")
|
|
@RequestMapping("/list")
|
|
@@ -305,7 +306,7 @@ public class CreateBannerController extends SimpleController{
|
|
|
|
|
|
//处理上传文件路径
|
|
//处理上传文件路径
|
|
path = getLocalFilePath(uploadName);
|
|
path = getLocalFilePath(uploadName);
|
|
- System.out.println("qqqqqqq+==="+path);
|
|
|
|
|
|
+ //System.out.println("qqqqqqq+==="+path);
|
|
|
|
|
|
File localFile = new File(path);
|
|
File localFile = new File(path);
|
|
//上传目录不存在,则新建目录
|
|
//上传目录不存在,则新建目录
|
|
@@ -321,7 +322,7 @@ public class CreateBannerController extends SimpleController{
|
|
//生成缩略图
|
|
//生成缩略图
|
|
smallPicture(localFile,pathSmall,uploadName);
|
|
smallPicture(localFile,pathSmall,uploadName);
|
|
|
|
|
|
- responseStr="上传成功";
|
|
|
|
|
|
+ responseStr="文件上传成功";
|
|
//保存上传文件路径
|
|
//保存上传文件路径
|
|
bannerTemplate.setPath(replacePath(path));
|
|
bannerTemplate.setPath(replacePath(path));
|
|
//保存缩略图路径
|
|
//保存缩略图路径
|
|
@@ -340,6 +341,9 @@ public class CreateBannerController extends SimpleController{
|
|
model.addAttribute("agentId", agentId);
|
|
model.addAttribute("agentId", agentId);
|
|
|
|
|
|
//创建素材
|
|
//创建素材
|
|
|
|
+ if(suitSize(path, bannerTemplate)==null){
|
|
|
|
+ return "图片有点大了!";
|
|
|
|
+ }
|
|
bannerTemplate= suitSize(path, bannerTemplate);
|
|
bannerTemplate= suitSize(path, bannerTemplate);
|
|
bannerTemplate.setName(uploadName);
|
|
bannerTemplate.setName(uploadName);
|
|
bannerTemplate.setType(judgeType(fileType));
|
|
bannerTemplate.setType(judgeType(fileType));
|
|
@@ -542,7 +546,9 @@ public BannerTemplate suitSize(String path,BannerTemplate bannerTemplate) throws
|
|
Image src = javax.imageio.ImageIO.read(file);
|
|
Image src = javax.imageio.ImageIO.read(file);
|
|
int width = src.getWidth(null);
|
|
int width = src.getWidth(null);
|
|
int height =src.getHeight(null);
|
|
int height =src.getHeight(null);
|
|
- Size size = new Size();
|
|
|
|
|
|
+ Size size = new Size();
|
|
|
|
+ long max_width = 0;
|
|
|
|
+ long max_height = 0;
|
|
int i;
|
|
int i;
|
|
int n =0;
|
|
int n =0;
|
|
//查找所有广告位
|
|
//查找所有广告位
|
|
@@ -555,24 +561,33 @@ public BannerTemplate suitSize(String path,BannerTemplate bannerTemplate) throws
|
|
size = sizeList.get(i);
|
|
size = sizeList.get(i);
|
|
_width[i] = size.getWidth();
|
|
_width[i] = size.getWidth();
|
|
_height[i] = size.getHeight();
|
|
_height[i] = size.getHeight();
|
|
|
|
+ if(_width[i]>max_width){
|
|
|
|
+ max_width = _width[i];
|
|
|
|
+ }
|
|
|
|
+ if(_height[i]>max_height){
|
|
|
|
+ max_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]));
|
|
suit[i] =Math.sqrt(Math.abs(width-_width[i])*Math.abs(width-_width[i])+Math.abs(height-_height[i])*Math.abs(height-_height[i]));
|
|
}
|
|
}
|
|
- double min =suit[0];
|
|
|
|
- for (i=0;i<suit.length;i++){
|
|
|
|
- if (suit[i]<min){
|
|
|
|
- min = suit[i];
|
|
|
|
- n=i;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ if(width>max_width||height>max_height){
|
|
|
|
+ bannerTemplate = null;
|
|
|
|
+ }else{
|
|
|
|
+ double min =suit[0];
|
|
|
|
+ for (i=0;i<suit.length;i++){
|
|
|
|
+ if (suit[i]<min){
|
|
|
|
+ min = suit[i];
|
|
|
|
+ n=i;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- bannerTemplate.setWidth(_width[n]);
|
|
|
|
- bannerTemplate.setHeight(_height[n]);
|
|
|
|
- return bannerTemplate;
|
|
|
|
- }
|
|
|
|
|
|
+ bannerTemplate.setWidth(_width[n]);
|
|
|
|
+ bannerTemplate.setHeight(_height[n]);
|
|
|
|
+ }
|
|
|
|
+ return bannerTemplate;
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|