|
|
|
@ -6,10 +6,14 @@ import client.vo.SimpleUser;
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import com.luoo.comment.dao.CommentDao;
|
|
|
|
|
import com.luoo.comment.enums.CommentStatusEnum;
|
|
|
|
|
import com.luoo.comment.enums.Province;
|
|
|
|
|
import com.luoo.comment.pojo.Comment;
|
|
|
|
|
import com.luoo.comment.pojo.CommentDto;
|
|
|
|
|
import com.luoo.comment.pojo.CommentVo;
|
|
|
|
|
import com.luoo.comment.service.CommentService;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import net.renfei.ip2location.IP2Location;
|
|
|
|
|
import net.renfei.ip2location.IPResult;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.data.domain.*;
|
|
|
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
|
@ -20,6 +24,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import util.IdWorker;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
@ -29,6 +34,7 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
@Transactional
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class CommentServiceImpl implements CommentService {
|
|
|
|
|
|
|
|
|
|
// @Autowired
|
|
|
|
@ -48,6 +54,20 @@ public class CommentServiceImpl implements CommentService {
|
|
|
|
|
return commentDao.findById(id).get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getCityNameByIp(String ip) {
|
|
|
|
|
IP2Location loc = new IP2Location();
|
|
|
|
|
String binFile = "classpath:/IP2LOCATION-LITE-DB11.BIN";
|
|
|
|
|
try {
|
|
|
|
|
loc.Open(binFile, true);
|
|
|
|
|
IPResult rec = loc.IPQuery(ip);
|
|
|
|
|
String city = rec.getCity();
|
|
|
|
|
return Province.getCityName(city);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
log.info("getCityNameByIp error {}",ip,e);
|
|
|
|
|
return "未知 IP";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void save(CommentDto commentDto){
|
|
|
|
|
Comment comment = new Comment();
|
|
|
|
|
comment.setContent(commentDto.getContent());
|
|
|
|
@ -59,7 +79,7 @@ public class CommentServiceImpl implements CommentService {
|
|
|
|
|
comment.setLevel(1);
|
|
|
|
|
comment.setTargetId(commentDto.getTargetId());
|
|
|
|
|
comment.setType(0);
|
|
|
|
|
comment.setCity("上海");
|
|
|
|
|
comment.setCity(getCityNameByIp(commentDto.getIpAddress()));
|
|
|
|
|
comment.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
|
comment.setShare(0);
|
|
|
|
|
comment.setThumbup(0);
|
|
|
|
|