public class SaveHotKeySkillReq extends CommandBase {
@Resource
//数据库操作
private EntityManager em;
protected void execute() throws GMessageException {
CRequesthotKeyChange msg = pak.readMsg(CRequesthotKeyChange.class);
int item_id= msg.item_id;
int index = msg.index;
ActorSetting actorSetting = em.createQuery(ActorSetting.class).setParameter("actorId", actorSession.getActorId()).getSingleResult();
String skill = actorSetting.getSkillSetting();
JSONArray jsonArray = null;
if(skill != null && !skill.equals("")){
jsonArray = JSONArray.fromObject(skill);
}
if(jsonArray == null){
jsonArray = new JSONArray();
}
boolean isupdate = false;
for (Object object : jsonArray) {
JSONObject json = (JSONObject)object;
if(json.getInt("index") == index){
json.put("item_id", item_id);
isupdate = true;
}
}
if(isupdate == false){
JSONObject json = new JSONObject();
json.put("index", index);
json.put("item_id", item_id);
jsonArray.add(json);
}
if (actorSetting == null) {
throw new GMessageException(GMessageException.ACTOR_DATA_ERROR);
}
actorSetting.setSkillSetting(skill);
em.merge(actorSetting);
}