治理设备管理功能
This commit is contained in:
@@ -22,6 +22,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -42,10 +45,10 @@ public class CsElementController extends BaseController {
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("组态图元新增")
|
||||
@ApiImplicitParam(name = "param", value = "组态图元", required = true)
|
||||
public HttpResult<String> add(@RequestBody @Validated CsPageParm param){
|
||||
@ApiImplicitParam(name = "multipartFile", value = "组态图元数据流", required = true)
|
||||
public HttpResult<String> add(@RequestBody @Validated MultipartFile multipartFile){
|
||||
String methodDescribe = getMethodDescribe("add");
|
||||
csElementService.addElement(param.getJsonFile());
|
||||
csElementService.addElement(multipartFile);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, CommonResponseEnum.SUCCESS.getMessage(), methodDescribe);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.csharmonic.param.CsPageParm;
|
||||
import com.njcn.csharmonic.pojo.po.CsElement;
|
||||
import com.njcn.csharmonic.pojo.vo.ElementsVO;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -17,9 +18,9 @@ public interface ICsElementService extends IService<CsElement> {
|
||||
|
||||
/**
|
||||
* 新增组态图元
|
||||
* @param json 参数
|
||||
* @param multipartFile 文件
|
||||
*/
|
||||
void addElement(String json);
|
||||
void addElement(MultipartFile multipartFile);
|
||||
|
||||
/**
|
||||
* 组态图元数据查询
|
||||
|
||||
@@ -13,11 +13,9 @@ import com.njcn.oss.utils.FileStorageUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -38,9 +36,9 @@ public class CsElementServiceImpl extends ServiceImpl<CsElementMapper, CsElement
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void addElement(String json) {
|
||||
public void addElement(MultipartFile multipartFile) {
|
||||
CsElement csElement = new CsElement();
|
||||
if (Objects.isNull(json)){
|
||||
if (Objects.isNull(multipartFile)){
|
||||
throw new BusinessException("组态图元json缺失");
|
||||
}
|
||||
LambdaQueryWrapper<CsElement> lambdaQueryWrapper = new LambdaQueryWrapper<CsElement>();
|
||||
@@ -50,9 +48,13 @@ public class CsElementServiceImpl extends ServiceImpl<CsElementMapper, CsElement
|
||||
} else {
|
||||
csElement = new CsElement();
|
||||
}
|
||||
InputStream inputStream = this.writeJsonStringToInputStream(json);
|
||||
String path = fileStorageUtil.uploadStream(inputStream, OssPath.ELEMENT, FileUtil.generateFileName("json"));
|
||||
csElement.setPath(path);
|
||||
try {
|
||||
InputStream inputStream = multipartFile.getInputStream();
|
||||
String path = fileStorageUtil.uploadStream(inputStream, OssPath.ELEMENT, FileUtil.generateFileName("json"));
|
||||
csElement.setPath(path);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.saveOrUpdate(csElement);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user