评论

收藏

[Java] java实现app签到功能

编程语言 编程语言 发布于:2021-10-07 11:38 | 阅读数:305 | 评论:0

这篇文章主要为大家详细介绍了java实现app签到功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了java实现app签到功能的具体代码,供大家参考,具体内容如下
1.首先设计二张表,第一张表sign_calc记录用户连续签到次数,字段id,user_id,continue_days,第二张表sign_detail签到详情表id,user_id,sign_date。
2.app端用户点击签到接口controller如下:
/***
   * app签到接口
   * @author xuhaibo
   * @param accid
   * @return
   */
  @responsebody
  @requestmapping(value = "/dosign")
  public jsonobject dosign(integer accid) {
  jsonobject result = new jsonobject();
  map<string, object> data = new hashmap<>();
  if (!cinemaconstants.accid_map.contains(accid)) {
    integer previousid = cinemaconstants.accid_map.put(accid, accid);
    if (previousid == null) {
    try {
      /****
       * 查询用户今日的签到
       */
      signdetail signtoday = signservice.todaydetail(accid);//
      system.out.println(signtoday);
      if (signtoday == null) {//今天未签到 1:查询本月昨日签到情况
      signdetail signdetail_yesterday = signservice.yesterdaydetail(accid);
      signcalc signcalcget = signservice.getsigncalc(accid);
      if (signdetail_yesterday == null) {
        signdetail signdetail = new signdetail();
        signdetail.setuser_id(accid);
        signdetail.setsign_date(new date());
        signservice.addsigndetail(signdetail);
        if (signcalcget == null) {
        signcalc signcalc = new signcalc();
        signcalc.setuser_id(accid);
        signcalc.setcontinue_days(1);
        signservice.addsigncalc(signcalc);
        } else {
        signcalc signcalc = new signcalc();
        signcalc.setuser_id(accid);
        signcalc.setcontinue_days(1);
        signservice.updatesigncalc(signcalc);
        }
        integral integral = new integral();
        integral.setsourceid(0);
        integral.setuserid(accid);
        integral.setscore(cinemaconstants.integral_type_sign_scores);
        integral.setcreatetime(new date());
        integral.setnote(cinemaconstants.integral_type_sign_describe);
        integral.setsourcetype(cinemaconstants.integral_type_sign);
        integralservice.add(integral);
        accountservice.addintegralbyuserid(accid, cinemaconstants.integral_type_sign_scores);
        result.put(constants.result_code, "00");
        data.put("data", "签到成功");
      } else {//昨日已签到
        signdetail signdetail = new signdetail();
        signcalc signcalc = new signcalc();
        signdetail.setuser_id(accid);
        signdetail.setsign_date(new date());
        signservice.addsigndetail(signdetail);
        signcalc.setuser_id(accid);
        signcalc.setcontinue_days(signcalcget.getcontinue_days() + 1);
        signservice.updatesigncalc(signcalc);
        integral integral = new integral();
        integral.setuserid(accid);
        integral.setsourceid(0);
        integral.setscore(cinemaconstants.integral_type_sign_scores);
        integral.setnote(cinemaconstants.integral_type_sign_describe);
        integral.setcreatetime(new date());
        integral.setsourcetype(cinemaconstants.integral_type_sign);
        integralservice.add(integral);
        accountservice.addintegralbyuserid(accid, cinemaconstants.integral_type_sign_scores);
        result.put(constants.result_code, "00");
        data.put("data", "签到成功");
      }
      } else {//当日已签到
      result.put(constants.result_code, "-1");
      data.put("data", "当日已签到");
      }
      result.put("data", data);
    } catch (exception e) {
      e.printstacktrace();
      result.put(constants.result_code, "-1");
      result.put("data", "服务器错误");
    }
    cinemaconstants.accid_map.remove(accid);
    } else {
    result.put(constants.result_code, "-1");
    result.put("data", "操作正在进行,请重试");
    }
  } else {
    result.put(constants.result_code, "-1");
    result.put("data", "操作正在进行,请重试");
  }
  return result;
  }
领取连续签到奖励接口:
/***
   * 领取连续签到奖励接口(7天,15天,30天)
   * @param accid
   * @param signtype
   * @return
   */
  @responsebody
  @requestmapping(value = "/getsigngift")
  public jsonobject getseven(integer accid, integer signtype) {
  calendar a = calendar.getinstance();
  a.set(calendar.date, 1);//把日期设置为当月第一天
  a.roll(calendar.date, -1);//日期回滚一天,也就是最后一天
  int maxdate = a.get(calendar.date);
  system.out.print(maxdate);
  jsonobject result = new jsonobject();
  map<string, object> data = new hashmap<>();
  if (!cinemaconstants.accid_map.contains(accid)) {
    integer previousid = cinemaconstants.accid_map.put(accid, accid);
    if (previousid == null) {
    try {
      signcalc signcalc = signservice.getsigncalc(accid);
      int signserven = integralservice.signquery(accid, cinemaconstants.integral_type_sign_7);
      int signfifteen = integralservice.signquery(accid, cinemaconstants.integral_type_sign_15);
      int signthirty = integralservice.signquery(accid, cinemaconstants.integral_type_sign_30);
      if (signserven==0&&signtype == 7 && signcalc.getcontinue_days() >= 7) {
      integral integral = new integral();
      integral.setuserid(accid);
      integral.setnote(cinemaconstants.integral_type_sign_7_describe);
      integral.setscore(cinemaconstants.integral_type_sign_7_scores);
      integral.setcreatetime(new date());
      integral.setsourcetype(cinemaconstants.integral_type_sign_7);
      integralservice.add(integral);
      accountservice.addintegralbyuserid(accid, cinemaconstants.integral_type_sign_7_scores);
      result.put(constants.result_code, "00");
      data.put("data", "领取成功");
      } //
      else if (signfifteen==0&&signtype == 15 && signcalc.getcontinue_days() >= 15) {
      integral integral = new integral();
      integral.setuserid(accid);
      integral.setnote(cinemaconstants.integral_type_sign_15_describe);
      integral.setscore(cinemaconstants.integral_type_sign_15_scores);
      integral.setcreatetime(new date());
      integral.setsourcetype(cinemaconstants.integral_type_sign_15);
      integralservice.add(integral);
      accountservice.addintegralbyuserid(accid, cinemaconstants.integral_type_sign_15_scores);
      result.put(constants.result_code, "00");
      data.put("data", "领取成功");
      } else if (signthirty==0&&signtype == 30 && signcalc.getcontinue_days() >= maxdate) {
      integral integral = new integral();
      integral.setuserid(accid);
      integral.setnote(cinemaconstants.integral_type_sign_30_describe);
      integral.setscore(cinemaconstants.integral_type_sign_30_scores);
      integral.setcreatetime(new date());
      integral.setsourcetype(cinemaconstants.integral_type_sign_30);
      integralservice.add(integral);
      accountservice.addintegralbyuserid(accid, cinemaconstants.integral_type_sign_30_scores);
      result.put(constants.result_code, "00");
      data.put("data", "领取成功");
      } else {
      result.put(constants.result_code, "-1");
      data.put("msg", "已领取或未到标");
      }
      result.put("data", data);
    } catch (exception e) {
      e.printstacktrace();
      result.put(constants.result_code, "-1");
      result.put("data", "服务器错误");
    }
    cinemaconstants.accid_map.remove(accid);
    } else {
    result.put(constants.result_code, "-1");
    result.put("data", "操作正在进行,请重试");
    }
  } else {
    result.put(constants.result_code, "-1");
    result.put("data", "操作正在进行,请重试");
  }
  return result;
  }
签到页面的接口:
/***
   * 签到页面app端接口
   * @param accid
   * @return
   */
  @requestmapping(value = "/signgift")
  @responsebody
  public map<string, object> signgift(integer accid) {
  hashmap result = new hashmap();
  jsonobject data = new jsonobject();
  string signdetail = "";
  simpledateformat sdf = new simpledateformat("yyyy-mm-dd");
  try {
    account account = accountservice.getaccount(accid);
    signcalc signcalc = signservice.getsigncalc(accid);
    list<map<string, string>> list = signservice.getdetailbyid(accid);
    system.out.println(list);
    string countdate = signservice.countdate(accid);
    if (account == null) {
    result.put(constants.result_code, "-1");
    result.put("data", "没数据");
    } else {
    string[] strings = account.getavatar().split(".png");
    data.put("nick_name", account.getnick_name());//昵称
    data.put("avatar", strings[0]);
    data.put("integral", account.getintegral());//总积分
    data.put("count_date", countdate);//累计签到天数
    if (list.size() > 0) {
      for (map<string, string> map : list) {
      for (map.entry<string, string> entry : map.entryset()) {
        string value = sdf.format(entry.getvalue());
        signdetail += value + ",";
      }
      }
    }
    int j = signdetail.lastindexof(",");
    signdetail = signdetail.substring(0, j);
    data.put("sign_date", signdetail);//签到明细
    }
    data.put("sign_today", true);
    int signserven = integralservice.signquery(accid, cinemaconstants.integral_type_sign_7);
    if (signcalc.getcontinue_days() < 7) {
    data.put("sign_seven", "0");//未达标
    } else if (signserven>0) {
    data.put("sign_seven", "2");//已领取
    } else {
    data.put("sign_seven", "1");//未领取
    }
    int signfifteen = integralservice.signquery(accid, cinemaconstants.integral_type_sign_15);
    if (signcalc.getcontinue_days() < 15) {
    data.put("sign_fifteen", "0");//未达标
    } else if (signfifteen > 0) {
    data.put("sign_fifteen", "2");//已领取
    } else {
    data.put("sign_fifteen", "1");//未领取
    }
    int signthirty = integralservice.signquery(accid, cinemaconstants.integral_type_sign_30);
    if (signcalc.getcontinue_days() < 30 ) {
    data.put("sign_thirty", "0");//未达标
    } else if (signthirty>0) {
    data.put("sign_thirty", "2");//已领取
    } else {
    data.put("sign_thirty", "1");//未领取
    }
    result.put(constants.result_code, "00");
    result.put("data", data);
  } catch (exception e) {
    e.printstacktrace();
    result.put(constants.result_code, "-1");
    result.put("data", "数据获取异常");
  }
  return result;
  }
效果如下:
DSC0000.jpg

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持CodeAE代码之家
原文链接:https://blog.csdn.net/haibo8023/article/details/76725370

关注下面的标签,发现更多相似文章