|
@@ -27,6 +27,8 @@ import com.bizmatics.service.util.SecurityUtils;
|
|
|
import com.bizmatics.service.vo.*;
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.File;
|
|
@@ -154,28 +156,40 @@ public class DeviceAnalogVariableListServiceImpl extends AbstractCrudService<Dev
|
|
|
return file.getName();
|
|
|
}
|
|
|
|
|
|
+ @Transactional
|
|
|
@Override
|
|
|
public void variableListImport(MultipartFile multipartFile){
|
|
|
SysUser user = SecurityUtils.getLoginUser().getUser();
|
|
|
ImportParams params = new ImportParams();
|
|
|
params.setHeadRows(1);
|
|
|
+ String err="文件导入失败";
|
|
|
try {
|
|
|
List<DeviceAnalogVariableListImport> deviceAnalogVariableListImportList = ExcelImportUtil.importExcel(multipartFile.getInputStream(),
|
|
|
DeviceAnalogVariableListImport.class, params);
|
|
|
if (CollectionUtils.isNotEmpty(deviceAnalogVariableListImportList)){
|
|
|
+ int rot=0;
|
|
|
for (DeviceAnalogVariableListImport deviceAnalogVariableListImportLists:deviceAnalogVariableListImportList) {
|
|
|
DeviceAnalogVariableList deviceAnalogVariableList = BeanMapperUtils.map(deviceAnalogVariableListImportLists, DeviceAnalogVariableList.class);
|
|
|
deviceAnalogVariableList.setVariableCoding(deviceAnalogVariableListImportLists.getDeviceCode()+"_"+deviceAnalogVariableListImportLists.getVariableCoding());
|
|
|
deviceAnalogVariableList.setStatus(1);
|
|
|
deviceAnalogVariableList.setCreator(user.getUserName());
|
|
|
deviceAnalogVariableList.setCreateTime(new Date());
|
|
|
- this.save(deviceAnalogVariableList);
|
|
|
+ try{
|
|
|
+ this.save(deviceAnalogVariableList);
|
|
|
+ }catch (Exception e){
|
|
|
+ int h=rot+2;
|
|
|
+ err="文件导入失败,第"+h+"行数据导入失败";
|
|
|
+ throw new BusinessException(err);
|
|
|
+ }
|
|
|
+ rot++;
|
|
|
}
|
|
|
}else {
|
|
|
- throw new BusinessException("文件不能为空");
|
|
|
+ err="文件不能为空";
|
|
|
+ throw new BusinessException(err);
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
- throw new BusinessException("文件导入失败"+e.getMessage());
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ throw new BusinessException(err);
|
|
|
}
|
|
|
}
|
|
|
|