问卷调查
parent
bfdfdef554
commit
14ce0d866c
|
@ -39,4 +39,5 @@ public class MongoKey {
|
|||
public final static String friendManager = "friendManager";
|
||||
|
||||
public final static String guildMyInfo = "guildMyInfo";
|
||||
public final static String questionManager = "questionManager";
|
||||
}
|
||||
|
|
|
@ -154,6 +154,9 @@ public class RedisKey {
|
|||
|
||||
public static final String SESSION_OFFLINE = "SESSION_OFFLINE";
|
||||
|
||||
//问卷调查
|
||||
public static final String QUESTION_FROMBACK = "QUESTION_FROMBACK";
|
||||
|
||||
public static String getKey(String type, String key, boolean withoutServerId) {
|
||||
if (withoutServerId) {
|
||||
return GameApplication.areaId + Delimiter_colon + type + Delimiter_colon + String.valueOf(key);
|
||||
|
|
|
@ -21,6 +21,7 @@ public interface GlobalItemType {
|
|||
int SecretBox=10; // 宝箱
|
||||
int HEAD_FRAME = 11;//头像框
|
||||
int CHANGE_NAME_CARD = 12;//改名道具卡
|
||||
int SOUL_MARK =13;//
|
||||
int ESPECIAL_EQUIP = 14;//法宝
|
||||
//物品使用类型
|
||||
int NO_USE = 0 ; //不使用
|
||||
|
|
|
@ -15,6 +15,7 @@ import com.ljsd.jieling.logic.dao.*;
|
|||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
import com.ljsd.jieling.logic.hotfix.DoFix;
|
||||
import com.ljsd.jieling.logic.player.PlayerLogic;
|
||||
import com.ljsd.jieling.logic.question.QuestionLogic;
|
||||
import com.ljsd.jieling.logic.store.BuyGoodsLogic;
|
||||
import com.ljsd.jieling.netty.cocdex.PacketNetData;
|
||||
import com.ljsd.jieling.network.session.ISession;
|
||||
|
@ -59,6 +60,7 @@ public class GetPlayerInfoHandler extends BaseHandler{
|
|||
|
||||
User user = UserManager.getUser(userId);
|
||||
PlayerLogic.getInstance().sendDayilyMail(user,-1);
|
||||
QuestionLogic.getInstence().onLogin(user);
|
||||
PlayerManager playerInfoManager = user.getPlayerInfoManager();
|
||||
GlobalDataManaager.checkNeedReFlush(iSession,user,null);
|
||||
playerInfoManager.setLoginTime(TimeUtils.now());
|
||||
|
@ -114,6 +116,11 @@ public class GetPlayerInfoHandler extends BaseHandler{
|
|||
Integer goodsEndTime = entry.getValue();
|
||||
goodsTypeDurations.add(CommonProto.GoodsTypeDuration.newBuilder().setGoodsType(sRechargeCommodityConfig.getType()).setEndTime(goodsEndTime).build());
|
||||
}
|
||||
//问卷状态
|
||||
int questState =0;
|
||||
if(user.getQuestionManager().getQuestId()!=0){
|
||||
questState=user.getQuestionManager().getQuestState();
|
||||
}
|
||||
//图鉴信息
|
||||
Set<Integer> heroHandBookSet = user.getHeroManager().getHeroHandBook().keySet();
|
||||
Set<Integer> equipHandBookSet = user.getEquipManager().getEquipHandBook().keySet();
|
||||
|
@ -145,6 +152,7 @@ public class GetPlayerInfoHandler extends BaseHandler{
|
|||
.setIsDayFirst(playerInfoManager.getIsdayFirst())
|
||||
.setEndInfo(endless)
|
||||
.setPlayerBindPhone(playerBindPhone)
|
||||
.setQuestionState(questState)
|
||||
.build();
|
||||
try {
|
||||
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.GET_PLAYERINFO_RESPONSE_VALUE, getPlayerInfoResponse, true);
|
||||
|
|
|
@ -33,6 +33,10 @@ public class GetPhoneRewardRequestHandler extends BaseHandler<PlayerInfoProto.Ge
|
|||
int uid = iSession.getUid();
|
||||
User user = UserManager.getUser(uid);
|
||||
CommonProto.Drop.Builder drop = ItemUtil.drop(user,rewardIds, 1, 1, BIReason.BIND_PHONE);
|
||||
if(user.getPlayerInfoManager().getPhoneBindInfo().getState()!=1){
|
||||
MessageUtil.sendErrorResponse(iSession, 0, MessageTypeProto.MessageType.GET_PHONE_REWARD_RESPONSE_VALUE, "");
|
||||
return;
|
||||
}
|
||||
user.getPlayerInfoManager().getPhoneBindInfo().setState(2);
|
||||
PlayerInfoProto.GetPhoneRewardResponse.Builder builder = PlayerInfoProto.GetPhoneRewardResponse.newBuilder().setDrop(drop);
|
||||
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.GET_PHONE_REWARD_RESPONSE_VALUE,builder.build() , true);
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
package com.ljsd.jieling.handler.question;
|
||||
|
||||
import com.ljsd.jieling.handler.BaseHandler;
|
||||
import com.ljsd.jieling.logic.dao.Question;
|
||||
import com.ljsd.jieling.logic.dao.UserManager;
|
||||
import com.ljsd.jieling.logic.dao.root.GlobalSystemControl;
|
||||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
import com.ljsd.jieling.network.session.ISession;
|
||||
import com.ljsd.jieling.protocols.CommonProto;
|
||||
import com.ljsd.jieling.protocols.MessageTypeProto;
|
||||
import com.ljsd.jieling.protocols.PlayerInfoProto;
|
||||
import com.ljsd.jieling.util.MessageUtil;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class GetQuestionRequestHandler extends BaseHandler<PlayerInfoProto.GetQuestionRequest> {
|
||||
@Override
|
||||
public MessageTypeProto.MessageType getMessageCode() {
|
||||
return MessageTypeProto.MessageType.GET_QUESTION_REQUEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processWithProto(ISession iSession, PlayerInfoProto.GetQuestionRequest proto) throws Exception {
|
||||
|
||||
int uid = iSession.getUid();
|
||||
User user = UserManager.getUser(uid);
|
||||
if (user.getQuestionManager().getQuestId() == 0) {
|
||||
MessageUtil.sendErrorResponse(iSession, 0, MessageTypeProto.MessageType.GET_QUESTION_RESPONSE_VALUE, "");
|
||||
return;
|
||||
}
|
||||
GlobalSystemControl globalSystemControl = GlobalSystemControl.getGlobalSystemControl();
|
||||
Question question = globalSystemControl.getQuestionMap(String.valueOf(user.getQuestionManager().getQuestId()));
|
||||
if (null == question) {
|
||||
MessageUtil.sendErrorResponse(iSession, 0, MessageTypeProto.MessageType.UPDATE_QUESTION_RESPONSE_VALUE, "");
|
||||
return;
|
||||
}
|
||||
List<CommonProto.QuestionOptions> list = new ArrayList<>();
|
||||
question.getcQuestionOptionBeans().forEach(cQuestionOptionBean -> {
|
||||
list.add(CommonProto.QuestionOptions.newBuilder().setContent(cQuestionOptionBean.getContent()).setType(cQuestionOptionBean.getType()).addAllOptions(Arrays.asList(cQuestionOptionBean.getOptions())).build());
|
||||
});
|
||||
|
||||
GlobalSystemControl.save(globalSystemControl);
|
||||
PlayerInfoProto.GetQuestionResponse.Builder builder = PlayerInfoProto.GetQuestionResponse.newBuilder();
|
||||
builder.setId(question.getId());
|
||||
builder.setQuestDes(question.getQuestDes());
|
||||
builder.setStart(question.getStart());
|
||||
builder.setEnd(question.getEnd());
|
||||
builder.addAllQuestOptions(list);
|
||||
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.GET_QUESTION_RESPONSE_VALUE, builder.build(), true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.ljsd.jieling.handler.question;
|
||||
|
||||
import com.ljsd.jieling.config.SErrorCodeEerverConfig;
|
||||
import com.ljsd.jieling.globals.Global;
|
||||
import com.ljsd.jieling.handler.BaseHandler;
|
||||
import com.ljsd.jieling.logic.dao.Question;
|
||||
import com.ljsd.jieling.logic.dao.UserManager;
|
||||
import com.ljsd.jieling.logic.dao.root.GlobalSystemControl;
|
||||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
import com.ljsd.jieling.logic.mail.MailLogic;
|
||||
import com.ljsd.jieling.network.session.ISession;
|
||||
import com.ljsd.jieling.protocols.MessageTypeProto;
|
||||
import com.ljsd.jieling.protocols.PlayerInfoProto;
|
||||
import com.ljsd.jieling.util.ItemUtil;
|
||||
import com.ljsd.jieling.util.MessageUtil;
|
||||
import com.ljsd.jieling.util.TimeUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@Component
|
||||
public class UpdateQuestionRequestHandler extends BaseHandler<PlayerInfoProto.upDataQuestionRequest> {
|
||||
@Override
|
||||
public MessageTypeProto.MessageType getMessageCode() {
|
||||
return MessageTypeProto.MessageType.UPDATE_QUESTION_REQUEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processWithProto(ISession iSession, PlayerInfoProto.upDataQuestionRequest proto) throws Exception {
|
||||
|
||||
int uid = iSession.getUid();
|
||||
User user = UserManager.getUser(uid);
|
||||
if (user.getQuestionManager().getQuestId() != 0) {
|
||||
//check
|
||||
GlobalSystemControl globalSystemControl = GlobalSystemControl.getGlobalSystemControl();
|
||||
Question question =globalSystemControl.getQuestionMap(String.valueOf(user.getQuestionManager().getQuestId()));
|
||||
if (null == question) {
|
||||
MessageUtil.sendErrorResponse(iSession, 0, MessageTypeProto.MessageType.UPDATE_QUESTION_RESPONSE_VALUE, "");
|
||||
return;
|
||||
}
|
||||
if (proto.getOptionsCount() != question.getcQuestionOptionBeans().size()) {
|
||||
PlayerInfoProto.upDataQuestionResponse.Builder builder = PlayerInfoProto.upDataQuestionResponse.newBuilder();
|
||||
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.UPDATE_QUESTION_RESPONSE_VALUE, builder.setResult(-1).build(), true);
|
||||
return;
|
||||
}
|
||||
user.getQuestionManager().addQuestion(question.getId(),proto.getOptionsList());
|
||||
|
||||
//移除过剩问卷答案
|
||||
Set<String> removeSet =user.getQuestionManager().getAnswerMap().keySet();
|
||||
removeSet.removeAll(globalSystemControl.getQuestionMap().keySet());
|
||||
removeSet.forEach(user.getQuestionManager()::removeAnswer);
|
||||
|
||||
if(user.getQuestionManager().getQuestState() != 1){
|
||||
user.getQuestionManager().setQuestState(1);
|
||||
//sendmail
|
||||
String title = SErrorCodeEerverConfig.getI18NMessage("questionnaire_title");
|
||||
String content = SErrorCodeEerverConfig.getI18NMessage("questionnaire_txt");
|
||||
int nowTime = (int) (TimeUtils.now() / 1000);
|
||||
MailLogic.getInstance().sendMail(user.getId(), title, content, question.getReward(), nowTime, Global.MAIL_EFFECTIVE_TIME);
|
||||
}
|
||||
GlobalSystemControl.save(globalSystemControl);
|
||||
}
|
||||
|
||||
PlayerInfoProto.upDataQuestionResponse.Builder builder = PlayerInfoProto.upDataQuestionResponse.newBuilder();
|
||||
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.UPDATE_QUESTION_RESPONSE_VALUE, builder.build(), true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package com.ljsd.jieling.logic.dao;
|
||||
|
||||
import com.ljsd.common.mogodb.MongoBase;
|
||||
import com.ljsd.jieling.logic.question.CQuestionOptionBean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Question extends MongoBase {
|
||||
|
||||
private String id;
|
||||
private String questDes;
|
||||
private String reward;
|
||||
private String start;
|
||||
private String end;
|
||||
private List<CQuestionOptionBean> cQuestionOptionBeans;
|
||||
|
||||
public Question(String id, String questDes, String reward, String start, String end, List<CQuestionOptionBean> cQuestionOptionBeans) {
|
||||
this.id = id;
|
||||
this.questDes = questDes;
|
||||
this.reward = reward;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.cQuestionOptionBeans = cQuestionOptionBeans;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getQuestDes() {
|
||||
return questDes;
|
||||
}
|
||||
|
||||
public String getReward() {
|
||||
return reward;
|
||||
}
|
||||
|
||||
public String getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public String getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
public List<CQuestionOptionBean> getcQuestionOptionBeans() {
|
||||
return cQuestionOptionBeans;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
package com.ljsd.jieling.logic.dao;
|
||||
|
||||
import com.ljsd.common.mogodb.MongoBase;
|
||||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class QuestionManager extends MongoBase {
|
||||
|
||||
private int questId;//当前开启的问卷id
|
||||
private int questState;//当前问卷的状态 0未答 1已答
|
||||
Map<String, List<String>> answerMap = new HashMap<>();
|
||||
public QuestionManager(){
|
||||
this.setRootCollection(User._COLLECTION_NAME);
|
||||
}
|
||||
|
||||
public Map<String, List<String>> getAnswerMap() {
|
||||
return answerMap;
|
||||
}
|
||||
|
||||
public void addQuestion(String id, List<String> question) throws Exception {
|
||||
updateString("answerMap." + id, question);
|
||||
answerMap.put(id, question);
|
||||
}
|
||||
public List<String> getQuestion(String key) {
|
||||
return answerMap.get(key);
|
||||
}
|
||||
|
||||
public void removeAnswer(String key) {
|
||||
if (answerMap.containsKey(key)){
|
||||
answerMap.remove(key);
|
||||
removeString(getMongoKey() + ".answerMap." + key);
|
||||
}
|
||||
}
|
||||
|
||||
public int getQuestId() {
|
||||
return questId;
|
||||
}
|
||||
|
||||
public void setQuestId(int questId) {
|
||||
updateString("questId",questId);
|
||||
this.questId = questId;
|
||||
}
|
||||
|
||||
public int getQuestState() {
|
||||
return questState;
|
||||
}
|
||||
|
||||
public void setQuestState(int questState) {
|
||||
updateString("questState",questState);
|
||||
this.questState = questState;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.ljsd.jieling.logic.dao;
|
||||
|
||||
|
||||
public class QuestionOption {
|
||||
private String content = "";
|
||||
private int type;
|
||||
private String[] options ;
|
||||
|
||||
public QuestionOption(String content, int type, String[] options) {
|
||||
this.content = content;
|
||||
this.type = type;
|
||||
this.options = options;
|
||||
}
|
||||
}
|
|
@ -1,9 +1,13 @@
|
|||
package com.ljsd.jieling.logic.dao.root;
|
||||
|
||||
import com.ljsd.GameApplication;
|
||||
import com.ljsd.jieling.db.mongo.MongoUtil;
|
||||
import com.ljsd.jieling.logic.dao.Question;
|
||||
import com.ljsd.jieling.logic.dao.TimeControllerOfFunction;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class GlobalSystemControl {
|
||||
|
||||
|
@ -12,16 +16,90 @@ public class GlobalSystemControl {
|
|||
private int id; //serverId
|
||||
|
||||
private Map<Integer, TimeControllerOfFunction> timeControllerOfFunctionMap = new HashMap<>();
|
||||
private Map<String, Question> questionMap = new ConcurrentHashMap<>();
|
||||
|
||||
public GlobalSystemControl(int id){
|
||||
private int questId;//本服开启的问卷id
|
||||
|
||||
@Transient
|
||||
private boolean dirty = false;
|
||||
|
||||
public static GlobalSystemControl getGlobalSystemControl() throws Exception {
|
||||
GlobalSystemControl globalSystemControl = MongoUtil.getInstence().getMyMongoTemplate().findById(GameApplication.serverId, GlobalSystemControl.class);
|
||||
if (globalSystemControl == null) {
|
||||
globalSystemControl = new GlobalSystemControl(GameApplication.serverId);
|
||||
}
|
||||
return globalSystemControl;
|
||||
}
|
||||
|
||||
public GlobalSystemControl(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void updateTimeControllerOfFunction(TimeControllerOfFunction timeControllerOfFunction){
|
||||
timeControllerOfFunctionMap.put(timeControllerOfFunction.getId(),timeControllerOfFunction);
|
||||
public void updateTimeControllerOfFunction(TimeControllerOfFunction timeControllerOfFunction) {
|
||||
this.dirty = true;
|
||||
timeControllerOfFunctionMap.put(timeControllerOfFunction.getId(), timeControllerOfFunction);
|
||||
}
|
||||
|
||||
public Map<Integer, TimeControllerOfFunction> getTimeControllerOfFunctionMap() {
|
||||
return timeControllerOfFunctionMap;
|
||||
}
|
||||
|
||||
public int getQuestId() {
|
||||
return questId;
|
||||
}
|
||||
|
||||
public void setQuestId(int questId) {
|
||||
this.dirty = true;
|
||||
this.questId = questId;
|
||||
}
|
||||
|
||||
public Question getQuestionMap(String key) {
|
||||
return questionMap.get(key);
|
||||
}
|
||||
|
||||
|
||||
public Map<String, Question> getQuestionMap() {
|
||||
return questionMap;
|
||||
}
|
||||
|
||||
public void addQuestion(Question question) {
|
||||
this.dirty = true;
|
||||
this.questionMap.put(question.getId(), question);
|
||||
}
|
||||
|
||||
public void removeQuestion(String key) {
|
||||
this.dirty = true;
|
||||
this.questionMap.remove(key);
|
||||
}
|
||||
|
||||
public static void save(GlobalSystemControl globalSystemControl) throws Exception {
|
||||
if (globalSystemControl.dirty) {
|
||||
MongoUtil.getInstence().getMyMongoTemplate().save(globalSystemControl);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<String> resetLast(){
|
||||
List<String> stringsList = new LinkedList<>();
|
||||
if(questionMap.size()<=30){
|
||||
return stringsList;
|
||||
}
|
||||
TreeSet<Question> last = new TreeSet<>((Question o1, Question o2) -> {
|
||||
if (Long.valueOf(o1.getEnd()) > Long.valueOf(o2.getEnd())) {
|
||||
return 1;
|
||||
} else if (Long.valueOf(o1.getEnd()) == Long.valueOf(o2.getEnd())) {
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
});
|
||||
last.addAll(questionMap.values());
|
||||
for (int i = 0; i <10 ; i++) {
|
||||
String id = last.pollFirst().getId();
|
||||
removeQuestion(id);
|
||||
stringsList.add(id);
|
||||
}
|
||||
return stringsList;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,6 +49,8 @@ public class User {
|
|||
|
||||
private RoomInfo roomInfo;
|
||||
|
||||
private QuestionManager questionManager;
|
||||
|
||||
//构造函数必须要声明,否则从mongodb读出来反编译成类不通过
|
||||
public User(){
|
||||
}
|
||||
|
@ -73,6 +75,7 @@ public class User {
|
|||
this.userMissionManager = new UserMissionManager();
|
||||
this.friendManager = new FriendManager();
|
||||
this.guildMyInfo = new GuildMyInfo();
|
||||
this.questionManager = new QuestionManager();
|
||||
|
||||
//綁定关系
|
||||
|
||||
|
@ -94,6 +97,7 @@ public class User {
|
|||
this.userMissionManager.init(id,MongoKey.userMissionManager);
|
||||
this.friendManager.init(id,MongoKey.friendManager);
|
||||
this.guildMyInfo.init(id,MongoKey.guildMyInfo);
|
||||
this.questionManager.init(id,MongoKey.questionManager);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
|
@ -214,4 +218,12 @@ public class User {
|
|||
}
|
||||
return roomInfo;
|
||||
}
|
||||
|
||||
public QuestionManager getQuestionManager() {
|
||||
if(null ==questionManager){
|
||||
this.questionManager = new QuestionManager();
|
||||
this.questionManager.init(id,MongoKey.questionManager);
|
||||
}
|
||||
return questionManager;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
package com.ljsd.jieling.logic.question;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CQuestionBean {
|
||||
|
||||
private String id;
|
||||
private String questDes;
|
||||
private String reward;
|
||||
private String start;
|
||||
private String end;
|
||||
private List<CQuestionOptionBean> cQuestionOptionBeans= new ArrayList<>();
|
||||
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public void setStart(String start) {
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
public String getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
public void setEnd(String end) {
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
public String getQuestDes() {
|
||||
return questDes;
|
||||
}
|
||||
|
||||
public void setQuestDes(String questDes) {
|
||||
this.questDes = questDes;
|
||||
}
|
||||
|
||||
public String getReward() {
|
||||
return reward;
|
||||
}
|
||||
|
||||
public void setReward(String reward) {
|
||||
this.reward = reward;
|
||||
}
|
||||
|
||||
|
||||
public List<CQuestionOptionBean> getcQuestionOptionBeans() {
|
||||
return cQuestionOptionBeans;
|
||||
}
|
||||
|
||||
public void setcQuestionOptionBeans(List<CQuestionOptionBean> cQuestionOptionBeans) {
|
||||
this.cQuestionOptionBeans = cQuestionOptionBeans;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
package com.ljsd.jieling.logic.question;
|
||||
|
||||
|
||||
public class CQuestionOptionBean {
|
||||
private String content = "";
|
||||
private int type;
|
||||
private String[] options ;
|
||||
|
||||
public CQuestionOptionBean(String content, int type, String[] options) {
|
||||
this.content = content;
|
||||
this.type = type;
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String[] getOptions() {
|
||||
return options;
|
||||
}
|
||||
|
||||
public void setOptions(String[] options) {
|
||||
this.options = options;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,138 @@
|
|||
package com.ljsd.jieling.logic.question;
|
||||
|
||||
import com.ljsd.GameApplication;
|
||||
import com.ljsd.jieling.db.mongo.MongoUtil;
|
||||
import com.ljsd.jieling.db.redis.RedisKey;
|
||||
import com.ljsd.jieling.db.redis.RedisUtil;
|
||||
import com.ljsd.jieling.logic.OnlineUserManager;
|
||||
import com.ljsd.jieling.logic.blood.BloodLogic;
|
||||
import com.ljsd.jieling.logic.dao.Question;
|
||||
import com.ljsd.jieling.logic.dao.root.GlobalSystemControl;
|
||||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
import com.ljsd.jieling.network.session.ISession;
|
||||
import com.ljsd.jieling.protocols.MessageTypeProto;
|
||||
import com.ljsd.jieling.protocols.PlayerInfoProto;
|
||||
import com.ljsd.jieling.util.AyyncWorker;
|
||||
import com.ljsd.jieling.util.InnerMessageUtil;
|
||||
import com.ljsd.jieling.util.MessageUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class QuestionLogic {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(BloodLogic.class);
|
||||
|
||||
|
||||
public static QuestionLogic getInstence() {
|
||||
return QuestionLogic.InnerClass.instance;
|
||||
}
|
||||
|
||||
private static class InnerClass {
|
||||
private static final QuestionLogic instance = new QuestionLogic();
|
||||
}
|
||||
|
||||
|
||||
public void onLogin(User user) throws Exception{
|
||||
GlobalSystemControl globalSystemControl = GlobalSystemControl.getGlobalSystemControl();
|
||||
if (user.getQuestionManager().getQuestId() != globalSystemControl.getQuestId()) {
|
||||
user.getQuestionManager().setQuestId(globalSystemControl.getQuestId());
|
||||
user.getQuestionManager().setQuestState(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 每分钟检测问卷
|
||||
*/
|
||||
public void checkQuestion() throws Exception {
|
||||
|
||||
RedisUtil redisUtil = RedisUtil.getInstence();
|
||||
Map<Integer, CQuestionBean> questionBeanMap = redisUtil.getMapValues(RedisKey.QUESTION_FROMBACK, "", Integer.class, CQuestionBean.class);
|
||||
|
||||
TreeSet<CQuestionBean> last = new TreeSet<>((CQuestionBean o1, CQuestionBean o2) -> {
|
||||
if (Long.valueOf(o1.getStart()) > Long.valueOf(o2.getStart())) {
|
||||
return -1;
|
||||
} else if (Long.valueOf(o1.getStart()) == Long.valueOf(o2.getStart())) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
|
||||
Set<Integer> remove = new HashSet<>();
|
||||
|
||||
|
||||
//按开启时间排序 获取最近开启的问卷
|
||||
//删除过期的问卷
|
||||
GlobalSystemControl globalSystemControl = MongoUtil.getInstence().getMyMongoTemplate().findById(GameApplication.serverId, GlobalSystemControl.class);
|
||||
if (globalSystemControl == null) {
|
||||
globalSystemControl = new GlobalSystemControl(GameApplication.serverId);
|
||||
}
|
||||
boolean isNeedUp = false;
|
||||
long time = System.currentTimeMillis() / 1000;
|
||||
|
||||
for (Map.Entry<Integer, CQuestionBean> entry : questionBeanMap.entrySet()) {
|
||||
long start = Long.valueOf(entry.getValue().getStart());
|
||||
long end = Long.valueOf(entry.getValue().getEnd());
|
||||
if (start > time) {
|
||||
continue;
|
||||
}
|
||||
//移除当前时间以前的
|
||||
if (end < time) {
|
||||
remove.add(entry.getKey());
|
||||
continue;
|
||||
}
|
||||
last.add(entry.getValue());
|
||||
remove.add(entry.getKey());
|
||||
}
|
||||
|
||||
|
||||
if (remove.contains(globalSystemControl.getQuestId()) && last.size() == 0) {
|
||||
//关闭
|
||||
globalSystemControl.setQuestId(0);
|
||||
isNeedUp = true;
|
||||
PlayerInfoProto.QuestionIndication builder = PlayerInfoProto.QuestionIndication.newBuilder().setState(-1).build();
|
||||
InnerMessageUtil.broadcastWithRandom(new AyyncWorker() {
|
||||
@Override
|
||||
public void work(User user) throws Exception {
|
||||
user.getQuestionManager().setQuestId(0);
|
||||
user.getQuestionManager().setQuestState(0);
|
||||
ISession sessionByUid = OnlineUserManager.getSessionByUid(user.getId());
|
||||
MessageUtil.sendIndicationMessage(sessionByUid, 1, MessageTypeProto.MessageType.PLAYER_BACKCINFO_INDICATION_VALUE, builder, true);
|
||||
}
|
||||
}, new ArrayList<>(OnlineUserManager.sessionMap.keySet()), 120);
|
||||
|
||||
}
|
||||
|
||||
if (last.size() != 0) {
|
||||
//开启
|
||||
CQuestionBean cQuestionBean = last.first();
|
||||
int qid = Integer.valueOf(cQuestionBean.getId());
|
||||
if (qid != globalSystemControl.getQuestId()) {
|
||||
globalSystemControl.setQuestId(Integer.valueOf(cQuestionBean.getId()));
|
||||
globalSystemControl.addQuestion(new Question(cQuestionBean.getId(), cQuestionBean.getQuestDes(), cQuestionBean.getReward(), cQuestionBean.getStart(), cQuestionBean.getEnd(), cQuestionBean.getcQuestionOptionBeans()));
|
||||
globalSystemControl.resetLast();
|
||||
isNeedUp = true;
|
||||
PlayerInfoProto.QuestionIndication builder = PlayerInfoProto.QuestionIndication.newBuilder().setState(1).build();
|
||||
InnerMessageUtil.broadcastWithRandom(new AyyncWorker() {
|
||||
@Override
|
||||
public void work(User user) throws Exception {
|
||||
user.getQuestionManager().setQuestId(qid);
|
||||
user.getQuestionManager().setQuestState(0);
|
||||
ISession sessionByUid = OnlineUserManager.getSessionByUid(user.getId());
|
||||
MessageUtil.sendIndicationMessage(sessionByUid, 1, MessageTypeProto.MessageType.PLAYER_BACKCINFO_INDICATION_VALUE, builder, true);
|
||||
}
|
||||
}, new ArrayList<>(OnlineUserManager.sessionMap.keySet()), 120);
|
||||
}
|
||||
if (isNeedUp) {
|
||||
MongoUtil.getInstence().getMyMongoTemplate().save(globalSystemControl);
|
||||
}
|
||||
}
|
||||
//remove
|
||||
RedisUtil.getInstence().removeMapEntrys(RedisKey.QUESTION_FROMBACK, "", remove);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -18,6 +18,7 @@ import com.ljsd.jieling.logic.family.GuildFightLogic;
|
|||
import com.ljsd.jieling.logic.fight.CheckFight;
|
||||
import com.ljsd.jieling.logic.fight.CombatLogic;
|
||||
import com.ljsd.jieling.logic.mail.MailLogic;
|
||||
import com.ljsd.jieling.logic.question.QuestionLogic;
|
||||
import com.ljsd.jieling.logic.store.StoreLogic;
|
||||
import com.ljsd.jieling.network.server.ProtocolsManager;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -53,6 +54,7 @@ public class MinuteTask extends Thread {
|
|||
CheckFight.getInstance().luaHotFix();
|
||||
MongoUtil.getInstence().lastUpdate();
|
||||
GuildFightLogic.familyFightStatus();
|
||||
QuestionLogic.getInstence().checkQuestion();
|
||||
MailLogic.getInstance().checkReadyToMail();
|
||||
ProtocolsManager.getInstance().minuteCheckForbidUser();
|
||||
LOGGER.info("MinuteTask end...");
|
||||
|
|
|
@ -408,6 +408,7 @@ public class ItemUtil {
|
|||
case GlobalItemType.HEAD_FRAME:
|
||||
case GlobalItemType.SecretBox:
|
||||
case GlobalItemType.CHANGE_NAME_CARD:
|
||||
case GlobalItemType.SOUL_MARK:
|
||||
itemType = GlobalItemType.ITEM;
|
||||
break;
|
||||
case GlobalItemType.RANDOM_ITME:
|
||||
|
|
Loading…
Reference in New Issue