Administrator
2018-11-29 ebb3551170b255defc25fe93bbf6eb1e84cd321d
fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/ThreeSaleSerivceImpl.java
@@ -1,10 +1,17 @@
package com.yeshi.fanli.service.impl.hongbao;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.hibernate.HibernateException;
import org.hibernate.Query;
@@ -13,18 +20,20 @@
import org.springframework.orm.hibernate4.HibernateCallback;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.yeshi.utils.NumberUtil;
import com.yeshi.fanli.dao.mybatis.ThreeSaleMapper;
import com.yeshi.fanli.dao.mybatis.UserInfoMapper;
import com.yeshi.fanli.dao.user.ThreeSaleDao;
import com.yeshi.fanli.entity.bus.user.ThreeSale;
import com.yeshi.fanli.entity.bus.user.ThreeSaleExtraInfo;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.service.inter.config.InviteGetMoneyService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.util.Constant;
import org.yeshi.utils.NumberUtil;
import com.yeshi.fanli.util.StringUtil;
@Service
public class ThreeSaleSerivceImpl implements ThreeSaleSerivce {
@@ -310,6 +319,217 @@
   public int updateExpire(List<Long> list){
      return threeSaleMapper.updateExpire(list);
   }
   @Override
   public List<ThreeSale> listFirstTeamQuery(long start, int count, Long uid, Integer state, String startTime,
         String endTime) {
      return threeSaleMapper.listFirstTeamQuery(start, count, uid, state, startTime, endTime);
   }
   @Override
   public long countFirstTeamQuery(Long uid, Integer state, String startTime, String endTime) {
      return threeSaleMapper.countFirstTeamQuery(uid, state, startTime, endTime);
   }
   @Override
   public List<ThreeSale> listSecondTeamQuery(long start, int count, Long uid, Integer state, String startTime,
         String endTime) {
      return threeSaleMapper.listSecondTeamQuery(start, count, uid, state, startTime, endTime);
   }
   @Override
   public long countSecondTeamQuery(Long uid, Integer state, String startTime, String endTime) {
      return threeSaleMapper.countSecondTeamQuery(uid, state, startTime, endTime);
   }
   @Override
   public List<ThreeSale> listSuperiorQuery(long start, int count, Integer state, Long uid) {
      return threeSaleMapper.listSuperiorQuery(start, count, state, uid);
   }
   @Override
   public long countSuperiorQuery(Integer state, Long uid) {
      return threeSaleMapper.countSuperiorQuery(state, uid);
   }
   @Override
   public List<ThreeSale> listFirstTeam(long start, int count, Long uid) {
      return threeSaleMapper.listFirstTeam(start, count, uid);
   }
   @Override
   public long countFirstTeam(Long uid, Integer state) {
      return threeSaleMapper.countFirstTeam(uid, state);
   }
   @Override
   public List<ThreeSale> listSecondTeam(long start, int count, Long uid) {
      return threeSaleMapper.listSecondTeam(start, count, uid);
   }
   @Override
   public long countSecondTeam(Long uid, Integer state) {
      return threeSaleMapper.countSecondTeam(uid, state);
   }
   
   @Override
   public ThreeSale getMyBoss(Long uid) {
      return threeSaleMapper.getMyBoss(uid);
   }
   @Override
   public ThreeSale selectByPrimaryKey(Long id) {
      return threeSaleMapper.selectByPrimaryKey(id);
   }
   @Override
   public List<ThreeSale> listbyIdAndBossId(Long id, Long uid, Integer expire) {
      return threeSaleMapper.listbyIdAndBossId(id, uid, expire);
   }
   @Override
   public JSONObject getMyFirstTeam(long start, int count, Long uid) {
      List<ThreeSale> list = threeSaleMapper.listFirstTeam(start, count, uid);
      if (list == null) {
         list = new ArrayList<ThreeSale>();
      }
      long countTotal = threeSaleMapper.countFirstTeam(uid, null);
      return organizeTeam(countTotal, list);
   }
   @Override
   public JSONObject getMySecondTeam(long start, int count, Long uid) {
      List<ThreeSale> list = threeSaleMapper.listSecondTeam(start, count, uid);
      if (list == null) {
         list = new ArrayList<ThreeSale>();
      }
      long countTotal = threeSaleMapper.countSecondTeam(uid, null);
      return organizeTeam(countTotal, list);
   }
   public JSONObject organizeTeam(long count, List<ThreeSale> list) {
      JSONObject result = new JSONObject();
      JSONArray resultArray  = new JSONArray();
      for (ThreeSale threeSale: list) {
         JSONObject object = new JSONObject();
         SimpleDateFormat sdf = new SimpleDateFormat("MM.dd HH:mm");
         SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
         SimpleDateFormat formatYears = new SimpleDateFormat("yyyy");
         Date todayTime = new Date();
         // 邀请id
         object.put("inviteId", threeSale.getId());
         // 加入队列时间
         Long createTime = threeSale.getCreateTime();
         Date inviteTime = new Date(createTime);
         object.put("inviteTime", format.format(inviteTime) + " 加入");
         String memoName = "";
         ThreeSaleExtraInfo threeSaleExtraInfo = threeSale.getThreeSaleExtraInfo();
         if (threeSaleExtraInfo != null) {
            if (!StringUtil.isNullOrEmpty(threeSaleExtraInfo.getNickname())) {
               memoName = threeSaleExtraInfo.getNickname();
            }
         }
         object.put("memoName", memoName);
         String nickName = "";
         String portrait = "";
         Long lastLoginTime = null;
         UserInfo worker = threeSale.getWorker();
         if (worker != null) {
            portrait = worker.getPortrait();
            lastLoginTime = worker.getLastLoginTime();
            nickName = worker.getNickName();
         }
         object.put("nickName", nickName);
         object.put("portrait", portrait);
         int state = 0;
         String fontColor1 = "#888888";
         String fontColor2 = "#F14242";
         JSONArray array  = new JSONArray();
         if (threeSale.getState()) {
            state = 1;
            if (lastLoginTime == null) {
               lastLoginTime = threeSale.getCreateTime();
            }
            JSONObject contentJson = new JSONObject();
            contentJson.put("color", fontColor1);
            if (formatYears.format(todayTime).equals(formatYears.format(lastLoginTime))) {
               // 本年
               contentJson.put("content", "最近登陆 " + sdf.format(lastLoginTime));
            } else {
               // 往年
               contentJson.put("content", "最近登陆 " + format.format(lastLoginTime));
            }
            array.add(contentJson);
         } else if ( threeSale.getExpire()!= null && (threeSale.getExpire() == 1 || threeSale.getExpire().equals(1))) {
            state = 2;
            JSONObject contentJson = new JSONObject();
            contentJson.put("color", fontColor1);
            contentJson.put("content", "已经脱离邀请关系");
            array.add(contentJson);
         } else {
            state = 0;
            Calendar c = Calendar.getInstance();
            c.setTime(inviteTime);
            c.add(Calendar.DAY_OF_MONTH, 60);// 邀请不超过60天
            long days =  (c.getTimeInMillis() -todayTime.getTime()) / (1000*3600*24);
            if (days < 0) {
               days = 0;
            }
            JSONObject contentJson1 = new JSONObject();
            contentJson1.put("color", fontColor1);
            contentJson1.put("content", "将于");
            JSONObject contentJson2 = new JSONObject();
            contentJson2.put("color", fontColor2);
            contentJson2.put("content", days+"天");
            JSONObject contentJson3 = new JSONObject();
            contentJson3.put("color", fontColor1);
            contentJson3.put("content", "后脱离邀请关系");
            array.add(contentJson1);
            array.add(contentJson2);
            array.add(contentJson3);
         }
         object.put("state", state);
         object.put("recentMsg", array);
         resultArray.add(object);
      }
      result.put("count", count);
      result.put("result_list", resultArray);
      return result;
   }
   
}