Commit 9d94f300 authored by 王夏晖's avatar 王夏晖

设备类型图片上传

parent d190a75e
......@@ -11,6 +11,7 @@ import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.Valid;
import java.util.List;
......@@ -63,4 +64,10 @@ public class BusDeviceTpController extends PaginationController<BusDeviceTp> {
public List<Map<String,Object>> queryBusDeviceTpList(@RequestParam String proId) {
return busDeviceTpServiceImpl.queryBusDeviceTpList(proId);
}
@RequestMapping("/upload")
public Result upload(@RequestParam MultipartFile file,@RequestParam String devTpId) {
PersistModel pm = busDeviceTpServiceImpl.upload(file,devTpId);
return Result.builder(pm, MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, null);
}
}
......@@ -24,6 +24,8 @@ public class BusDeviceTp{
private String devTpNm;
private String devTpImg;
}
......@@ -2,6 +2,7 @@ package org.rcisoft.business.manage.service;
import org.rcisoft.business.manage.entity.BusDeviceTp;
import org.rcisoft.core.model.PersistModel;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.Map;
......@@ -40,6 +41,6 @@ public interface BusDeviceTpService {
List<Map<String,Object>> queryBusDeviceTpList(String proId);
PersistModel upload(MultipartFile file,String devTpId);
}
package org.rcisoft.business.manage.service.impl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.rcisoft.business.manage.dao.BusDeviceTpRepository;
import org.rcisoft.business.manage.entity.BusDeviceTp;
import org.rcisoft.business.manage.entity.BusDevicetpParam;
......@@ -9,12 +10,15 @@ import org.rcisoft.business.manage.service.BusDeviceTpService;
import org.rcisoft.business.manage.service.BusDevicetpParamService;
import org.rcisoft.core.model.PersistModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import tk.mybatis.mapper.entity.Example;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -32,6 +36,8 @@ public class BusDeviceTpServiceImpl implements BusDeviceTpService {
private BusDeviceTpRepository busDeviceTpRepository;
@Autowired
private BusDevicetpParamService busDevicetpParamService;
@Value("${filepath.devicetp}")
private String filepath;
/**
......@@ -90,5 +96,29 @@ public class BusDeviceTpServiceImpl implements BusDeviceTpService {
return list;
}
@Override
public PersistModel upload(MultipartFile file, String devTpId) {
int line = 1;
String fileName = file.getOriginalFilename();
String suffixName = fileName.substring(fileName.lastIndexOf("."));
//文件路径
String savePath = filepath + devTpId + suffixName;
File saveFile = new File(savePath);
if(saveFile.exists()){
line = 0;
}
try{
FileUtils.copyInputStreamToFile(file.getInputStream(), saveFile);
BusDeviceTp busDeviceTp = new BusDeviceTp();
busDeviceTp.setDevTpId(devTpId);
busDeviceTp.setDevTpImg(savePath);
merge(busDeviceTp);
line = 1;
}catch(Exception e){
e.printStackTrace();
}
return new PersistModel(line);
}
}
......@@ -4,4 +4,5 @@ spring:
filepath:
analysis: D:\zhny\filepath\analysis\
equipment: D:\zhny\filepath\equipment\
\ No newline at end of file
equipment: D:\zhny\filepath\equipment\
devicetp: D:\zhny\filepath\devicetp\
\ No newline at end of file
......@@ -4,6 +4,7 @@
<resultMap id="BaseResultMap" type="org.rcisoft.business.manage.entity.BusDeviceTp">
<id column="DEV_TP_ID" jdbcType="VARCHAR" property="devTpId"/>
<result column="DEV_TP_NM" jdbcType="VARCHAR" property="devTpNm"/>
<result column="DEV_TP_IMG" jdbcType="VARCHAR" property="devTpImg"/>
</resultMap>
<!--<cache type="${corePackag!}.util.RedisCache"/>-->
......
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