diff --git a/src/com/w1hd/zzhnc/model/Lotterylog.java b/src/com/w1hd/zzhnc/model/Lotterylog.java index b108ff1..bd76f51 100644 --- a/src/com/w1hd/zzhnc/model/Lotterylog.java +++ b/src/com/w1hd/zzhnc/model/Lotterylog.java @@ -6,7 +6,7 @@ import java.util.Date; import javax.persistence.Id; -public class Lotterylog implements Serializable{ +public class Lotterylog implements Serializable { /** * */ @@ -18,13 +18,13 @@ public class Lotterylog implements Serializable{ private BigDecimal mny; private Integer status; private Integer turn; - + private Integer prizeId; private Date createdtime; public Integer getId() { return id; } - + public String getPrizeName() { return prizeName; } @@ -33,7 +33,6 @@ public class Lotterylog implements Serializable{ this.prizeName = prizeName; } - public void setId(Integer id) { this.id = id; } @@ -53,6 +52,7 @@ public class Lotterylog implements Serializable{ public void setMny(BigDecimal mny) { this.mny = mny; } + public Integer getStatus() { return status; } @@ -77,5 +77,11 @@ public class Lotterylog implements Serializable{ this.createdtime = createdtime; } + public Integer getPrizeId() { + return prizeId; + } + public void setPrizeId(Integer prizeId) { + this.prizeId = prizeId; + } } \ No newline at end of file diff --git a/src/com/w1hd/zzhnc/service/ActivityService.java b/src/com/w1hd/zzhnc/service/ActivityService.java index 4255842..b3d0556 100644 --- a/src/com/w1hd/zzhnc/service/ActivityService.java +++ b/src/com/w1hd/zzhnc/service/ActivityService.java @@ -132,6 +132,7 @@ public class ActivityService { public void updateActivityPrize(Integer type, Prize prize) { Activity setting = getActivitySetting(); + prize.setId(type); switch (type) { case 1: setting.setP1(prize); diff --git a/src/com/w1hd/zzhnc/service/AutoreplyService.java b/src/com/w1hd/zzhnc/service/AutoreplyService.java index ec445fe..2d45364 100644 --- a/src/com/w1hd/zzhnc/service/AutoreplyService.java +++ b/src/com/w1hd/zzhnc/service/AutoreplyService.java @@ -76,16 +76,12 @@ public class AutoreplyService { AutoreplyDao autoreplyDao; static List filterList = Lists.newArrayList(); - static RegexKeywordFilter projectNameFilter = new RegexKeywordFilter(); - static Map projectNameMap = Maps.newHashMap(); static boolean inited = false; public void init(boolean hard) { if (hard) { inited = false; filterList = Lists.newArrayList(); - projectNameFilter = new RegexKeywordFilter(); - projectNameMap = Maps.newHashMap(); } init(); } @@ -105,33 +101,15 @@ public class AutoreplyService { filter.compile(); filterList.add(filter); }); - projectNameMap.put("全部", 0); - projectNameFilter.add("全部"); - projectNameFilter.compile(); inited = true; } @Autowired RedisTemplate redisTemplate; - public void conentProjectName(String content, String fromUserName) { - boolean b = projectNameFilter.hasKeywords(content); - if (b) { - Set set = projectNameMap.keySet(); - set.stream().forEach(s -> { - int count = projectNameFilter.count(content, s); - if (count > 0) { - log.info("包含{},修改projectId为{}", s, projectNameMap.get(s)); - redisTemplate.opsForValue().set("dvmini171027_dvmini_cache_project_" + fromUserName, - projectNameMap.get(s) + ""); - } - - }); - - } - } + - public Autoreply autoreply(String string, Integer projectId) { + public Autoreply autoreply(String string) { List sets = Lists.newArrayList(); @@ -164,7 +142,7 @@ public class AutoreplyService { return null; List list = Lists.newArrayList(); list.addAll(sets.get(0)); - List autoreplys = autoreplyDao.findByKeys(list, projectId); + List autoreplys = autoreplyDao.findByKeys(list, null); if (autoreplys.isEmpty()) return null; @@ -218,14 +196,6 @@ public class AutoreplyService { return pageresult; } - /* - * (非 Javadoc) Description: - * - * @see - * com.w1hd.zzhnc.service.AutoreplyService#addAutoReply(java.lang.String, - * boolean, java.lang.String) - */ - public String addAutoReply(String keywords, boolean isRedirectStaff, String content, Integer projectId, String projectName, Integer sort) { if (Strings.isNullOrEmpty(keywords)) @@ -321,15 +291,10 @@ public class AutoreplyService { } public HashMap autoreply(String content, Integer projectId, String fromUserName) { - conentProjectName(content, fromUserName); - String projectIdStr = redisTemplate.opsForValue().get("dvmini171027_dvmini_cache_project_" + fromUserName); + Autoreply autoreply = null; - if (!Strings.isNullOrEmpty(projectIdStr)) { - projectId = Integer.parseInt(projectIdStr); - autoreply = autoreply(content, projectId); - } if (autoreply == null) { - autoreply = autoreply(content, 0); + autoreply = autoreply(content); } HashMap result = Maps.newHashMap(); diff --git a/src/com/w1hd/zzhnc/service/PrizeService.java b/src/com/w1hd/zzhnc/service/PrizeService.java index 53cb17d..05b128f 100644 --- a/src/com/w1hd/zzhnc/service/PrizeService.java +++ b/src/com/w1hd/zzhnc/service/PrizeService.java @@ -121,7 +121,7 @@ public class PrizeService { p.setNum(p.getNum() - 1); setting.setP8(p); break; - + default: break; } @@ -131,9 +131,10 @@ public class PrizeService { lotterylog.setFansid(fansId); lotterylog.setMny(mny); lotterylog.setPrizeName(p.getName()); - if("谢谢".equals(p.getName())) { + lotterylog.setPrizeId(pType); + if ("谢谢".equals(p.getName())) { lotterylog.setStatus(3); - }else { + } else { lotterylog.setStatus(1); } lotterylog.setTurn(setting.getTurn()); @@ -174,70 +175,94 @@ public class PrizeService { Activity activity = activityService.getActivitySetting(); int nextInt = RandomUtils.nextInt(0, 100); System.out.println("幸运数字 ---》》》" + nextInt); - Prize p8 = activity.getP8(); - Prize p7 = activity.getP7(); - Prize p6 = activity.getP6(); - Prize p5 = activity.getP5(); - Prize p4 = activity.getP4(); - Prize p3 = activity.getP3(); - Prize p2 = activity.getP2(); - Prize p1 = activity.getP1(); - nextInt = 51; + int sumNum = 0; + int sumPro = 0; + Prize tmp = null; + List prizeList = activityService.getPrizeList(); + for (Prize p : prizeList) { + if (p != null) { + sumNum += p.getNum(); + sumPro += p.getProbability(); + if (p.getName().contains("谢谢")) { + tmp = p; + } + } + } int mny = 0; Integer logId = 0; - if (p1 != null && nextInt < p1.getProbability() && p1.getNum() > 1) { - if (p1.getIsMoney()) { - mny = RandomUtils.nextInt(p1.getMixMoney(), p1.getMaxMoney()); - } - logId = insert(fansId, 1, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP)); - } else if (p2 != null && nextInt < (p2.getProbability() + p1.getProbability()) && p2.getNum() > 1) { - if (p2.getIsMoney()) { - mny = RandomUtils.nextInt(p2.getMixMoney(), p2.getMaxMoney()); - } - logId = insert(fansId, 2, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP)); - } else if (p3 != null && nextInt < (p3.getProbability() + p2.getProbability() + p1.getProbability()) - && p3.getNum() > 1) { - if (p3.getIsMoney()) { - mny = RandomUtils.nextInt(p3.getMixMoney(), p3.getMaxMoney()); - } - logId = insert(fansId, 3, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP)); - } else if (p4 != null - && nextInt < (p4.getProbability() + p3.getProbability() + p2.getProbability() + p1.getProbability()) - && p4.getNum() > 1) { - if (p4.getIsMoney()) { - mny = RandomUtils.nextInt(p4.getMixMoney(), p4.getMaxMoney()); - } - logId = insert(fansId, 4, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP)); - } else if (p5 != null && nextInt < (p5.getProbability() + p4.getProbability() + p3.getProbability() - + p2.getProbability() + p1.getProbability()) && p5.getNum() > 1) { - if (p5.getIsMoney()) { - mny = RandomUtils.nextInt(p5.getMixMoney(), p5.getMaxMoney()); + if (nextInt > sumPro) { + if (tmp != null) { + if (tmp.getIsMoney()) { + mny = RandomUtils.nextInt(tmp.getMixMoney(), tmp.getMaxMoney()); + } + logId = insert(fansId, tmp.getId(), new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP)); } - logId = insert(fansId, 5, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP)); - } else if (p6 != null && nextInt < (p6.getProbability() + p5.getProbability() + p4.getProbability() - + p3.getProbability() + p2.getProbability() + p1.getProbability()) && p6.getNum() > 1) { - if (p6.getIsMoney()) { - mny = RandomUtils.nextInt(p6.getMixMoney(), p6.getMaxMoney()); - } - logId = insert(fansId, 6, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP)); - } else if (p7 != null && nextInt < (p7.getProbability() + p6.getProbability() + p5.getProbability() - + p4.getProbability() + p3.getProbability() + p2.getProbability() + p1.getProbability()) - && p7.getNum() > 1) { - if (p7.getIsMoney()) { - mny = RandomUtils.nextInt(p7.getMixMoney(), p7.getMaxMoney()); - } - logId = insert(fansId, 7, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP)); - } else if (p8 != null - && nextInt < (p8.getProbability() + p7.getProbability() + p6.getProbability() + p5.getProbability() - + p4.getProbability() + p3.getProbability() + p2.getProbability() + p1.getProbability()) - && p8.getNum() > 1) { - if (p8.getIsMoney()) { - mny = RandomUtils.nextInt(p7.getMixMoney(), p7.getMaxMoney()); - } - logId = insert(fansId, 8, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP)); } else { - return -0; + Prize p8 = activity.getP8(); + Prize p7 = activity.getP7(); + Prize p6 = activity.getP6(); + Prize p5 = activity.getP5(); + Prize p4 = activity.getP4(); + Prize p3 = activity.getP3(); + Prize p2 = activity.getP2(); + Prize p1 = activity.getP1(); + + if (p1 != null && nextInt < p1.getProbability() && p1.getNum() > 1) { + if (p1.getIsMoney()) { + mny = RandomUtils.nextInt(p1.getMixMoney(), p1.getMaxMoney()); + } + logId = insert(fansId, 1, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP)); + } else if (p2 != null && nextInt < (p2.getProbability() + p1.getProbability()) && p2.getNum() > 1) { + if (p2.getIsMoney()) { + mny = RandomUtils.nextInt(p2.getMixMoney(), p2.getMaxMoney()); + } + logId = insert(fansId, 2, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP)); + } else if (p3 != null && nextInt < (p3.getProbability() + p2.getProbability() + p1.getProbability()) + && p3.getNum() > 1) { + if (p3.getIsMoney()) { + mny = RandomUtils.nextInt(p3.getMixMoney(), p3.getMaxMoney()); + } + logId = insert(fansId, 3, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP)); + } else if (p4 != null && nextInt < (p4.getProbability() + p3.getProbability() + p2.getProbability() + + p1.getProbability()) && p4.getNum() > 1) { + if (p4.getIsMoney()) { + mny = RandomUtils.nextInt(p4.getMixMoney(), p4.getMaxMoney()); + } + logId = insert(fansId, 4, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP)); + } else if (p5 != null && nextInt < (p5.getProbability() + p4.getProbability() + p3.getProbability() + + p2.getProbability() + p1.getProbability()) && p5.getNum() > 1) { + if (p5.getIsMoney()) { + mny = RandomUtils.nextInt(p5.getMixMoney(), p5.getMaxMoney()); + } + logId = insert(fansId, 5, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP)); + } else if (p6 != null && nextInt < (p6.getProbability() + p5.getProbability() + p4.getProbability() + + p3.getProbability() + p2.getProbability() + p1.getProbability()) && p6.getNum() > 1) { + if (p6.getIsMoney()) { + mny = RandomUtils.nextInt(p6.getMixMoney(), p6.getMaxMoney()); + } + logId = insert(fansId, 6, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP)); + } else if (p7 != null + && nextInt < (p7.getProbability() + p6.getProbability() + p5.getProbability() + + p4.getProbability() + p3.getProbability() + p2.getProbability() + p1.getProbability()) + && p7.getNum() > 1) { + if (p7.getIsMoney()) { + mny = RandomUtils.nextInt(p7.getMixMoney(), p7.getMaxMoney()); + } + logId = insert(fansId, 7, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP)); + } else if (p8 != null && nextInt < (p8.getProbability() + p7.getProbability() + p6.getProbability() + + p5.getProbability() + p4.getProbability() + p3.getProbability() + p2.getProbability() + + p1.getProbability()) && p8.getNum() > 1) { + if (p8.getIsMoney()) { + mny = RandomUtils.nextInt(p7.getMixMoney(), p7.getMaxMoney()); + } + logId = insert(fansId, 8, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP)); + } else { + if (sumNum > 0) { + return randomKill(fansId); + } + } } + redisTemplate.opsForValue().set(PRIZE_KILL_FANSID + fansId, logId); return logId; }