Commit 801039c6 by jinfeng.wang

fix

parent 92609607
......@@ -6,7 +6,6 @@ import com.mobvista.apptag.config.WebSecurityConfig;
import com.mobvista.apptag.entity.Feat;
import com.mobvista.apptag.entity.Tag;
import com.mobvista.apptag.entity.TagResult;
import com.mobvista.apptag.entity.User;
import com.mobvista.apptag.mapper.FeatDao;
import com.mobvista.apptag.mapper.ResultDao;
import com.mobvista.apptag.mapper.TagDao;
......@@ -54,8 +53,9 @@ public class ResultController {
@GetMapping("/edit")
String edit(@SessionAttribute(WebSecurityConfig.SESSION_KEY) String userName,
@RequestParam(name = "packageName") String packageName, Model model) {
User user = userDao.find(userName);
@RequestParam(name = "packageName") String packageName,
@RequestParam(name = "userId") String userId, Model model) {
// User user = userDao.find(userName);
Tag tag = tagDao.find(packageName);
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];
......@@ -65,7 +65,7 @@ public class ResultController {
}
model.addAttribute("tag", tag);
TagResult result = resultDao.find(packageName, user.getUserId());
TagResult result = resultDao.find(packageName, userId);
model.addAttribute("resultCategory", JSONObject.fromObject(result.getFeatId()));
List<Feat> categoryFeat = featDao.firstList("01");
JSONArray jsonArray = JSONArray.fromObject(categoryFeat);
......
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.Table;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant;
import java.io.Serializable;
import java.util.Date;
/**
* @author wangjf
*/
......@@ -38,6 +38,9 @@ public class Tag implements Serializable {
// 标注状态:0.未标注,1.已标注
@Column(name = "tag", type = MySqlTypeConstant.INT, length = 10, isNull = true, defaultValue = "0")
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)
private Date updateTime;
......@@ -144,18 +147,32 @@ public class Tag implements Serializable {
/**
* @return the tag
*/
public int getTag() {
public Integer getTag() {
return tag;
}
/**
* @param tag the tag to set
*/
public void setTag(int tag) {
public void setTag(Integer 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
*/
public Date getUpdateTime() {
......
......@@ -31,6 +31,9 @@ public class TagResult implements Serializable {
// 标注的中文全名
@Column(name = "comment", type = MySqlTypeConstant.VARCHAR)
private String comment;
// 是否入库
@Column(name = "flag", type = MySqlTypeConstant.INT,defaultValue = "0")
private Integer flag;
// 用户ID
@Column(name = "user_id", type = MySqlTypeConstant.VARCHAR, isNull = false)
private String userId;
......@@ -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
*/
// @Id
......
......@@ -49,7 +49,7 @@ public interface ResultDao {
class ListMapperProvider {
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)) {
sql += " AND LOWER(package_name) LIKE '%" + search + "%'";
}
......@@ -81,9 +81,9 @@ public interface ResultDao {
class ListAllMapperProvider {
public String listAll(String search) {
String sql = "SELECT * FROM tag_result";
String sql = "SELECT * FROM tag_result WHERE flag != 1";
if (StringUtils.isNotBlank(search)) {
sql += " WHERE LOWER(package_name) LIKE '%" + search + "%'";
sql += " AND LOWER(package_name) LIKE '%" + search + "%'";
}
return sql;
}
......@@ -99,7 +99,7 @@ public interface ResultDao {
class CountMapperProvider {
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)) {
sql += " AND LOWER(package_name) LIKE '%" + search + "%'";
}
......@@ -117,9 +117,9 @@ public interface ResultDao {
class CountAllMapperProvider {
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)) {
sql += " WHERE LOWER(package_name) LIKE '%" + search + "%'";
sql += " AND LOWER(package_name) LIKE '%" + search + "%'";
}
return sql;
}
......
......@@ -41,7 +41,7 @@ public interface TagDao {
String sql = "SELECT * FROM tag_list WHERE tag < " + tag;
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)) {
sql += " AND LOWER(package_name) LIKE '%" + search + "%'";
......@@ -92,7 +92,7 @@ public interface TagDao {
public String count(String search, int tag, String userId) {
String sql = "SELECT COUNT(1) FROM tag_list WHERE tag < " + tag;
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)) {
sql += " AND LOWER(package_name) LIKE '%" + search + "%'";
......
......@@ -67,14 +67,12 @@ public class ResultServiceImpl implements ResultService {
User user = userDao.find(userId);
List<TagResult> results;
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) {
results = resultDao.list(userId, query.getSearch().toLowerCase());
} else {
results = resultDao.listAll(query.getSearch().toLowerCase());
}
*/
List<TagResult> results2 = new ArrayList<>();
for (TagResult result : results) {
......@@ -87,14 +85,11 @@ public class ResultServiceImpl implements ResultService {
@Override
public int count(String userId, String search) {
// User user = userDao.find(userId);
return resultDao.count(userId, search);
/*
User user = userDao.find(userId);
if (user.getRole() == 0) {
return resultDao.count(userId, search);
} else {
return resultDao.countAll(search);
}
*/
}
}
\ No newline at end of file
......@@ -19,27 +19,31 @@ import java.util.*;
* @phone: 152-1062-7698
*/
public class StorageTag {
// 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";
static final String DRIVER = "com.mysql.jdbc.Driver";
// static final String USER = "root";
static final String USER = "apptag_rw";
// static final String PASSWORD = "19920627";
static final String PASSWORD = "7gyLEVtkER3u8c9";
static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
static ObjectMapper mapper = new ObjectMapper();
static Connection connection = null;
static PreparedStatement preparedStatement = null;
private 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://dataplatform-app-tag.c5yzcdreb1xr.us-east-1.rds.amazonaws.com:3306/app_tag?useUnicode=true&characterEncoding=utf8&useSSL=false";
private static final String DRIVER = "com.mysql.jdbc.Driver";
private static final String USER = "root";
// private static final String USER = "apptag_rw";
private static final String PASSWORD = "19920627";
// private static final String PASSWORD = "7gyLEVtkER3u8c9";
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private static ObjectMapper mapper = new ObjectMapper();
private static Connection connection = null;
private static PreparedStatement preparedStatement = null;
private static PreparedStatement preparedStatement_admin = null;
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 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 {
Class.forName(DRIVER);
connection = DriverManager.getConnection(CONNECTION_URL, USER, PASSWORD);
preparedStatement = connection.prepareStatement(sql);
preparedStatement_admin = connection.prepareStatement(sqlAdmin);
ResultSet resultSetAdmin = preparedStatement_admin.executeQuery();
ResultSet resultSet = preparedStatement.executeQuery();
Map<String, Integer> map = new HashMap<>();
while (resultSet.next()) {
......@@ -61,7 +65,9 @@ public class StorageTag {
}
insert(map);
insertAdmin(resultSetAdmin);
resultSet.close();
resultSetAdmin.close();
preparedStatement.close();
connection.close();
} catch (Exception e) {
......@@ -71,6 +77,9 @@ public class StorageTag {
if (preparedStatement != null) {
preparedStatement.close();
}
if (preparedStatement_admin != null) {
preparedStatement_admin.close();
}
} catch (SQLException se) {
}
try {
......@@ -99,8 +108,68 @@ public class StorageTag {
sql.append("'").append(packageName).append("',");
}
stmt1.execute(deleteSql1 + "(" + sql.substring(0, sql.length() - 1) + ")");
stmt1.close();
stmt2.execute(deleteSql2 + "(" + sql.substring(0, sql.length() - 1) + ")");
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) {
e.printStackTrace();
}
......@@ -142,7 +211,9 @@ public class StorageTag {
}
}
delete(packageSet);
if (packageSet.size() > 0) {
delete(packageSet);
}
Iterator<String> iters = tagMap.keySet().iterator();
while (iters.hasNext()) {
......@@ -163,12 +234,19 @@ public class StorageTag {
"VALUES";
// 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));
stmt.executeQuery(insert_sql1 + insertSql_1.substring(0, insertSql_1.length() - 1));
stmt1.executeQuery(insert_sql2 + insertSql_2.substring(0, insertSql_2.length() - 1));
if (insertSql_1.length() > 0) {
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();
} catch (Exception e) {
e.printStackTrace();
}
if (packageSet.size() > 0) {
update(packageSet);
}
}
private static Map<String, String> getMap() {
......
......@@ -72,8 +72,7 @@ function load() {
'<a class="btn btn-primary btn-sm ' +
s_edit_h +
'" href="#" mce_href="#" title="编辑" onclick="edit(\'' +
row.packageName +
'\')"><i class="fa fa-edit"></i></a> ';
row.packageName +'\',\''+row.userId+ '\')"><i class="fa fa-edit"></i></a> ';
return e;
}
}
......@@ -95,13 +94,13 @@ function reLoad(type) {
}
function edit(package_name) {
function edit(package_name, user_id) {
layer.open({
type: 2,
title: "标签标注",
maxmin: true,
shadeClose: true, // 点击遮罩关闭层
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