模块化拆分
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
package cn.celess.extension.serviceimpl;
|
||||
|
||||
import cn.celess.common.mapper.*;
|
||||
import cn.celess.common.service.CountService;
|
||||
import cn.celess.common.util.RedisUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/02 22:06
|
||||
*/
|
||||
@Service
|
||||
public class CountServiceImpl implements CountService {
|
||||
@Autowired
|
||||
ArticleMapper articleMapper;
|
||||
@Autowired
|
||||
TagMapper tagMapper;
|
||||
@Autowired
|
||||
CommentMapper commentMapper;
|
||||
@Autowired
|
||||
CategoryMapper categoryMapper;
|
||||
@Autowired
|
||||
UserMapper userMapper;
|
||||
@Autowired
|
||||
VisitorMapper visitorMapper;
|
||||
@Autowired
|
||||
RedisUtil redisUtil;
|
||||
|
||||
@Override
|
||||
public long getCommentCount() {
|
||||
return commentMapper.count();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getArticleCount() {
|
||||
return articleMapper.count();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCategoriesCount() {
|
||||
return categoryMapper.count();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTagsCount() {
|
||||
return tagMapper.count();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getUserCount() {
|
||||
return userMapper.count();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getVisitorCount() {
|
||||
return visitorMapper.count();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDayVisitCount() {
|
||||
String dayVisitCount = redisUtil.get("dayVisitCount");
|
||||
if (dayVisitCount == null) {
|
||||
return 1;
|
||||
}
|
||||
return Integer.parseInt(dayVisitCount);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package cn.celess.extension.serviceimpl;
|
||||
|
||||
import cn.celess.common.service.MailService;
|
||||
import org.springframework.mail.SimpleMailMessage;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/22 14:26
|
||||
*/
|
||||
@Service
|
||||
public class MailServiceImpl implements MailService {
|
||||
public static final String FROM = "<xiaohai2271@163.com>";
|
||||
@Resource
|
||||
JavaMailSender javaMailSender;
|
||||
|
||||
@Override
|
||||
@Async
|
||||
public Boolean AsyncSend(SimpleMailMessage message) {
|
||||
this.send(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean send(SimpleMailMessage message) {
|
||||
String nick = null;
|
||||
try {
|
||||
nick = javax.mail.internet.MimeUtility.encodeText("小海博客");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
message.setFrom(nick + FROM);
|
||||
javaMailSender.send(message);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package cn.celess.extension.serviceimpl;
|
||||
|
||||
import cn.celess.common.entity.vo.QiniuResponse;
|
||||
import cn.celess.common.service.QiniuService;
|
||||
import com.qiniu.common.QiniuException;
|
||||
import com.qiniu.common.Zone;
|
||||
import com.qiniu.http.Response;
|
||||
import com.qiniu.storage.BucketManager;
|
||||
import com.qiniu.storage.Configuration;
|
||||
import com.qiniu.storage.UploadManager;
|
||||
import com.qiniu.storage.model.FileInfo;
|
||||
import com.qiniu.util.Auth;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/25 18:15
|
||||
*/
|
||||
@Service
|
||||
public class QiniuServiceImpl implements QiniuService {
|
||||
private static final Configuration cfg = new Configuration(Zone.zone2());
|
||||
private static UploadManager uploadManager;
|
||||
private static BucketManager bucketManager;
|
||||
private static Auth auth;
|
||||
|
||||
@Value("${qiniu.accessKey}")
|
||||
private String accessKey;
|
||||
@Value("${qiniu.secretKey}")
|
||||
private String secretKey;
|
||||
@Value("${qiniu.bucket}")
|
||||
private String bucket;
|
||||
|
||||
private void init() {
|
||||
if (auth == null || uploadManager == null || bucketManager == null) {
|
||||
auth = Auth.create(accessKey, secretKey);
|
||||
uploadManager = new UploadManager(cfg);
|
||||
bucketManager = new BucketManager(auth, cfg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public QiniuResponse uploadFile(InputStream is, String fileName) {
|
||||
init();
|
||||
//文件存在则删除文件
|
||||
if (continueFile(fileName)) {
|
||||
try {
|
||||
System.out.println(bucketManager.delete(bucket, fileName).toString());
|
||||
} catch (QiniuException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
//上传
|
||||
try {
|
||||
Response response = uploadManager.put(is, fileName, auth.uploadToken(bucket), null, null);
|
||||
return response.jsonToObject(QiniuResponse.class);
|
||||
} catch (QiniuException e) {
|
||||
Response r = e.response;
|
||||
System.err.println(r.toString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileInfo[] getFileList() {
|
||||
init();
|
||||
BucketManager.FileListIterator fileListIterator = bucketManager.createFileListIterator(bucket, "", 1000, "");
|
||||
FileInfo[] items = null;
|
||||
while (fileListIterator.hasNext()) {
|
||||
//处理获取的file list结果
|
||||
items = fileListIterator.next();
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
private boolean continueFile(String key) {
|
||||
FileInfo[] allFile = getFileList();
|
||||
for (FileInfo fileInfo : allFile) {
|
||||
if (key.equals(fileInfo.key)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user