Commit dee2d70e authored by 赵然's avatar 赵然

zr

parent 346317e9
......@@ -12,7 +12,7 @@ public class MysqlUtils {
//数据库密码
private String PASSWORD; //= "yanzi";
//驱动信息
private String DRIVER="com.mysql.jdbc.Driver";
private String DRIVER="com.mysql.cj.jdbc.Driver"; //com.mysql.jdbc.Driver
//数据库地址
private String URL;// = "jdbc:mysql://localhost:3306/mydb";
private Connection connection;
......@@ -57,7 +57,7 @@ public class MysqlUtils {
//
// }
public static MysqlUtils mysqlDuiba(String databaseName){
return new MysqlUtils("duiba_test","svbP3KUw2PurAnBb2rbs3vohF","172.16.80.25","3306",databaseName);
return new MysqlUtils("duiba_tmp","duiba_tmpkduiba_tmduiba_tmp","47.97.127.67","13002",databaseName);
}
/**
......@@ -144,13 +144,17 @@ public class MysqlUtils {
public List<Map<String, Object>> findModeResult(String sql, Object ...params) throws SQLException{
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
int index = 1;
pstmt = connection.prepareStatement(sql);
pstmt = connection.prepareStatement(sql,ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
pstmt.setFetchSize(Integer.MIN_VALUE);
pstmt.setFetchDirection(ResultSet.FETCH_REVERSE);
if(params != null && !(params.length==0)){
for(int i=0; i<params.length; i++){
pstmt.setObject(index++, params[i]);
}
}
resultSet = pstmt.executeQuery();
ResultSetMetaData metaData = resultSet.getMetaData();
int cols_len = metaData.getColumnCount();
while(resultSet.next()){
......
package main.com.atguigu.springmvc.entities;
import java.util.Date;
public class AppDO {
private Long id;
private String name;
private String appKey;
private String appSecret;
private Date gmtCreate;
private Date gmtModified;
private Long consumeTemplateId;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAppKey() {
return appKey;
}
public void setAppKey(String appKey) {
this.appKey = appKey;
}
public String getAppSecret() {
return appSecret;
}
public void setAppSecret(String appSecret) {
this.appSecret = appSecret;
}
public Date getGmtCreate() {
return gmtCreate;
}
public void setGmtCreate(Date gmtCreate) {
this.gmtCreate = gmtCreate;
}
public Date getGmtModified() {
return gmtModified;
}
public void setGmtModified(Date gmtModified) {
this.gmtModified = gmtModified;
}
public Long getConsumeTemplateId() {
return consumeTemplateId;
}
public void setConsumeTemplateId(Long consumeTemplateId) {
this.consumeTemplateId = consumeTemplateId;
}
}
package main.com.atguigu.springmvc.entities;
import java.util.Date;
public class UserDO {
private Long id;
private String name; //用户名
private Long credits = 0L ;//积分余额
private boolean enable = false; //该用户是否可用
private Long version=0L;
private Long appId;
private String gmtCreate;
private String gmtModified;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Long getCredits() {
return credits;
}
public void setCredits(Long credits) {
this.credits = credits;
}
public boolean isEnable() {
return enable;
}
public void setEnable(boolean enable) {
this.enable = enable;
}
public String getGmtCreate() {
return gmtCreate;
}
public void setGmtCreate(String gmtCreate) {
this.gmtCreate = gmtCreate;
}
public String getGmtModified() {
return gmtModified;
}
public void setGmtModified(String gmtModified) {
this.gmtModified = gmtModified;
}
public Long getVersion() {
return version;
}
public void setVersion(Long version) {
this.version = version;
}
public Long getAppId() {
return appId;
}
public void setAppId(Long appId) {
this.appId = appId;
}
}
......@@ -33,6 +33,7 @@ public class CollectModule {
final Base64.Decoder decoder = Base64.getDecoder();
private MysqlUtils jdbc;
private String consumer_base64 = null ;
/**
* 功能:助力集卡综合操作
* @return
......@@ -175,27 +176,40 @@ public class CollectModule {
@ResponseBody
public Map doSet(HttpServletRequest request) throws Exception {
String userId = request.getParameter("userId");
//String userId = request.getParameter("userId");
java.net.URLDecoder urlDecoder=new java.net.URLDecoder();
String userId = urlDecoder.decode(request.getParameter("userId"),"utf-8");
String cardId = request.getParameter("cardId");
String count = request.getParameter("count");
String type = request.getParameter("type");
consumer_base64 = urlDecoder.decode(request.getParameter("ac"),"utf-8");
System.out.println("用户id:" + userId);
System.out.println("用户ac:" + consumer_base64);
System.out.println("卡片id:" + cardId);
System.out.println("卡片type:" + type);
Response good = sqlService.findSimpleResult("select * from goods.item where id = "+cardId);
String card_name = String.valueOf(good.jsonPath().getString("name"));
//userid转consumerid
Map<String,String> login_map = authorization.dafuwengLogin(Integer.parseInt(userId));
System.out.println("用户login_map为:" + login_map.toString());
String consumer_base64 = String.valueOf(login_map.get("_ac"));
System.out.println("用户consumer_base64为:" + consumer_base64);
//Map<String,String> login_map = authorization.dafuwengLogin(Integer.parseInt(userId));
if(consumer_base64.isEmpty()|| consumer_base64.equals(null) || consumer_base64.equals("")) {
Map<String, String> login_map = authorization.dafuwengLoginStr(userId);
System.out.println("用户login_map为:" + login_map.toString());
consumer_base64 = String.valueOf(login_map.get("_ac"));
System.out.println("用户consumer_base64为:" + consumer_base64);
}
String decodedText = new String(decoder.decode(consumer_base64));
System.out.println("用户consumer_base64转码后为:" + decodedText);
String consumerId = MatcherString.getString(decodedText, "cid\":(.*?)}", 1);
System.out.println("用户consumer_id为:" + consumerId);
String appId = MatcherString.getString(decodedText, "aid\":(.*?),", 1);
System.out.println("用户appid为:" + appId);
String tag = String.format("%04d", Long.parseLong(consumerId) % 1024);
System.out.println("用户consumer_id的取余为:" + tag);
......@@ -203,14 +217,17 @@ public class CollectModule {
map.put("cardId", cardId);
String sql = "SELECT * FROM ckvtable.tb_kvtable_"+tag+" where consumer_id = '"+consumerId+"' and vkey = 'cl_good_cid_itemId_"+consumerId+"_"+cardId+"';";
//String sql = "SELECT * FROM ckvtable.tb_kvtable_"+tag+" where consumer_id = '"+consumerId+"' and vkey = 'cl_good_cid_itemId_"+consumerId+"_"+cardId+"';";
String sql = "SELECT * FROM collect_card_consumer.tb_collect_card_info_"+tag+" where consumer_id = '"+consumerId+"' and item_id = '"+cardId+"';";
Response response = sqlService.findSimpleResult(sql);
System.out.println("查询结果为:" + response.asString());
if (response.asString().equals("{}")) {
try {
String sqlAdd = "INSERT INTO ckvtable.tb_kvtable_"+tag+" ( `consumer_id`, `vspace`, `vkey`, `int_value`, `string_value`, `gmt_create`, `gmt_modified`) VALUES ( '"+consumerId+"', 'duiba-activity-web', 'cl_good_cid_itemId_"+consumerId+"_"+cardId+"', '"+count+"', NULL, '2018-09-04 16:05:19', '2018-09-05 16:14:48')";
//String sqlAdd = "INSERT INTO ckvtable.tb_kvtable_"+tag+" ( `consumer_id`, `vspace`, `vkey`, `int_value`, `string_value`, `gmt_create`, `gmt_modified`) VALUES ( '"+consumerId+"', 'duiba-activity-web', 'cl_good_cid_itemId_"+consumerId+"_"+cardId+"', '"+count+"', NULL, '2018-09-04 16:05:19', '2018-09-05 16:14:48')";
String sqlAdd = "INSERT INTO collect_card_consumer.tb_collect_card_info_"+tag+" ( `app_id`, `consumer_id`, `partner_user_id`, `item_type`, `item_id`, `item_count`, `item_total_count`, `gmt_create`, `gmt_modify`) VALUES ( '"+appId+"','"+consumerId+"', '"+userId+"', '"+type+"', '"+cardId+"','"+count+"','"+count+"', '2018-09-04 16:05:19', '2018-09-05 16:14:48')";
System.out.println("sql为:" + sqlAdd);
sqlService.update(sqlAdd);
System.out.println("如果卡片原本为空,重置成功!");
......@@ -222,7 +239,9 @@ public class CollectModule {
}
}else {
try {
sqlService.update("update ckvtable.tb_kvtable_"+tag+" set int_value = '"+count+"' where consumer_id = '"+consumerId+"' and vkey = 'cl_good_cid_itemId_"+consumerId+"_"+cardId+"'");
//sqlService.update("update ckvtable.tb_kvtable_"+tag+" set int_value = '"+count+"' where consumer_id = '"+consumerId+"' and vkey = 'cl_good_cid_itemId_"+consumerId+"_"+cardId+"'");
sqlService.update("update collect_card_consumer.tb_collect_card_info_"+tag+" set item_count = '"+count+"',item_total_count = '"+count+"' where consumer_id = '"+consumerId+"' and item_id = '"+cardId+"'");
System.out.println("如果卡片原本有值,重置成功!");
map.put("success", "true");
......@@ -244,21 +263,27 @@ public class CollectModule {
@ResponseBody
public Map doClear(HttpServletRequest request) throws Exception {
String userId = request.getParameter("userId");
//String userId = request.getParameter("userId");
java.net.URLDecoder urlDecoder=new java.net.URLDecoder();
String userId = urlDecoder.decode(request.getParameter("userId"),"utf-8");
String ruleId = request.getParameter("ruleId");
String termId = request.getParameter("termId");
consumer_base64 = request.getParameter("ac");
System.out.println("用户id:" + userId);
System.out.println("助力id:" + ruleId);
consumer_base64 = urlDecoder.decode(request.getParameter("ac"),"utf-8");
//userid转consumerid
Map<String,String> login_map = authorization.dafuwengLogin(Integer.parseInt(userId));
System.out.println("用户login_map为:" + login_map.toString());
String consumer_base64 = String.valueOf(login_map.get("_ac"));
System.out.println("用户consumer_base64为:" + consumer_base64);
if(consumer_base64.isEmpty()|| consumer_base64.equals(null) || consumer_base64.equals("")) {
Map<String, String> login_map = authorization.dafuwengLogin(Integer.parseInt(userId));
System.out.println("用户login_map为:" + login_map.toString());
consumer_base64 = String.valueOf(login_map.get("_ac"));
System.out.println("用户consumer_base64为:" + consumer_base64);
}
String decodedText = new String(decoder.decode(consumer_base64));
System.out.println("用户consumer_base64转码后为:" + decodedText);
String consumerId = MatcherString.getString(decodedText, "cid\":(.*?)}", 1);
......@@ -270,7 +295,9 @@ public class CollectModule {
Map<String, String> map = new HashMap<>();
String sql = "SELECT * FROM ckvtable.tb_kvtable_"+tag+" where consumer_id = '"+consumerId+"' and vkey = 'cl_good_cid_Crule_grade_"+consumerId+"_"+ruleId+"_"+termId+"'";
//String sql = "SELECT * FROM ckvtable.tb_kvtable_"+tag+" where consumer_id = '"+consumerId+"' and vkey = 'cl_good_cid_Crule_grade_"+consumerId+"_"+ruleId+"_"+termId+"'";
String sql = "SELECT * FROM collect_card.tb_collect_card_win_record where consumer_id = '"+consumerId+"' and rule_id = '"+ruleId+"' and grade_level = '"+termId+"'";
System.out.println("sql为:" + sql);
// jdbc = MysqlUtils.mysqlDuiba("ckvtable");
......@@ -284,7 +311,7 @@ public class CollectModule {
}else {
try {
//jdbc.update("delete FROM tb_kvtable_"+tag+" where consumer_id = '"+consumerId+"' and vkey = 'cl_good_cid_Crule_grade_"+consumerId+"_"+ruleId+"_"+termId+"'");
sqlService.update("delete FROM ckvtable.tb_kvtable_"+tag+" where consumer_id = '"+consumerId+"' and vkey = 'cl_good_cid_Crule_grade_"+consumerId+"_"+ruleId+"_"+termId+"'");
sqlService.update("delete FROM collect_card.tb_collect_card_win_record where consumer_id = '"+consumerId+"' and rule_id = '"+ruleId+"' and grade_level = '"+termId+"'");
map.put("success", "true");
map.put("message", "用户"+userId+"的开大奖记录清除成功");
......
package main.com.atguigu.springmvc.handlers;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.restassured.response.Response;
import main.com.atguigu.springmvc.common.MatcherString;
import main.com.atguigu.springmvc.common.MysqlUtils;
import main.com.atguigu.springmvc.entities.AppDO;
import main.com.atguigu.springmvc.entities.UserDO;
import main.com.atguigu.springmvc.service.Authorization;
import main.com.atguigu.springmvc.service.NewActivityService;
import main.com.atguigu.springmvc.service.SqlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.testng.Assert;
import javax.servlet.http.HttpServletRequest;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import java.net.URLDecoder;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import static io.restassured.RestAssured.given;
@Controller
public class UserModule {
......@@ -20,11 +30,15 @@ public class UserModule {
NewActivityService newActivityService;
@Autowired
Authorization authorization;
@Autowired
SqlService sqlService;
private MysqlUtils jdbc;
private static Map<String,String> appMap = new ConcurrentHashMap<>();
final Base64.Decoder decoder = Base64.getDecoder();
/**
* 功能:查询用户基本信息
* 功能:partnerId查询用户基本信息
* @return
*/
@RequestMapping(value = "/searchInfo", method= RequestMethod.POST)
......@@ -58,4 +72,444 @@ public class UserModule {
return map;
}
/**
* 功能:consumerId查询用户基本信息
* @return
*/
@RequestMapping(value = "/searchInfo2", method= RequestMethod.POST)
@ResponseBody
public Map searchInfo2(HttpServletRequest request) throws Exception {
String consumerId = request.getParameter("consumerId");
System.out.println("用户consumerId为:" + consumerId);
Map<String, String> map = new HashMap<>();
int num = (int)Math.floor(Long.parseLong(consumerId) / 10000000L);
System.out.println("用户consumer_id取整为:" + num);
String tag = String.format("%04d", num);
System.out.println("用户consumer_id的分表tag为:" + tag);
Response sqlresul = sqlService.findSimpleResult("select * from new_consumer.consumer_"+tag+" where id = "+consumerId);
String partnerId = String.valueOf(sqlresul.jsonPath().getString("partner_user_id"));
String credits = String.valueOf(sqlresul.jsonPath().getString("credits"));
String appId = String.valueOf(sqlresul.jsonPath().getString("app_id"));
sqlresul = sqlService.findSimpleResult("select * from credits_dev.consumer_extra where consumer_id = "+consumerId);
String nickname = String.valueOf(sqlresul.jsonPath().getString("nickname"));
String avatar = String.valueOf(sqlresul.jsonPath().getString("avatar"));
String result = "consumer_id分表tag为:" + tag + "\npartnerId为:" + partnerId + "\n用户当前积分为:" + credits+ "\nappId为:" + appId+ "\n用户昵称为:" + nickname+ "\n用户头像为:" + avatar;
map.put("message", result);
return map;
}
/**
* 功能:查询所有用户基本信息
* @return
*/
@RequestMapping(value = "/user", method= RequestMethod.GET)
@ResponseBody
public Object user() throws Exception {
Response response = sqlService.findModeResult("select * from dafuweng.user ");
//System.out.println("值为:" + response.print());
String str = response.asString();
JSONArray ar = JSONArray.parseArray(str);
List<JSONObject> list = new ArrayList<>();
for(int i =0;i<ar.size();i++){
list.add(ar.getJSONObject(i));
}
return list;
}
/**
* 功能:查询所有应用基本信息
* @return
*/
@RequestMapping(value = "/app", method= RequestMethod.GET)
@ResponseBody
public Map app() throws Exception {
Response response = sqlService.findModeResult("select * from dafuweng.app ");
//System.out.println("值为:" + response.print());
String str = response.asString();
JSONArray ar = JSONArray.parseArray(str);
// List<JSONObject> list = new ArrayList<>();
// for(int i =0;i<ar.size();i++){
// list.add(ar.getJSONObject(i));
// }
Map<String, String> appMap = new HashMap<>();
for (int i =0;i<ar.size();i++) {
appMap.put(ar.getJSONObject(i).getString("id"), ar.getJSONObject(i).getString("name"));
}
return appMap;
}
/**
* 功能:查询所有应用基本信息
* @return
*/
@RequestMapping(value = "/app2", method= RequestMethod.POST)
@ResponseBody
public Map app2(HttpServletRequest request) throws Exception {
String appId = request.getParameter("appId");
if(appId.equals("")){
if(appMap==null||appMap.size()==0){
Response response = sqlService.findModeResult("select * from dafuweng.app where 1 = 1");
String str = response.asString();
JSONArray ar = JSONArray.parseArray(str);
appMap = new HashMap<>();
for (int i = 0; i < ar.size(); i++) {
appMap.put(ar.getJSONObject(i).getString("id"), ar.getJSONObject(i).getString("name"));
}
}else {
return appMap;
}
}else {
boolean tag = appMap.containsKey(appId);
if (tag == false ) {
Response response = sqlService.findModeResult("select * from dafuweng.app where id =" + appId);
String str = response.asString();
JSONArray ar = JSONArray.parseArray(str);
appMap = new HashMap<>();
appMap.put(ar.getJSONObject(0).getString("id"), ar.getJSONObject(0).getString("name"));
}else {
return appMap;
}
}
return appMap;
}
/**
* 功能:查询所有用户基本信息
* @return
*/
@RequestMapping(value = "/app3", method= RequestMethod.POST)
@ResponseBody
public Object app3(HttpServletRequest request) throws Exception {
String appId = request.getParameter("appId");
//获取用户
String Sql= "select * from dafuweng.app where 1 = 1";
if (!appId.equals("")){
Sql= Sql + " and id = "+ appId ;
}
Response response = sqlService.findModeResult(Sql);
String str = response.asString();
JSONArray ar = JSONArray.parseArray(str);
List<AppDO> applist = new ArrayList<>();
for(int i =0;i<ar.size();i++) {
AppDO appDO = new AppDO();
appDO.setId(Long.valueOf(ar.getJSONObject(i).getString("id")));
appDO.setName(ar.getJSONObject(i).getString("name"));
applist.add(appDO);
}
Map<Long, AppDO> appMap = new HashMap<>();
for (AppDO app : applist) {
appMap.put(app.getId(), app);
}
return appMap;
}
/**
* 功能:查询所有应用基本信息
* @return
*/
@RequestMapping(value = "/app4", method= RequestMethod.POST)
@ResponseBody
public Object app4(HttpServletRequest request) throws Exception {
String appId = request.getParameter("appId");
//获取用户
String Sql= "select * from dafuweng.app where 1 = 1";
if (!appId.equals("")){
Sql= Sql + " and id = "+ appId ;
}
Response response = sqlService.findModeResult(Sql);
String str = response.asString();
JSONArray ar = JSONArray.parseArray(str);
List<AppDO> applist = new ArrayList<>();
for(int i =0;i<ar.size();i++) {
AppDO appDO = new AppDO();
appDO.setId(Long.valueOf(ar.getJSONObject(i).getString("id")));
appDO.setName(ar.getJSONObject(i).getString("name"));
applist.add(appDO);
}
return applist;
}
/**
* 功能:查询所有应用基本信息
* @return
*/
@RequestMapping(value = "/app5", method= RequestMethod.POST)
@ResponseBody
public Object app5(HttpServletRequest request) throws Exception {
String appId = request.getParameter("appId");
//获取用户
String Sql= "select id,name from app where 1 = 1";
if (!appId.equals("")){
Sql= Sql + " and id = "+ appId ;
}
Sql= Sql + " order by id ASC ";
//链接数据库
jdbc = MysqlUtils.mysqlDuiba("dafuweng");
//执行数据库
List<Map<String, Object>> applist = jdbc.findModeResult(Sql);
//释放数据库
jdbc.releaseConn();
return applist;
}
/**
* 功能:查询对应用户基本信息
* @return
*/
@RequestMapping(value = "/sltuser", method= RequestMethod.POST)
@ResponseBody
public Object sltuser(HttpServletRequest request) throws Exception {
String userId = request.getParameter("userId");
String name = request.getParameter("name");
name = URLDecoder.decode(name , "utf-8");
String appId = request.getParameter("appId");
System.out.println("用户partnerId为:" + userId);
System.out.println("用户名称为:" + name);
System.out.println("appId为:" + appId);
//获取用户
String Sql= "select * from dafuweng.user where 1 = 1";
if (!userId.equals("")) {
Sql= Sql + " and id = "+ userId ;
}
if (!appId.equals("")){
Sql= Sql + " and app_id = "+ appId ;
}
if (!name.equals("")){
Sql= Sql + " and name like '%"+ name +"%'";
}
System.out.println("sql为:" + Sql);
Response response = sqlService.findModeResult(Sql);
System.out.println("值为:" + response.print());
String str = response.asString();
JSONArray ar = JSONArray.parseArray(str);
List<JSONObject> list = new ArrayList<>();
for(int i =0;i<ar.size();i++){
list.add(ar.getJSONObject(i));
//list.add(i,ar_app.getJSONObject(Integer.valueOf(ar.getJSONObject(i).getString("app_id"))));
}
return list;
}
/**
* 功能:查询对应用户基本信息
* @return
*/
@RequestMapping(value = "/sltuser2", method= RequestMethod.POST)
@ResponseBody
public Object sltuser2(HttpServletRequest request) throws Exception {
String userId = request.getParameter("userId");
String name = request.getParameter("name");
name = URLDecoder.decode(name , "utf-8");
String appId = request.getParameter("appId");
System.out.println("用户partnerId为:" + userId);
System.out.println("用户名称为:" + name);
System.out.println("appId为:" + appId);
//获取用户
String Sql= "select * from dafuweng.user where 1 = 1";
if (!userId.equals("")) {
Sql= Sql + " and id = "+ userId ;
}
if (!appId.equals("")){
Sql= Sql + " and app_id = "+ appId ;
}
if (!name.equals("")){
Sql= Sql + " and name like '%"+ name +"%'";
}
System.out.println("sql为:" + Sql);
Response response = sqlService.findModeResult(Sql);
System.out.println("值为:" + response.print());
String str = response.asString();
JSONArray ar = JSONArray.parseArray(str);
List<UserDO> userlist = new ArrayList<>();
for(int i =0;i<ar.size();i++) {
UserDO userDO = new UserDO();
userDO.setId(Long.valueOf(ar.getJSONObject(i).getString("id")));
userDO.setName(ar.getJSONObject(i).getString("name"));
userDO.setCredits(Long.valueOf(ar.getJSONObject(i).getString("credits")));
userDO.setAppId(Long.valueOf(ar.getJSONObject(i).getString("app_id")));
userDO.setGmtCreate(ar.getJSONObject(i).getString("gmt_create"));
userDO.setGmtModified(ar.getJSONObject(i).getString("gmt_modified"));
userlist.add(userDO);
}
return userlist;
}
/**
* 功能:查询对应用户基本信息
* @return
*/
@RequestMapping(value = "/sltuser3", method= RequestMethod.POST)
@ResponseBody
public Object sltuser3(HttpServletRequest request) throws Exception {
String userId = request.getParameter("userId");
String name = request.getParameter("name");
name = URLDecoder.decode(name , "utf-8");
String appId = request.getParameter("appId");
System.out.println("用户partnerId为:" + userId);
System.out.println("用户名称为:" + name);
System.out.println("appId为:" + appId);
//获取用户
String Sql= "select id,credits,gmt_create,gmt_modified,name,app_id from user where 1 = 1";
if (!userId.equals("")) {
Sql= Sql + " and id = "+ userId ;
}
if (!appId.equals("")){
Sql= Sql + " and app_id = "+ appId ;
}
if (!name.equals("")){
Sql= Sql + " and name like '%"+ name +"%'";
}
Sql= Sql + " order by id ASC ";
System.out.println("sql为:" + Sql);
//链接数据库
jdbc = MysqlUtils.mysqlDuiba("dafuweng");
//执行数据库
List<Map<String, Object>> userlist = jdbc.findModeResult(Sql);
//释放数据库
jdbc.releaseConn();
return userlist;
}
/**
* 功能:删除用户基本信息
* @return
*/
@RequestMapping(value = "/deluser", method= RequestMethod.POST)
@ResponseBody
public Map deluser(HttpServletRequest request) throws Exception {
String userId = request.getParameter("userId");
System.out.println("用户partnerId为:" + userId);
String Sql= "DELETE FROM dafuweng.user where id = "+userId;
Response response = sqlService.update(Sql);
Map<String, String> map = new HashMap<>();
if(response.asString().equals("true")) {
map.put("message", "success");
}else {
map.put("message", "false");
}
return map;
}
/**
* 功能:批量删除用户基本信息
* @return
*/
@RequestMapping(value = "/delbatch", method= RequestMethod.POST)
@ResponseBody
public Map delbatch(HttpServletRequest request) throws Exception {
Map<String, String> map = new HashMap<>();
int stid = Integer.valueOf(request.getParameter("stid"));
int edid = Integer.valueOf(request.getParameter("edid"));
for(int i=stid;i < edid+1;i++) {
String Sql = "DELETE FROM dafuweng.user where id = " + i;
Response response = sqlService.update(Sql);
if (response.asString().equals("true")) {
map.put("message"+i, "用户"+i+"删除成功");
} else {
map.put("message"+i, "用户"+i+"删除失败");
}
Thread.sleep(500);
}
return map;
}
/**
* 功能:创建用户
* @return
*/
@RequestMapping(value = "/crtuser", method= RequestMethod.POST)
@ResponseBody
public Map crtuser(HttpServletRequest request) throws Exception {
String name = request.getParameter("name");
name = URLDecoder.decode(name , "utf-8");
String appId = request.getParameter("appId");
String credits = request.getParameter("credits");
System.out.println("创建用户name为:" + name);
Map<String, String> map = new HashMap<>();
map.put("name",name);
map.put("appId",appId);
map.put("credits",credits);
Response response = given().contentType("application/x-www-form-urlencoded;charset=UTF-8").params(map).post("http://dafuweng.duibatest.com.cn/user/create");
Map<String, String> map2 = new HashMap<>();
if(String.valueOf(response.getStatusCode()).equals("302")){
map2.put("message","success");
map2.put("desc",name+"创建成功\n");
}else{
map2.put("message","false");
map2.put("desc",name+"创建失败\n");
}
return map2;
}
}
......@@ -59,6 +59,8 @@ public class Authorization {
private static Map<String,String> dafuwengCookies;
private static Map<Integer,Map> dafuwengCookiesMap = new HashMap<>();
private static Map<String,Map> dafuwengCookiesMapStr = new HashMap<>();
private static Map<String,String> hdCookies;
private static Map<String,String> hdCookiesMabo;
private Map<String,String> ssoCookies =null;
......@@ -103,6 +105,44 @@ public class Authorization {
return dafuwengCookiesMap.get(uid);
}
public Map dafuwengLoginStr(String uid){
int i=10;
while((dafuwengCookiesMapStr==null||dafuwengCookiesMapStr.get(uid)==null||dafuwengCookiesMapStr.get(uid).size()==0)&&i>0) {
// String url = PROTOCOL + dafuwengHost + ":" + dafuwengPort + dafuwengLoginPath;
String url = PROTOCOL + dafuwengHost + dafuwengLoginPath;
Response response=given().redirects().follow(false).param("uid",uid).get(url);
String location = response.getHeader("location");
dafuwengCookies=response.getCookies();
//logger.info(location);
URL url1=null;
try {
url1= new URL(location);
} catch (MalformedURLException e) {
e.printStackTrace();
}
if(url1!=null&&url1.getProtocol().equals("http")) {
response=given().cookies(dafuwengCookies).redirects().follow(false).get(location);
}else if(url1!=null&&url1.getProtocol().equals("https")){
response=given().cookies(dafuwengCookies).relaxedHTTPSValidation().redirects().follow(false).get(location);
}
dafuwengCookies=response.getCookies();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
dafuwengCookiesMapStr.put(uid,dafuwengCookies);
i--;
}
if(i==0&&dafuwengCookies==null){
// logger.info("dafuweng登陆app失败,cookies为null");
}
// logger.info("dafuweng cookies:"+dafuwengCookies.toString());
return dafuwengCookiesMapStr.get(uid);
}
/**
* 大富翁登陆
* @param uid
......
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