@ -1,20 +1,30 @@
package com.hw.dms.service.impl ;
import java.text.SimpleDateFormat ;
import java.util.List ;
import com.hw.common.core.constant.DmsConstants ;
import com.hw.common.core.constant.QmsConstants ;
import com.hw.common.core.constant.SecurityConstants ;
import com.hw.common.core.exception.ServiceException ;
import com.hw.common.core.utils.DateUtils ;
import com.hw.common.core.utils.StringUtils ;
import com.hw.common.security.utils.SecurityUtils ;
import com.hw.dms.domain.DmsBillsInspectInstance ;
import com.hw.dms.domain.DmsBillsInspectInstanceActivity ;
import com.hw.dms.mapper.DmsBillsInspectInstanceActivityMapper ;
import com.hw.dms.mapper.DmsRepairInstanceMapper ;
import com.hw.dms.domain.DmsInspectInstanceDetail ;
import com.hw.dms.domain.DmsInspectInstanceDetailProject ;
import com.hw.dms.domain.vo.DmsBillsInspectInstanceScanVo ;
import com.hw.dms.mapper.* ;
import com.hw.dms.service.IDmsBillsInspectInstanceService ;
import com.hw.system.api.RemoteSysCommonService ;
import com.hw.system.api.model.LoginUser ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
import com.hw.dms.mapper.DmsBillsInspectInstanceMapper ;
import com.hw.dms.domain.DmsBillsInspectInstance ;
import com.hw.dms.service.IDmsBillsInspectInstanceService ;
import org.springframework.transaction.annotation.Transactional ;
import java.math.BigDecimal ;
import java.text.SimpleDateFormat ;
import java.util.ArrayList ;
import java.util.Date ;
import java.util.List ;
/ * *
* 巡 检 工 单 Service 业 务 层 处 理
@ -23,8 +33,7 @@ import com.hw.dms.service.IDmsBillsInspectInstanceService;
* @date 2024 - 01 - 23
* /
@Service
public class DmsBillsInspectInstanceServiceImpl implements IDmsBillsInspectInstanceService
{
public class DmsBillsInspectInstanceServiceImpl implements IDmsBillsInspectInstanceService {
@Autowired
private DmsBillsInspectInstanceMapper dmsBillsInspectInstanceMapper ;
@Autowired
@ -32,6 +41,12 @@ public class DmsBillsInspectInstanceServiceImpl implements IDmsBillsInspectInsta
@Autowired
private DmsRepairInstanceMapper dmsRepairInstanceMapper ;
@Autowired
private DmsInspectInstanceDetailMapper dmsInspectInstanceDetailMapper ;
@Autowired
private DmsInspectInstanceDetailProjectMapper dmsInspectInstanceDetailProjectMapper ;
@Autowired
private DmsInspectInstanceDetailProjectMapper dmsInspectInstanceDetailPrjectMapper ;
@Autowired
private RemoteSysCommonService remoteSysCommonService ;
/ * *
@ -41,8 +56,7 @@ public class DmsBillsInspectInstanceServiceImpl implements IDmsBillsInspectInsta
* @return 巡 检 工 单
* /
@Override
public DmsBillsInspectInstance selectDmsBillsInspectInstanceByInspectInstanceId ( Long inspectInstanceId )
{
public DmsBillsInspectInstance selectDmsBillsInspectInstanceByInspectInstanceId ( Long inspectInstanceId ) {
return dmsBillsInspectInstanceMapper . selectDmsBillsInspectInstanceByInspectInstanceId ( inspectInstanceId ) ;
}
@ -53,8 +67,7 @@ public class DmsBillsInspectInstanceServiceImpl implements IDmsBillsInspectInsta
* @return 巡 检 工 单
* /
@Override
public List < DmsBillsInspectInstance > selectDmsBillsInspectInstanceList ( DmsBillsInspectInstance dmsBillsInspectInstance )
{
public List < DmsBillsInspectInstance > selectDmsBillsInspectInstanceList ( DmsBillsInspectInstance dmsBillsInspectInstance ) {
return dmsBillsInspectInstanceMapper . selectDmsBillsInspectInstanceList ( dmsBillsInspectInstance ) ;
}
@ -75,14 +88,13 @@ public class DmsBillsInspectInstanceServiceImpl implements IDmsBillsInspectInsta
* @return 结 果
* /
@Override
public int insertDmsBillsInspectInstance ( DmsBillsInspectInstance dmsBillsInspectInstance )
{
public int insertDmsBillsInspectInstance ( DmsBillsInspectInstance dmsBillsInspectInstance ) {
LoginUser user = new LoginUser ( ) ;
//写死105, 也可根据传入对象的wfprocessid作为传参。
Long aLong = dmsRepairInstanceMapper . selectWfProcessActivityId ( 105l ) ;
if ( dmsBillsInspectInstance . getInspectType ( ) . equals ( "1" ) ) {
if ( dmsBillsInspectInstance . getInspectType ( ) . equals ( "1" ) ) {
dmsBillsInspectInstance . setWfProcessId ( 105l ) ;
} else if ( dmsBillsInspectInstance . getInspectType ( ) . equals ( "2" ) ) {
} else if ( dmsBillsInspectInstance . getInspectType ( ) . equals ( "2" ) ) {
dmsBillsInspectInstance . setWfProcessId ( 104l ) ;
}
dmsBillsInspectInstance . setCreateTime ( DateUtils . getNowDate ( ) ) ;
@ -109,8 +121,7 @@ public class DmsBillsInspectInstanceServiceImpl implements IDmsBillsInspectInsta
* @return 结 果
* /
@Override
public int updateDmsBillsInspectInstance ( DmsBillsInspectInstance dmsBillsInspectInstance )
{
public int updateDmsBillsInspectInstance ( DmsBillsInspectInstance dmsBillsInspectInstance ) {
dmsBillsInspectInstance . setUpdateTime ( DateUtils . getNowDate ( ) ) ;
return dmsBillsInspectInstanceMapper . updateDmsBillsInspectInstance ( dmsBillsInspectInstance ) ;
}
@ -122,8 +133,7 @@ public class DmsBillsInspectInstanceServiceImpl implements IDmsBillsInspectInsta
* @return 结 果
* /
@Override
public int deleteDmsBillsInspectInstanceByInspectInstanceIds ( Long [ ] inspectInstanceIds )
{
public int deleteDmsBillsInspectInstanceByInspectInstanceIds ( Long [ ] inspectInstanceIds ) {
return dmsBillsInspectInstanceMapper . deleteDmsBillsInspectInstanceByInspectInstanceIds ( inspectInstanceIds ) ;
}
@ -134,8 +144,7 @@ public class DmsBillsInspectInstanceServiceImpl implements IDmsBillsInspectInsta
* @return 结 果
* /
@Override
public int deleteDmsBillsInspectInstanceByInspectInstanceId ( Long inspectInstanceId )
{
public int deleteDmsBillsInspectInstanceByInspectInstanceId ( Long inspectInstanceId ) {
return dmsBillsInspectInstanceMapper . deleteDmsBillsInspectInstanceByInspectInstanceId ( inspectInstanceId ) ;
}
@ -143,13 +152,12 @@ public class DmsBillsInspectInstanceServiceImpl implements IDmsBillsInspectInsta
public int insertDmsBillsInspectInstancePDA ( DmsBillsInspectInstance dmsBillsInspectInstance ) {
Long along = null ;
SimpleDateFormat sdf = new SimpleDateFormat ( "yyyyMMddHH" ) ;
if ( dmsBillsInspectInstance . getInspectType ( ) . equals ( "1" ) ) {
if ( dmsBillsInspectInstance . getInspectType ( ) . equals ( "1" ) ) {
dmsBillsInspectInstance . setWfProcessId ( 105l ) ;
along = remoteSysCommonService . selectProcessActivityIdByWfProcessId ( SecurityConstants . INNER , 105l ) ;
}
else if ( dmsBillsInspectInstance . getInspectType ( ) . equals ( "2" ) ) {
along = remoteSysCommonService . selectProcessActivityIdByWfProcessId ( SecurityConstants . INNER , 105l ) ;
} else if ( dmsBillsInspectInstance . getInspectType ( ) . equals ( "2" ) ) {
dmsBillsInspectInstance . setWfProcessId ( 104l ) ;
along = remoteSysCommonService . selectProcessActivityIdByWfProcessId ( SecurityConstants . INNER , 104l ) ;
along = remoteSysCommonService . selectProcessActivityIdByWfProcessId ( SecurityConstants . INNER , 104l ) ;
}
dmsBillsInspectInstance . setBillsInspectCode ( sdf . format ( DateUtils . getNowDate ( ) ) ) ;
@ -171,4 +179,153 @@ public class DmsBillsInspectInstanceServiceImpl implements IDmsBillsInspectInsta
}
/ * *
* 获 取 最 新 一 条 未 完 成 的 巡 检 工 单
*
* @param dmsBillsInspectInstance
* @return
* /
@Override
public DmsBillsInspectInstance getNewestBillsInspectInstance ( DmsBillsInspectInstance dmsBillsInspectInstance ) {
dmsBillsInspectInstance . setInspectStatusStr ( DmsConstants . DMS_BILLS_INSPECT_INSTANCE_INSPECT_STATUS_TO_INSPECT + "," + DmsConstants . DMS_BILLS_INSPECT_INSTANCE_INSPECT_STATUS_INSPECTING ) ;
DmsBillsInspectInstance newestBillsInspectInstance = dmsBillsInspectInstanceMapper . selectNewestDmsBillsInspectInstance ( dmsBillsInspectInstance ) ;
if ( newestBillsInspectInstance ! = null ) {
DmsInspectInstanceDetail queryInspectInstanceDetail = new DmsInspectInstanceDetail ( ) ;
queryInspectInstanceDetail . setInspectInstanceId ( newestBillsInspectInstance . getInspectInstanceId ( ) ) ;
List < DmsInspectInstanceDetail > inspectInstanceDetails = dmsInspectInstanceDetailMapper . selectDmsInspectInstanceDetailJoinList ( queryInspectInstanceDetail ) ;
newestBillsInspectInstance . setDmsInspectInstanceDetailList ( inspectInstanceDetails ) ;
}
return newestBillsInspectInstance ;
}
/ * *
* 扫 描 设 备 验 证 并 获 取 巡 检 项 目 信 息
*
* @param dmsBillsInspectInstanceScanVo
* @return
* /
@Override
public DmsInspectInstanceDetail scanInspectInstanceDetail ( DmsBillsInspectInstanceScanVo dmsBillsInspectInstanceScanVo ) {
DmsInspectInstanceDetail dmsInspectInstanceDetail = dmsInspectInstanceDetailMapper . selectDmsInspectInstanceDetailByUI ( dmsBillsInspectInstanceScanVo . getInspectInstanceId ( ) ,
dmsBillsInspectInstanceScanVo . getDeviceCode ( ) ) ;
if ( dmsInspectInstanceDetail = = null ) {
throw new ServiceException ( "无此设备的检查工单" ) ;
}
Long deviceId = dmsInspectInstanceDetail . getDeviceId ( ) ;
DmsInspectInstanceDetailProject queryInspectInstanceDetailProject = new DmsInspectInstanceDetailProject ( ) ;
queryInspectInstanceDetailProject . setDeviceId ( deviceId ) ;
List < DmsInspectInstanceDetailProject > dmsInspectInstanceDetailProjects = dmsInspectInstanceDetailPrjectMapper . selectDmsInspectInstanceDetailProjectJoinList ( queryInspectInstanceDetailProject ) ;
dmsInspectInstanceDetail . setDmsInspectInstanceDetailProjectList ( dmsInspectInstanceDetailProjects ) ;
return dmsInspectInstanceDetail ;
}
/ * *
* 更 新 点 巡 检 工 单 明 细
*
* @param dmsInspectInstanceDetail 点 巡 检 工 单 明 细
* @return 结 果
* /
@Transactional
@Override
public int updateDmsInspectInstanceDetail ( DmsInspectInstanceDetail dmsInspectInstanceDetail ) {
String userName = SecurityUtils . getUsername ( ) ;
Date currentDate = new Date ( ) ;
dmsInspectInstanceDetail . setUpdateTime ( currentDate ) ;
dmsInspectInstanceDetail . setUpdateBy ( userName ) ;
DmsInspectInstanceDetail returnInspectInstanceDetail = handleDmsInspectInstanceDetailProject ( dmsInspectInstanceDetail ) ;
if ( returnInspectInstanceDetail ! = null ) {
dmsInspectInstanceDetail . setInspectStatus ( returnInspectInstanceDetail . getInspectStatus ( ) ) ;
dmsInspectInstanceDetail . setInstanceDetailStatus ( returnInspectInstanceDetail . getInstanceDetailStatus ( ) ) ;
dmsInspectInstanceDetail . setDmsInspectInstanceDetailProjectList ( returnInspectInstanceDetail . getDmsInspectInstanceDetailProjectList ( ) ) ;
batchUpdateDmsInspectInstanceDetailProject ( dmsInspectInstanceDetail ) ;
}
return dmsInspectInstanceDetailMapper . updateDmsInspectInstanceDetail ( dmsInspectInstanceDetail ) ;
}
/ * *
* 更 新 点 巡 检 工 单 明 细 项 目 信 息
*
* @param dmsInspectInstanceDetail 点 巡 检 工 单 明 细
* /
public DmsInspectInstanceDetail handleDmsInspectInstanceDetailProject ( DmsInspectInstanceDetail dmsInspectInstanceDetail ) {
String instanceDetailStatus = DmsConstants . DMS_INSPECT_INSTANCE_DETAIL_STATUS_FINISH ;
String inspectStatus = DmsConstants . DMS_INSPECT_INSTANCE_DETAIL_INSPECT_STATUS_PASS ; //质检结果检验状态
List < DmsInspectInstanceDetailProject > inspectInstanceDetailProjectList = dmsInspectInstanceDetail . getDmsInspectInstanceDetailProjectList ( ) ;
if ( StringUtils . isNotNull ( inspectInstanceDetailProjectList ) ) {
DmsInspectInstanceDetail returnInspectInstanceDetail = new DmsInspectInstanceDetail ( ) ;
List < DmsInspectInstanceDetailProject > toUpdatedList = new ArrayList < > ( ) ;
for ( DmsInspectInstanceDetailProject inspectInstanceDetailProject : inspectInstanceDetailProjectList ) {
String inspectProjectProperty = inspectInstanceDetailProject . getInspectProjectProperty ( ) ;
if ( inspectProjectProperty . equals ( DmsConstants . DMS_INSPECT_INSTANCE_PROJECT_PROPERTY_QUALITATIVE ) ) { //如果是定性
String inspectProjectStatus = inspectInstanceDetailProject . getInspectProjectStatus ( ) ;
if ( inspectProjectStatus ! = null ) {
if ( inspectProjectStatus . equals ( DmsConstants . DMS_INSPECT_INSTANCE_DETAIL_PROJECT_STATUS_FAIL ) ) {
inspectStatus = DmsConstants . DMS_INSPECT_INSTANCE_DETAIL_INSPECT_STATUS_FAIL ;
}
} else {
instanceDetailStatus = DmsConstants . DMS_INSPECT_INSTANCE_DETAIL_STATUS_INSPECTING ;
}
} else { //如果是定量
BigDecimal inspectProjectResult = inspectInstanceDetailProject . getInspectProjectResult ( ) ;
if ( inspectProjectResult ! = null ) {
BigDecimal standardValue = inspectInstanceDetailProject . getDefValue ( ) ;
BigDecimal upperDiff = inspectInstanceDetailProject . getUpLimit ( ) ;
BigDecimal downDiff = inspectInstanceDetailProject . getLowLimit ( ) ;
if ( upperDiff = = null ) { //如果没设置上差值,则标准值为上差值
upperDiff = standardValue ;
} else if ( downDiff = = null ) { //如果没设置下差值,则标准值为下差值
downDiff = standardValue ;
}
if ( inspectProjectResult . compareTo ( downDiff ) > = 0 & & inspectProjectResult . compareTo ( upperDiff ) < = 0 ) {
inspectInstanceDetailProject . setInspectProjectStatus ( DmsConstants . DMS_INSPECT_INSTANCE_DETAIL_PROJECT_STATUS_PASS ) ;
} else {
inspectInstanceDetailProject . setInspectProjectStatus ( DmsConstants . DMS_INSPECT_INSTANCE_DETAIL_PROJECT_STATUS_FAIL ) ;
inspectStatus = DmsConstants . DMS_INSPECT_INSTANCE_DETAIL_INSPECT_STATUS_FAIL ;
}
} else {
instanceDetailStatus = DmsConstants . DMS_INSPECT_INSTANCE_DETAIL_STATUS_INSPECTING ;
}
}
toUpdatedList . add ( inspectInstanceDetailProject ) ;
}
returnInspectInstanceDetail . setInspectStatus ( inspectStatus ) ;
returnInspectInstanceDetail . setInstanceDetailStatus ( instanceDetailStatus ) ;
returnInspectInstanceDetail . setDmsInspectInstanceDetailProjectList ( toUpdatedList ) ;
return returnInspectInstanceDetail ;
}
return null ;
}
/ * *
* 批 量 更 新 点 巡 检 工 单 明 细 项 目 信 息 ( 事 务 , 需 要 用 public , 不 能 用 private )
* /
public void batchUpdateDmsInspectInstanceDetailProject ( DmsInspectInstanceDetail dmsInspectInstanceDetail ) {
List < DmsInspectInstanceDetailProject > inspectInstanceDetailProjects = dmsInspectInstanceDetail . getDmsInspectInstanceDetailProjectList ( ) ;
for ( DmsInspectInstanceDetailProject dmsInspectInstanceDetailProject : inspectInstanceDetailProjects ) {
if ( dmsInspectInstanceDetailProject . getInstanceDetailProjectId ( ) = = null ) {
dmsInspectInstanceDetailProject . setInstanceDetailId ( dmsInspectInstanceDetail . getInstanceDetailId ( ) ) ;
dmsInspectInstanceDetailProjectMapper . insertDmsInspectInstanceDetailProject ( dmsInspectInstanceDetailProject ) ;
} else {
dmsInspectInstanceDetailProjectMapper . updateDmsInspectInstanceDetailProject ( dmsInspectInstanceDetailProject ) ;
}
}
}
}