Commit d285c948 authored by 赵然's avatar 赵然

zr

parent be7dc363
...@@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.ResponseBody; ...@@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.net.URLEncoder;
import java.util.Base64; import java.util.Base64;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -63,7 +64,7 @@ public class CreatUrlModule { ...@@ -63,7 +64,7 @@ public class CreatUrlModule {
params.put("uid",userId); params.put("uid",userId);
params.put("credits",credits); params.put("credits",credits);
if(dcustom!=null&&dcustom!=""&&dcustom != "null") { if(dcustom!=null&&dcustom!=""&&dcustom != "null") {
params.put("dcustom", dcustom); params.put("dcustom", URLEncoder.encode( dcustom, "UTF-8" ));
} }
if(transfer!=null&&transfer!=""&&transfer != "null"){ if(transfer!=null&&transfer!=""&&transfer != "null"){
params.put("transfer",transfer); params.put("transfer",transfer);
......
package main.com.atguigu.springmvc.handlers; 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.MatcherString;
import main.com.atguigu.springmvc.common.MysqlUtils; import main.com.atguigu.springmvc.common.MysqlUtils;
import main.com.atguigu.springmvc.service.Authorization; import main.com.atguigu.springmvc.service.Authorization;
import main.com.atguigu.springmvc.service.NewActivityService; import main.com.atguigu.springmvc.service.NewActivityService;
import io.restassured.response.Response;
import main.com.atguigu.springmvc.service.SqlService; import main.com.atguigu.springmvc.service.SqlService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.Base64; import java.text.SimpleDateFormat;
import java.util.HashMap; import java.util.*;
import java.util.Map;
import static io.restassured.RestAssured.given;
//@RequestMapping("/Sign")
@Controller @Controller
public class CollectModule { public class NewSignModule {
@Autowired @Autowired
NewActivityService newActivityService; NewActivityService newActivityService;
@Autowired @Autowired
...@@ -31,300 +29,263 @@ public class CollectModule { ...@@ -31,300 +29,263 @@ public class CollectModule {
SqlService sqlService; SqlService sqlService;
final Base64.Decoder decoder = Base64.getDecoder(); final Base64.Decoder decoder = Base64.getDecoder();
private MysqlUtils jdbc;
private String consumer_base64 = null ;
/** /**
* 功能:助力集卡综合操作 * 功能:清除所有的签到记录
* @return * @return
*/ */
@RequestMapping(value = "/doAction", method= RequestMethod.POST) @RequestMapping(value = "/clearAll", method= RequestMethod.POST)
@ResponseBody @ResponseBody
public Map doAction(HttpServletRequest request) throws Exception { public Map clearAll(HttpServletRequest request) throws Exception {
String action = request.getParameter("action");
String activity_id = request.getParameter("activity_id"); //String userId = request.getParameter("userId");
String share_id = request.getParameter("share_id"); java.net.URLDecoder urlDecoder=new java.net.URLDecoder();
String rule_id = request.getParameter("rule_id"); String userId = urlDecoder.decode(request.getParameter("userId"),"utf-8");
String help_id = request.getParameter("help_id");
String projectId = request.getParameter("projectId");
String playwayId = request.getParameter("playwayId");
System.out.println("用户id:" + userId);
System.out.println("项目id:" + projectId);
System.out.println("玩法id:" + playwayId);
//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);
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);
System.out.println("活动id:" + activity_id);
System.out.println("分享者为:" + share_id);
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
if (action.equals("searchShareCode")) {
Response response = newActivityService.getShareCode(activity_id, "hdtool", Integer.parseInt(share_id));
String shareCode = String.valueOf(response.jsonPath().getString("shareCode"));
//Map<String, String> map = new HashMap<>();
map.put("action", "searchShareCode");
map.put("shareCode", shareCode);
} else if (action.equals("helpCollect")) {
Response response = newActivityService.getShareCode(activity_id, "hdtool", Integer.parseInt(share_id));
String shareCode = String.valueOf(response.jsonPath().getString("shareCode"));
response = newActivityService.helpShareCodeV2(Integer.parseInt(help_id),rule_id,activity_id,"hdtool",shareCode);
String itemId = response.jsonPath().getString("itmeId");
String success = response.jsonPath().getString("success");
String message = response.jsonPath().getString("message");
if(message.equals("请求成功")){
Map good = jdbc.findSimpleResult("select * from goods.item where id = "+itemId);
String card_name = String.valueOf(good.get("name"));
map.put("message", "助力成功,分享者新增卡片id为:"+itemId+",卡片名称为:"+card_name);
//释放数据库
jdbc.releaseConn();
}else {
map.put("message", message);
}
map.put("action", "helpCollect");
map.put("success", success);
} else if (action.equals("dohelp")) {
Response response = newActivityService.getShareCode(activity_id, "hdtool", Integer.parseInt(share_id));
String shareCode = String.valueOf(response.jsonPath().getString("shareCode"));
System.out.println("分享码为:" + shareCode);
response = newActivityService.doHelp(Integer.parseInt(help_id),activity_id,"hdtool",shareCode);
System.out.println("doHelp结果为:" + response.asString());
String data = String.valueOf(response.jsonPath().getString("data"));
System.out.println("订单号为:" + data);
String success = String.valueOf(response.jsonPath().getString("success"));
String desc = String.valueOf(response.jsonPath().getString("desc"));
System.out.println("success为:" + success);
System.out.println("message为:" + desc);
if(success.equals("true")){
response = newActivityService.inviteBonusRecord(data,Integer.parseInt(help_id));
System.out.println("轮询结果:" + response.asString());
String recordStatus = response.jsonPath().getString("data.recordStatus");
System.out.println("状态码为:" + recordStatus);
int i= 10;
while(i>0&&(recordStatus.equals("0"))){
Thread.sleep(1000);
response = newActivityService.inviteBonusRecord(data,Integer.parseInt(help_id));
recordStatus = response.jsonPath().getString("data.recordStatus");
System.out.println("状态码为:" + recordStatus);
i--;
System.out.println("轮询结果:" + response.asString());
}
String bonusDetail = String.valueOf(response.jsonPath().getString("data.bonusDetail"));
System.out.println("返回的结果为:" + bonusDetail);
if(bonusDetail.equals("null")) {
map.put("message", "助力成功,但助力者并没有获得任何奖励哦~~" );
}else{
String type = MatcherString.getString(bonusDetail, "\\{\"(.*?)\"", 1);
System.out.println("助力结果为:" + type);
if (type.equals("itemId")) {
String itemId = MatcherString.getString(bonusDetail, "\":(.*?)\\}", 1);
System.out.println("itemId为:" + itemId);
Map good = jdbc.findSimpleResult("select * from goods.item where id = " + itemId);
String card_name = String.valueOf(good.get("name"));
map.put("message", "助力成功,助力者新增卡片id为:" + itemId + ",卡片名称为:" + card_name);
//释放数据库
jdbc.releaseConn();
} else {
String times = MatcherString.getString(bonusDetail, "times\":(.*?)\\}", 1);
map.put("message", "助力成功,助力者新增抽奖次数为:" + times);
}
}
}else {
map.put("message", desc);
}
map.put("action", "dohelp");
map.put("success", success);
}
else if (action.equals("clearRecord")) {
map.put("action", "clearRecord");
jdbc = MysqlUtils.mysqlDuiba("act_com_conf");
//获取分享者分享码
Response response = newActivityService.getShareCode(activity_id, "hdtool", Integer.parseInt(share_id));
String shareCode = String.valueOf(response.jsonPath().getString("shareCode"));
//获取助力者consumer_id
Map<String,String> login_map = authorization.dafuwengLogin(Integer.parseInt(help_id));
System.out.println("助力者login_map为:" + login_map.toString());
String 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 sql = "SELECT * FROM ckvtable.tb_kvtable_"+tag+" where consumer_id = '"+consumerId+"' and vkey = 'cl_good_cid_itemId_"+consumerId+"_"+cardId+"';";
String sql = "SELECT * FROM projectx.tb_action_record where user_id = '"+consumerId+"' and project_id = '"+projectId+"' and playway_id = '"+playwayId+"'";
Response response = sqlService.findSimpleResult(sql);
System.out.println("查询结果为:" + response.asString());
if (response.asString().equals("{}")) {
map.put("success", "true");
map.put("message", "该用户未签到!");
}else {
try { try {
jdbc.update("delete from tb_share_code_record where invited_consumer_id = '"+consumerId+"' and share_code = '"+shareCode+"'", null); //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("DELETE FROM projectx.tb_action_record where user_id = '"+consumerId+"' and project_id = '"+projectId+"' and playway_id = '"+playwayId+"'");
map.put("success", "true"); map.put("success", "true");
map.put("message", "用户"+userId+"的签到记录清除成功!");
} catch (Exception e) { } catch (Exception e) {
map.put("success", "false"); map.put("success", "false");
map.put("message", "清除签到数据失败!");
} }
//释放数据库
jdbc.releaseConn();
} }
return map; return map;
} }
/** /**
* 功能:设置卡片数量操作 * 功能:清除当天签到记录
* @return * @return
*/ */
@RequestMapping(value = "/doSet", method= RequestMethod.POST) @RequestMapping(value = "/clearToday", method= RequestMethod.POST)
@ResponseBody @ResponseBody
public Map doSet(HttpServletRequest request) throws Exception { public Map clearToday(HttpServletRequest request) throws Exception {
//String userId = request.getParameter("userId"); //String userId = request.getParameter("userId");
java.net.URLDecoder urlDecoder=new java.net.URLDecoder(); java.net.URLDecoder urlDecoder=new java.net.URLDecoder();
String userId = urlDecoder.decode(request.getParameter("userId"),"utf-8"); String userId = urlDecoder.decode(request.getParameter("userId"),"utf-8");
String cardId = request.getParameter("cardId"); String projectId = request.getParameter("projectId");
String count = request.getParameter("count"); String playwayId = request.getParameter("playwayId");
String type = request.getParameter("type");
consumer_base64 = urlDecoder.decode(request.getParameter("ac"),"utf-8");
System.out.println("用户id:" + userId); System.out.println("用户id:" + userId);
System.out.println("用户ac:" + consumer_base64); System.out.println("项目id:" + projectId);
System.out.println("卡片id:" + cardId); System.out.println("玩法id:" + playwayId);
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 //userid转consumerid
//Map<String,String> login_map = authorization.dafuwengLogin(Integer.parseInt(userId)); Map<String,String> login_map = authorization.dafuwengLogin(Integer.parseInt(userId));
if(consumer_base64.isEmpty()|| consumer_base64.equals(null) || consumer_base64.equals("")) { System.out.println("用户login_map为:" + login_map.toString());
Map<String, String> login_map = authorization.dafuwengLoginStr(userId); String consumer_base64 = String.valueOf(login_map.get("_ac"));
System.out.println("用户login_map为:" + login_map.toString()); System.out.println("用户consumer_base64为:" + consumer_base64);
consumer_base64 = String.valueOf(login_map.get("_ac"));
System.out.println("用户consumer_base64为:" + consumer_base64);
}
String decodedText = new String(decoder.decode(consumer_base64)); String decodedText = new String(decoder.decode(consumer_base64));
System.out.println("用户consumer_base64转码后为:" + decodedText); System.out.println("助力者consumer_base64转码后为:" + decodedText);
String consumerId = MatcherString.getString(decodedText, "cid\":(.*?)}", 1); String consumerId = MatcherString.getString(decodedText, "cid\":(.*?)}", 1);
System.out.println("用户consumer_id为:" + consumerId); 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);
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
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+"';"; String sql = "SELECT * FROM projectx.tb_action_record where user_id = '"+consumerId+"' and project_id = '"+projectId+"' and playway_id = '"+playwayId+"' and to_days(gmt_create) = to_days(now())";
Response response = sqlService.findSimpleResult(sql); Response response = sqlService.findSimpleResult(sql);
System.out.println("查询结果为:" + response.asString()); System.out.println("查询结果为:" + response.asString());
if (response.asString().equals("{}")) { if (response.asString().equals("{}")) {
try { map.put("success", "true");
//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')"; map.put("message", "该用户当天未签到!");
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("如果卡片原本为空,重置成功!");
map.put("success", "true");
map.put("message", "卡片数设置成功,用户"+userId+"的"+card_name+"(卡)数量为:"+count);
} catch (Exception e) {
map.put("success", "false");
map.put("message", "卡片数设置失败!");
}
}else { }else {
try { 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+"'"); sqlService.update("DELETE FROM projectx.tb_action_record where user_id = '"+consumerId+"' and project_id = '"+projectId+"' and playway_id = '"+playwayId+"' and to_days(gmt_create) = to_days(now())" );
System.out.println("如果卡片原本有值,重置成功!");
map.put("success", "true"); map.put("success", "true");
map.put("message", "卡片数设置成功,用户"+userId+"的"+card_name+"(卡)数量为:"+count); map.put("message", "用户"+userId+"当日的签到记录清除成功!");
} catch (Exception e) { } catch (Exception e) {
map.put("success", "false"); map.put("success", "false");
map.put("message", "卡片数设置失败!"); map.put("message", "清除签到数据失败!");
} }
} }
return map; return map;
} }
/** /**
* 功能:清除开大奖记录 * 功能:查询签到记录
* @return * @return
*/ */
@RequestMapping(value = "/doClear", method= RequestMethod.POST) @RequestMapping(value = "/getSignInfo", method= RequestMethod.POST)
@ResponseBody @ResponseBody
public Map doClear(HttpServletRequest request) throws Exception { public Map getSignInfo(HttpServletRequest request) throws Exception {
//String userId = request.getParameter("userId"); //String userId = request.getParameter("userId");
java.net.URLDecoder urlDecoder=new java.net.URLDecoder(); java.net.URLDecoder urlDecoder=new java.net.URLDecoder();
String userId = urlDecoder.decode(request.getParameter("userId"),"utf-8"); String userId = urlDecoder.decode(request.getParameter("userId"),"utf-8");
String ruleId = request.getParameter("ruleId"); String projectId = request.getParameter("projectId");
String termId = request.getParameter("termId"); String playwayId = request.getParameter("playwayId");
consumer_base64 = request.getParameter("ac");
System.out.println("用户id:" + userId); System.out.println("用户id:" + userId);
System.out.println("助力id:" + ruleId); System.out.println("项目id:" + projectId);
consumer_base64 = urlDecoder.decode(request.getParameter("ac"),"utf-8"); System.out.println("玩法id:" + playwayId);
//userid转consumerid //userid转consumerid
if(consumer_base64.isEmpty()|| consumer_base64.equals(null) || consumer_base64.equals("")) { Map<String,String> login_map = authorization.dafuwengLogin(Integer.parseInt(userId));
Map<String, String> login_map = authorization.dafuwengLogin(Integer.parseInt(userId)); System.out.println("用户login_map为:" + login_map.toString());
System.out.println("用户login_map为:" + login_map.toString()); String consumer_base64 = String.valueOf(login_map.get("_ac"));
consumer_base64 = String.valueOf(login_map.get("_ac")); System.out.println("用户consumer_base64为:" + consumer_base64);
System.out.println("用户consumer_base64为:" + consumer_base64);
}
String decodedText = new String(decoder.decode(consumer_base64)); String decodedText = new String(decoder.decode(consumer_base64));
System.out.println("用户consumer_base64转码后为:" + decodedText); System.out.println("助力者consumer_base64转码后为:" + decodedText);
String consumerId = MatcherString.getString(decodedText, "cid\":(.*?)}", 1); String consumerId = MatcherString.getString(decodedText, "cid\":(.*?)}", 1);
System.out.println("用户consumer_id为:" + consumerId); System.out.println("用户consumer_id为:" + consumerId);
String tag = String.format("%04d", Long.parseLong(consumerId) % 1024);
System.out.println("用户consumer_id的取余为:" + tag);
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
//String sql = "SELECT * FROM ckvtable.tb_kvtable_"+tag+" where consumer_id = '"+consumerId+"' and vkey = 'cl_good_cid_itemId_"+consumerId+"_"+cardId+"';";
String sql = "SELECT * FROM projectx.tb_action_record where user_id = '"+consumerId+"' and project_id = '"+projectId+"' and playway_id = '"+playwayId+"'";
//String sql = "SELECT * FROM ckvtable.tb_kvtable_"+tag+" where consumer_id = '"+consumerId+"' and vkey = 'cl_good_cid_Crule_grade_"+consumerId+"_"+ruleId+"_"+termId+"'"; Response response = sqlService.findModeResult(sql);
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");
// Map data = jdbc.findSimpleResult(sql);
Response response = sqlService.findSimpleResult(sql);
System.out.println("查询结果为:" + response.asString()); System.out.println("查询结果为:" + response.asString());
if (response.asString().equals("{}")) {
map.put("success", "false"); if (response.asString().equals("[]")) {
map.put("message", "该用户未开过大奖"); map.put("success", "true");
map.put("message", "该用户未签到!");
}else { }else {
try { String str = response.asString();
//jdbc.update("delete FROM tb_kvtable_"+tag+" where consumer_id = '"+consumerId+"' and vkey = 'cl_good_cid_Crule_grade_"+consumerId+"_"+ruleId+"_"+termId+"'"); JSONArray ar = JSONArray.parseArray(str);
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"); // List<JSONObject> list = new ArrayList<>();
map.put("message", "用户"+userId+"的开大奖记录清除成功"); // for(int i =0;i<ar.size();i++){
} catch (Exception e) { // list.add(ar.getJSONObject(i));
map.put("success", "false"); // }
map.put("message", "用户"+userId+"的开大奖记录清除失败"); //
// //取值
// System.out.println(list.get(0).getString("gmt_create"));
String SignInfo = "";
for(int i =0;i<ar.size();i++){
SignInfo = SignInfo + ar.getJSONObject(i).getString("gmt_create") + " 签到成功\n";
} }
map.put("success", "true");
map.put("message", SignInfo);
} }
return map;
}
/**
* 功能:模拟用户连续签到记录(不含当天)
* @return
*/
@RequestMapping(value = "/doSign", method= RequestMethod.POST)
@ResponseBody
public Map doSign(HttpServletRequest request) throws Exception {
java.net.URLDecoder urlDecoder=new java.net.URLDecoder();
String userId = urlDecoder.decode(request.getParameter("userId"),"utf-8");
String projectId = request.getParameter("projectId");
String playwayId = request.getParameter("playwayId");
String continue_day = request.getParameter("days");
String discon = request.getParameter("discon");
System.out.println("用户id:" + userId);
System.out.println("项目id:" + projectId);
System.out.println("玩法id:" + playwayId);
System.out.println("连续签到天数为:" + continue_day);
System.out.println("是否断签:" + discon);
String[] temp = playwayId.split("_");
System.out.println("分割前数据为:" + temp[0] + "分割后数据为:" + temp[1]);
//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);
//释放数据库 String decodedText = new String(decoder.decode(consumer_base64));
//jdbc.releaseConn(); System.out.println("助力者consumer_base64转码后为:" + decodedText);
String consumerId = MatcherString.getString(decodedText, "cid\":(.*?)}", 1);
System.out.println("用户consumer_id为:" + consumerId);
int i= Integer.valueOf(continue_day);
if(discon.equals("1")) {
while (i > 1) {
String sign_date = this.getTime(i * (-1));
Thread.sleep(500);
String sql2 = "INSERT INTO projectx.tb_action_record (project_id, playway_id, action_id, user_id, playway_type, extra, gmt_create, gmt_modified) values ( '" + projectId + "', '" + playwayId + "', '" + temp[0] + "', '" + consumerId + "', " + temp[1] + ", null, '" + sign_date + "', '2019-10-10 16:20:57')";
sqlService.update(sql2);
i--;
}
}else {
while (i > 0) {
String sign_date = this.getTime(i * (-1));
Thread.sleep(500);
String sql2 = "INSERT INTO projectx.tb_action_record (project_id, playway_id, action_id, user_id, playway_type, extra, gmt_create, gmt_modified) values ( '" + projectId + "', '" + playwayId + "', '" + temp[0] + "', '" + consumerId + "', " + temp[1] + ", null, '" + sign_date + "', '2019-10-10 16:20:57')";
sqlService.update(sql2);
i--;
}
}
Map<String, String> map = new HashMap<>();
map.put("success", "true");
map.put("message", "签到模拟成功!\n请点击【查看记录】确认用户当前签到情况~");
return map; return map;
} }
public String getTime(int amount){
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH, amount);
date = calendar.getTime();
String time = dateFormat.format(date);
return time;
}
} }
package main.com.atguigu.springmvc.handlers; package main.com.atguigu.springmvc.handlers;
import main.com.atguigu.springmvc.common.MysqlUtils; import main.com.atguigu.springmvc.common.MysqlUtils;
import main.com.atguigu.springmvc.service.SqlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
...@@ -16,6 +18,8 @@ import java.util.Locale; ...@@ -16,6 +18,8 @@ import java.util.Locale;
@Controller @Controller
public class SignModule { public class SignModule {
@Autowired
SqlService sqlService;
private MysqlUtils jdbc; private MysqlUtils jdbc;
private static final String SUCCESS = "success"; private static final String SUCCESS = "success";
...@@ -35,12 +39,18 @@ public class SignModule { ...@@ -35,12 +39,18 @@ public class SignModule {
//链接数据库 //链接数据库
jdbc = MysqlUtils.mysqlDuiba("sign_record"); //jdbc = MysqlUtils.mysqlDuiba("sign_record");
//执行数据库 //执行数据库
jdbc.update("delete from sign_record.tb_sign_log where consumer_id="+consumer_id+" and source_relation_id="+source_relation_id+""); //jdbc.update("delete from sign_record.tb_sign_log where consumer_id="+consumer_id+" and source_relation_id="+source_relation_id+"");
jdbc.update("delete from sign_record.tb_sign_statics where consumer_id="+consumer_id+" and source_relation_id="+source_relation_id+""); //jdbc.update("delete from sign_record.tb_sign_statics where consumer_id="+consumer_id+" and source_relation_id="+source_relation_id+"");
//释放数据库 //释放数据库
jdbc.releaseConn(); //jdbc.releaseConn();
String sql1 = "delete from sign_record.tb_sign_log where consumer_id='"+consumer_id+"' and source_relation_id='"+source_relation_id+"'";
String sql2 = "delete from sign_record.tb_sign_statics where consumer_id='"+consumer_id+"' and source_relation_id='"+source_relation_id+"'";
sqlService.update(sql1);
sqlService.update(sql2);
return new ModelAndView(SUCCESS); return new ModelAndView(SUCCESS);
} }
...@@ -71,22 +81,26 @@ public class SignModule { ...@@ -71,22 +81,26 @@ public class SignModule {
System.out.println("签到类型为:"+sign_type); System.out.println("签到类型为:"+sign_type);
//链接数据库 //链接数据库
jdbc = MysqlUtils.mysqlDuiba("sign_record"); //jdbc = MysqlUtils.mysqlDuiba("sign_record");
//执行数据库 //执行数据库
jdbc.update("INSERT INTO `tb_sign_statics` (`consumer_id`, `source_type`, `source_relation_id`, `continue_day`, `last_sign_day`, `gmt_create`, `gmt_modified`, `app_id`, `acm_day`) VALUES ( '"+consumer_id+"', '2', '"+source_relation_id+"', '"+continue_day+"', '"+last_sign_day+"', '"+last_sign_day+"', '"+last_sign_day+"', '"+app_id+"', '"+continue_day+"')", null); //jdbc.update("INSERT INTO sign_record.tb_sign_statics (`consumer_id`, `source_type`, `source_relation_id`, `continue_day`, `last_sign_day`, `gmt_create`, `gmt_modified`, `app_id`, `acm_day`) VALUES ( '"+consumer_id+"', '2', '"+source_relation_id+"', '"+continue_day+"', '"+last_sign_day+"', '"+last_sign_day+"', '"+last_sign_day+"', '"+app_id+"', '"+continue_day+"')", null);
String sql1 = "INSERT INTO sign_record.tb_sign_statics (`consumer_id`, `source_type`, `source_relation_id`, `continue_day`, `last_sign_day`, `gmt_create`, `gmt_modified`, `app_id`, `acm_day`, `max_continue_day`) VALUES ( '"+consumer_id+"', '2', '"+source_relation_id+"', '"+continue_day+"', '"+last_sign_day+"', '"+last_sign_day+"', '"+last_sign_day+"', '"+app_id+"', '"+continue_day+"', '"+continue_day+"')";
sqlService.update(sql1);
int i= Integer.valueOf(continue_day); int i= Integer.valueOf(continue_day);
while(i>0){ while(i>0){
String sign_date =this.getTime(i*(-1)); String sign_date =this.getTime(i*(-1));
Thread.sleep(500); Thread.sleep(500);
String log_id = String.valueOf(System.currentTimeMillis()); String log_id = String.valueOf(System.currentTimeMillis());
jdbc.update("INSERT INTO `tb_sign_log` ( `log_id`, `biz_id`, `consumer_id`, `credits`, `sign_type`, `log_statue`, `gmt_create`, `gmt_modified`, `source_type`, `source_relation_id`, `activity_count`, `activity_count_remark`, `credits_remark`, `activity_count_status`, `credits_status`, `sign_date`, `re_sign`, `sign_remark`, `app_id`) VALUES ( '"+log_id+"', NULL, '"+consumer_id+"', '0', '"+sign_type+"', '2', '"+sign_date+"', '"+sign_date+"', '2', '"+source_relation_id+"', '0', '{\\\"rw\\\":{}}', '{\\\"rw\\\":{}}', '2', '2', '"+sign_date+"', '0', NULL, '"+app_id+"')"); //jdbc.update("INSERT INTO sign_record.tb_sign_log ( `log_id`, `biz_id`, `consumer_id`, `credits`, `sign_type`, `log_statue`, `gmt_create`, `gmt_modified`, `source_type`, `source_relation_id`, `activity_count`, `activity_count_remark`, `credits_remark`, `activity_count_status`, `credits_status`, `sign_date`, `re_sign`, `sign_remark`, `app_id`) VALUES ( '"+log_id+"', NULL, '"+consumer_id+"', '0', '"+sign_type+"', '2', '"+sign_date+"', '"+sign_date+"', '2', '"+source_relation_id+"', '0', '{\\\"rw\\\":{}}', '{\\\"rw\\\":{}}', '2', '2', '"+sign_date+"', '0', NULL, '"+app_id+"')");
String sql2 = "INSERT INTO sign_record.tb_sign_log ( `log_id`, `biz_id`, `consumer_id`, `credits`, `sign_type`, `log_statue`, `gmt_create`, `gmt_modified`, `source_type`, `source_relation_id`, `activity_count`, `activity_count_remark`, `credits_remark`, `activity_count_status`, `credits_status`, `sign_date`, `re_sign`, `sign_remark`, `app_id`) VALUES ( '"+log_id+"', NULL, '"+consumer_id+"', '0', '"+sign_type+"', '2', '"+sign_date+"', '"+sign_date+"', '2', '"+source_relation_id+"', '0', '{\\\"rw\\\":{}}', '{\\\"rw\\\":{}}', '2', '2', '"+sign_date+"', '0', NULL, '"+app_id+"')";
sqlService.update(sql2);
i--; i--;
} }
//释放数据库 //释放数据库
jdbc.releaseConn(); //jdbc.releaseConn();
return new ModelAndView(SUCCESS); return new ModelAndView(SUCCESS);
} }
......
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