package com.xiaopeng.maintenance.controller; import cn.hutool.core.collection.CollUtil; import com.xiaopeng.api.feignClient.vehicleConvoy.XpFleetClient; import com.xiaopeng.api.feignClient.vehicleConvoy.XpVehicleClient; import com.xiaopeng.api.model.maintenance.XpCheckLocation; import com.xiaopeng.common.core.domain.R; import com.xiaopeng.common.core.enums.DisabledEnum; import com.xiaopeng.common.core.web.page.PageInfo; import com.xiaopeng.common.security.service.TokenService; import com.xiaopeng.maintenance.dto.LocationUpdateStatusDTO; import com.xiaopeng.maintenance.model.query.XpCheckLocationQuery; import com.xiaopeng.maintenance.service.IXpCheckLocationService; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Lazy; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.List; /** * @author MiTao * @date 2026-02-12 21:17 * */ @Validated @RestController @RequiredArgsConstructor(onConstructor_ = @Lazy) public class XpCheckLocationController { private final IXpCheckLocationService xpCheckLocationService; private final XpFleetClient xpFleetClient; private final TokenService tokenService; @GetMapping("/api/v1/check-location/list") @ApiOperation(value = "获取打卡地址列表", tags = {"管理后台-车队管理"}) public R> getList(){ return R.ok(xpCheckLocationService.lambdaQuery().eq(XpCheckLocation::getStatus, DisabledEnum.YES.getCode()).list()); } @GetMapping("/logan/inner/check-location/queryById") @ApiOperation(value = "根据ID查询打卡地址", tags = {"内部接口"}) public R queryById(@RequestParam Long id) { return R.ok(xpCheckLocationService.getById(id)); } @PostMapping("/logan/inner/check-location/listByIds") @ApiOperation(value = "根据ID列表批量查询打卡地址", tags = {"内部接口"}) public R> listByIds(@RequestBody List ids) { if (CollUtil.isEmpty(ids)) { return R.ok(new ArrayList<>()); } return R.ok(xpCheckLocationService.listByIds(ids)); } @ApiOperation(value = "根据ID查询打卡地址", tags = {"运维APP-排班与考勤"}) @GetMapping("/maintenance-app/api/v1/check-location/queryByUserId") public R queryByUserId() { Long id = tokenService.getLoginOperationUser().getId(); return R.ok(xpCheckLocationService.queryByUserId(id)); } @PostMapping("/api/v1/check-location/pageList") @ApiOperation(value = "获取打卡地址分页列表", tags = {"管理后台-运维执行"}) public R> pageList(@RequestBody XpCheckLocationQuery query){ PageInfo pageList = xpCheckLocationService.pageList(query); return R.ok(pageList); } @PostMapping("/api/v1/check-location/add") @ApiOperation(value = "新增打卡地", tags = {"管理后台-运维执行"}) public R add(@RequestBody XpCheckLocation dto){ xpCheckLocationService.save(dto); return R.ok(); } @PostMapping("/api/v1/check-location/edit") @ApiOperation(value = "编辑打卡地", tags = {"管理后台-运维执行"}) public R edit(@RequestBody XpCheckLocation dto){ xpCheckLocationService.updateById(dto); return R.ok(); } @DeleteMapping("/api/v1/check-location/deleteById") @ApiOperation(value = "删除打卡地", tags = {"管理后台-运维执行"}) public R deleteById(@RequestParam Long id){ // 判断打卡地是否已被使用 Long data = xpFleetClient.getUseCountByLocationId(id).getData(); if (data > 0) { return R.fail("打卡地已被使用,请先解除关联"); } xpCheckLocationService.removeById(id); return R.ok(); } @PostMapping("/api/v1/check-location/updateStatus") @ApiOperation(value = "启用禁用打卡地", tags = {"管理后台-运维执行"}) public R updateStatus(@RequestBody LocationUpdateStatusDTO dto){ XpCheckLocation xpCheckLocation = xpCheckLocationService.getById(dto.getId()); xpCheckLocation.setStatus(dto.getStatus()); xpCheckLocationService.updateById(xpCheckLocation); return R.ok(); } }