|
@@ -3,12 +3,14 @@ package com.persagy.dmp.rwd.digital.controller;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
import com.persagy.dmp.basic.model.QueryCriteria;
|
|
|
import com.persagy.dmp.basic.utils.JsonNodeUtils;
|
|
|
import com.persagy.dmp.common.constant.CommonConstant;
|
|
|
import com.persagy.dmp.common.constant.ResponseCode;
|
|
|
+import com.persagy.dmp.common.context.AppContext;
|
|
|
import com.persagy.dmp.common.exception.BusinessException;
|
|
|
import com.persagy.dmp.common.model.response.CommonResult;
|
|
|
import com.persagy.dmp.common.utils.ParamCheckUtil;
|
|
@@ -20,6 +22,7 @@ import com.persagy.dmp.rwd.basic.dto.RequestData;
|
|
|
import com.persagy.dmp.rwd.digital.service.IObjectDigitalService;
|
|
|
import com.persagy.dmp.rwd.digital.service.ProjectBusinessService;
|
|
|
import com.persagy.dmp.rwd.digital.utils.ObjectDigitalCriteriaHelper;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
@@ -73,23 +76,30 @@ public class ObjectDigitalController{
|
|
|
|
|
|
@PostMapping("/createOne")
|
|
|
@Deprecated
|
|
|
- public CommonResult<ObjectDigital> create(@Valid @RequestBody ObjectNode node){
|
|
|
+ public CommonResult<ObjectDigital> create(@RequestBody ObjectNode node){
|
|
|
//基础参数校验
|
|
|
ParamCheckUtil.checkParam(CommonConstant.QUERY_GROUPCODE,CommonConstant.QUERY_PROJECTID);
|
|
|
-
|
|
|
ObjectDigital vo = JsonNodeUtils.toEntity(node, ObjectDigital.class, ObjectDigital.EXTRA_COLUMN);
|
|
|
List<ObjectDigital> voList = CollUtil.newArrayList(vo);
|
|
|
+ //创建默认条件
|
|
|
+ createDefaultValue(voList);
|
|
|
+ //新增对象信息
|
|
|
service.insert(voList);
|
|
|
return ResultHelper.single(vo);
|
|
|
}
|
|
|
|
|
|
@PostMapping("/create")
|
|
|
@Deprecated
|
|
|
- public CommonResult<List<ObjectDigital>> createBatch(@Valid @RequestBody ArrayNode array){
|
|
|
+ public CommonResult<List<ObjectDigital>> createBatch(@RequestBody ArrayNode array){
|
|
|
//基础参数校验
|
|
|
ParamCheckUtil.checkParam(CommonConstant.QUERY_GROUPCODE,CommonConstant.QUERY_PROJECTID);
|
|
|
+ //创建对象入参校验
|
|
|
+ createInstanceParamVerify(array);
|
|
|
|
|
|
List<ObjectDigital> voList = JsonNodeUtils.toEntity(array, ObjectDigital.class, ObjectDigital.EXTRA_COLUMN);
|
|
|
+ //创建默认条件
|
|
|
+ createDefaultValue(voList);
|
|
|
+ //批量新增对象信息
|
|
|
voList = service.insert(voList);
|
|
|
return ResultHelper.multi(voList);
|
|
|
}
|
|
@@ -99,9 +109,11 @@ public class ObjectDigitalController{
|
|
|
public CommonResult<ObjectDigital> update(@Valid @RequestBody ObjectNode node){
|
|
|
//基础参数校验
|
|
|
ParamCheckUtil.checkParam(CommonConstant.QUERY_GROUPCODE,CommonConstant.QUERY_PROJECTID);
|
|
|
-
|
|
|
ObjectDigital vo = JsonNodeUtils.toEntity(node, ObjectDigital.class, ObjectDigital.EXTRA_COLUMN);
|
|
|
List<ObjectDigital> voList = CollUtil.newArrayList(vo);
|
|
|
+ //创建默认条件
|
|
|
+ createDefaultValue(voList);
|
|
|
+ //修改对象信息
|
|
|
service.update(voList);
|
|
|
return ResultHelper.single(vo);
|
|
|
}
|
|
@@ -111,8 +123,13 @@ public class ObjectDigitalController{
|
|
|
public CommonResult<List<ObjectDigital>> updateBatch(@Valid @RequestBody ArrayNode array){
|
|
|
//基础参数校验
|
|
|
ParamCheckUtil.checkParam(CommonConstant.QUERY_GROUPCODE,CommonConstant.QUERY_PROJECTID);
|
|
|
+ //修改对象入参校验
|
|
|
+ updateInstanceParamVerify(array);
|
|
|
|
|
|
List<ObjectDigital> voList = JsonNodeUtils.toEntity(array, ObjectDigital.class, ObjectDigital.EXTRA_COLUMN);
|
|
|
+ //创建默认条件
|
|
|
+ createDefaultValue(voList);
|
|
|
+ //批量修改对象信息
|
|
|
voList = service.update(voList);
|
|
|
return ResultHelper.multi(voList);
|
|
|
}
|
|
@@ -120,14 +137,20 @@ public class ObjectDigitalController{
|
|
|
@PostMapping("/deleteOne")
|
|
|
@Deprecated
|
|
|
public CommonResult delete(@RequestBody String id){
|
|
|
+ if(StringUtils.isEmpty(id)){
|
|
|
+ throw new BusinessException(ResponseCode.A0400.getCode(), "id不能为空");
|
|
|
+ }
|
|
|
service.delete(CollUtil.newArrayList(id));
|
|
|
return ResultHelper.success();
|
|
|
}
|
|
|
|
|
|
@PostMapping("/delete")
|
|
|
@Deprecated
|
|
|
- public CommonResult deleteBatch(@RequestBody List<String> id){
|
|
|
- service.delete(id);
|
|
|
+ public CommonResult deleteBatch(@RequestBody List<String> ids){
|
|
|
+ if(ids == null || ids.size()<=0){
|
|
|
+ throw new BusinessException(ResponseCode.A0400.getCode(), "id不能为空");
|
|
|
+ }
|
|
|
+ service.delete(ids);
|
|
|
return ResultHelper.success();
|
|
|
}
|
|
|
/***
|
|
@@ -159,4 +182,61 @@ public class ObjectDigitalController{
|
|
|
return projectBusinessService.batchQueryProjectByGroupManageZoneIds(requestData.getGroupManageZoneIds());
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建默认条件
|
|
|
+ * @param voList
|
|
|
+ */
|
|
|
+ private void createDefaultValue(List<ObjectDigital> voList){
|
|
|
+ String groupCode = AppContext.getContext().getGroupCode();
|
|
|
+ if(StringUtils.isEmpty(groupCode)){
|
|
|
+ //默认集团
|
|
|
+ groupCode = CommonConstant.DEFAULT_ID;
|
|
|
+ }
|
|
|
+ String projectId = AppContext.getContext().getProjectId();
|
|
|
+ if(StringUtils.isEmpty(projectId)){
|
|
|
+ //默认项目
|
|
|
+ projectId = CommonConstant.DEFAULT_ID;
|
|
|
+ }
|
|
|
+ for (ObjectDigital vo : voList) {
|
|
|
+ vo.setGroupCode(groupCode);
|
|
|
+ vo.setProjectId(projectId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建实例入参校验
|
|
|
+ * @param array
|
|
|
+ */
|
|
|
+ private void createInstanceParamVerify(ArrayNode array){
|
|
|
+ if(array == null || array.size()<=0){
|
|
|
+ throw new BusinessException(ResponseCode.A0400.getCode(),ResponseCode.A0400.getCode());
|
|
|
+ }
|
|
|
+ for (JsonNode jsonNode : array) {
|
|
|
+ JsonNode name = jsonNode.get("name");
|
|
|
+ if(name == null){
|
|
|
+ throw new BusinessException(ResponseCode.A0400.getCode(),"对象名称不能为空");
|
|
|
+ }
|
|
|
+ JsonNode classCode = jsonNode.get("classCode");
|
|
|
+ if(classCode == null){
|
|
|
+ throw new BusinessException(ResponseCode.A0400.getCode(),"类型编码不能为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改实例入参校验
|
|
|
+ * @param array
|
|
|
+ */
|
|
|
+ private void updateInstanceParamVerify(ArrayNode array){
|
|
|
+ if(array == null || array.size()<=0){
|
|
|
+ throw new BusinessException(ResponseCode.A0400.getCode(),ResponseCode.A0400.getCode());
|
|
|
+ }
|
|
|
+ for (JsonNode jsonNode : array) {
|
|
|
+ JsonNode id = jsonNode.get("id");
|
|
|
+ if(id == null){
|
|
|
+ throw new BusinessException(ResponseCode.A0400.getCode(),"id不能为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|