Commit 2e618e11 authored by yangyang's avatar yangyang

fix bug 20235 、20255、20232、20340

parent 17a5e543
package com.yeejoin.amos.boot.module.hygf.api.util;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
* spring redis 工具类
* <p>
* ProjectName: qms
* PackageName: com.yeejoin.amos.qms.api.spc.utils
*
* @author yangyang
* @version v1.0
* @date 2024/4/19 10:15
*/
@Component
@Slf4j
public class RedisLockUtil {
@Autowired
public RedisTemplate redisTemplate;
/**
* 加锁,阻塞
*
* @param key 锁主键
* @param value 缓存值
* @param expireTime 锁有效时间,-1永久存储,单位秒
* @param waitTime 获取锁阻塞等待时间,单位秒
* @return result
*/
public Boolean tryLock(String key, String value, long expireTime, long waitTime) {
long start = System.currentTimeMillis();
// 默认10秒
waitTime = (waitTime < 0 ? 10 : waitTime) * 1000;
expireTime = expireTime < 0 ? -1 : expireTime;
for (; ; ) {
//SET命令返回OK ,则证明获取锁成功
Boolean ret = redisTemplate.opsForValue().setIfAbsent(key, value, expireTime, TimeUnit.SECONDS);
if (BooleanUtils.isTrue(ret)) {
return true;
}
//否则循环等待,在等待超时时间内仍未获取到锁,则获取失败
long end = System.currentTimeMillis() - start;
if (end >= waitTime) {
return false;
}
}
}
/**
* 删除单个对象
*
* @param key
*/
public boolean releaseLock(final String key) {
return redisTemplate.delete(key);
}
/**
* 替代keys
*
* @param pattern key模糊
*/
public Set<String> scan(final String pattern) {
return (Set<String>) redisTemplate.execute((RedisCallback<Set<String>>) connection -> {
Set<String> keys = new HashSet<>();
try (Cursor<byte[]> cursor = connection.scan(new ScanOptions.ScanOptionsBuilder().match(pattern).count(1000).build())) {
while (cursor.hasNext()) {
keys.add(new String(cursor.next(), StandardCharsets.UTF_8));
}
} catch (Exception e) {
log.error(e.getMessage());
}
return keys;
});
}
}
......@@ -17,15 +17,18 @@ import com.yeejoin.amos.boot.module.hygf.api.entity.BasicGridAcceptance;
import com.yeejoin.amos.boot.module.hygf.api.mapper.AcceptanceRectificationOrderMapper;
import com.yeejoin.amos.boot.module.hygf.api.mapper.BasicGridAcceptanceMapper;
import com.yeejoin.amos.boot.module.hygf.api.service.IAcceptanceRectificationOrderService;
import com.yeejoin.amos.boot.module.hygf.api.util.RedisLockUtil;
import com.yeejoin.amos.component.robot.BadRequest;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import io.seata.spring.annotation.GlobalTransactional;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.rdbms.service.BaseService;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
......@@ -47,7 +50,8 @@ public class AcceptanceRectificationOrderServiceImpl extends BaseService<Accepta
private WorkflowImpl workflow;
@Autowired
private RedisUtils redisUtils;
@Resource (type = RedisLockUtil.class)
private RedisLockUtil redisLockUtil;
/**
* 分页查询
*/
......@@ -107,6 +111,17 @@ public class AcceptanceRectificationOrderServiceImpl extends BaseService<Accepta
AcceptanceRectificationOrder entity = new AcceptanceRectificationOrder();
BeanUtils.copyProperties(model, entity);
String lockName = String.format("LockName:updateAndDriveWorkflow:%s", entity.getSequenceNbr());
Boolean isLocked = redisLockUtil.tryLock(lockName, lockName, 10, 1);
if (BooleanUtils.isNotTrue(isLocked)) {
throw new BadRequest("其他用户正在操作,请稍后再试!");
}
try {
AcceptanceRectificationOrder acceptanceRectificationOrder = acceptanceRectificationOrderMapper.selectById(entity.getSequenceNbr());
if (String.valueOf(RectificationStatusEnum.整改已完成.getCode()).equals(acceptanceRectificationOrder.getRectificationStatus())) {
throw new BadRequest("整改已完成,请稍后再试!");
}
acceptanceRectificationOrderMapper.updateById(entity);
......@@ -126,6 +141,9 @@ public class AcceptanceRectificationOrderServiceImpl extends BaseService<Accepta
basicGridAcceptanceMapper.updateById(basicGridAcceptance);
}
} finally {
redisLockUtil.releaseLock(lockName);
}
return model;
}
}
......
package com.yeejoin.amos.boot.module.hygf.biz.service.impl;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
......@@ -18,14 +17,17 @@ import com.yeejoin.amos.boot.module.hygf.api.mapper.AcceptanceMapper;
import com.yeejoin.amos.boot.module.hygf.api.mapper.BasicGridAcceptanceMapper;
import com.yeejoin.amos.boot.module.hygf.api.mapper.PeasantHouseholdMapper;
import com.yeejoin.amos.boot.module.hygf.api.service.IAcceptanceService;
import com.yeejoin.amos.boot.module.hygf.api.util.RedisLockUtil;
import com.yeejoin.amos.component.robot.BadRequest;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
......@@ -43,6 +45,9 @@ public class AcceptanceServiceImpl implements IAcceptanceService {
private AcceptanceCheckItemMapper acceptanceCheckItemMapper;
@Autowired
WorkflowImpl workflow;
@Resource(type = RedisLockUtil.class)
private RedisLockUtil redisLockUtil;
/**
* 分页查询验收列表数据
*
......@@ -111,23 +116,34 @@ public class AcceptanceServiceImpl implements IAcceptanceService {
}
@Override
@GlobalTransactional
public void checkAccept( Long basicGridAcceptanceId ,String userId){
BasicGridAcceptance basicGridAcceptanc= basicGridAcceptanceMapper.selectById(basicGridAcceptanceId);
public void checkAccept(Long basicGridAcceptanceId, String userId) {
String lockName = String.format("LockName:checkAccept:%s", basicGridAcceptanceId);
Boolean isLocked = redisLockUtil.tryLock(lockName, lockName, 10, 1);
if (BooleanUtils.isNotTrue(isLocked)) {
throw new BadRequest("其他用户正在操作,请稍后再试!");
}
try {
BasicGridAcceptance basicGridAcceptanc = basicGridAcceptanceMapper.selectById(basicGridAcceptanceId);
if (AcceptanceStatusEnum.待投融验收.getCode().equals(basicGridAcceptanc.getAcceptanceStatus())) {
throw new BadRequest("待投融验收,请稍后再试!");
}
basicGridAcceptanc.setAcceptanceStatus(AcceptanceStatusEnum.待投融验收.getCode());
basicGridAcceptanc.setAcceptanceRecDate(new Date());
//执行工作流
StandardDto standardDto=new StandardDto();
StandardDto standardDto = new StandardDto();
standardDto.setTaskId(basicGridAcceptanc.getNextTaskId());
workflow.standard(basicGridAcceptanc,standardDto,userId);
workflow.standard(basicGridAcceptanc, standardDto, userId);
basicGridAcceptanceMapper.updateById(basicGridAcceptanc);
//线上验收
LambdaUpdateWrapper<PeasantHousehold> up =new LambdaUpdateWrapper<>();
up.set(PeasantHousehold::getConstructionState, ArrivalStateeEnum.线上验收.getCode());
long idsk= basicGridAcceptanc.getPeasantHouseholdId();
up.eq(PeasantHousehold::getSequenceNbr,idsk);
long idsk = basicGridAcceptanc.getPeasantHouseholdId();
up.eq(PeasantHousehold::getSequenceNbr, idsk);
peasantHouseholdMapper.update(null,up);
} finally {
redisLockUtil.releaseLock(lockName);
}
}
......
......@@ -2,7 +2,6 @@ package com.yeejoin.amos.boot.module.hygf.biz.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
......@@ -12,14 +11,18 @@ import com.yeejoin.amos.boot.module.hygf.api.entity.*;
import com.yeejoin.amos.boot.module.hygf.api.mapper.*;
import com.yeejoin.amos.boot.module.hygf.api.service.IBasicGridAcceptanceService;
import com.yeejoin.amos.boot.module.hygf.api.util.NumberUtil;
import com.yeejoin.amos.boot.module.hygf.api.util.RedisLockUtil;
import com.yeejoin.amos.component.robot.BadRequest;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.typroject.tyboot.core.foundation.utils.DateUtil;
import org.typroject.tyboot.core.rdbms.service.BaseService;
import javax.annotation.Resource;
import java.util.*;
@Slf4j
......@@ -47,7 +50,8 @@ public class BasicGridAcceptanceServiceImpl
RegionalCompaniesMapper regionalCompaniesMapper;
@Autowired
WorkOrderMapper workOrderMapper;
@Resource (type = RedisLockUtil.class)
private RedisLockUtil redisLockUtil;
@Autowired
PeasantHouseholdMapper peasantHouseholdMapper;
@Autowired
......@@ -203,6 +207,12 @@ public class BasicGridAcceptanceServiceImpl
@GlobalTransactional
public void execute(AcceptanceCheckItem dto, String userId) {
String lockName = String.format("LockName:executeWorkflow:%s", dto.getBasicGridAcceptanceId());
Boolean isLocked = redisLockUtil.tryLock(lockName, lockName, 10, 1);
if (BooleanUtils.isNotTrue(isLocked)) {
throw new BadRequest("其他用户正在操作,请稍后再试!");
}
try {
// 查询并网审批信息
BasicGridAcceptance basicGridAcceptanc = basicGridAcceptanceMapper.selectById(dto.getBasicGridAcceptanceId());
String nextNodeKey = basicGridAcceptanc.getNextNodeKey();
......@@ -306,6 +316,9 @@ public class BasicGridAcceptanceServiceImpl
}
basicGridAcceptanceMapper.updateById(workBasicGridAcceptance);
} finally {
redisLockUtil.releaseLock(lockName);
}
}
}
......@@ -16,6 +16,7 @@ import com.yeejoin.amos.boot.module.hygf.api.entity.*;
import com.yeejoin.amos.boot.module.hygf.api.fegin.IdxFeginService;
import com.yeejoin.amos.boot.module.hygf.api.mapper.*;
import com.yeejoin.amos.boot.module.hygf.api.service.IPowerStationService;
import com.yeejoin.amos.boot.module.hygf.api.util.RedisLockUtil;
import com.yeejoin.amos.boot.module.hygf.biz.feign.WorkflowFeignClient;
import com.yeejoin.amos.component.feign.model.FeignClientResult;
import com.yeejoin.amos.component.robot.AmosRequestContext;
......@@ -23,6 +24,7 @@ import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -34,6 +36,7 @@ import org.typroject.tyboot.core.rdbms.annotation.Condition;
import org.typroject.tyboot.core.rdbms.annotation.Operator;
import org.typroject.tyboot.core.rdbms.service.BaseService;
import javax.annotation.Resource;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
......@@ -88,6 +91,8 @@ public class PowerStationServiceImpl extends BaseService<PowerStationDto, PowerS
WorkflowImpl workflow;
@Autowired
HouseholdContractMapper householdContractMapper;
@Resource (type = RedisLockUtil.class)
private RedisLockUtil redisLockUtil;
public Page<PowerStationDto> queryForPowerStationUserRoles(Page<PowerStationDto> page, String powerStationCode,
String ownersName, AgencyUserModel userInfo, String serviceAgent, String regionalCompaniesName, String processStatus) {
......@@ -238,6 +243,11 @@ public class PowerStationServiceImpl extends BaseService<PowerStationDto, PowerS
@Override
public String powerStationExamine(long pageId, String nodeCode, String stationId, String taskId,
String planInstanceId, Map<String, Object> kv) {
String lockName = String.format("LockName:powerStationExamine:%s", stationId);
Boolean isLocked = redisLockUtil.tryLock(lockName, lockName, 10, 1);
if (BooleanUtils.isNotTrue(isLocked)) {
throw new com.yeejoin.amos.component.robot.BadRequest("其他用户正在操作,请稍后再试!");
}
String meg = "";
// 1. 业务相关数据落表
PowerStation powerStation = this.baseMapper.selectById(stationId);
......@@ -366,8 +376,10 @@ public class PowerStationServiceImpl extends BaseService<PowerStationDto, PowerS
// }
} catch (Exception e) {
e.printStackTrace();
log.error("powerStationExamine error:", e);
} finally {
redisLockUtil.releaseLock(lockName);
}
return code;
......
......@@ -18,6 +18,7 @@ import com.yeejoin.amos.boot.module.hygf.api.service.IPowerStationService;
import com.yeejoin.amos.boot.module.hygf.api.service.ISurveyInformationService;
import com.yeejoin.amos.boot.module.hygf.api.util.BeanDtoUtils;
import com.yeejoin.amos.boot.module.hygf.api.util.NumberUtil;
import com.yeejoin.amos.boot.module.hygf.api.util.RedisLockUtil;
import com.yeejoin.amos.boot.module.hygf.biz.feign.WorkflowFeignClient;
import com.yeejoin.amos.component.feign.model.FeignClientResult;
import com.yeejoin.amos.component.robot.AmosRequestContext;
......@@ -26,6 +27,7 @@ import com.yeejoin.amos.feign.systemctl.Systemctl;
import com.yeejoin.amos.feign.systemctl.model.RegionModel;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
......@@ -38,6 +40,7 @@ import org.typroject.tyboot.core.foundation.exception.BaseException;
import org.typroject.tyboot.core.rdbms.service.BaseService;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
......@@ -125,7 +128,8 @@ public class SurveyInformationServiceImpl
WorkOrderPowerStationMapper workOrderPowerStationMapper;
@Autowired
AmosRequestContext requestContext;
@Resource(type = RedisLockUtil.class)
private RedisLockUtil redisLockUtil;
@Autowired
WorkflowImpl workflow;
......@@ -145,6 +149,7 @@ public class SurveyInformationServiceImpl
@GlobalTransactional
public SurveyInfoAllDto saveSurveyInfo(SurveyInfoAllDto surveyInfoAllDto, String operationType) {
String lockName = null;
try {
JSONArray regionName = getRegionName();
......@@ -153,6 +158,22 @@ public class SurveyInformationServiceImpl
// 更新勘察基本信息
SurveyInformation surveyInformation = BeanDtoUtils.convert(surveyInfoAllDto.getSurveyInformation(),
SurveyInformation.class);
lockName = String.format("LockName:saveSurveyInfo:%s", surveyInformation.getSequenceNbr());
Boolean isLocked = redisLockUtil.tryLock(lockName, lockName, 10, 1);
if (BooleanUtils.isNotTrue(isLocked)) {
throw new BadRequest("其他用户正在操作,请稍后再试!");
}
QueryWrapper<PeasantHousehold> peasantHouseholdQueryWrapper = new QueryWrapper<>();
peasantHouseholdQueryWrapper.eq("survey_information_id", surveyInformation.getSequenceNbr());
PeasantHousehold peasantHousehold = peasantHouseholdServiceImpl.getBaseMapper()
.selectOne(peasantHouseholdQueryWrapper);
if (ArrivalStateeEnum.勘察中.getCode().equals(peasantHousehold.getConstructionState())) {
throw new BadRequest("勘察中,请稍后再试!");
}
surveyInformation.setReview(0);
if (OPERATION_TYPE_APPLY.equals(operationType) && null == surveyInformation.getCreatorTime()) {
surveyInformation.setCreatorTime(new Date());
......@@ -196,10 +217,10 @@ public class SurveyInformationServiceImpl
.eq(Commercial::getSurveyInformationId, surveyInformation.getSequenceNbr()));
//commercialService.saveOrUpdate(commercial);
// 勘察后,更新状态
QueryWrapper<PeasantHousehold> peasantHouseholdQueryWrapper = new QueryWrapper<>();
peasantHouseholdQueryWrapper.eq("survey_information_id", surveyInformation.getSequenceNbr());
PeasantHousehold peasantHousehold = peasantHouseholdServiceImpl.getBaseMapper()
.selectOne(peasantHouseholdQueryWrapper);
// QueryWrapper<PeasantHousehold> peasantHouseholdQueryWrapper = new QueryWrapper<>();
// peasantHouseholdQueryWrapper.eq("survey_information_id", surveyInformation.getSequenceNbr());
// PeasantHousehold peasantHousehold = peasantHouseholdServiceImpl.getBaseMapper()
// .selectOne(peasantHouseholdQueryWrapper);
// 更新资料归档信息
Information information = BeanDtoUtils.convert(surveyInfoAllDto.getInformation(), Information.class);
......@@ -282,6 +303,10 @@ public class SurveyInformationServiceImpl
} catch (Exception e) {
e.printStackTrace();
} finally {
if (StringUtils.isNotEmpty(lockName)) {
redisLockUtil.releaseLock(lockName);
}
}
return surveyInfoAllDto;
......@@ -371,6 +396,7 @@ public class SurveyInformationServiceImpl
} catch (Exception e) {
e.printStackTrace();
log.error("submitExamine error:", e);
}
// PowerStation powerStation = powerStationService.getObjByNhId(String.valueOf(peasantHousehold.getSequenceNbr()), PowerStationProcessStateEnum.作废.getCode());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment