Browse Source

fix: 删除特种设备同步删除关联的检验记录

zhongwei
liwen 7 months ago
parent
commit
a49c0e96a5
  1. 2
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/SpecialDeviceController.java
  2. 8
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/SpecialDeviceInspectionMapper.java
  3. 11
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/SpecialDeviceInspectionMapper.xml
  4. 7
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ISpecialDeviceService.java
  5. 24
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/SpecialDeviceServiceImpl.java

2
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/SpecialDeviceController.java

@ -63,7 +63,7 @@ public class SpecialDeviceController extends BladeController {
@ApiOperationSupport(order = 3)
@Operate(label = "删除设备", type = BusinessType.DELETE, ignore = false)
public R remove(@RequestParam Long id) {
return R.status(specialDeviceService.removeById(id));
return R.status(specialDeviceService.removeDevice(id));
}
@GetMapping("/detail")

8
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/SpecialDeviceInspectionMapper.java

@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hnac.hzims.safeproduct.entity.SpecialDeviceInspectionEntity;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
import java.util.Map;
/**
@ -23,4 +24,11 @@ public interface SpecialDeviceInspectionMapper extends BaseMapper<SpecialDeviceI
* @return 设备检验记录数据
*/
IPage<SpecialDeviceInspectionEntity> getInspectionPage(IPage<SpecialDeviceInspectionEntity> page, Map<String, Object> param);
/**
* 获取设备相关检验记录
* @param deviceId 设备id
* @return 设备检验记录列表
*/
List<SpecialDeviceInspectionEntity> getRefDeviceInspection(Long deviceId);
}

11
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/SpecialDeviceInspectionMapper.xml

@ -21,4 +21,15 @@
ORDER BY
create_time DESC
</select>
<select id="getRefDeviceInspection"
resultType="com.hnac.hzims.safeproduct.entity.SpecialDeviceInspectionEntity">
SELECT
*
FROM
hzims_device_inspection
WHERE
is_deleted = 0
AND device_id = #{deviceId}
</select>
</mapper>

7
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ISpecialDeviceService.java

@ -19,4 +19,11 @@ public interface ISpecialDeviceService extends IService<SpecialDeviceEntity> {
* @param endTime 结束时间
*/
List<SpecialDeviceEntity> getExpiredDeviceByTime(String startTime, String endTime);
/**
* 删除特种设备
* @param id 设备id
* @return true-成功false-失败
*/
boolean removeDevice(Long id);
}

24
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/SpecialDeviceServiceImpl.java

@ -2,13 +2,19 @@ package com.hnac.hzims.safeproduct.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hnac.hzims.safeproduct.constants.SafeProductConstant;
import com.hnac.hzims.safeproduct.entity.SpecialDeviceEntity;
import com.hnac.hzims.safeproduct.entity.SpecialDeviceInspectionEntity;
import com.hnac.hzims.safeproduct.enums.DeviceStatusEnum;
import com.hnac.hzims.safeproduct.mapper.SpecialDeviceInspectionMapper;
import com.hnac.hzims.safeproduct.mapper.SpecialDeviceMapper;
import com.hnac.hzims.safeproduct.service.ISpecialDeviceService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
/**
* 特种设备服务实现类
@ -19,6 +25,9 @@ import java.util.List;
@Service
public class SpecialDeviceServiceImpl extends ServiceImpl<SpecialDeviceMapper, SpecialDeviceEntity> implements ISpecialDeviceService {
@Resource
SpecialDeviceInspectionMapper specialDeviceInspectionMapper;
/**
* 查找时间范围内的过期设备
*/
@ -30,4 +39,19 @@ public class SpecialDeviceServiceImpl extends ServiceImpl<SpecialDeviceMapper, S
.le(SpecialDeviceEntity::getInspectionNextTime, endTime);
return this.list(queryWrapper);
}
/**
* 删除特种设备
*/
@Transactional(rollbackFor = Exception.class)
@Override
public boolean removeDevice(Long id) {
List<SpecialDeviceInspectionEntity> inspections = specialDeviceInspectionMapper.getRefDeviceInspection(id);
List<Long> ids = inspections.stream().map(SpecialDeviceInspectionEntity::getId).collect(Collectors.toList());
int removeInspection = specialDeviceInspectionMapper.deleteBatchIds(ids);
if (removeInspection == SafeProductConstant.SUCCESS) {
return this.removeById(id);
}
return false;
}
}

Loading…
Cancel
Save