You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
174 lines
6.5 KiB
Java
174 lines
6.5 KiB
Java
package com.glxp.api.controller.dev;
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
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.dev.DeviceCheckItemDictEntity;
|
|
import com.glxp.api.entity.dev.DevicePlanDetailItemEntity;
|
|
import com.glxp.api.req.dev.DevicePlanDetailItemParam;
|
|
import com.glxp.api.req.dev.DevicePlanDetailItemQuery;
|
|
import com.glxp.api.res.PageSimpleResponse;
|
|
import com.glxp.api.service.dev.DeviceCheckItemDictService;
|
|
import com.glxp.api.service.dev.DevicePlanDetailItemService;
|
|
import com.glxp.api.service.dev.DevicePlanDetailService;
|
|
import com.glxp.api.vo.dev.DevicePlanDetailVo;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.validation.Valid;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 设备管理
|
|
* data: 2023/11/10
|
|
*/
|
|
@RestController
|
|
@RequestMapping
|
|
@RequiredArgsConstructor
|
|
@Slf4j
|
|
public class DevicePlanDetailItemController extends BaseController {
|
|
|
|
private final DevicePlanDetailService devicePlanDetailService;
|
|
private final DevicePlanDetailItemService devicePlanDetailItemService;
|
|
private final DeviceCheckItemDictService deviceCheckItemDictService;
|
|
|
|
|
|
/**
|
|
* 设备巡检计划明细项目分页
|
|
*
|
|
* @param query
|
|
* @return
|
|
*/
|
|
@AuthRuleAnnotation("")
|
|
@PostMapping("/udi/device/plan/detail/item/group/page")
|
|
public BaseResponse groupPage(@RequestBody @Valid DevicePlanDetailItemQuery query) {
|
|
List<DevicePlanDetailItemEntity> list = devicePlanDetailItemService.pageList(query);
|
|
PageInfo pageInfo = new PageInfo<>(list);
|
|
PageSimpleResponse page = new PageSimpleResponse();
|
|
page.setTotal(pageInfo.getTotal());
|
|
page.setList(pageInfo.getList());
|
|
return ResultVOUtils.success(page);
|
|
}
|
|
|
|
|
|
/**
|
|
* 设备巡检计划明细项目分页
|
|
*
|
|
* @param query
|
|
* @return
|
|
*/
|
|
@AuthRuleAnnotation("")
|
|
@PostMapping("/udi/device/plan/detail/item/page")
|
|
public BaseResponse page(@RequestBody @Valid DevicePlanDetailItemQuery query) {
|
|
List<DevicePlanDetailItemEntity> list = devicePlanDetailItemService.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/detail/item/add")
|
|
public BaseResponse add(@RequestBody @Valid DevicePlanDetailItemParam param) {
|
|
param.valid(devicePlanDetailService);
|
|
List<DevicePlanDetailItemEntity> entityList = param.getEntity(deviceCheckItemDictService);
|
|
if (StrUtil.isBlank(param.getDeviceCode())) {
|
|
devicePlanDetailItemService.replaceBatch(entityList);
|
|
} else {
|
|
devicePlanDetailItemService.insertIgnoreBatch(entityList);
|
|
}
|
|
return ResultVOUtils.successMsg("添加成功");
|
|
}
|
|
|
|
/**
|
|
* 设备巡检计划明细项目批量新增
|
|
*
|
|
* @param param 参数
|
|
* @return 计划id
|
|
*/
|
|
@AuthRuleAnnotation("")
|
|
@PostMapping("/udi/device/plan/detail/item/batch/add")
|
|
public BaseResponse batchAdd(@RequestBody @Valid DevicePlanDetailItemParam param) {
|
|
List<DevicePlanDetailVo> list = devicePlanDetailService.listByPlanId(param.getPlanId());
|
|
if (CollUtil.isNotEmpty(list)) {
|
|
for (DevicePlanDetailVo item : list) {
|
|
List<DeviceCheckItemDictEntity> itemDictEntities = deviceCheckItemDictService.listByIds(param.getItemCodes());
|
|
List<DevicePlanDetailItemEntity> entityList = new ArrayList<>();
|
|
itemDictEntities.forEach(i -> {
|
|
DevicePlanDetailItemEntity build = DevicePlanDetailItemEntity.builder()
|
|
.planId(param.getPlanId())
|
|
.productId(item.getProductId())
|
|
.deviceCode(StrUtil.blankToDefault(item.getDeviceCode(), ""))
|
|
.itemCode(i.getCode())
|
|
.name(i.getName())
|
|
.content(i.getContent())
|
|
.build();
|
|
entityList.add(build);
|
|
});
|
|
if (StrUtil.isBlank(param.getDeviceCode())) {
|
|
devicePlanDetailItemService.replaceBatch(entityList);
|
|
} else {
|
|
devicePlanDetailItemService.insertIgnoreBatch(entityList);
|
|
}
|
|
}
|
|
|
|
}
|
|
return ResultVOUtils.successMsg("添加成功");
|
|
}
|
|
|
|
|
|
/**
|
|
* 设备巡检计划明细项目删除
|
|
*
|
|
* @param planId 计划id
|
|
* @param productId 产品id
|
|
* @param itemCode 项目编码
|
|
*/
|
|
@AuthRuleAnnotation("")
|
|
@DeleteMapping("/udi/device/plan/detail/item/delByProduct/{planId}/{productId}/{itemCode}")
|
|
public BaseResponse delByProduct(@PathVariable Long planId, @PathVariable Long productId, @PathVariable String itemCode) {
|
|
devicePlanDetailItemService.remove(Wrappers.lambdaQuery(DevicePlanDetailItemEntity.class)
|
|
.eq(DevicePlanDetailItemEntity::getPlanId, planId)
|
|
.eq(DevicePlanDetailItemEntity::getProductId, productId)
|
|
.eq(DevicePlanDetailItemEntity::getItemCode, itemCode)
|
|
);
|
|
return ResultVOUtils.successMsg("删除成功");
|
|
}
|
|
|
|
|
|
/**
|
|
* 设备巡检计划明细项目删除
|
|
*
|
|
* @param planId 计划id
|
|
* @param deviceCode 设备编码
|
|
* @param itemCode 项目编码
|
|
*/
|
|
@AuthRuleAnnotation("")
|
|
@DeleteMapping("/udi/device/plan/detail/item/delByDevice/{planId}/{deviceCode}/{itemCode}")
|
|
public BaseResponse delByDevice(@PathVariable Long planId, @PathVariable String deviceCode, @PathVariable String itemCode) {
|
|
devicePlanDetailItemService.remove(Wrappers.lambdaQuery(DevicePlanDetailItemEntity.class)
|
|
.eq(DevicePlanDetailItemEntity::getPlanId, planId)
|
|
.eq(DevicePlanDetailItemEntity::getDeviceCode, deviceCode)
|
|
.eq(DevicePlanDetailItemEntity::getItemCode, itemCode)
|
|
);
|
|
return ResultVOUtils.successMsg("删除成功");
|
|
}
|
|
|
|
|
|
}
|