package com.yeshi.fanli.service.impl;
|
|
import java.io.BufferedReader;
|
import java.io.File;
|
import java.io.FileReader;
|
import java.io.IOException;
|
import java.io.Serializable;
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import com.yeshi.fanli.dao.MaskKeyDao;
|
import com.yeshi.fanli.entity.bus.recommend.MaskKey;
|
import com.yeshi.fanli.service.MaskKeyService;
|
import com.yeshi.fanli.util.Constant;
|
|
@Service
|
public class MaskKeyServiceImpl implements MaskKeyService {
|
|
@Resource
|
private MaskKeyDao dao;
|
|
@Resource
|
private MaskKeyService maskKeyService;
|
|
public void addMaskKeys(String path) {
|
BufferedReader bufferedReader = null;
|
try {
|
File file = new File(path);
|
bufferedReader = new BufferedReader(new FileReader(file));
|
String line;
|
while ((line = bufferedReader.readLine()) != null) {
|
MaskKey mk = new MaskKey();
|
mk.setContent(line);
|
dao.create(mk);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
if (bufferedReader != null) {
|
try {
|
bufferedReader.close();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
|
}
|
|
public List<MaskKey> getMaskKeys(String key, int page) {
|
int start = (page - 1) * Constant.PAGE_SIZE;
|
String hql = "from MaskKey mk where mk.content like ? order by mk.id desc ";
|
return dao.list(hql, start, Constant.PAGE_SIZE, new Serializable[] { "%" + key + "%" });
|
}
|
|
public int getCount(String key) {
|
return (int) dao.getCount("select count(*) from MaskKey mk where mk.content like ? ",
|
new Serializable[] { "%" + key + "%" });
|
}
|
|
@Transactional
|
public long addMaskKey(String key) {
|
return (Long) dao.save(new MaskKey(key));
|
}
|
|
@Transactional
|
public void delete(long id) {
|
dao.delete(new MaskKey(id));
|
}
|
|
@Cacheable(value = "maskKeyCache")
|
public List<MaskKey> getAll() {
|
|
return dao.list("from MaskKey");
|
}
|
|
public String maskAction(String content) {
|
|
List<MaskKey> maskKeys = maskKeyService.getAll();
|
String xin = "";
|
for (MaskKey maskKey : maskKeys) {
|
xin = "";
|
String key = maskKey.getContent();
|
int length = key.length();
|
for (int i = 0; i < length; i++) {
|
xin = xin + "*";
|
}
|
content = content.replace(key, xin);
|
}
|
return content;
|
|
}
|
|
}
|