吉安感知网项目-后端
rain
2026-02-09 66bfbdb9251c22ffa2b5f05595a76a3547a2f5eb
drone-service/drone-fw/src/main/java/org/sxkj/fw/device/service/impl/FwDeviceScrapServiceImpl.java
@@ -16,28 +16,66 @@
 */
package org.sxkj.fw.device.service.impl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.secure.utils.AuthUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.sxkj.fw.device.dto.FwDeviceScrapDTO;
import org.sxkj.fw.device.entity.FwDeviceEntity;
import org.sxkj.fw.device.entity.FwDeviceScrapEntity;
import org.sxkj.fw.device.vo.FwDeviceScrapVO;
import org.sxkj.fw.device.excel.FwDeviceScrapExcel;
import org.sxkj.fw.device.mapper.FwDeviceScrapMapper;
import org.sxkj.fw.device.service.IFwDeviceScrapService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.sxkj.fw.device.service.IFwDeviceService;
import org.sxkj.fw.device.vo.FwDeviceScrapVO;
import org.sxkj.fw.device.wrapper.FwDeviceScrapWrapper;
import org.sxkj.system.cache.SysCache;
import java.util.Collections;
import java.util.List;
/**
 * 设备报废记录表 服务实现类
 *
 * @author lw
 * @since 2026-01-07
 * @since 2026-01-08
 */
@Service
@AllArgsConstructor
public class FwDeviceScrapServiceImpl extends BaseServiceImpl<FwDeviceScrapMapper, FwDeviceScrapEntity> implements IFwDeviceScrapService {
   private final IFwDeviceService fwDeviceService;
   @Override
   public IPage<FwDeviceScrapVO> selectFwDeviceScrapPage(IPage<FwDeviceScrapVO> page, FwDeviceScrapVO fwDeviceScrap) {
   public FwDeviceScrapVO getFwDeviceScrapById(Long id) {
      return baseMapper.getFwDeviceScrapById(id);
   }
   @Override
   @Transactional
   public boolean saveFwDeviceScrap(FwDeviceScrapDTO dto) {
      // 先保存报废记录,成功后再处理设备状态与逻辑删除
      boolean isSuccess = super.save(FwDeviceScrapWrapper.build().entityDTO(dto));
      if (isSuccess) {
         FwDeviceEntity fwDevice = new FwDeviceEntity();
         fwDevice.setId(dto.getDeviceId());
         fwDevice.setStatus(3);
         // 更新设备状态并做逻辑删除,保持报废与设备状态一致
         isSuccess = fwDeviceService.updateById(fwDevice) && fwDeviceService.deleteLogic(Collections.singletonList(fwDevice.getId()));
      }
      return isSuccess;
   }
   @Override
   public IPage<FwDeviceScrapVO> selectFwDeviceScrapPage(IPage<FwDeviceScrapVO> page, FwDeviceScrapDTO fwDeviceScrap) {
      // 按当前部门及下级部门范围过滤数据
      if (!AuthUtil.isAdministrator()) {
         List<Long> deptList = SysCache.getDeptChildIds(Long.valueOf(AuthUtil.getDeptId()));
         fwDeviceScrap.setDeptList(deptList);
      }
      return page.setRecords(baseMapper.selectFwDeviceScrapPage(page, fwDeviceScrap));
   }
@@ -45,9 +83,6 @@
   @Override
   public List<FwDeviceScrapExcel> exportFwDeviceScrap(Wrapper<FwDeviceScrapEntity> queryWrapper) {
      List<FwDeviceScrapExcel> fwDeviceScrapList = baseMapper.exportFwDeviceScrap(queryWrapper);
      //fwDeviceScrapList.forEach(fwDeviceScrap -> {
      //   fwDeviceScrap.setTypeName(DictCache.getValue(DictEnum.YES_NO, FwDeviceScrap.getType()));
      //});
      return fwDeviceScrapList;
   }