Commit 801039c6 by jinfeng.wang

fix

parent 92609607
...@@ -6,7 +6,6 @@ import com.mobvista.apptag.config.WebSecurityConfig; ...@@ -6,7 +6,6 @@ import com.mobvista.apptag.config.WebSecurityConfig;
import com.mobvista.apptag.entity.Feat; import com.mobvista.apptag.entity.Feat;
import com.mobvista.apptag.entity.Tag; import com.mobvista.apptag.entity.Tag;
import com.mobvista.apptag.entity.TagResult; import com.mobvista.apptag.entity.TagResult;
import com.mobvista.apptag.entity.User;
import com.mobvista.apptag.mapper.FeatDao; import com.mobvista.apptag.mapper.FeatDao;
import com.mobvista.apptag.mapper.ResultDao; import com.mobvista.apptag.mapper.ResultDao;
import com.mobvista.apptag.mapper.TagDao; import com.mobvista.apptag.mapper.TagDao;
...@@ -54,8 +53,9 @@ public class ResultController { ...@@ -54,8 +53,9 @@ public class ResultController {
@GetMapping("/edit") @GetMapping("/edit")
String edit(@SessionAttribute(WebSecurityConfig.SESSION_KEY) String userName, String edit(@SessionAttribute(WebSecurityConfig.SESSION_KEY) String userName,
@RequestParam(name = "packageName") String packageName, Model model) { @RequestParam(name = "packageName") String packageName,
User user = userDao.find(userName); @RequestParam(name = "userId") String userId, Model model) {
// User user = userDao.find(userName);
Tag tag = tagDao.find(packageName); Tag tag = tagDao.find(packageName);
if (StringUtils.isNotBlank(tag.getUrl()) && tag.getUrl().length() > 2 && tag.getUrl().startsWith("[") && tag.getUrl().endsWith("]")) { if (StringUtils.isNotBlank(tag.getUrl()) && tag.getUrl().length() > 2 && tag.getUrl().startsWith("[") && tag.getUrl().endsWith("]")) {
String url = tag.getUrl().substring(2, tag.getUrl().length() - 2).replace("\"", "").split(",")[0]; String url = tag.getUrl().substring(2, tag.getUrl().length() - 2).replace("\"", "").split(",")[0];
...@@ -65,7 +65,7 @@ public class ResultController { ...@@ -65,7 +65,7 @@ public class ResultController {
} }
model.addAttribute("tag", tag); model.addAttribute("tag", tag);
TagResult result = resultDao.find(packageName, user.getUserId()); TagResult result = resultDao.find(packageName, userId);
model.addAttribute("resultCategory", JSONObject.fromObject(result.getFeatId())); model.addAttribute("resultCategory", JSONObject.fromObject(result.getFeatId()));
List<Feat> categoryFeat = featDao.firstList("01"); List<Feat> categoryFeat = featDao.firstList("01");
JSONArray jsonArray = JSONArray.fromObject(categoryFeat); JSONArray jsonArray = JSONArray.fromObject(categoryFeat);
......
package com.mobvista.apptag.entity; package com.mobvista.apptag.entity;
import java.io.Serializable;
import java.util.Date;
import com.gitee.sunchenbin.mybatis.actable.annotation.Column; import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import com.gitee.sunchenbin.mybatis.actable.annotation.Table; import com.gitee.sunchenbin.mybatis.actable.annotation.Table;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant; import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant;
import java.io.Serializable;
import java.util.Date;
/** /**
* @author wangjf * @author wangjf
*/ */
...@@ -38,6 +38,9 @@ public class Tag implements Serializable { ...@@ -38,6 +38,9 @@ public class Tag implements Serializable {
// 标注状态:0.未标注,1.已标注 // 标注状态:0.未标注,1.已标注
@Column(name = "tag", type = MySqlTypeConstant.INT, length = 10, isNull = true, defaultValue = "0") @Column(name = "tag", type = MySqlTypeConstant.INT, length = 10, isNull = true, defaultValue = "0")
private Integer tag; private Integer tag;
// 标注状态:0.未标注,1.已标注
@Column(name = "flag", type = MySqlTypeConstant.INT, length = 10, isNull = true, defaultValue = "0")
private Integer flag;
// 标注时间 // 标注时间
@Column(name = "update_time", type = MySqlTypeConstant.DATETIME, isNull = true) @Column(name = "update_time", type = MySqlTypeConstant.DATETIME, isNull = true)
private Date updateTime; private Date updateTime;
...@@ -144,18 +147,32 @@ public class Tag implements Serializable { ...@@ -144,18 +147,32 @@ public class Tag implements Serializable {
/** /**
* @return the tag * @return the tag
*/ */
public int getTag() { public Integer getTag() {
return tag; return tag;
} }
/** /**
* @param tag the tag to set * @param tag the tag to set
*/ */
public void setTag(int tag) { public void setTag(Integer tag) {
this.tag = tag; this.tag = tag;
} }
/** /**
* @return the flag
*/
public Integer getFlag() {
return flag;
}
/**
* @param flag the flag to set
*/
public void setFlag(Integer flag) {
this.flag = flag;
}
/**
* @return the updateTime * @return the updateTime
*/ */
public Date getUpdateTime() { public Date getUpdateTime() {
......
...@@ -31,6 +31,9 @@ public class TagResult implements Serializable { ...@@ -31,6 +31,9 @@ public class TagResult implements Serializable {
// 标注的中文全名 // 标注的中文全名
@Column(name = "comment", type = MySqlTypeConstant.VARCHAR) @Column(name = "comment", type = MySqlTypeConstant.VARCHAR)
private String comment; private String comment;
// 是否入库
@Column(name = "flag", type = MySqlTypeConstant.INT,defaultValue = "0")
private Integer flag;
// 用户ID // 用户ID
@Column(name = "user_id", type = MySqlTypeConstant.VARCHAR, isNull = false) @Column(name = "user_id", type = MySqlTypeConstant.VARCHAR, isNull = false)
private String userId; private String userId;
...@@ -110,6 +113,22 @@ public class TagResult implements Serializable { ...@@ -110,6 +113,22 @@ public class TagResult implements Serializable {
} }
/** /**
*
* @return the flag
*/
public Integer getFlag() {
return flag;
}
/**
*
* @param flag the flag to set
*/
public void setFlag(Integer flag) {
this.flag = flag;
}
/**
* @return the userId * @return the userId
*/ */
// @Id // @Id
......
...@@ -49,7 +49,7 @@ public interface ResultDao { ...@@ -49,7 +49,7 @@ public interface ResultDao {
class ListMapperProvider { class ListMapperProvider {
public String list(String userId, String search) { public String list(String userId, String search) {
String sql = "SELECT * FROM tag_result WHERE user_id = #{userId}"; String sql = "SELECT * FROM tag_result WHERE user_id = #{userId} AND flag != 1";
if (StringUtils.isNotBlank(search)) { if (StringUtils.isNotBlank(search)) {
sql += " AND LOWER(package_name) LIKE '%" + search + "%'"; sql += " AND LOWER(package_name) LIKE '%" + search + "%'";
} }
...@@ -81,9 +81,9 @@ public interface ResultDao { ...@@ -81,9 +81,9 @@ public interface ResultDao {
class ListAllMapperProvider { class ListAllMapperProvider {
public String listAll(String search) { public String listAll(String search) {
String sql = "SELECT * FROM tag_result"; String sql = "SELECT * FROM tag_result WHERE flag != 1";
if (StringUtils.isNotBlank(search)) { if (StringUtils.isNotBlank(search)) {
sql += " WHERE LOWER(package_name) LIKE '%" + search + "%'"; sql += " AND LOWER(package_name) LIKE '%" + search + "%'";
} }
return sql; return sql;
} }
...@@ -99,7 +99,7 @@ public interface ResultDao { ...@@ -99,7 +99,7 @@ public interface ResultDao {
class CountMapperProvider { class CountMapperProvider {
public String count(String userId, String search) { public String count(String userId, String search) {
String sql = "SELECT COUNT(1) FROM tag_result WHERE user_id = #{userId}"; String sql = "SELECT COUNT(1) FROM tag_result WHERE user_id = #{userId} AND flag != 1";
if (StringUtils.isNotBlank(search)) { if (StringUtils.isNotBlank(search)) {
sql += " AND LOWER(package_name) LIKE '%" + search + "%'"; sql += " AND LOWER(package_name) LIKE '%" + search + "%'";
} }
...@@ -117,9 +117,9 @@ public interface ResultDao { ...@@ -117,9 +117,9 @@ public interface ResultDao {
class CountAllMapperProvider { class CountAllMapperProvider {
public String countAll(String search) { public String countAll(String search) {
String sql = "SELECT COUNT(1) FROM tag_result"; String sql = "SELECT COUNT(1) FROM tag_result WHERE flag != 1";
if (StringUtils.isNotBlank(search)) { if (StringUtils.isNotBlank(search)) {
sql += " WHERE LOWER(package_name) LIKE '%" + search + "%'"; sql += " AND LOWER(package_name) LIKE '%" + search + "%'";
} }
return sql; return sql;
} }
......
...@@ -41,7 +41,7 @@ public interface TagDao { ...@@ -41,7 +41,7 @@ public interface TagDao {
String sql = "SELECT * FROM tag_list WHERE tag < " + tag; String sql = "SELECT * FROM tag_list WHERE tag < " + tag;
if (StringUtils.isNotBlank(userId)) { if (StringUtils.isNotBlank(userId)) {
sql += " AND user_id NOT LIKE '%" + userId + "%'"; sql += " AND (user_id NOT LIKE '%" + userId + "%' OR user_id IS NULL) AND flag = 0";
} }
if (StringUtils.isNotBlank(search)) { if (StringUtils.isNotBlank(search)) {
sql += " AND LOWER(package_name) LIKE '%" + search + "%'"; sql += " AND LOWER(package_name) LIKE '%" + search + "%'";
...@@ -92,7 +92,7 @@ public interface TagDao { ...@@ -92,7 +92,7 @@ public interface TagDao {
public String count(String search, int tag, String userId) { public String count(String search, int tag, String userId) {
String sql = "SELECT COUNT(1) FROM tag_list WHERE tag < " + tag; String sql = "SELECT COUNT(1) FROM tag_list WHERE tag < " + tag;
if (StringUtils.isNotBlank(userId)) { if (StringUtils.isNotBlank(userId)) {
sql += " AND user_id NOT LIKE '%" + userId + "%'"; sql += " AND (user_id NOT LIKE '%" + userId + "%' OR user_id IS NULL) AND flag = 0";
} }
if (StringUtils.isNotBlank(search)) { if (StringUtils.isNotBlank(search)) {
sql += " AND LOWER(package_name) LIKE '%" + search + "%'"; sql += " AND LOWER(package_name) LIKE '%" + search + "%'";
......
...@@ -67,14 +67,12 @@ public class ResultServiceImpl implements ResultService { ...@@ -67,14 +67,12 @@ public class ResultServiceImpl implements ResultService {
User user = userDao.find(userId); User user = userDao.find(userId);
List<TagResult> results; List<TagResult> results;
PageHelper.startPage(query.getOffset() / query.getLimit() + 1, query.getLimit()); PageHelper.startPage(query.getOffset() / query.getLimit() + 1, query.getLimit());
results = resultDao.list(userId, query.getSearch().toLowerCase()); // results = resultDao.list(userId, query.getSearch().toLowerCase());
/*
if (user.getRole() == 0) { if (user.getRole() == 0) {
results = resultDao.list(userId, query.getSearch().toLowerCase()); results = resultDao.list(userId, query.getSearch().toLowerCase());
} else { } else {
results = resultDao.listAll(query.getSearch().toLowerCase()); results = resultDao.listAll(query.getSearch().toLowerCase());
} }
*/
List<TagResult> results2 = new ArrayList<>(); List<TagResult> results2 = new ArrayList<>();
for (TagResult result : results) { for (TagResult result : results) {
...@@ -87,14 +85,11 @@ public class ResultServiceImpl implements ResultService { ...@@ -87,14 +85,11 @@ public class ResultServiceImpl implements ResultService {
@Override @Override
public int count(String userId, String search) { public int count(String userId, String search) {
// User user = userDao.find(userId); User user = userDao.find(userId);
return resultDao.count(userId, search);
/*
if (user.getRole() == 0) { if (user.getRole() == 0) {
return resultDao.count(userId, search); return resultDao.count(userId, search);
} else { } else {
return resultDao.countAll(search); return resultDao.countAll(search);
} }
*/
} }
} }
\ No newline at end of file
...@@ -19,27 +19,31 @@ import java.util.*; ...@@ -19,27 +19,31 @@ import java.util.*;
* @phone: 152-1062-7698 * @phone: 152-1062-7698
*/ */
public class StorageTag { public class StorageTag {
// static final String CONNECTION_URL = "jdbc:mysql://localhost:3306/app_tag?useUnicode=true&characterEncoding=utf8&useSSL=false"; private static final String CONNECTION_URL = "jdbc:mysql://localhost:3306/app_tag?useUnicode=true&characterEncoding=utf8&useSSL=false";
static final String CONNECTION_URL = "jdbc:mysql://dataplatform-app-tag.c5yzcdreb1xr.us-east-1.rds.amazonaws.com:3306/app_tag?useUnicode=true&characterEncoding=utf8&useSSL=false"; // private static final String CONNECTION_URL = "jdbc:mysql://dataplatform-app-tag.c5yzcdreb1xr.us-east-1.rds.amazonaws.com:3306/app_tag?useUnicode=true&characterEncoding=utf8&useSSL=false";
static final String DRIVER = "com.mysql.jdbc.Driver"; private static final String DRIVER = "com.mysql.jdbc.Driver";
// static final String USER = "root"; private static final String USER = "root";
static final String USER = "apptag_rw"; // private static final String USER = "apptag_rw";
// static final String PASSWORD = "19920627"; private static final String PASSWORD = "19920627";
static final String PASSWORD = "7gyLEVtkER3u8c9"; // private static final String PASSWORD = "7gyLEVtkER3u8c9";
static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
static ObjectMapper mapper = new ObjectMapper(); private static ObjectMapper mapper = new ObjectMapper();
static Connection connection = null; private static Connection connection = null;
static PreparedStatement preparedStatement = null; private static PreparedStatement preparedStatement = null;
private static PreparedStatement preparedStatement_admin = null;
public static void main(String[] args) { public static void main(String[] args) {
String sql = String.format("SELECT a.package_name,a.app_name,a.platform,JSON_KEYS(feat_id) tag_arr,t.tag FROM app_tag.tag_result a LEFT JOIN (SELECT package_name,tag FROM app_tag.tag_list WHERE tag > 1) t ON a.package_name = t.package_name WHERE t.package_name IS NOT NULL"); String sql = String.format("SELECT a.package_name,a.app_name,a.platform,JSON_KEYS(feat_id) tag_arr,t.tag FROM app_tag.tag_result a LEFT JOIN (SELECT package_name,tag FROM app_tag.tag_list WHERE tag > 1) t ON a.package_name = t.package_name WHERE t.package_name IS NOT NULL");
String sqlAdmin = String.format("SELECT a.package_name,a.app_name,a.platform,feat_id tag FROM app_tag.tag_result a LEFT JOIN app_tag.user u ON a.user_id = u.user_id WHERE u.role = 1");
try { try {
Class.forName(DRIVER); Class.forName(DRIVER);
connection = DriverManager.getConnection(CONNECTION_URL, USER, PASSWORD); connection = DriverManager.getConnection(CONNECTION_URL, USER, PASSWORD);
preparedStatement = connection.prepareStatement(sql); preparedStatement = connection.prepareStatement(sql);
preparedStatement_admin = connection.prepareStatement(sqlAdmin);
ResultSet resultSetAdmin = preparedStatement_admin.executeQuery();
ResultSet resultSet = preparedStatement.executeQuery(); ResultSet resultSet = preparedStatement.executeQuery();
Map<String, Integer> map = new HashMap<>(); Map<String, Integer> map = new HashMap<>();
while (resultSet.next()) { while (resultSet.next()) {
...@@ -61,7 +65,9 @@ public class StorageTag { ...@@ -61,7 +65,9 @@ public class StorageTag {
} }
insert(map); insert(map);
insertAdmin(resultSetAdmin);
resultSet.close(); resultSet.close();
resultSetAdmin.close();
preparedStatement.close(); preparedStatement.close();
connection.close(); connection.close();
} catch (Exception e) { } catch (Exception e) {
...@@ -71,6 +77,9 @@ public class StorageTag { ...@@ -71,6 +77,9 @@ public class StorageTag {
if (preparedStatement != null) { if (preparedStatement != null) {
preparedStatement.close(); preparedStatement.close();
} }
if (preparedStatement_admin != null) {
preparedStatement_admin.close();
}
} catch (SQLException se) { } catch (SQLException se) {
} }
try { try {
...@@ -99,8 +108,68 @@ public class StorageTag { ...@@ -99,8 +108,68 @@ public class StorageTag {
sql.append("'").append(packageName).append("',"); sql.append("'").append(packageName).append("',");
} }
stmt1.execute(deleteSql1 + "(" + sql.substring(0, sql.length() - 1) + ")"); stmt1.execute(deleteSql1 + "(" + sql.substring(0, sql.length() - 1) + ")");
stmt1.close();
stmt2.execute(deleteSql2 + "(" + sql.substring(0, sql.length() - 1) + ")"); stmt2.execute(deleteSql2 + "(" + sql.substring(0, sql.length() - 1) + ")");
con.close(); con.close();
stmt2.close();
} catch (Exception e) {
e.printStackTrace();
}
}
private static void update(Set<String> set) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(CONNECTION_URL, USER, PASSWORD);
Statement stmt1 = con.createStatement();
Statement stmt2 = con.createStatement();
String updateSql1 = "UPDATE app_tag.tag_result SET flag = 1 WHERE package_name IN ";
String updateSql2 = "UPDATE app_tag.tag_list SET flag = 1 WHERE package_name IN ";
Iterator<String> iterator = set.iterator();
StringBuffer sql = new StringBuffer();
while (iterator.hasNext()) {
String packageName = iterator.next();
sql.append("'").append(packageName).append("',");
}
stmt1.execute(updateSql1 + "(" + sql.substring(0, sql.length() - 1) + ")");
stmt1.close();
stmt2.execute(updateSql2 + "(" + sql.substring(0, sql.length() - 1) + ")");
stmt2.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* @param resultSet
* @throws SQLException
* @desc 插入超级管理员标注的标签
*/
private static void insertAdmin(ResultSet resultSet) throws SQLException {
StringBuffer insertSql = new StringBuffer();
Set<String> packageSet = new HashSet<>();
while (resultSet.next()) {
String packageName = resultSet.getString("package_name");
String appName = resultSet.getString("app_name");
String platform = resultSet.getString("platform");
String tag = resultSet.getString("tag");
insertSql.append("('").append(packageName).append("','").append(appName).append("','").append(platform).append("','").append(tag)
.append("','").append(sdf.format(new Date())).append("'),");
packageSet.add(packageName);
}
update(packageSet);
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(CONNECTION_URL, USER, PASSWORD);
Statement stmt = con.createStatement();
String insert_sql = "REPLACE INTO storage(package_name, app_name, platform, tag, update_time) " +
"VALUES";
// System.out.println(insert_sql + insertSql.substring(0, insertSql.length() - 1));
stmt.executeQuery(insert_sql + insertSql.substring(0, insertSql.length() - 1));
con.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -142,7 +211,9 @@ public class StorageTag { ...@@ -142,7 +211,9 @@ public class StorageTag {
} }
} }
delete(packageSet); if (packageSet.size() > 0) {
delete(packageSet);
}
Iterator<String> iters = tagMap.keySet().iterator(); Iterator<String> iters = tagMap.keySet().iterator();
while (iters.hasNext()) { while (iters.hasNext()) {
...@@ -163,12 +234,19 @@ public class StorageTag { ...@@ -163,12 +234,19 @@ public class StorageTag {
"VALUES"; "VALUES";
// System.out.println(insert_sql1 + insertSql_1.substring(0, insertSql_1.length() - 1)); // System.out.println(insert_sql1 + insertSql_1.substring(0, insertSql_1.length() - 1));
// System.out.println(insert_sql2 + insertSql_2.substring(0, insertSql_2.length() - 1)); // System.out.println(insert_sql2 + insertSql_2.substring(0, insertSql_2.length() - 1));
stmt.executeQuery(insert_sql1 + insertSql_1.substring(0, insertSql_1.length() - 1)); if (insertSql_1.length() > 0) {
stmt1.executeQuery(insert_sql2 + insertSql_2.substring(0, insertSql_2.length() - 1)); stmt.executeQuery(insert_sql1 + insertSql_1.substring(0, insertSql_1.length() - 1));
}
if (insertSql_2.length() > 0) {
stmt1.executeQuery(insert_sql2 + insertSql_2.substring(0, insertSql_2.length() - 1));
}
con.close(); con.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
if (packageSet.size() > 0) {
update(packageSet);
}
} }
private static Map<String, String> getMap() { private static Map<String, String> getMap() {
......
...@@ -72,8 +72,7 @@ function load() { ...@@ -72,8 +72,7 @@ function load() {
'<a class="btn btn-primary btn-sm ' + '<a class="btn btn-primary btn-sm ' +
s_edit_h + s_edit_h +
'" href="#" mce_href="#" title="编辑" onclick="edit(\'' + '" href="#" mce_href="#" title="编辑" onclick="edit(\'' +
row.packageName + row.packageName +'\',\''+row.userId+ '\')"><i class="fa fa-edit"></i></a> ';
'\')"><i class="fa fa-edit"></i></a> ';
return e; return e;
} }
} }
...@@ -95,13 +94,13 @@ function reLoad(type) { ...@@ -95,13 +94,13 @@ function reLoad(type) {
} }
function edit(package_name) { function edit(package_name, user_id) {
layer.open({ layer.open({
type: 2, type: 2,
title: "标签标注", title: "标签标注",
maxmin: true, maxmin: true,
shadeClose: true, // 点击遮罩关闭层 shadeClose: true, // 点击遮罩关闭层
area: ["800px", "580px"], area: ["800px", "580px"],
content: prefix + "/edit?packageName=" + package_name // iframe的url content: prefix + "/edit?packageName=" + package_name + "&userId=" + user_id // iframe的url
}); });
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment