package com.glxp.api.controller.dev; import com.github.pagehelper.PageInfo; import com.glxp.api.annotation.AuthRuleAnnotation; import com.glxp.api.common.res.BaseResponse; import com.glxp.api.common.util.ResultVOUtils; import com.glxp.api.controller.BaseController; import com.glxp.api.entity.auth.AuthAdmin; import com.glxp.api.entity.dev.DevicePlanEntity; import com.glxp.api.req.dev.DevicePlanParam; import com.glxp.api.req.dev.DevicePlanQuery; import com.glxp.api.res.PageSimpleResponse; import com.glxp.api.service.auth.DeptService; import com.glxp.api.service.dev.DevicePlanService; import com.glxp.api.vo.dev.DevicePlanVo; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import java.util.List; @RestController @RequestMapping @RequiredArgsConstructor @Slf4j public class DevicePlanController extends BaseController { private final DevicePlanService devicePlanService; private final DeptService deptService; /** * 设备巡检计划分页 * * @param query * @return */ @AuthRuleAnnotation("") @PostMapping("/udi/device/plan/page") public BaseResponse page(@RequestBody @Valid DevicePlanQuery query) { List list = devicePlanService.pageList(query); PageInfo pageInfo = new PageInfo<>(list); PageSimpleResponse page = new PageSimpleResponse(); page.setTotal(pageInfo.getTotal()); page.setList(pageInfo.getList()); return ResultVOUtils.success(page); } /** * 设备巡检计划保存 * * @param param 参数 * @return 计划id */ @AuthRuleAnnotation("") @PostMapping("/udi/device/plan/save") public BaseResponse save(@RequestBody @Valid DevicePlanParam param) { AuthAdmin user = super.getUser(); param.valid(deptService); DevicePlanEntity entity = param.getEntity(user); if (param.getPlanId() == null) { devicePlanService.save(entity); } else { devicePlanService.updateById(entity); } return ResultVOUtils.success("保存成功", entity.getPlanId()); } /** * 设备巡检计划详情 * * @param planId 计划id * @return */ @AuthRuleAnnotation("") @GetMapping("/udi/device/plan/info/{planId}") public BaseResponse info(@PathVariable Long planId) { DevicePlanEntity entity = devicePlanService.getById(planId); if (entity == null) { return ResultVOUtils.error("计划不存在"); } return ResultVOUtils.success(entity); } /** * 设备巡检计划删除 * * @param planId 计划id * @return */ @AuthRuleAnnotation("") @DeleteMapping("/udi/device/plan/del/{planId}") public BaseResponse del(@PathVariable Long planId) { devicePlanService.deletePlan(planId); return ResultVOUtils.successMsg("删除成功"); } }