leon 5 лет назад
Родитель
Сommit
18de81e354

+ 14 - 3
src/main/java/com/mokamrp/privates/controller/pangu/PromoteQrcodePoolController.java

@@ -31,6 +31,9 @@ import com.mokamrp.privates.mapper.pangu.pojo.PromoteQrcodePool;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.validation.Valid;
+import javax.xml.bind.SchemaOutputResolver;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.text.DecimalFormat;
 import java.util.Date;
 import java.util.List;
@@ -89,9 +92,9 @@ public class PromoteQrcodePoolController extends BaseController<PromoteQrcodePoo
         if (bindingResult.hasErrors()) {
             return AjaxResult.error(HttpStatus.ERROR, bindingResult.getFieldError().getDefaultMessage());
         }
-        this.delRedis(delHandle.getIds());
         QueryWrapper<PromoteQrcodePool> QueryWrapper = new QueryWrapper<>();
         String[] ids = delHandle.getIds().split(",");
+        this.delRedis(ids);
         QueryWrapper.in("id", ids);
         boolean res = promoteQrcodePoolService.remove(QueryWrapper);
         if (!res) {
@@ -106,6 +109,13 @@ public class PromoteQrcodePoolController extends BaseController<PromoteQrcodePoo
         if (bindingResult.hasErrors()) {
             return AjaxResult.error(HttpStatus.ERROR, bindingResult.getFieldError().getDefaultMessage());
         }
+        //.排重
+        PromoteQrcodePool hasone = promoteQrcodePoolService.getOne(new QueryWrapper<PromoteQrcodePool>()
+                .eq("promote_id",addHandle.getRaw().getPromoteId())
+                .eq("custservice_id",addHandle.getRaw().getCustserviceId()));
+        if (hasone != null){
+            return AjaxResult.error(addHandle.getRaw().getCustserviceId()+"号个微码已经存在");
+        }
         PromoteCode promoteCode = promoteCodeService.getOne(new QueryWrapper<PromoteCode>().eq("id", addHandle.getRaw().getPromoteId()));
         PromoteQrcodePool promoteQrcodePool = promoteQrcodePoolService.getOne(
                 new QueryWrapper<PromoteQrcodePool>()
@@ -141,7 +151,8 @@ public class PromoteQrcodePoolController extends BaseController<PromoteQrcodePoo
     }
 
     private Boolean addRedis(Integer promoteId, Integer custserviceId, Integer weight) {
-        Float score = weight.floatValue() / 10000;
+        String scoreStr = BigDecimal.valueOf(weight.doubleValue()/10000).setScale(5, RoundingMode.HALF_EVEN).stripTrailingZeros().toPlainString();
+        float score = Float.parseFloat(scoreStr);
         Long index = stringRedisTemplate.opsForZSet().rank(RedisKey.PanCustServiceIdView + promoteId, Integer.toString(custserviceId));
         if (index == null) {
             stringRedisTemplate.opsForZSet().add(RedisKey.PanCustServiceIdView + promoteId, Integer.toString(custserviceId), score);
@@ -153,7 +164,7 @@ public class PromoteQrcodePoolController extends BaseController<PromoteQrcodePoo
         return true;
     }
 
-    private Boolean delRedis(String qrcodePoolIds) {
+    private Boolean delRedis(String[] qrcodePoolIds) {
         List<PromoteQrcodePool> res = promoteQrcodePoolService.list(new QueryWrapper<PromoteQrcodePool>().in("id", qrcodePoolIds));
         if (res == null) {
             return false;

+ 32 - 23
src/main/java/com/mokamrp/privates/service/pangu/impl/CustserviceServiceImpl.java

@@ -30,58 +30,67 @@ import java.util.*;
 @Service
 public class CustserviceServiceImpl extends ServiceImpl<CustserviceMapper, Custservice> implements CustserviceService {
 
-    @Autowired CustserviceMapper custserviceMapper;
+    @Autowired
+    CustserviceMapper custserviceMapper;
 
     @Autowired
     public StringRedisTemplate stringRedisTemplate;
+
     /**
      * 盘古客服库列表
+     *
      * @param custserviceListHandle
      * @return
      */
-    public Object getlist(CustserviceListHandle custserviceListHandle){
-        Page<CustserviceVo> page = new Page<CustserviceVo>(custserviceListHandle.getPage(),custserviceListHandle.getPagesize());
-        List<CustserviceVo> custservices = custserviceMapper.getlist(page,custserviceListHandle);
-        Map<String,Object> res = new HashMap<>();
-        res.put("list",custservices);
-        res.put("total",page.getTotal());
+    public Object getlist(CustserviceListHandle custserviceListHandle) {
+        Page<CustserviceVo> page = new Page<CustserviceVo>(custserviceListHandle.getPage(), custserviceListHandle.getPagesize());
+        List<CustserviceVo> custservices = custserviceMapper.getlist(page, custserviceListHandle);
+        Map<String, Object> res = new HashMap<>();
+        res.put("list", custservices);
+        res.put("total", page.getTotal());
         return res;
     }
 
     /**
      * (API)按阈值大小获取客服码
+     *
      * @param promoteId
      * @return
      */
-    public Map<String,Object> getRandCustservice(String promoteId){
-        Map<String,Object> res = new HashMap<>();
-        res.put("err",null);
+    public Map<String, Object> getRandCustservice(String promoteId) {
+        Map<String, Object> res = new HashMap<>();
+        res.put("err", null);
         //.获取活码小时访问量上限
-        String promoteInfoStr = stringRedisTemplate.opsForHash().get(RedisKey.PanPromoteCodeInfo,promoteId).toString();
+        Object promoteInfoObj = stringRedisTemplate.opsForHash().get(RedisKey.PanPromoteCodeInfo, promoteId);
+        if (promoteInfoObj == null) {
+            res.put("err", "promote info null");
+            return res;
+        }
+        String promoteInfoStr = promoteInfoObj.toString();
         PromoteCode promoteCode = JSON.parseObject(promoteInfoStr, PromoteCode.class);
-        Set<String> ids = stringRedisTemplate.opsForZSet().reverseRangeByScore(RedisKey.PanCustServiceIdView+promoteId,-1,promoteCode.getHourUvMax(),0,1);
-        if (ids == null || ids.size() == 0){
-            res.put("err","ids null");
+        Set<String> ids = stringRedisTemplate.opsForZSet().reverseRangeByScore(RedisKey.PanCustServiceIdView + promoteId, -1, promoteCode.getHourUvMax(), 0, 1);
+        if (ids == null || ids.size() == 0) {
+            res.put("err", "ids null");
             return res;
         }
         //.校验当前客服ID全天访问量是否达到上限
         String custserviceId = ids.toArray()[0].toString();
-        Double dayView = stringRedisTemplate.opsForZSet().score(RedisKey.PanCustServiceIdDayView+promoteId, custserviceId);
-        if (dayView == null){
+        Double dayView = stringRedisTemplate.opsForZSet().score(RedisKey.PanCustServiceIdDayView + promoteId, custserviceId);
+        if (dayView == null) {
             dayView = 0.00;
         }
-        if (dayView > promoteCode.getDayUvMax()){
-            res.put("err","custservice day view max");
+        if (dayView > promoteCode.getDayUvMax()) {
+            res.put("err", "custservice day view max");
             return res;
         }
         //.获取个微客服相信信息
-        Object jsonStr = stringRedisTemplate.opsForHash().get(RedisKey.PanCustServiceInfo,custserviceId);
-        Custservice custservice = JSON.parseObject(jsonStr.toString(),Custservice.class);
+        Object jsonStr = stringRedisTemplate.opsForHash().get(RedisKey.PanCustServiceInfo, custserviceId);
+        Custservice custservice = JSON.parseObject(jsonStr.toString(), Custservice.class);
         //.记录打点数
-        stringRedisTemplate.opsForZSet().incrementScore(RedisKey.PanCustServiceIdView+promoteId,custserviceId,1);
+        stringRedisTemplate.opsForZSet().incrementScore(RedisKey.PanCustServiceIdView + promoteId, custserviceId, 1);
         //.记录全天打点数
-        stringRedisTemplate.opsForZSet().incrementScore(RedisKey.PanCustServiceIdDayView+promoteId,custserviceId,1);
-        res.put("res",custservice);
+        stringRedisTemplate.opsForZSet().incrementScore(RedisKey.PanCustServiceIdDayView + promoteId, custserviceId, 1);
+        res.put("res", custservice);
         return res;
     }
 

+ 4 - 1
src/main/java/com/mokamrp/privates/tast/pangu/ResetCustserviceDayViewTask.java

@@ -16,6 +16,8 @@ import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
@@ -49,7 +51,8 @@ public class ResetCustserviceDayViewTask {
     }
 
     private Boolean addRedis(Integer promoteId, Integer custserviceId, Integer weight) {
-        Float score = weight.floatValue() / 10000;
+        String scoreStr = BigDecimal.valueOf(weight.doubleValue()/10000).setScale(5, RoundingMode.HALF_EVEN).stripTrailingZeros().toPlainString();
+        float score = Float.parseFloat(scoreStr);
         Long index = stringRedisTemplate.opsForZSet().rank(RedisKey.PanCustServiceIdDayView + promoteId, Integer.toString(custserviceId));
         //.redis存在记录时才做更新
         if (index != null) {

+ 4 - 1
src/main/java/com/mokamrp/privates/tast/pangu/ResetCustserviceViewTask.java

@@ -13,6 +13,8 @@ import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.List;
 
 @Component
@@ -40,7 +42,8 @@ public class ResetCustserviceViewTask {
     }
 
     private Boolean addRedis(Integer promoteId, Integer custserviceId, Integer weight) {
-        Float score = weight.floatValue() / 10000;
+        String scoreStr = BigDecimal.valueOf(weight.doubleValue()/10000).setScale(5, RoundingMode.HALF_EVEN).stripTrailingZeros().toPlainString();
+        float score = Float.parseFloat(scoreStr);
         Long index = stringRedisTemplate.opsForZSet().rank(RedisKey.PanCustServiceIdView + promoteId, Integer.toString(custserviceId));
         //.redis存在记录时才做更新
         if (index != null) {

+ 11 - 0
src/main/java/com/mokamrp/privates/utils/Cmd.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.mokamrp.privates.utils.http.HttpUtils;
 
+import java.text.NumberFormat;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -17,4 +18,14 @@ public class Cmd {
         String res = HttpUtils.sendPost(url,JSON.toJSONString(body),"utf-8");
         return true;
     }
+
+    private static String formatDouble(double d){
+        NumberFormat nf = NumberFormat.getInstance();
+        //设置保留多少位小数
+        nf.setMaximumFractionDigits(20);
+        // 取消科学计数法
+        nf.setGroupingUsed(false);
+        //返回结果
+        return nf.format(d);
+    }
 }

+ 23 - 1
src/test/java/com/mokamrp/Tests.java

@@ -1,2 +1,24 @@
-package com.mokamrp;public class Test {
+package com.mokamrp;
+
+import org.junit.Test;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.text.NumberFormat;
+
+public class Tests {
+
+    private static String formatDouble(double d) {
+        NumberFormat nf = NumberFormat.getInstance();
+        //设置保留多少位小数
+        nf.setMaximumFractionDigits(5);
+        // 取消科学计数法
+        nf.setGroupingUsed(false);
+        //返回结果
+        return nf.format(d);
+    }
+    @Test
+    public void test(){
+        System.out.println(BigDecimal.valueOf(1f/10000).setScale(5, RoundingMode.HALF_EVEN));
+    }
 }