|
|
@ -23,6 +23,8 @@ import com.hnac.hzims.operational.defect.service.IOperAppearanceService; |
|
|
|
import com.hnac.hzims.operational.defect.service.IOperDefectService; |
|
|
|
import com.hnac.hzims.operational.defect.service.IOperDefectService; |
|
|
|
import com.hnac.hzims.operational.defect.service.IOperDefectStatisticsService; |
|
|
|
import com.hnac.hzims.operational.defect.service.IOperDefectStatisticsService; |
|
|
|
import com.hnac.hzims.operational.defect.vo.SolveHomeVO; |
|
|
|
import com.hnac.hzims.operational.defect.vo.SolveHomeVO; |
|
|
|
|
|
|
|
import com.hnac.hzims.operational.station.entity.StationEntity; |
|
|
|
|
|
|
|
import com.hnac.hzims.operational.station.feign.IStationClient; |
|
|
|
import com.hnac.hzims.operational.util.TimeUtils; |
|
|
|
import com.hnac.hzims.operational.util.TimeUtils; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
@ -40,8 +42,11 @@ import org.springblade.flow.core.utils.FlowUtil; |
|
|
|
import org.springblade.system.cache.DictCache; |
|
|
|
import org.springblade.system.cache.DictCache; |
|
|
|
import org.springblade.system.feign.ISysClient; |
|
|
|
import org.springblade.system.feign.ISysClient; |
|
|
|
import org.springblade.system.user.feign.IUserClient; |
|
|
|
import org.springblade.system.user.feign.IUserClient; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import org.springframework.util.Assert; |
|
|
|
|
|
|
|
|
|
|
|
import java.beans.BeanInfo; |
|
|
|
import java.beans.BeanInfo; |
|
|
|
import java.beans.Introspector; |
|
|
|
import java.beans.Introspector; |
|
|
@ -49,8 +54,11 @@ import java.beans.PropertyDescriptor; |
|
|
|
import java.lang.reflect.Field; |
|
|
|
import java.lang.reflect.Field; |
|
|
|
import java.lang.reflect.InvocationTargetException; |
|
|
|
import java.lang.reflect.InvocationTargetException; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
|
|
|
import java.time.YearMonth; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
|
|
|
|
import java.time.temporal.TemporalAdjusters; |
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -69,7 +77,9 @@ public class DefectCheckServiceImpl extends BaseServiceImpl<OperPhenomenonMapper |
|
|
|
|
|
|
|
|
|
|
|
private final ISysClient sysClient; |
|
|
|
private final ISysClient sysClient; |
|
|
|
private final IUserClient userClient; |
|
|
|
private final IUserClient userClient; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
private RedisTemplate redisTemplate; |
|
|
|
|
|
|
|
private IStationClient stationClient; |
|
|
|
private final IFlowClient processClient; |
|
|
|
private final IFlowClient processClient; |
|
|
|
|
|
|
|
|
|
|
|
private final IMessageClient messageClient; |
|
|
|
private final IMessageClient messageClient; |
|
|
@ -84,6 +94,13 @@ public class DefectCheckServiceImpl extends BaseServiceImpl<OperPhenomenonMapper |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public OperPhenomenonEntity startCheck(OperPhenomenonEntity entity) { |
|
|
|
public OperPhenomenonEntity startCheck(OperPhenomenonEntity entity) { |
|
|
|
|
|
|
|
if (ObjectUtil.isEmpty(AuthUtil.getDeptId())) { |
|
|
|
|
|
|
|
throw new ServiceException("获取当前用户机构失败!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//加锁
|
|
|
|
|
|
|
|
Boolean lock = redisTemplate.opsForValue().setIfAbsent("SysUserLock" + AuthUtil.getDeptId(), AuthUtil.getDeptId(), 30, TimeUnit.SECONDS); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
if (lock) { |
|
|
|
// 步骤1.保存现象
|
|
|
|
// 步骤1.保存现象
|
|
|
|
if (!this.savePhenomenon(entity)) { |
|
|
|
if (!this.savePhenomenon(entity)) { |
|
|
|
throw new ServiceException("保存现象失败!"); |
|
|
|
throw new ServiceException("保存现象失败!"); |
|
|
@ -94,7 +111,20 @@ public class DefectCheckServiceImpl extends BaseServiceImpl<OperPhenomenonMapper |
|
|
|
last("limit 1"); |
|
|
|
last("limit 1"); |
|
|
|
}}); |
|
|
|
}}); |
|
|
|
this.startDefectCheckV2(operPhenomenon); |
|
|
|
this.startDefectCheckV2(operPhenomenon); |
|
|
|
|
|
|
|
redisTemplate.delete("SysUserLock" + AuthUtil.getDeptId()); //删除key,释放锁
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// 加锁失败,抛出异常
|
|
|
|
|
|
|
|
throw new ServiceException("开启现象流程失败!"); |
|
|
|
|
|
|
|
} |
|
|
|
return entity; |
|
|
|
return entity; |
|
|
|
|
|
|
|
}catch (Exception e){ |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
log.error("保存现象失败!"+e); |
|
|
|
|
|
|
|
//抛出异常,以便回滚
|
|
|
|
|
|
|
|
throw new ServiceException("保存现象失败!"); |
|
|
|
|
|
|
|
}finally { |
|
|
|
|
|
|
|
redisTemplate.delete("SysUserLock" + AuthUtil.getDeptId()); //删除key,释放锁
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -104,10 +134,31 @@ public class DefectCheckServiceImpl extends BaseServiceImpl<OperPhenomenonMapper |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private boolean savePhenomenon(OperPhenomenonEntity entity) { |
|
|
|
private boolean savePhenomenon(OperPhenomenonEntity entity) { |
|
|
|
DateTimeFormatter format = DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME_MINI); |
|
|
|
String deptId = AuthUtil.getDeptId(); |
|
|
|
// 缺陷编码 : 缺陷来源 + 时间格式化 + 三位长度随机值
|
|
|
|
if (StringUtils.isNotBlank(deptId)) { |
|
|
|
if (Func.isEmpty(entity.getDefectCode())) { |
|
|
|
throw new ServiceException("获取当前用户机构失败!"); |
|
|
|
entity.setDefectCode(entity.getSourceCode() + format.format(LocalDateTime.now()) + Func.random(3)); |
|
|
|
} |
|
|
|
|
|
|
|
StationEntity station = new StationEntity(); |
|
|
|
|
|
|
|
station.setRefDept(Long.valueOf(deptId)); |
|
|
|
|
|
|
|
R<StationEntity> stationR = stationClient.getOne(station); |
|
|
|
|
|
|
|
Assert.isTrue(stationR.isSuccess() && ObjectUtil.isNotEmpty(stationR.getData()) && Func.isNotEmpty(stationR.getData().getSignage()), () -> { |
|
|
|
|
|
|
|
throw new ServiceException("该工作票站点下未获取到两票抬头!"); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMM"); |
|
|
|
|
|
|
|
String yearMonth = YearMonth.now().format(formatter); |
|
|
|
|
|
|
|
LocalDateTime date = LocalDateTime.now(); |
|
|
|
|
|
|
|
LocalDateTime firstDay = date.with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0); |
|
|
|
|
|
|
|
LocalDateTime lastDay = date.with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59); |
|
|
|
|
|
|
|
List<OperPhenomenonEntity> ticketList = this.list( |
|
|
|
|
|
|
|
Wrappers.<OperPhenomenonEntity>lambdaQuery().eq(OperPhenomenonEntity::getCreateDept, entity.getCreateDept()) |
|
|
|
|
|
|
|
.ge(OperPhenomenonEntity::getCreateTime, firstDay).le(OperPhenomenonEntity::getCreateTime, lastDay) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
String suffix = String.format(String.format("%03d", ticketList.size() + 1)); |
|
|
|
|
|
|
|
String result = stationR.getData().getSignage() + yearMonth + suffix; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 缺陷编码 : 按项目+年+月+序号
|
|
|
|
|
|
|
|
if (Func.isEmpty(result)) { |
|
|
|
|
|
|
|
entity.setDefectCode(result); |
|
|
|
} |
|
|
|
} |
|
|
|
// 现象发起人 : 当前用户Id
|
|
|
|
// 现象发起人 : 当前用户Id
|
|
|
|
if (Func.isEmpty(entity.getFinder())) { |
|
|
|
if (Func.isEmpty(entity.getFinder())) { |
|
|
|