|
@@ -1,14 +1,30 @@
|
|
|
package com.ruoyi.asset.service.impl;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.ruoyi.asset.domain.TbAsset;
|
|
|
+import com.ruoyi.asset.domain.TbAssetBorrowRecord;
|
|
|
+import com.ruoyi.asset.domain.TbAssetStatusRecord;
|
|
|
+import com.ruoyi.asset.domain.dto.TbFaultReportProcessDTO;
|
|
|
+import com.ruoyi.asset.domain.enums.TbAssetStatusEnum;
|
|
|
+import com.ruoyi.asset.domain.enums.TbFaultProcessStateEnum;
|
|
|
+import com.ruoyi.asset.mapper.TbAssetBorrowRecordMapper;
|
|
|
+import com.ruoyi.asset.mapper.TbAssetMapper;
|
|
|
+import com.ruoyi.asset.mapper.TbAssetStatusRecordMapper;
|
|
|
+import com.ruoyi.asset.utils.UserUtils;
|
|
|
+import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
+import com.ruoyi.common.exception.ServiceException;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.ruoyi.asset.mapper.TbFaultReportMapper;
|
|
|
import com.ruoyi.asset.domain.TbFaultReport;
|
|
|
import com.ruoyi.asset.service.ITbFaultReportService;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
/**
|
|
|
* 故障报备Service业务层处理
|
|
|
*
|
|
@@ -21,6 +37,15 @@ public class TbFaultReportServiceImpl extends ServiceImpl<TbFaultReportMapper, T
|
|
|
@Autowired
|
|
|
private TbFaultReportMapper tbFaultReportMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private TbAssetMapper tbAssetMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TbAssetBorrowRecordMapper tbAssetBorrowRecordMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TbAssetStatusRecordMapper tbAssetStatusRecordMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 查询故障报备
|
|
|
*
|
|
@@ -92,4 +117,99 @@ public class TbFaultReportServiceImpl extends ServiceImpl<TbFaultReportMapper, T
|
|
|
{
|
|
|
return tbFaultReportMapper.deleteTbFaultReportById(id);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 小程序:新增故障报备信息
|
|
|
+ *
|
|
|
+ * @param tbFaultReport 故障报备信息
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public AjaxResult saveTbFaultReport(TbFaultReport tbFaultReport) {
|
|
|
+ String assetBarCode = tbFaultReport.getAssetBarCode();
|
|
|
+ TbAsset tbAsset = tbAssetMapper.selectTbAssetByBarCode(assetBarCode);
|
|
|
+ if (tbAsset == null) {
|
|
|
+ return AjaxResult.error("资产设备不存在");
|
|
|
+ }
|
|
|
+ Long status = tbAsset.getStatus();
|
|
|
+ if (status != 1) {
|
|
|
+ return AjaxResult.error("资产设备已报备");
|
|
|
+ }
|
|
|
+ QueryWrapper<TbAssetBorrowRecord> borrowRecordQueryWrapper = new QueryWrapper<>();
|
|
|
+ borrowRecordQueryWrapper.eq("asset_bar_code", tbAsset.getBarCode()).orderByDesc("borrow_date").last("limit 1");
|
|
|
+ TbAssetBorrowRecord borrowRecord = tbAssetBorrowRecordMapper.selectOne(borrowRecordQueryWrapper);
|
|
|
+ if (borrowRecord != null && borrowRecord.getIsreturn() < 1) {
|
|
|
+ return AjaxResult.error("资产设备未归还");
|
|
|
+ }
|
|
|
+ Long loginUserId = UserUtils.getLoginUserId();
|
|
|
+ tbFaultReport.setUserId(loginUserId);
|
|
|
+ Date faultReportDate = new Date();
|
|
|
+ tbFaultReport.setReportDate(faultReportDate);
|
|
|
+
|
|
|
+ tbFaultReport.setId(null);
|
|
|
+ tbFaultReport.setProcessState(TbFaultProcessStateEnum.pending.getProcessStateCode());
|
|
|
+ tbFaultReport.setProcessResult(null);
|
|
|
+
|
|
|
+ boolean result = save(tbFaultReport);
|
|
|
+ if (result) {
|
|
|
+ int updateResult = tbAssetMapper.updateTbAssetStatus(assetBarCode, TbAssetStatusEnum.fault.getStatusCode());
|
|
|
+ if (updateResult < 1) {
|
|
|
+ throw new ServiceException("故障上报失败", 500);
|
|
|
+ }
|
|
|
+ TbAssetStatusRecord tbAssetStatusRecord = tbAssetStatusRecordMapper.selectTbAssetStatusRecordByAssetBarCode(assetBarCode);
|
|
|
+ if (tbAssetStatusRecord == null) {
|
|
|
+ TbAssetStatusRecord statusRecord = new TbAssetStatusRecord();
|
|
|
+ statusRecord.setAssetBarCode(assetBarCode);
|
|
|
+ statusRecord.setFaultNumber(1L);
|
|
|
+ statusRecord.setLastFaultDate(faultReportDate);
|
|
|
+ int insert = tbAssetStatusRecordMapper.insert(statusRecord);
|
|
|
+ if (insert < 1) {
|
|
|
+ throw new ServiceException("故障上报失败");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Long faultNumber = tbAssetStatusRecord.getFaultNumber();
|
|
|
+ tbAssetStatusRecord.setFaultNumber(faultNumber+1);
|
|
|
+ tbAssetStatusRecord.setLastFaultDate(faultReportDate);
|
|
|
+ int update = tbAssetStatusRecordMapper.updateById(tbAssetStatusRecord);
|
|
|
+ if (update < 1) {
|
|
|
+ throw new ServiceException("故障上报失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result ? AjaxResult.success("故障上报成功", tbFaultReport) : AjaxResult.error("故障上报失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 故障报备处理
|
|
|
+ *
|
|
|
+ * @param faultReportProcessDTO 处理信息
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public AjaxResult tbFaultReportProcess(TbFaultReportProcessDTO faultReportProcessDTO) {
|
|
|
+ Long faultReportId = faultReportProcessDTO.getTbFaultReportId();
|
|
|
+ TbFaultReport faultReport = getById(faultReportId);
|
|
|
+ if (faultReport == null) {
|
|
|
+ return AjaxResult.error("故障报备不存在");
|
|
|
+ }
|
|
|
+ Long processState = faultReport.getProcessState();
|
|
|
+ if (processState != null && processState.equals(TbFaultProcessStateEnum.processed.getProcessStateCode())) {
|
|
|
+ return AjaxResult.error("故障报备已处理");
|
|
|
+ }
|
|
|
+ Long feedbackStatus = faultReportProcessDTO.getFeedbackStatus();
|
|
|
+ if (feedbackStatus == null || feedbackStatus < 1 || feedbackStatus > 2){
|
|
|
+ feedbackStatus = TbAssetStatusEnum.normal.getStatusCode();
|
|
|
+ }
|
|
|
+ faultReport.setProcessState(TbFaultProcessStateEnum.processed.getProcessStateCode());
|
|
|
+ faultReport.setProcessResult(faultReportProcessDTO.getProcessResult());
|
|
|
+ boolean result = updateById(faultReport);
|
|
|
+ if (result) {
|
|
|
+ int updateResult = tbAssetMapper.updateTbAssetStatus(faultReport.getAssetBarCode(), feedbackStatus);
|
|
|
+ if (updateResult < 1) {
|
|
|
+ throw new ServiceException("故障报备处理失败", 500);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result ? AjaxResult.success("故障报备处理成功", faultReport) : AjaxResult.error("故障报备处理失败");
|
|
|
+ }
|
|
|
+
|
|
|
}
|