|
@@ -1,19 +1,25 @@
|
|
|
package com.fdkankan.manage.service.impl;
|
|
|
|
|
|
+import cn.dev33.satoken.stp.StpUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.fdkankan.dingtalk.DingTalkSendUtils;
|
|
|
+import com.fdkankan.manage.common.PageInfo;
|
|
|
import com.fdkankan.manage.common.ResultCode;
|
|
|
-import com.fdkankan.manage.entity.RtkAccount;
|
|
|
-import com.fdkankan.manage.entity.RtkInfo;
|
|
|
+import com.fdkankan.manage.entity.*;
|
|
|
import com.fdkankan.manage.exception.BusinessException;
|
|
|
import com.fdkankan.manage.mapper.IRtkAccountMapper;
|
|
|
import com.fdkankan.manage.service.IRtkAccountService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fdkankan.manage.service.IRtkUseLogService;
|
|
|
+import com.fdkankan.manage.service.ISysUserService;
|
|
|
import com.fdkankan.manage.util.SendMailUtils;
|
|
|
+import com.fdkankan.manage.vo.request.RtkInfoParam;
|
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
@@ -25,6 +31,7 @@ import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -41,29 +48,45 @@ public class RtkAccountServiceImpl extends ServiceImpl<IRtkAccountMapper, RtkAcc
|
|
|
|
|
|
@Autowired
|
|
|
RedisUtil redisUtil;
|
|
|
+ @Autowired
|
|
|
+ IRtkUseLogService rtkUseLogService;
|
|
|
+ @Autowired
|
|
|
+ ISysUserService sysUserService;
|
|
|
|
|
|
@Override
|
|
|
public RtkAccount getOneNotUseAccount(String rtkSnCode) {
|
|
|
String redisKey = "4dkankan:rtk:snCode:"+rtkSnCode;
|
|
|
if(redisUtil.hasKey(redisKey)){
|
|
|
String jsonStr = redisUtil.get(redisKey);
|
|
|
- redisUtil.expire(redisKey,60);
|
|
|
+ redisUtil.expire(redisKey,8 * 60 * 60);
|
|
|
return JSONObject.parseObject(jsonStr, RtkAccount.class);
|
|
|
}
|
|
|
|
|
|
LambdaQueryWrapper<RtkAccount> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.in(RtkAccount::getStatus,0,1);
|
|
|
- wrapper.orderByAsc(RtkAccount::getId);
|
|
|
+ wrapper.orderByAsc(RtkAccount::getUpdateTime);
|
|
|
List<RtkAccount> list = this.list(wrapper);
|
|
|
if(list == null || list.isEmpty()){
|
|
|
//账号库存不足,钉钉通知
|
|
|
sendDingDingMsg(0);
|
|
|
- throw new BusinessException(ResultCode.RTK_SN_CODE_NOT_EXIT);
|
|
|
+ throw new BusinessException(ResultCode.RTK_ACCOUNT_NOT_EXIT);
|
|
|
}
|
|
|
- RtkAccount rtkAccount = list.get(0);
|
|
|
- updateAccountStatus(rtkAccount.getId(),2);
|
|
|
- redisUtil.set(redisKey,JSONObject.toJSONString(rtkAccount),60);
|
|
|
modelThreshold(list.size() -1);
|
|
|
+
|
|
|
+ RtkAccount rtkAccount = null;
|
|
|
+ RtkUseLog rtkUseLog = rtkUseLogService.getByRtkSn(rtkSnCode);
|
|
|
+ if(rtkUseLog != null && rtkUseLog.getRtkAccountId() != null){
|
|
|
+ RtkAccount rtkAccount2 = this.getById(rtkUseLog.getRtkAccountId());
|
|
|
+ if(rtkAccount2 != null && rtkAccount2.getStatus() == 1){
|
|
|
+ rtkAccount = rtkAccount2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(rtkAccount == null){
|
|
|
+ rtkAccount = list.get(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ updateAccountStatus(rtkAccount.getId(),2);
|
|
|
+ redisUtil.set(redisKey,JSONObject.toJSONString(rtkAccount),8 * 60 * 60);
|
|
|
return rtkAccount;
|
|
|
}
|
|
|
|
|
@@ -75,7 +98,22 @@ public class RtkAccountServiceImpl extends ServiceImpl<IRtkAccountMapper, RtkAcc
|
|
|
this.update(wrapper1);
|
|
|
}
|
|
|
|
|
|
- private void modelThreshold( int size) {
|
|
|
+ @Override
|
|
|
+ public void stop(String rtkSnCode) {
|
|
|
+ String redisKey = "4dkankan:rtk:snCode:"+rtkSnCode;
|
|
|
+ if(redisUtil.hasKey(redisKey)){
|
|
|
+ String jsonStr = redisUtil.get(redisKey);
|
|
|
+ RtkAccount rtkAccount = JSONObject.parseObject(jsonStr, RtkAccount.class);
|
|
|
+ updateAccountStatus(rtkAccount.getId(),1);
|
|
|
+ redisUtil.del(redisKey);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void modelThreshold(int size) {
|
|
|
+ if(size == 0){
|
|
|
+ sendDingDingMsg(size);
|
|
|
+ return;
|
|
|
+ }
|
|
|
BigDecimal totalCount = new BigDecimal(this.count());
|
|
|
BigDecimal dbCount = new BigDecimal(size);
|
|
|
|
|
@@ -87,6 +125,9 @@ public class RtkAccountServiceImpl extends ServiceImpl<IRtkAccountMapper, RtkAcc
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
@Scheduled(initialDelay = 2000, fixedDelay = 1000 * 60)
|
|
|
public void checkAccount() {
|
|
|
HashMap<String,RtkAccount> map = new HashMap<>();
|
|
@@ -134,4 +175,74 @@ public class RtkAccountServiceImpl extends ServiceImpl<IRtkAccountMapper, RtkAcc
|
|
|
log.info("发送钉钉消息失败:{}",e);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object pageList(RtkInfoParam param) {
|
|
|
+ LambdaQueryWrapper<RtkAccount> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ if(StringUtils.isNotBlank(param.getUserName())){
|
|
|
+ wrapper.like(RtkAccount::getUserName,param.getUserName());
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(param.getStartTime())&& StringUtils.isNotBlank(param.getEndTime()) ) {
|
|
|
+ wrapper.between(RtkAccount::getCreateTime,param.getStartTime(),param.getEndTime());
|
|
|
+ }
|
|
|
+ wrapper.orderByDesc(RtkAccount::getCreateTime);
|
|
|
+ wrapper.orderByDesc(RtkAccount::getId);
|
|
|
+ Page<RtkAccount> page = this.page(new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
|
|
|
+ Set<Long> createUserIds = page.getRecords().stream().map(RtkAccount::getCreateUserId).collect(Collectors.toSet());
|
|
|
+ HashMap<Long, SysUser> byIds = sysUserService.getByIds(createUserIds);
|
|
|
+
|
|
|
+ for (RtkAccount record : page.getRecords()) {
|
|
|
+ SysUser sysUser = byIds.get(record.getCreateUserId());
|
|
|
+ if(sysUser != null){
|
|
|
+ record.setCreateUserName(sysUser.getUserName());
|
|
|
+ record.setCreateNickName(sysUser.getNickName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return PageInfo.PageInfo(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void saveOrEditEntity(RtkAccount param) {
|
|
|
+ if(StringUtils.isBlank(param.getUserName()) || param.getPassword() == null){
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ }
|
|
|
+ RtkAccount rtkAccount = this.getByUserName(param.getUserName());
|
|
|
+ if(rtkAccount != null && param.getId() == null){
|
|
|
+ throw new BusinessException(ResultCode.RTK_SN_EXIST);
|
|
|
+ }
|
|
|
+ if(rtkAccount != null && !param.getId().equals(rtkAccount.getId())){
|
|
|
+ throw new BusinessException(ResultCode.RTK_SN_EXIST);
|
|
|
+ }
|
|
|
+ if(param.getId()== null){
|
|
|
+ param.setCreateUserId(Long.valueOf(StpUtil.getLoginId().toString()));
|
|
|
+ }
|
|
|
+ if(param.getId()!= null){
|
|
|
+ param.setUpdateUserId(Long.valueOf(StpUtil.getLoginId().toString()));
|
|
|
+ }
|
|
|
+
|
|
|
+ this.saveOrUpdate(param);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void del(RtkAccount param) {
|
|
|
+ if(param.getId() == null){
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ }
|
|
|
+ RtkAccount rtkAccount = this.getById(param.getId());
|
|
|
+ if(rtkAccount != null){
|
|
|
+ LambdaUpdateWrapper<RtkAccount> wrapper = new LambdaUpdateWrapper<>();
|
|
|
+ wrapper.eq(RtkAccount::getId,param.getId());
|
|
|
+ wrapper.set(RtkAccount::getDelUserId,Long.valueOf(StpUtil.getLoginId().toString()));
|
|
|
+ wrapper.set(RtkAccount::getRecStatus,"I");
|
|
|
+ this.update(wrapper);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RtkAccount getByUserName(String userName) {
|
|
|
+ LambdaQueryWrapper<RtkAccount> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(RtkAccount::getUserName,userName);
|
|
|
+ return this.getOne(wrapper);
|
|
|
+ }
|
|
|
}
|