Merge remote-tracking branch 'origin/master'

This commit is contained in:
2025-04-23 15:44:56 +08:00
9 changed files with 64 additions and 11 deletions
@@ -71,7 +71,8 @@ public class FilesController {
if(StringUtils.isNotBlank(model.getFilename())){
filename = model.getFilename();
}
GridFSInputFile gridFSInputFile = fileDao.saveToGridFs(file.getInputStream(), filename, contentType);
String type = model.getType();
GridFSInputFile gridFSInputFile = fileDao.saveToGridFs(file.getInputStream(), filename, contentType, type);
UniversalDto dto = UniversalDto.newDto();
if(OpenConfig.getConfig().isProductionEnvironment()){
dto.append("link", "http://static.fangjia.com/stc/files/" + gridFSInputFile.get("_id").toString());
@@ -780,6 +780,7 @@ public class WeiXinEvaluationController {
dataMap.put("fjw", averageStatistics.getFangjiaPrice());
dataMap.put("soufang", averageStatistics.getSoufangEsfPrice());
dataMap.put("anjuke", averageStatistics.getAnjukeEsfPrice());
dataMap.put("beike", averageStatistics.getBeikeEsfPrice());
}
}
jsonMmodel.setJsonModel(dataMap);
@@ -7,6 +7,10 @@ public class FilesModel extends FangjiaApiModel {
private MultipartFile file;
private String contentType;
private String filename;
/**
* ÎļþÀàÐÍ
*/
private String type;
public MultipartFile getFile() {
return file;
@@ -31,4 +35,12 @@ public class FilesModel extends FangjiaApiModel {
public void setFilename(String filename) {
this.filename = filename;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
@@ -8,6 +8,7 @@ import com.mongodb.gridfs.GridFS;
import com.mongodb.gridfs.GridFSDBFile;
import com.mongodb.gridfs.GridFSInputFile;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.bson.types.ObjectId;
import java.io.InputStream;
@@ -70,6 +71,18 @@ public class FileDao {
return fsInputFile;
}
public GridFSInputFile saveToGridFs(InputStream inputStream, String filename, String contentType, String type){
GridFSInputFile fsInputFile = gridFs.createFile(inputStream, filename);
fsInputFile.put("contentType", contentType);
if (StringUtils.isNotBlank(type)){
fsInputFile.put("t", type);
} else {
fsInputFile.put("t", "default");
}
fsInputFile.save();
return fsInputFile;
}
public GridFSDBFile findByIdInGridFS(String id){
return gridFs.findOne(new ObjectId(id));
}
@@ -24,7 +24,7 @@ import java.util.regex.Pattern
class SMSOutgoingListener extends BaseBatch {
private static DBCollection LOG_COLL = MongoUtils.getCollectionByName("fangjia_log", "sms_outgoing_log", "log.mongo.db.fangjia.com", 52002)
public static final DBCollection CONTACT_PERSION = MongoUtils.getCollectionByName("fangjia_stat", "contact_person", "mongo.db.fangjia.com",27017)
public static final DBCollection CONTACT_PERSION = MongoUtils.getCollectionByName("fangjia_stat", "contact_person", "mongo.db.fangjia.com",28017)
private static Jms jms = Jms.create("tcp://jms.db.fangjia.com:61616")
@@ -159,9 +159,9 @@ class SMSOutgoingListener extends BaseBatch {
def mobile = msg.getObject().mobile
String content = msg.getObject().msgContent.trim()
content = content.replace("【房价网】", "【上海估家】")
if(!content.startsWith("【")){
content = "【房价网】" + content;
content = "【上海估家】" + content;
}
if(content.lastIndexOf("【") > 0){
println("非法短信内容:" + content)
@@ -310,7 +310,7 @@ class SMSOutgoingListener extends BaseBatch {
if(StringUtils.isNotBlank(checkCode)){
JSONObject con = new JSONObject()
con.put("code", checkCode);
return AliyunSmsClient.sendSms(mobile, "SMS_483345375", con.toString())
return AliyunSmsClient.sendSms(mobile, "SMS_483925328", con.toString())
}
}
int resCode = SingletonClient.getClient().sendSMS([mobile] as String[],content, 5)
@@ -61,7 +61,7 @@ public class ProvinceData {
/**城市:省份*/
public static Map<String, String> CITY_PROVINCE_MAP = new HashMap<String, String>();
static DBCollection SERVER_AREA = MongoUtils.getCollectionByName("fangjia", "server_area", "mongo.db.fangjia.com", 27017);
static DBCollection SERVER_AREA = MongoUtils.getCollectionByName("fangjia", "server_area", "mongo.db.fangjia.com", 28017);
static final Map<String, String> PROVINCE_MAP = new HashMap<String, String>() {{
@@ -55,9 +55,9 @@ public class FileDao {
FIELDS.put("content_type", 1);
FIELDS.put("a_date", 1);
try {
Mongo mongo = new Mongo("fs.mongo.db.fangjia.com", Integer.getInteger("fs.mongo.port", 27017));
Mongo mongo = new Mongo("fs.mongo.db.fangjia.com", Integer.getInteger("fs.mongo.port", 27000));
db = mongo.getDB("fangjia_fs");
mongo = new Mongo("capped.mongo.db.fangjia.com", Integer.getInteger("capped.mongo.port", 27017));
mongo = new Mongo("capped.mongo.db.fangjia.com", Integer.getInteger("capped.mongo.port", 27000));
cappedFsDb = mongo.getDB("fangjia_fs");
} catch (Exception e) {
@@ -37,9 +37,9 @@ public class FileDao {
IMPORTANT_CATEGORY = Arrays.asList(System.getProperty("fangjia.important.category", "district,shop,office,avatar,flash,user_house,upload,news,attachment").split(","));
try {
filesCollection = new Mongo("fs.mongo.db.fangjia.com", Integer.getInteger("fs.mongo.port", 27017)).getDB("fangjia").getCollection("files");
filesCollection = new Mongo("fs.mongo.db.fangjia.com", Integer.getInteger("fs.mongo.port", 27000)).getDB("fangjia").getCollection("files");
gridFs = new GridFS(filesCollection.getDB(), "fangjia");
cappedCollection = new Mongo("capped.mongo.db.fangjia.com", Integer.getInteger("capped.mongo.port", 27017)).getDB("fangjia_fs").getCollection("files_capped");
cappedCollection = new Mongo("capped.mongo.db.fangjia.com", Integer.getInteger("capped.mongo.port", 27000)).getDB("fangjia_fs").getCollection("files_capped");
} catch (Exception e) {
e.printStackTrace();
}
@@ -1,17 +1,22 @@
package com.fangjia.stc2;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Date;
import java.util.zip.GZIPOutputStream;
import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.time.DateUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -63,7 +68,28 @@ public class GridFsServlet extends HttpServlet {
resp.getOutputStream().flush();*/
OutputStream out = resp.getOutputStream();
try {
gridFSDBFile.writeTo(out);
// 压缩返回流
String size = req.getParameter("size");
// 如果有size参数(如"100x90"),则进行图片尺寸调整
if (StringUtils.isNotBlank(size)) {
// 1. 解析尺寸参数(格式如 "100x90")
String[] dimensions = size.split("\\*");
int width = Integer.parseInt(dimensions[0]);
int height = Integer.parseInt(dimensions[1]);
// 2. 将GridFS文件读入内存作为BufferedImage
BufferedImage originalImage = ImageIO.read(gridFSDBFile.getInputStream());
// 3. 创建缩放后的图片
BufferedImage resizedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage.getScaledInstance(width, height, Image.SCALE_SMOOTH), 0, 0, null);
g.dispose();
// 5. 输出调整后的图片
ImageIO.write(resizedImage, "JPEG", out); // 根据实际格式调整
} else {
gridFSDBFile.writeTo(out);
}
} catch (Exception e) {
logger.error("", e);
} finally {