Commit ed887bac authored by 赵然's avatar 赵然

'zr'

parent b6786341
<component name="libraryTable">
<library name="Maven: commons-logging:commons-logging:1.2">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/commons-logging/commons-logging/1.2/commons-logging-1.2.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/commons-logging/commons-logging/1.2/commons-logging-1.2-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/commons-logging/commons-logging/1.2/commons-logging-1.2-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
......@@ -7,11 +7,9 @@ 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.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import java.net.URLEncoder;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
......@@ -65,13 +63,14 @@ public class CreatUrlModule {
System.out.println("userId为:"+userId);
System.out.println("credits为:"+credits);
System.out.println("dcustom为:"+dcustom);
System.out.println("type为:"+type);
CreditTool tool=new CreditTool(appkey, appsecret);
Map<String, String> params=new HashMap<String, String>();
params.put("uid",userId);
params.put("credits",credits);
if(dcustom!=null&&dcustom!=""&&dcustom != "null") {
if(type.equals("1")||type == null) {
if(type == null || type.equals("1")) {
params.put("dcustom", dcustom);
}else {
params.put("dcustom", URLEncoder.encode(dcustom, "UTF-8"));
......
......@@ -15,9 +15,9 @@ import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.LinkedBlockingQueue;
@Controller
public class RankModule {
......@@ -31,6 +31,9 @@ public class RankModule {
ViewService viewService;
final Base64.Decoder decoder = Base64.getDecoder();
private static String next_reset_time2;
private static String next_op_time2;
/**
* 功能:清除排行榜指定期次的开奖记录
......@@ -48,7 +51,8 @@ public class RankModule {
Map<String, String> map = new HashMap<>();
String sql = "select * from projectx.tb_ranking_config where project_id='"+projectId+"' and type = '"+type+"'";
//判断排行榜归档表tb_leaderboard_archive期次是否存在
String sql = "select * from projectx.tb_leaderboard_archive where project_id='"+projectId+"' and ranking_type = '"+type+"'";
Response response = sqlService.findSimpleResult(sql);
System.out.println("查询结果为:" + response.asString());
......@@ -58,13 +62,17 @@ public class RankModule {
map.put("message", "该期次无排行榜信息!");
}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 projectx.tb_ranking_config set send_prize='1',send_prize_time = NULL where project_id ='"+projectId+"' and type = '"+type+"'");
Thread.sleep(1000);
sqlService.update("update projectx.tb_ranking set prize_id=NULL,send_prize='0',send_prize_time = null where project_id ='"+projectId+"' and type = '"+type+"'");
//清除分数统计表tb_ranking人员的开奖信息
sqlService.update("update projectx.tb_ranking set prize_id = NULL,send_prize='0',send_prize_time = null where project_id ='"+projectId+"' and type = '"+type+"'");
Thread.sleep(500);
//重置归档表tb_leaderboard_archive表的开奖状态
sqlService.update("update projectx.tb_leaderboard_archive set op_status = '1',actual_op_time = NULL where project_id ='"+projectId+"' and ranking_type = '"+type+"'");
map.put("success", "true");
map.put("message", "期次"+type+"的开奖记录清除成功!");
} catch (Exception e) {
map.put("success", "false");
map.put("message", "清除开奖数据失败!");
......@@ -74,7 +82,47 @@ public class RankModule {
}
/**
* 功能:构建排行榜数据
* 功能:活动开始后,原本下期生效的奖品同步至本期
* @return
*/
@RequestMapping(value = "/syncprize", method= RequestMethod.POST)
@ResponseBody
public Map syncprize(HttpServletRequest request) throws Exception {
String projectId = request.getParameter("projectId");
//String type = request.getParameter("type");
System.out.println("项目id:" + projectId);
//System.out.println("期次id:" + type);
Map<String, String> map = new HashMap<>();
//判断排行榜配置表tb_leaderboard_config期次是否存在
String sql = "select * from projectx.tb_leaderboard_config where project_id='"+projectId+"'";
Response response = sqlService.findSimpleResult(sql);
System.out.println("查询结果为:" + response.asString());
if (response.asString().equals("{}")) {
map.put("success", "false");
map.put("message", "项目id无对应的配置信息!");
}else{
//提取当前配置的奖品json
String option = String.valueOf(response.jsonPath().getString("option_json"));
String current_version = String.valueOf(response.jsonPath().getString("current_version"));
//同步到当前期次
String sql2 = "UPDATE projectx.tb_leaderboard_archive set option_json = '"+option+"' where project_id='"+projectId+"' and leaderboard_version = '"+current_version+"'";
sqlService.update(sql2);
map.put("success", "true");
map.put("message", "原本下期生效的奖品已同步至当期!");
}
return map;
}
/**
* 功能:构建排行榜数据(手动)
* @return
*/
@RequestMapping(value = "/creatRankData", method= RequestMethod.POST)
......@@ -82,10 +130,23 @@ public class RankModule {
public Map creatRankData(HttpServletRequest request) throws Exception {
String projectId = request.getParameter("projectId");
String type = request.getParameter("type");
String tag = request.getParameter("tag");
System.out.println("项目id:" + projectId);
System.out.println("期次id:" + type);
Map<String, String> map = new HashMap<>();
//构建数据前先确认归档表tb_leaderboard_archive是否有对应的期次
String sql2 = "select * from projectx.tb_leaderboard_archive where project_id='"+projectId+"' and ranking_type = '"+type+"'";
Response response = sqlService.findSimpleResult(sql2);
System.out.println("查询结果为:" + response.asString());
if (response.asString().equals("{}")) {
map.put("success", "false");
map.put("message", "归档表无对应的期次,请先生成对应期次!");
}else{
//入参数据准备
String uids = request.getParameter("uids");
String[] uidParams = uids.split(",");
......@@ -102,10 +163,8 @@ public class RankModule {
//System.out.println("用户consumer_id为:" + consumerId);
consumerIds[i] = consumerId;
}
String score = request.getParameter("scores");
String[] scores = score.split(",");
int max;
if (uidParams.length < scores.length) {
max = uidParams.length;
......@@ -114,47 +173,313 @@ public class RankModule {
}
System.out.println("max值为:" + max);
Map<String, String> map = new HashMap<>();
//构建tb_ranking_config数据
String sql2 = "select * from projectx.tb_ranking_config where project_id='" + projectId + "' and type = '" + type + "'";
Response response = sqlService.findSimpleResult(sql2);
System.out.println("查询结果为:" + response.asString());
if (response.asString().equals("{}")) {
String sql3 = "insert into projectx.tb_ranking_config(project_id, type, ranking_name, send_prize, manual_send_prize, send_prize_time, error_message) values ('" + projectId + "', '" + type + "', '" + type + "', 1, 0, null, '')";
//清除原有数据
if(tag == null || tag.equals("1")) {
String sql3 = "DELETE FROM projectx.tb_ranking where project_id='" + projectId + "' and type = '" + type + "'";
sqlService.update(sql3);
}
//构建tb_ranking数据
//构建tb_ranking对应期次数据
for (int n = 0; n < max; n++) {
String a = scores[n];
Long base = 999999999999L;
Long b = Long.valueOf((new Date().getTime())/10);
//maxScoreOrder=分数+""+(999999999999-(当前时间戳/10));
BigDecimal num = new BigDecimal(base);
BigDecimal num2 = new BigDecimal(b);
BigDecimal result = num.subtract(num2);
String order = a.concat(String.valueOf(result));
String sql = "insert into projectx.tb_ranking(project_id, type, user_id, max_score, max_score_order, send_prize, prize_id, send_prize_time) values ('" + projectId + "', '" + type + "', '" + consumerIds[n] + "', '" + scores[n] + "', '" + order + "', 0, null, null)";
System.out.println("创建SQL为:" + sql);
sqlService.update(sql);
Thread.sleep(100);
}
map.put("success", "true");
map.put("message", type+"期排行榜数据构建成功!");
}
return map;
}
/**
* 功能:构建排行榜数据(自动)
* @return
*/
@RequestMapping(value = "/creatRankDataAuto", method= RequestMethod.POST)
@ResponseBody
public Map creatRankDataAuto(HttpServletRequest request) throws Exception {
String projectId = request.getParameter("projectId");
String type = request.getParameter("type");
int playerNum = Integer.parseInt(request.getParameter("playerNum"));
int scoreslimt = Integer.parseInt(request.getParameter("scoreslimt"));
String tag = request.getParameter("tag");
System.out.println("项目id:" + projectId);
System.out.println("期次id:" + type);
String appId = request.getParameter("appId");
//由appId获取dafuweng库app表id
Response response = sqlService.findSimpleResult("SELECT * FROM credits_dev.app where id = '"+appId+"'");
String app_key = String.valueOf(response.jsonPath().getString("app_key"));
Response response2 = sqlService.findSimpleResult("SELECT * FROM dafuweng.app where app_key = '"+app_key+"'");
String id = String.valueOf(response2.jsonPath().getString("id"));
//由大富翁模拟后台的应用id获取指定用户数
Response response3 = sqlService.findModeResult("SELECT id FROM dafuweng.user where app_id = '"+id+"' LIMIT "+playerNum+"");
//System.out.println("创建活动接口返回为:"+response3.asString());
//将获得的uid转成consumerId
//String aaa = String.valueOf(response3.jsonPath().getString("[0].id"));
String[] consumerIds = new String[playerNum];
for (int i = 0; i < consumerIds.length; i++) {
//将userid转consumerid
Map<String, String> login_map = authorization.dafuwengLogin(Integer.parseInt(response3.jsonPath().getString("["+i+"].id")));
String consumer_base64 = String.valueOf(login_map.get("_ac"));
String decodedText = new String(decoder.decode(consumer_base64));
String consumerId = MatcherString.getString(decodedText, "cid\":(.*?)}", 1);
System.out.println("用户consumerId为:"+consumerId);
consumerIds[i] = consumerId;
}
//构建数据前先确认归档表tb_leaderboard_archive是否有对应的期次
String sql2 = "select * from projectx.tb_leaderboard_archive where project_id='"+projectId+"' and ranking_type = '"+type+"'";
Response response4 = sqlService.findSimpleResult(sql2);
System.out.println("查询结果为:" + response4.asString());
Map<String, String> map = new HashMap<>();
if (response4.asString().equals("{}")) {
map.put("success", "false");
map.put("message", "归档表无对应的期次,请先生成对应期次!");
}else {
//清除原有数据
if(tag == null || tag.equals("1")) {
String sql3 = "DELETE FROM projectx.tb_ranking where project_id='" + projectId + "' and type = '" + type + "'";
sqlService.update(sql3);
}
//构建tb_ranking对应期次数据
for (int n = 0; n < consumerIds.length; n++) {
//构建随机分数
String a = String.valueOf((int)(Math.random()*(scoreslimt+1)));
Long base = 999999999999L;
Long b = Long.valueOf((new Date().getTime())/10);
//maxScoreOrder=分数+""+(999999999999-(当前时间戳/10));
BigDecimal num = new BigDecimal(base);
BigDecimal num2 = new BigDecimal(b);
BigDecimal result = num.subtract(num2);
String order = a.concat(String.valueOf(result));
String sql = "insert into projectx.tb_ranking(project_id, type, user_id, max_score, max_score_order, send_prize, prize_id, send_prize_time) values ('" + projectId + "', '" + type + "', '" + consumerIds[n] + "', '" + scores[n] + "', '" + order + "', 0, null, null)";
String sql = "insert into projectx.tb_ranking(project_id, type, user_id, max_score, max_score_order, send_prize, prize_id, send_prize_time) values ('" + projectId + "', '" + type + "', '" + consumerIds[n] + "', '" + a + "', '" + order + "', 0, null, null)";
System.out.println("创建SQL为:" + sql);
sqlService.update(sql);
Thread.sleep(500);
Thread.sleep(100);
}
map.put("success", "true");
map.put("message", type+"期排行榜数据构建成功!");
}
return map;
}
/**
* 功能:查询排行榜期次信息
* @return
*/
@RequestMapping(value = "/rankInfo", method= RequestMethod.POST)
@ResponseBody
public Map rankInfo(HttpServletRequest request) throws Exception {
String projectId = request.getParameter("projectId");
//构建数据前先确认归档表tb_leaderboard_config是否有项目
String sql2 = "select * from projectx.tb_leaderboard_config where project_id='"+projectId+"'";
Response response = sqlService.findSimpleResult(sql2);
//System.out.println("查询结果为:" + response.asString());
Map<String, Object> resultMap = new HashMap<>();
if (response.asString().equals("{}")) {
resultMap.put("success", "false");
resultMap.put("message", "对应项目无排行榜配置!");
}else {
String sql = "SELECT ranking_type,start_time,end_time,op_status FROM projectx.tb_leaderboard_archive where project_id = '"+projectId+"'";
Response response2 = sqlService.findModeResult(sql);
JSONArray ar = JSONArray.parseArray(response2.asString());
/*for (int i =0;i<ar.size();i++) {
resultMap.put("ranking_type", ar.getJSONObject(i).getString("ranking_type"));
resultMap.put("start_time", ar.getJSONObject(i).getString("start_time"));
resultMap.put("end_time", ar.getJSONObject(i).getString("end_time"));
resultMap.put("op_status", ar.getJSONObject(i).getString("op_status"));
}*/
resultMap.put("success", "true");
resultMap.put("message", ar);
}
return resultMap;
}
/**
* 功能:排行榜期次周期推移
* @return
*/
@RequestMapping(value = "/typeRoll", method= RequestMethod.POST)
@ResponseBody
public Map typeRoll(HttpServletRequest request) throws Exception {
String projectId = request.getParameter("projectId");
int rolldays = Integer.valueOf(request.getParameter("rolldays"));
//开始处理tb_leaderboard_config表的时间:start_time、end_time、next_reset_time、next_op_time、current_ranking_type
String sql = "SELECT id,start_time,end_time,next_reset_time,next_op_time,current_ranking_type FROM projectx.tb_leaderboard_config where project_id = '"+projectId+"'";
Response response2 = sqlService.findModeResult(sql);
JSONArray config = JSONArray.parseArray(response2.asString());
//获取tb_leaderboard_config初始数据
String id = config.getJSONObject(0).getString("id");
String start_time = config.getJSONObject(0).getString("start_time");
String end_time = config.getJSONObject(0).getString("end_time");
String next_reset_time = config.getJSONObject(0).getString("next_reset_time");
String next_op_time = config.getJSONObject(0).getString("next_op_time");
String current_ranking_type = config.getJSONObject(0).getString("current_ranking_type");
//开始计算推移tb_leaderboard_config
String start_time2 = this.getTime(start_time,rolldays * (-1));
String end_time2 = this.getTime(end_time,rolldays * (-1));
if(next_reset_time!=null&&next_reset_time!=""&&next_reset_time != "null"){
next_reset_time2 = this.getTime(next_reset_time,rolldays * (-1));
}
if(next_op_time!=null&&next_op_time!=""&&next_op_time != "null") {
next_op_time2 = this.getTime(next_op_time,rolldays * (-1));
}
//截取current_ranking_type的年月日:4_2020-03-31
String dataString = current_ranking_type.substring(current_ranking_type.indexOf("_")+1).trim();
String dataStringDeal = this.getTime2(dataString,rolldays * (-1));
String current_ranking_type2 = id.concat("_").concat(dataStringDeal);
//开始更新tb_leaderboard_config
if(next_reset_time!=null&&next_reset_time!=""&&next_reset_time != "null") {
String sqlconfig1 = "update projectx.tb_leaderboard_config set next_reset_time = '" + next_reset_time2 + "' where project_id = '" + projectId + "'";
System.out.println(sqlconfig1);
sqlService.update(sqlconfig1);
}
if(next_op_time!=null&&next_op_time!=""&&next_op_time != "null"){
String sqlconfig2 = "update projectx.tb_leaderboard_config set next_op_time = '" + next_op_time2 + "' where project_id = '" + projectId + "'";
System.out.println(sqlconfig2);
sqlService.update(sqlconfig2);
}
String sqlconfig3 = "update projectx.tb_leaderboard_config set start_time = '" + start_time2 + "',end_time = '" + end_time2 + "',current_ranking_type='" + current_ranking_type2 + "' where project_id = '" + projectId + "'";
System.out.println(sqlconfig3);
sqlService.update(sqlconfig3);
//开始处理tb_leaderboard_archive表的时间:ranking_type、ranking_name、start_join_time、start_time、end_time
String sqlarchive = "SELECT ranking_type,ranking_name,start_join_time,start_time,end_time FROM projectx.tb_leaderboard_archive where project_id = '"+projectId+"'";
Response response3 = sqlService.findModeResult(sqlarchive);
JSONArray archive = JSONArray.parseArray(response3.asString());
for (int i =0;i<archive.size();i++) {
//获取tb_leaderboard_archive初始数据
String ranking_type = archive.getJSONObject(i).getString("ranking_type");
//String ranking_name = config.getJSONObject(i).getString("ranking_name");
String start_join_time = archive.getJSONObject(i).getString("start_join_time");
String start_time_archive = archive.getJSONObject(i).getString("start_time");
String end_time_archive = archive.getJSONObject(i).getString("end_time");
//开始计算推移tb_leaderboard_archive
String start_join_time_ar = this.getTime(start_join_time,rolldays * (-1));
String start_time_archive_ar = this.getTime(start_time_archive,rolldays * (-1));
String end_time_archive_ar = this.getTime(end_time_archive,rolldays * (-1));
//截取ranking_type的年月日:4_2020-03-31
String dataString_ar = ranking_type.substring(ranking_type.indexOf("_")+1).trim();
String dataStringDeal_ar = this.getTime2(dataString_ar,rolldays * (-1));
String ranking_type2 = id.concat("_").concat(dataStringDeal_ar);
String ranking_name2 = dataStringDeal_ar.concat("期");
//开始更新tb_leaderboard_archive
String sqlconfig4 = "update projectx.tb_leaderboard_archive set ranking_type = '" + ranking_type2 + "',ranking_name = '" + ranking_name2 + "',start_join_time='" + start_time_archive_ar + "',start_time='" + start_join_time_ar + "',end_time='" + end_time_archive_ar + "' where project_id = '" + projectId + "' and ranking_type = '"+ranking_type+"'";
System.out.println(sqlconfig4);
sqlService.update(sqlconfig4);
}
Map<String, String> map = new HashMap<>();
try {
map.put("success", "true");
map.put("message", "排行榜数据构建成功!");
} catch (Exception e) {
map.put("message", "排行榜周期推移成功!");
return map;
}
/**
* 功能:排行榜自动开奖辅助
* @return
*/
@RequestMapping(value = "/helpOpen", method= RequestMethod.POST)
@ResponseBody
public Map helpOpen(HttpServletRequest request) throws Exception {
String projectId = request.getParameter("projectId");
String type = request.getParameter("type");
String optime = request.getParameter("optime");
System.out.println("项目id:" + projectId);
System.out.println("期次id:" + type);
Map<String, String> map = new HashMap<>();
//判断排行榜归档表tb_leaderboard_archive期次是否存在
String sql = "select * from projectx.tb_leaderboard_archive where project_id='"+projectId+"' and ranking_type = '"+type+"'";
Response response = sqlService.findSimpleResult(sql);
System.out.println("查询结果为:" + response.asString());
if (response.asString().equals("{}")) {
map.put("success", "false");
map.put("message", "该期次无排行榜信息!");
}else{
String op_way = String.valueOf(response.jsonPath().getString("op_way"));
String op_status = String.valueOf(response.jsonPath().getString("op_status"));
if(op_way.equals("2")||op_status.equals("0")){
map.put("success", "false");
map.put("message", "排行榜数据构建失败T_T 请确认数据库数据");
map.put("message", "该期次为手动开奖或无需开奖,请确认!");
}else{
String sql2 = "UPDATE projectx.tb_leaderboard_archive set op_time = '"+optime+"',op_status = '1',actual_op_time = NULL WHERE project_id='"+projectId+"' and ranking_type = '"+type+"'";
System.out.println(sql2);
sqlService.update(sql2);
map.put("success", "true");
map.put("message", "请在星速台重新保存活动,以使定时任务生效!");
}
}
return map;
}
/**
* 功能:时间推移类(精确到秒)
* @return
*/
public String getTime(String data,int amount) throws ParseException {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH);
//Date date = new Date();
Date date = dateFormat.parse(data);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH, amount);
date = calendar.getTime();
String time = dateFormat.format(date);
return time;
}
/**
* 功能:时间推移类(精确到日)
* @return
*/
public String getTime2(String data,int amount) throws ParseException {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
//Date date = new Date();
Date date = dateFormat.parse(data);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH, amount);
date = calendar.getTime();
String time = dateFormat.format(date);
return time;
}
}
......@@ -17,7 +17,7 @@ public class SqlService {
private String pass = "qwe123";
private String aliyun = "false";
//只查一条结果
public Response findSimpleResult(String sql) throws Exception{
Map<String, String> map = new HashMap<>();
......@@ -31,6 +31,7 @@ public class SqlService {
}
//查询一组结果
public Response findModeResult(String sql) throws Exception{
Map<String, String> map = new HashMap<>();
......
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