Commit 2958c998 authored by wanglong's avatar wanglong

解决 删除不成功问题 增加项目资源条件判断

parent a86a0682
package com.yeejoin.amos.boot.module.ugp.biz.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yeejoin.amos.boot.biz.common.entity.BaseEntity;
import com.yeejoin.amos.boot.module.ugp.api.dto.ProjectMaterialDto;
import com.yeejoin.amos.boot.module.ugp.api.dto.WelderEquipmentDto;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.ugp.api.entity.Equipment;
import com.yeejoin.amos.boot.module.ugp.api.entity.Project;
import com.yeejoin.amos.boot.module.ugp.api.entity.ProjectResource;
import com.yeejoin.amos.boot.module.ugp.api.mapper.EquipmentMapper;
import com.yeejoin.amos.boot.module.ugp.api.mapper.ProjectResourceMapper;
import com.yeejoin.amos.boot.module.ugp.biz.service.impl.MaterialServiceImpl;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -178,9 +182,12 @@ public class ProjectResourceController extends BaseController {
@DeleteMapping(value = "/welderDelete")
@ApiOperation(httpMethod = "Delete", value = "项目设备删除", notes = "项目设备删除")
public ResponseModel<Boolean> welderDelete(
@RequestParam String ids
@RequestParam Long ids
){
this.projectResourceServiceImpl.welderDelete(ids);
LambdaQueryWrapper<ProjectResource> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ProjectResource::getResourceId,ids);
projectResourceMapper.delete(wrapper);
return ResponseHelper.buildResponse(true);
}
......@@ -192,7 +199,7 @@ public class ProjectResourceController extends BaseController {
@TycloudOperation(ApiLevel = UserType.AGENCY,needAuth = false)
@ApiOperation(httpMethod = "POST",value = "绑定项目所用到的设备管材", notes = "绑定项目所用到的设备管材")
@PostMapping(value = "/saveId")
public ResponseModel<ProjectResource> saveId(@RequestBody JSONObject jsonObject) {
public ResponseModel<ProjectResource> saveId(@RequestBody JSONObject jsonObject) throws Exception {
return ResponseHelper.buildResponse(projectResourceServiceImpl.saveIds(jsonObject));
}
......
......@@ -122,25 +122,25 @@ public class ProjectResourceServiceImpl extends BaseService<ProjectResourceDto,P
projectResourceMapper.insert(projectResource);
}
/**
* 项目设备删除
* @param ids
*/
@Transactional
public void welderDelete(String ids) {
this.list(new QueryWrapper<ProjectResource>().lambda().in(
ProjectResource::getSequenceNbr,
Arrays.stream(ids.split(",")).map(Long::valueOf).collect(Collectors.toList()))
).forEach(item -> {
this.equipmentMapper.deleteById(item.getResourceId());
this.projectResourceMapper.deleteById(item.getSequenceNbr());
});
}
// /**
// * 项目设备删除
// * @param ids
// */
// @Transactional
// public void welderDelete(String ids) {
// this.list(new QueryWrapper<ProjectResource>().lambda().in(
// ProjectResource::getSequenceNbr,
// Arrays.stream(ids.split(",")).map(Long::valueOf).collect(Collectors.toList()))
// ).forEach(item -> {
// this.equipmentMapper.deleteById(item.getResourceId());
// this.projectResourceMapper.deleteById(item.getSequenceNbr());
// });
// }
/**
* 绑定项目所用到的设备管材
*/
public ProjectResource saveIds(JSONObject jsonObject) {
public ProjectResource saveIds(JSONObject jsonObject) throws Exception {
JSONArray subForm = jsonObject.getJSONArray("subForm");
ProjectResource Resource = new ProjectResource();
......@@ -151,6 +151,11 @@ public class ProjectResourceServiceImpl extends BaseService<ProjectResourceDto,P
Long SequenceNbr = Long.valueOf(jsonObject.getString("sequenceNbr"));
String type = jsonObject.getString("type");
LambdaQueryWrapper<ProjectResource> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ProjectResource::getResourceId,select);
wrapper.eq(ProjectResource::getProjectId,SequenceNbr);
ProjectResource projectResourceVerify = projectResourceMapper.selectOne(wrapper);
if (ValidationUtil.isEmpty(projectResourceVerify)){
//判断资源类型并插入
if (type.equals(设备资源.getName())) {
projectResource.setType(设备资源.getCode());
......@@ -172,6 +177,9 @@ public class ProjectResourceServiceImpl extends BaseService<ProjectResourceDto,P
projectResource.setResourceId(Long.valueOf(select));
BeanUtils.copyProperties(projectResource,Resource);
this.save(projectResource);
}else {
throw new Exception("该资源已存在");
}
}
return Resource;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment