11 小时以前 620bb4712a31791231c4381581f0f60088f079fe
src/main/java/com/ruoyi/device/controller/DeviceLedgerController.java
@@ -12,8 +12,7 @@
import com.ruoyi.device.pojo.DeviceMaintenance;
import com.ruoyi.device.service.IDeviceLedgerService;
import com.ruoyi.framework.aspectj.lang.annotation.Anonymous;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.R;
import com.ruoyi.framework.web.domain.AjaxResult;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletResponse;
@@ -29,53 +28,52 @@
@RequestMapping("/device/ledger")
@RestController
@AllArgsConstructor
public class DeviceLedgerController extends BaseController {
public class DeviceLedgerController {
    private IDeviceLedgerService deviceLedgerService;
    private DeviceLedgerMapper deviceLedgerMapper;
    private DeviceMaintenanceMapper deviceMaintenanceMapper;
    @Operation(summary = "设备台账列表")
    @GetMapping("/page")
    public R<?> page(Page page , DeviceLedgerDto deviceLedger) {
        return R.ok(deviceLedgerService.queryPage(page,deviceLedger));
    public AjaxResult page(Page page, DeviceLedgerDto deviceLedger) {
        return AjaxResult.success(deviceLedgerService.queryPage(page, deviceLedger));
    }
    @PostMapping()
    @Operation(summary = "添加设备台账")
    public R<?> add(@RequestBody DeviceLedger deviceLedger) {
        return deviceLedgerService.saveDeviceLedger(deviceLedger);
    public AjaxResult add(@RequestBody DeviceLedgerDto deviceLedgerDto) {
        return deviceLedgerService.saveDeviceLedger(deviceLedgerDto);
    }
    @Operation(summary = "根据id查询设备台账")
    @GetMapping("/{id}")
    public R<?> detail(@PathVariable Long id) {
        return R.ok(deviceLedgerService.getById(id));
    public AjaxResult detail(@PathVariable Long id) {
        DeviceLedgerDto deviceLedgerDto = deviceLedgerService.getDeviceLedgerDetail(id);
        return AjaxResult.success(deviceLedgerDto);
    }
    @PutMapping ()
    @PutMapping()
    @Operation(summary = "修改设备台账")
    public R<?> update(@RequestBody DeviceLedger deviceLedger) {
        return deviceLedgerService.updateDeviceLedger(deviceLedger);
    public AjaxResult update(@RequestBody DeviceLedgerDto deviceLedgerDto) {
        return deviceLedgerService.updateDeviceLedger(deviceLedgerDto);
    }
    @DeleteMapping("/{ids}")
    @Operation(summary = "删除设备台账")
    public R<?> delete(@PathVariable("ids") ArrayList<Long> ids) {
    public AjaxResult delete(@PathVariable("ids") ArrayList<Long> ids) {
        boolean b = deviceLedgerService.removeBatchByIds(ids);
        if (!b) {
            return R.fail("删除失败");
            return AjaxResult.error("删除失败");
        }
        return R.ok();
        return AjaxResult.success();
    }
    @PostMapping("export")
    @Operation(summary = "导出设备台账")
    public void export(HttpServletResponse response, Long[] ids) {
         deviceLedgerService.export(response, ids);
        deviceLedgerService.export(response, ids);
    }
    @Operation(summary = "下载模板")
@@ -87,32 +85,32 @@
    @PostMapping("/import")
    @Operation(summary = "导入设备台账")
    public R<?> importData(MultipartFile file) throws IOException {
    public AjaxResult importData(MultipartFile file) throws IOException {
        Boolean b = deviceLedgerService.importData(file);
        if (b) {
            return R.ok(null, "导入成功");
            return AjaxResult.success("导入成功");
        }
        return R.fail("导入失败");
        return AjaxResult.error("导入失败");
    }
    @GetMapping("getDeviceLedger")
    @Operation(summary = "获取设备台账")
    public R<?> getDeviceLedger( ) {
        return R.ok(deviceLedgerService.list(new QueryWrapper<DeviceLedger>().lambda()
                .select(DeviceLedger::getId, DeviceLedger::getDeviceName,DeviceLedger::getDeviceModel)));
    public AjaxResult getDeviceLedger() {
        return AjaxResult.success(deviceLedgerService.list(new QueryWrapper<DeviceLedger>().lambda()
                .select(DeviceLedger::getId, DeviceLedger::getDeviceName, DeviceLedger::getDeviceModel)));
    }
    @GetMapping("scanDevice")
    @Operation(summary = "获取设备台账")
    @Anonymous
    public R<?> scanDevice(Long id) {
    public AjaxResult scanDevice(Long id) {
        List<DeviceMaintenance> list = deviceMaintenanceMapper.list1(id);
        DeviceLedger deviceLedger = deviceLedgerMapper.selectById1(id);
        if (list.size()>0){
            deviceLedger.setUpdateTime(list.get(0).getMaintenanceActuallyTime());//最后维护时间
        if (!list.isEmpty()) {
            deviceLedger.setUpdateTime(list.getFirst().getMaintenanceActuallyTime());//最后维护时间
        }
        deviceLedger.setCreateTime(deviceLedger.getUpdateTime().plusMonths(1));//下次维护时间
        return R.ok(deviceLedger);
        return AjaxResult.success(deviceLedger);
    }
}