|
|
@@ -5,10 +5,7 @@ import com.mokamrp.privates.constant.Constants;
|
|
|
import com.mokamrp.privates.constant.HttpStatus;
|
|
|
import com.mokamrp.privates.constant.RedisKey;
|
|
|
import com.mokamrp.privates.controller.BaseController;
|
|
|
-import com.mokamrp.privates.entity.AddHandle;
|
|
|
-import com.mokamrp.privates.entity.DelHandle;
|
|
|
-import com.mokamrp.privates.entity.EditHandle;
|
|
|
-import com.mokamrp.privates.entity.PostBasePageHandle;
|
|
|
+import com.mokamrp.privates.entity.*;
|
|
|
import com.mokamrp.privates.entity.pangu.GetPromoteQrcodePoolHandle;
|
|
|
import com.mokamrp.privates.entity.pangu.PlaybillListHandle;
|
|
|
import com.mokamrp.privates.entity.pangu.SetPromoteQrcodeHandle;
|
|
|
@@ -35,8 +32,7 @@ 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;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
@@ -111,10 +107,10 @@ public class PromoteQrcodePoolController extends BaseController<PromoteQrcodePoo
|
|
|
}
|
|
|
//.排重
|
|
|
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()+"号个微码已经存在");
|
|
|
+ .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(
|
|
|
@@ -124,11 +120,17 @@ public class PromoteQrcodePoolController extends BaseController<PromoteQrcodePoo
|
|
|
.last("limit 1")
|
|
|
);
|
|
|
if (promoteQrcodePool != null) {
|
|
|
- addHandle.getRaw().setWeight(promoteQrcodePool.getWeight() + 1);
|
|
|
+ Integer weight = promoteQrcodePool.getWeight();
|
|
|
+ //.权重自动分配最大999
|
|
|
+ if (weight >= 999) {
|
|
|
+ addHandle.getRaw().setWeight(999);
|
|
|
+ } else {
|
|
|
+ addHandle.getRaw().setWeight(weight + 1);
|
|
|
+ }
|
|
|
}
|
|
|
addHandle.getRaw().setDayUvMax(promoteCode.getDayUvMax());
|
|
|
addHandle.getRaw().setHourUvMax(promoteCode.getHourUvMax());
|
|
|
- this.onInsert(addHandle);
|
|
|
+ this.onInsert(addHandle.getRaw());
|
|
|
Boolean res = promoteQrcodePoolService.save(addHandle.getRaw());
|
|
|
if (res) {
|
|
|
//.同步到redis
|
|
|
@@ -139,6 +141,58 @@ public class PromoteQrcodePoolController extends BaseController<PromoteQrcodePoo
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @PostMapping("/adds")
|
|
|
+ public Object adds(@Valid @RequestBody AddsHandle<PromoteQrcodePool> addsHandle, BindingResult bindingResult) {
|
|
|
+ if (bindingResult.hasErrors()) {
|
|
|
+ return AjaxResult.error(HttpStatus.ERROR, bindingResult.getFieldError().getDefaultMessage());
|
|
|
+ }
|
|
|
+ Map<String, List<Integer>> result = new HashMap<String, List<Integer>>();
|
|
|
+ List<Integer> successList = new ArrayList<>();
|
|
|
+ List<Integer> errorList = new ArrayList<>();
|
|
|
+ for (PromoteQrcodePool raw : addsHandle.getRaws()) {
|
|
|
+ //.排重
|
|
|
+ PromoteQrcodePool hasone = promoteQrcodePoolService.getOne(new QueryWrapper<PromoteQrcodePool>()
|
|
|
+ .eq("promote_id", raw.getPromoteId())
|
|
|
+ .eq("custservice_id", raw.getCustserviceId()));
|
|
|
+ if (hasone != null) {
|
|
|
+ errorList.add(raw.getCustserviceId());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ PromoteCode promoteCode = promoteCodeService.getOne(new QueryWrapper<PromoteCode>().eq("id", raw.getPromoteId()));
|
|
|
+ PromoteQrcodePool promoteQrcodePool = promoteQrcodePoolService.getOne(
|
|
|
+ new QueryWrapper<PromoteQrcodePool>()
|
|
|
+ .eq("promote_id", raw.getPromoteId())
|
|
|
+ .orderByDesc("weight")
|
|
|
+ .last("limit 1")
|
|
|
+ );
|
|
|
+ if (promoteQrcodePool != null) {
|
|
|
+ Integer weight = promoteQrcodePool.getWeight();
|
|
|
+ //.权重自动分配最大999
|
|
|
+ if (weight >= 999) {
|
|
|
+ raw.setWeight(999);
|
|
|
+ } else {
|
|
|
+ raw.setWeight(weight + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ raw.setDayUvMax(promoteCode.getDayUvMax());
|
|
|
+ raw.setHourUvMax(promoteCode.getHourUvMax());
|
|
|
+ this.onInsert(raw);
|
|
|
+ Boolean res = promoteQrcodePoolService.save(raw);
|
|
|
+ if (res) {
|
|
|
+ //.同步到redis
|
|
|
+ this.addRedis(raw.getPromoteId(), raw.getCustserviceId(), raw.getWeight());
|
|
|
+ successList.add(raw.getCustserviceId());
|
|
|
+ continue;
|
|
|
+ } else {
|
|
|
+ errorList.add(raw.getCustserviceId());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ result.put("successList", successList);
|
|
|
+ result.put("errorList", errorList);
|
|
|
+ return AjaxResult.success(result);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@PostMapping("/edit")
|
|
|
public Object edit(@Valid @RequestBody EditHandle<PromoteQrcodePool> editHandle, BindingResult bindingResult) {
|
|
|
@@ -151,7 +205,7 @@ public class PromoteQrcodePoolController extends BaseController<PromoteQrcodePoo
|
|
|
}
|
|
|
|
|
|
private Boolean addRedis(Integer promoteId, Integer custserviceId, Integer weight) {
|
|
|
- String scoreStr = BigDecimal.valueOf(weight.doubleValue()/1000).setScale(4, RoundingMode.HALF_EVEN).stripTrailingZeros().toPlainString();
|
|
|
+ String scoreStr = BigDecimal.valueOf(weight.doubleValue() / 1000).setScale(4, RoundingMode.HALF_EVEN).stripTrailingZeros().toPlainString();
|
|
|
float score = Float.parseFloat(scoreStr);
|
|
|
Long index = stringRedisTemplate.opsForZSet().rank(RedisKey.PanCustServiceIdView + promoteId, Integer.toString(custserviceId));
|
|
|
if (index == null) {
|