lifeix+json解析+关注

来源:互联网 发布:linux rm -rf 命令撤回 编辑:程序博客网 时间:2024/05/23 00:07

package com.l99.web.pystest;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriBuilder;

import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.l99.client.HoroscopeClt;
import com.l99.commentclient.CommentRmiClient;
import com.l99.common.basetype.L99CommentType;
import com.l99.common.errormsg.ErrorMsg;
import com.l99.common.utils.CipherUtil;
import com.l99.dto.account.Account;
import com.l99.dto.mentaltest.MentalAnswer;
import com.l99.dto.mentaltest.MentalSubject;
import com.l99.dto.mentaltest.MentalUsers;
import com.l99.dto.mentaltest.Mentaltest;
import com.l99.dto.profile.AccountProfile;
import com.l99.dto.tag.Tag;
import com.l99.exception.service.L99IllegalOperateException;
import com.l99.service.mentaltest.MentalAnswerService;
import com.l99.service.mentaltest.MentalSubjectService;
import com.l99.service.mentaltest.MentalUsersService;
import com.l99.service.mentaltest.MentaltestService;
import com.l99.service.tag.TagSerivce;
import com.l99.service.util.AccountShare;
import com.l99.service.util.DashboardAppShare;
import com.l99.vo.dashboard.DashboardShareUrlVo;
import com.l99.web.L99ActionSupport;
import com.l99.web.L99MentaltestPath;
import com.l99.web.SessionKeys;
import com.l99.web.util.MentalHoroscope;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
import com.sun.jersey.api.representation.Form;
public class EditMentalShowAction extends L99ActionSupport{

 private static final long serialVersionUID = 2138300217057511805L;

 private static final Logger LOG = LoggerFactory.getLogger(EditMentalShowAction.class);

 private Mentaltest mentaltest;
 private MentalAnswer mentalAnswer;
 private MentalUsers mentalUsers;
 private MentalSubject mentalSubject;
 private Long testId;
 private String preTest;
 //显示结果
 private int show=1;
 //动态
 private int action=1;
 private int answerOrder=0;
 private Long accountId;
 private String linkStr;
 private String linkMsg;
 private Long answerId;
 private List<Mentaltest> aLikeList;
 private List<Mentaltest> testList;
 private List<Mentaltest> hotTestList;
 private List<Mentaltest> exactList;

 private List<MentalAnswer> answerList;
 private List<MentalUsers> userList;
 private List<Tag> tagList;
 private Long longNO;
 private int total=0;
 private int dataNum = 0;
 private int nowPage = 1;
 private int showdata = 10;
 private String order = "new";
 private Long tagId;
 //星座
 private String constellation;
 private String typeId;

 private String birthdayYear;
 private String birthdayMonth;
 private String birthdayDay;

 private Account user;

 //第三方分享vo
 private DashboardShareUrlVo urlVo;
 private Long targetId;

 //20130505心理测试数据库分离重飞 增加
 private String mentalUrlPath = L99MentaltestPath.getMentalUrlPath();
 public String pUrlPath=L99MentaltestPath.getPublicUrlPath();
 //是否有关注关系
 private Long isFollow=0l;
 //添加关注
 private Long addFollow=0l;
 /**
  * 随机心理测试
  * @return
  */
 /**
  * 退出登录
  * @return
  */
 public String logout(){
  logoutEvent();
  return "logout";
 }

 public String randomTest(){ 
  Object sessionAccount = getSessionOf(SessionKeys.ACCOUNTID);
  if (null == sessionAccount) {
   errorMessage = ErrorMsg.SESSIONOUT;
   return ERROR;
  }
  try {
   accountId =Long.valueOf(sessionAccount.toString());
   testId =MentalUsersService.findRandomTestIdByAccountId(accountId);
   if(testId==0){
    errorMessage =ErrorMsg.TEST_NOMORETEST;
    return ERROR;
   }
   else{
    return "randomTest";
   }
  }catch (Exception e) {
   return ERROR;
  }

 }

 /**
  * 单个心理测试
  * @return
  */
 public String view(){
  Object sessionAccount = getSessionOf(SessionKeys.ACCOUNTID);
  if (null == sessionAccount) {
   try{
    mentaltest =MentaltestService.findMentaltestById(testId);
    if(mentaltest==null||mentaltest.getTestStatus()!=1){
     errorMessage =ErrorMsg.TEST_NOTEST;
     return ERROR;
    }
    mentalSubject = MentalSubjectService.findSubjectAndOptionByTestIdAndOrder(testId, 1);
    tagList =TagSerivce.findTagsByObjectId(testId,5);
    aLikeList =MentaltestService.findAlikeTest(tagList, testId, 5);
    testList =MentaltestService.findAllTest(1, 0,5, "hot");
   } catch (Exception e) {
    LOG.error(e.getMessage(), e);
    return ERROR;
   }
   return "viewLogin";
  }
  if(testId==null||testId<1){
   errorMessage =ErrorMsg.TEST_NOTEST;
   return ERROR;
  }
  try {
   accountId =getSessionAccount();
   mentaltest =MentaltestService.findMentaltestById(testId);
   if(mentaltest==null||mentaltest.getTestStatus()!=1){
    errorMessage =ErrorMsg.TEST_NOTEST;
    return ERROR;
   }
   //   boolean likeFlag = L99CommentShare.findIsLikeTarget(accountId, testId,L99CommentType.TEST);  
   boolean likeFlag =CommentRmiClient.findIsLikeTarget(accountId, testId, L99CommentType.TEST);//052+
   mentaltest.setLikeFlag(likeFlag);
   mentalUsers = MentalUsersService.findByTestIdAndAnswerId(testId, accountId);
   mentalSubject = MentalSubjectService.findSubjectAndOptionByTestIdAndOrder(testId, 1);
   tagList =TagSerivce.findTagsByObjectId(testId,5);
   aLikeList =MentaltestService.findAlikeTest(tagList, testId, 5);
   testList =MentaltestService.findAllTest(1, 0,5, "hot");/////////////////////////
   if(mentalUsers!=null)userList =MentalUsersService.findTheSameUser(accountId, testId,mentalUsers.getAnswerId());///////////////////////
  } catch (Exception e) {
   LOG.error(e.getMessage(), e);
   return ERROR;
  }
  return "view";

 }

 /**
  * 回答问题
  * @return
  */
 public String answer(){
  if (!isLogin()) {
   return "common_index";
  }

  if(testId==null||answerOrder<1){
   errorMessage ="提交失败!请重试";
   return ERROR;
  }
  try {
   accountId = getSessionAccount();
   mentaltest =MentaltestService.findMentaltestById(testId);
   mentalAnswer = MentalAnswerService.findByTestIdAndOrder(testId, answerOrder);
   if(mentalAnswer==null){
    errorMessage ="提交失败!请重试";
    return ERROR;
   }
   mentalUsers =MentalUsersService.findByTestIdAndAnswerId(testId, accountId);
   if(mentalUsers==null){
    mentalUsers = new MentalUsers();
    mentalUsers.setAccountId(accountId); 
    mentalUsers.setTestId(testId);   //问题ID
    mentalUsers.setAnswerId(mentalAnswer.getId());  //答案ID
    mentalUsers.setTestTitle(mentaltest.getTitle());//问题名 
    mentalUsers.setTestPhoto(mentaltest.getPhotoUrl());//问题图片
    mentalUsers.setAnswerTitle(mentalAnswer.getAnswerTitle());//答案名
    mentalUsers.setAnswerDesc(mentalAnswer.getAnswerDesc());  //答案排序
    if(show==1){          //show=1显示,show==0不显示
     mentalUsers.setAnswerStatus(1);
    }else{
     mentalUsers.setAnswerStatus(0);
    }
    MentalUsersService.insert(mentalUsers);      
    mentalAnswer.setAnswerNO(mentalAnswer.getAnswerNO()+1);
    MentalAnswerService.updateAnswer(mentalAnswer);    //上传答案
    mentaltest.setTestNO(mentaltest.getTestNO()+1);   
    MentaltestService.updateMental(mentaltest);
   }
   //   if(action==1){
   //    //TODO动态
   //    EventCommentHandler.answerMentalTest(mentalUsers);
   //   }
   linkMsg="answer";
   linkStr=L99MentaltestPath.getMentalUrlPath()+"test/"+testId+"/answer/"+mentalAnswer.getId();
  } catch (Exception e) {
   LOG.error(e.getMessage(), e);
   errorMessage =ErrorMsg.SERVERERROR;
  }
  return "answer";                  //得出结论
 }
 /**
  * 显示结果页面
251892566
  * @return
  */
 public String showAnswer(){
  Object sessionAccount = getSessionOf(SessionKeys.ACCOUNTID);
  if (null == sessionAccount) {
   errorMessage = ErrorMsg.SESSIONOUT;
   return ERROR;
  }
  if(testId==null){
   errorMessage =ErrorMsg.TEST_NOTEST;
   return ERROR;
  }
  try {
   accountId =Long.valueOf(sessionAccount.toString());
   mentaltest = MentaltestService.findMentaltestById(testId);
   //   boolean likeFlag = L99CommentShare.findIsLikeTarget(accountId, testId,L99CommentType.TEST);//0521-
   boolean likeFlag =CommentRmiClient.findIsLikeTarget(accountId, testId, L99CommentType.TEST);//052+
   mentaltest.setLikeFlag(likeFlag);
   mentalAnswer =MentalAnswerService.findAnswerById(answerId);
   answerList =MentalAnswerService.findByTestId(testId);
   mentalUsers =MentalUsersService.findByTestIdAndAnswerId(testId, accountId);
   for (MentalAnswer temp : answerList) {
    if(mentaltest.getTestNO()==0)mentaltest.setTestNO(1);
    temp.setPrecentNO(Math.round(temp.getAnswerNO()*100/mentaltest.getTestNO()));
   }
   userList =MentalUsersService.findTheSameUser(accountId, testId, mentalUsers.getAnswerId());
   tagList =TagSerivce.findTagsByObjectId(testId,5);
   aLikeList =MentaltestService.findAlikeTest(tagList, testId, 5);
   testList =MentaltestService.findAllTest(1, 0,5, "hot");
  } catch (Exception e) {
   LOG.error(e.getMessage(), e);
  }
  return "showAnswer";
 } 
 /**
  * 我做过的心理测试
  * @return
  */
 public String myTest(){
  try {
   Long sessId =0l;
   if(longNO!=null){
    user =AccountShare.findBylongNO(longNO);
    accountId=user.getAccountId();
    if(isLogin())sessId=getSessionAccount();//获取当前登录用户的ID
    isFollow = FollowUtil.isFollow(sessId, accountId);
   }else{
    if(!isLogin()){
     return "common_index";
    }
    accountId =getSessionAccount();
    sessId =accountId;
   }
   total =MentalUsersService.getMytestNO(accountId);
   dataNum = (int) Math.ceil(total * 1.0D / showdata);
   nowPage = dataNum == 0 ? 1 : nowPage <= dataNum ?  nowPage <= 0 ? 1  : nowPage    : dataNum;
   int start = (nowPage - 1) * showdata;
   userList =MentalUsersService.findMyTest(accountId,sessId, start, showdata);
  } catch (Exception e) {
   LOG.error(e.getMessage(), e);
  }
  return "myTest";
 }
 /**
  * 添加关注
  * @return
  */
 public void addFollow() {
  Account account = AccountShare.findAccountById(getSessionAccount());
  try {
   if(longNO!=null){
    user =AccountShare.findBylongNO(longNO);
    accountId=user.getAccountId();
    String returnFollow =  FollowUtil.addFollow(accountId,account.getAccountId());
    response.getWriter().write(returnFollow);
   }
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
 /**
  * 心理测试数据分离重飞
  * @return
  * 20130505
  */

 public String reblogTest(){

  Object sessionAccount = getSessionOf(SessionKeys.ACCOUNTID);
  if (null == sessionAccount) {
   errorMessage = ErrorMsg.SESSIONOUT;
   return ERROR;
  }
  accountId =getSessionAccount();
  DashboardAppShare.initApp(accountId, targetId, 220);
  return "reblog";
 }

 //20130508星座运势
 public String HoroscopeTest() {
  try { 
   //20130509取星座
   Object sessionAccount = getSessionOf(SessionKeys.ACCOUNTID);
   if (null == sessionAccount) {
    errorMessage = ErrorMsg.SESSIONOUT;
    return ERROR;
   }
   accountId =Long.valueOf(sessionAccount.toString());
   String systemType = "d";
   String language ="zh_cn";
   String xingzuo ="";
   String birthday ="";
   String typeId = new String (this.getTypeId().getBytes("ISO8859_1"),"UTF-8");
   String year = new String(this.getBirthdayYear().getBytes("ISO8859_1"),"UTF-8");
   String month = new String(this.getBirthdayMonth().getBytes("ISO8859_1"),"UTF-8");;
   String day = new String(this.getBirthdayDay().getBytes("ISO8859_1"),"UTF-8");
   if((year==null||"".equals(year))||(month==null||"".equals(month))||(day==null||"".equals(day))){
    birthday ="";
   }else{
    birthday = year +"-"+month+"-"+day;

   }           

   if(typeId!=null||!"".equals(typeId)){
    Map xz = MentalHoroscope .getConstellationsNO();
    xingzuo = xz.get(typeId).toString();
    //    System.out.println(typeId+"==xingzuo="+xingzuo);
    AccountProfile accountProfile = MentaltestService.constellationName(accountId);
    if(birthday.length()>3){accountProfile.setBirthday(birthday);}
    accountProfile.setConstellation(xingzuo);
    MentaltestService.updateAccountProfile(accountProfile);
    String temp =HoroscopeClt.getConstellationInfo(Integer.parseInt(typeId), systemType, language);
    response.getWriter().write(temp);

   }
  } catch (Exception e) {
   LOG.error(e.getMessage(), e);
  }      
  return null;

 }


 public String HoroscopeTestY() {
  try {
   String systemType = "d";
   String language ="zh_cn";
   String temp =HoroscopeClt.getConstellationInfo(Integer.parseInt(typeId), systemType, language);
   response.getWriter().write(temp);
  } catch (Exception e) {
   LOG.error(e.getMessage(), e);
  }
  return null;
 }

 /**
  * 好友做过的心理测试题(无用注释)
  * @return
  * 无用注释20130425
  */
 /* public String friendTest(){                                //好友做过的心理测试在哪里显示?

  Object sessionAccount = getSessionOf(SessionKeys.LONGNO);
  Object sessionAccountId = getSessionOf(SessionKeys.ACCOUNTID);
  if (null == sessionAccount) {
   errorMessage = ErrorMsg.SESSIONOUT;
   return ERROR;
  }
  try {
   Long sessId =Long.valueOf(sessionAccountId.toString());
   if(longNO!=null){
    accountId =AccountShare.getAccountIdByLongNO(longNO);
   }else accountId =sessId;
   accountId=sessId;
   total =MentalUsersService.getMyFriendTestNO(accountId);
   dataNum = (int) Math.ceil(total * 1.0D / showdata);
   nowPage = dataNum == 0 ?    1 : nowPage <= dataNum ? nowPage <= 0 ? 1  : nowPage : dataNum;
   int start = (nowPage - 1) * showdata;
   userList =MentalUsersService.findMyFriendTest(accountId,sessId, start, showdata);
  } catch (Exception e) {
   LOG.error(e.getMessage(), e);
  }
  return "friendTest";
 }*/

 public String allTest(){   
  //题目列表
  try {
   total =MentaltestService.getTestNo(1);
   dataNum = (int) Math.ceil(total * 1.0D / showdata);
   nowPage = dataNum == 0 ? 1 : nowPage <= dataNum ? nowPage <= 0 ? 1  : nowPage : dataNum;
   int start = (nowPage - 1) * showdata;
   testList =MentaltestService.findAllTest(1, start, showdata, order);
   tagList =TagSerivce.findObjectHotTag(5, 8);   
   linkStr =L99MentaltestPath.getMentalUrlPath()+"Test_allTest.action?order="+order;
   hotTestList =MentaltestService.findAllTest(1, start, showdata, "hot");
   //20130509取星座
   Object sessionAccount = getSessionOf(SessionKeys.ACCOUNTID);
   if(null != sessionAccount){
    accountId =Long.valueOf(sessionAccount.toString());
    //   System.out.println("=accountId="+accountId);
    AccountProfile accountProfile = MentaltestService.constellationName(accountId);
    constellation = accountProfile.getConstellation();
    if(constellation==null||constellation.equals("")){
     constellation ="";
    }else{
     Map xz =MentalHoroscope.getConstellations();
     constellation = xz.get(constellation).toString(); 
    }
   }
  } catch (Exception e) {
   LOG.error(e.getMessage(), e);
  }
  return "allTest";
 }

 public String tagTest(){
  try {
   total =MentaltestService.getTestByTagId(tagId);
   dataNum = (int) Math.ceil(total * 1.0D / showdata);
   nowPage = dataNum == 0 ? 1 : nowPage <= dataNum ? nowPage <= 0 ? 1  : nowPage : dataNum;
   int start = (nowPage - 1) * showdata;
   testList =MentaltestService.findAllTestByTag(tagId,order, start, showdata);
   tagList =TagSerivce.findObjectHotTag(5, 8);
   linkStr =L99MentaltestPath.getMentalUrlPath()+"Test_tagTest.action?tagId="+tagId+"&order="+order;
   hotTestList =MentaltestService.findAllTest(1, start, showdata, "hot");

   //20130509取星座
   Object sessionAccount = getSessionOf(SessionKeys.ACCOUNTID);

   if(null != sessionAccount){
    accountId =Long.valueOf(sessionAccount.toString());
    //   System.out.println("=accountId="+accountId);
    AccountProfile accountProfile = MentaltestService.constellationName(accountId);
    constellation = accountProfile.getConstellation();

    if(constellation==null||constellation.equals("")){
     constellation ="";
    }else{
     Map xz =MentalHoroscope.getConstellations();
     constellation = xz.get(constellation).toString(); 
    }
   }
  } catch (Exception e) {
   LOG.error(e.getMessage(), e);
  }
  return "allTest";
 }
 /**
  * 一键分享
  * @return
  */


 public String share()  {   
  try{   
   urlVo= MentalUsersService.thridShareURL(testId,answerId);   
  } catch(L99IllegalOperateException e){
  } catch(Exception e){
   LOG.error(e.getMessage(), e);
  }
  return "share";
 }

 

 


 public MentalAnswer getMentalAnswer() {
  return mentalAnswer;
 }

 

 public void setMentalAnswer(MentalAnswer mentalAnswer) {
  this.mentalAnswer = mentalAnswer;
 }

 

 public MentalSubject getMentalSubject() {
  return mentalSubject;
 }

 

 public void setMentalSubject(MentalSubject mentalSubject) {
  this.mentalSubject = mentalSubject;
 }

 

 public Mentaltest getMentaltest() {
  return mentaltest;
 }

 

 public void setMentaltest(Mentaltest mentaltest) {
  this.mentaltest = mentaltest;
 }

 

 public Long getTestId() {
  return testId;
 }

 

 public void setTestId(Long testId) {
  this.testId = testId;
 }

 

 public String getPreTest() {
  return preTest;
 }

 

 public void setPreTest(String preTest) {
  this.preTest = preTest;
 }

 public int getAnswerOrder() {
  return answerOrder;
 }

 public void setAnswerOrder(int answerId) {
  this.answerOrder = answerId;
 }

 public int getShow() {
  return show;
 }

 public void setShow(int show) {
  this.show = show;
 }

 public MentalUsers getMentalUsers() {
  return mentalUsers;
 }

 public void setMentalUsers(MentalUsers mentalUsers) {
  this.mentalUsers = mentalUsers;
 }

 public Long getAccountId() {
  return accountId;
 }

 public void setAccountId(Long accountId) {
  this.accountId = accountId;
 }

 public String getLinkMsg() {
  return linkMsg;
 }

 public void setLinkMsg(String linkMsg) {
  this.linkMsg = linkMsg;
 }

 public String getLinkStr() {
  return linkStr;
 }

 public void setLinkStr(String linkStr) {
  this.linkStr = linkStr;
 }

 public List<MentalAnswer> getAnswerList() {
  return answerList;
 }

 public void setAnswerList(List<MentalAnswer> answerList) {
  this.answerList = answerList;
 }

 public Long getAnswerId() {
  return answerId;
 }

 public void setAnswerId(Long answerId) {
  this.answerId = answerId;
 }

 public List<MentalUsers> getUserList() {
  return userList;
 }

 public void setUserList(List<MentalUsers> userList) {
  this.userList = userList;
 }

 public List<Tag> getTagList() {
  return tagList;
 }

 public Account getUser() {
  return user;
 }

 public void setUser(Account user) {
  this.user = user;
 }

 public void setTagList(List<Tag> tagList) {
  this.tagList = tagList;
 }

 public List<Mentaltest> getALikeList() {
  return aLikeList;
 }

 public void setALikeList(List<Mentaltest> likeList) {
  aLikeList = likeList;
 }

 public List<Mentaltest> getTestList() {
  return testList;
 }

 public void setTestList(List<Mentaltest> testList) {
  this.testList = testList;
 }

 public Long getLongNO() {
  return longNO;
 }

 public void setLongNO(Long longNO) {
  this.longNO = longNO;
 }

 public int getTotal() {
  return total;
 }

 public void setTotal(int total) {
  this.total = total;
 }

 public int getDataNum() {
  return dataNum;
 }

 public void setDataNum(int dataNum) {
  this.dataNum = dataNum;
 }

 public int getNowPage() {
  return nowPage;
 }

 public void setNowPage(int nowPage) {
  this.nowPage = nowPage;
 }

 public int getShowdata() {
  return showdata;
 }

 public void setShowdata(int showdata) {
  this.showdata = showdata;
 }

 public String getOrder() {
  return order;
 }

 public void setOrder(String order) {
  this.order = order;
 }

 public Long getTagId() {
  return tagId;
 }

 public void setTagId(Long tagId) {
  this.tagId = tagId;
 }

 public List<Mentaltest> getExactList() {
  return exactList;
 }

 public void setExactList(List<Mentaltest> exactList) {
  this.exactList = exactList;
 }

 public List<Mentaltest> getHotTestList() {
  return hotTestList;
 }

 public void setHotTestList(List<Mentaltest> hotTestList) {
  this.hotTestList = hotTestList;
 }

 public int getAction() {
  return action;
 }

 public void setAction(int action) {
  this.action = action;
 }

 public DashboardShareUrlVo getUrlVo() {
  return urlVo;
 }

 public void setUrlVo(DashboardShareUrlVo urlVo) {
  this.urlVo = urlVo;
 }

 public String getConstellation() {
  return constellation;
 }

 public void setConstellation(String constellation) {
  this.constellation = constellation;
 }
 public Long getTargetId() {
  return targetId;
 }

 public void setTargetId(Long targetId) {
  this.targetId = targetId;
 }

 public String getpUrlPath() {
  return pUrlPath;
 }

 public void setpUrlPath(String pUrlPath) {
  this.pUrlPath = pUrlPath;
 }

 public String getMentalUrlPath() {
  return mentalUrlPath;
 }

 public void setMentalUrlPath(String mentalUrlPath) {
  this.mentalUrlPath = mentalUrlPath;
 }

 public String getTypeId() {
  return typeId;
 }

 public void setTypeId(String typeId) {
  this.typeId = typeId;
 }

 public String getBirthdayYear() {
  return birthdayYear;
 }

 public void setBirthdayYear(String birthdayYear) {
  this.birthdayYear = birthdayYear;
 }

 public String getBirthdayMonth() {
  return birthdayMonth;
 }

 public void setBirthdayMonth(String birthdayMonth) {
  this.birthdayMonth = birthdayMonth;
 }
 public String getBirthdayDay() {
  return birthdayDay;
 }

 public void setBirthdayDay(String birthdayDay) {
  this.birthdayDay = birthdayDay;
 }

 public Long getIsFollow() {
  return isFollow;
 }

 public void setIsFollow(Long isFollow) {
  this.isFollow = isFollow;
 }

 public Long getAddFollow() {
  return addFollow;
 }

 public void setAddFollow(Long addFollow) {
  this.addFollow = addFollow;
 }

}

原创粉丝点击