Commit 30f3cf35 authored by kevin's avatar kevin

#

parent 4fdea1d5
......@@ -5,29 +5,18 @@ import org.springframework.context.annotation.Configuration;
@Configuration
public class FileServiceConfig {
@Value("${file.server.url}")
private String serverUrl;
@Value("${file.server.upload}")
private String uploadUrl;
@Value("${file_upload_post_url}")
private String upload_post_url;
public String getUpload_post_url() {
return upload_post_url;
}
public void setUpload_post_url(String upload_post_url) {
this.upload_post_url = upload_post_url;
}
private String uploadUrl;
@Value("${file_upload_query_url}")
private String downloadUrl;
public String getServerUrl() {
return serverUrl;
public String getDownloadUrl() {
return downloadUrl;
}
public void setServerUrl(String serverUrl) {
this.serverUrl = serverUrl;
public void setDownloadUrl(String downloadUrl) {
this.downloadUrl = downloadUrl;
}
public String getUploadUrl() {
return uploadUrl;
}
......
......@@ -7,9 +7,14 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.ByteArrayBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.slf4j.Logger;
......@@ -18,11 +23,14 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.MultipartFile;
import pwc.taxtech.atms.common.CommonUtils;
import pwc.taxtech.atms.common.config.FileServiceConfig;
import pwc.taxtech.atms.dto.ApiResultDto;
import pwc.taxtech.atms.exception.ServiceException;
import java.io.IOException;
import java.net.URLEncoder;
import java.security.MessageDigest;
/**
* author kevin
......@@ -34,59 +42,58 @@ public class FileUploadUtil implements ApplicationContextAware {
// Spring应用上下文环境
private static ApplicationContext applicationContext;
private static FileServiceConfig config;
private static final String USER_TEMPLATE_PATH = "pwc/userTemplate/";
private static final String HTTP_HEADER = "application/json;charset=UTF-8";
private static final String HTTP_SUCCESS_CODE = "200";
public static String upload(MultipartFile file) throws ServiceException{
return upload( file, false);
}
protected static char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
public static String serverPath(boolean newUrl){
config = (FileServiceConfig)applicationContext.getBean("fileServiceConfig");
if(newUrl)
return config.getUpload_post_url();
return config.getServerUrl() + config.getUploadUrl();
public static String getUploadUrl() {
config = (FileServiceConfig) applicationContext.getBean("fileServiceConfig");
return config.getUploadUrl();
}
public static String serverPath(){
return serverPath(true);
public static String downLoadUrl() {
config = (FileServiceConfig) applicationContext.getBean("fileServiceConfig");
return config.getDownloadUrl();
}
/**
* 上传模板
*
* @param file MultipartFile
* @param fullPath 是否返回全路径 默认false ,如果为true返回的路径直接可以用于下载
* @return Boolean
*/
public static String upload( MultipartFile file, boolean fullPath) throws ServiceException {
public static String upload(MultipartFile file, String fileName) throws ServiceException {
if (StringUtils.isBlank(file.getOriginalFilename()) || null == file) {
throw new IllegalArgumentException("上传参数为空");
}
if (fileName == null) {
fileName = file.getOriginalFilename();
}
CloseableHttpClient httpClient = null;
String filePath = USER_TEMPLATE_PATH + file.getOriginalFilename();
String requestKey = CommonUtils.getUUID();
String requestUrl = getUploadUrl() + "/" + requestKey;
try {
String serverPath = serverPath();
/*String serverPath = serverPath();
httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(serverPath);
httpPost.addHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType());
JSONObject param = new JSONObject();
param.put("path", filePath);
param.put("file", file.getBytes());
HttpEntity httpEntity = new StringEntity(param.toJSONString(), ContentType.APPLICATION_JSON);
httpPost.addHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType());*/
httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(requestUrl);
String md5Str = getFileMD5String(file);
ByteArrayBody byteBody = new ByteArrayBody(file.getBytes(), ContentType.MULTIPART_FORM_DATA, StringUtils.isBlank(fileName) ? URLEncoder.encode(file.getOriginalFilename(), "UTF-8") : URLEncoder.encode(fileName, "UTF-8"));
StringBody md5 = new StringBody(md5Str, ContentType.create("text/plain"));
HttpEntity httpEntity = MultipartEntityBuilder.create().addPart("filecontent", byteBody).addPart("md5", md5).build();
httpPost.setEntity(httpEntity);
HttpResponse httpResponse = httpClient.execute(httpPost);
ApiResultDto resultDto = JSON.parseObject(IOUtils.toString(httpResponse.getEntity().getContent(), "UTF-8"), ApiResultDto.class);
if (resultDto.getCode() == ApiResultDto.SUCCESS) {
if(fullPath)
return config.getServerUrl() + "/" + filePath;
return filePath;
}
JSONObject resultDto = JSON.parseObject(IOUtils.toString(httpResponse.getEntity().getContent(), "UTF-8"));
if (HTTP_SUCCESS_CODE.equals(resultDto.getString("status_code")))
return requestKey;
return null;
} catch (Exception e) {
e.printStackTrace();
logger.error("uploadTemplate error.", e);
return null;
} finally {
if (null != httpClient) {
try {
......@@ -96,10 +103,23 @@ public class FileUploadUtil implements ApplicationContextAware {
}
}
}
throw new ServiceException("uploadTemplate error.");
}
public static boolean downLoad(String download_url) {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(downLoadUrl() + "/" + download_url);
HttpResponse httpResponse = null;
try {
httpResponse = httpClient.execute(httpGet);
JSONObject resultDto = JSON.parseObject(IOUtils.toString(httpResponse.getEntity().getContent(), "UTF-8"));
if (resultDto.getString("status_code").equals(HTTP_SUCCESS_CODE))
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
return false;
}
/**
......@@ -110,10 +130,35 @@ public class FileUploadUtil implements ApplicationContextAware {
public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
/**
* @return ApplicationContext
*/
public static ApplicationContext getApplicationContext() {
return applicationContext;
}
public static String getFileMD5String(MultipartFile file) throws Exception {
MessageDigest messagedigest = MessageDigest.getInstance("MD5");
messagedigest.update(file.getBytes());
byte bytes[] = messagedigest.digest();
return bufferToHex(bytes, 0, bytes.length);
}
private static String bufferToHex(byte bytes[], int m, int n) {
StringBuffer stringbuffer = new StringBuffer(2 * n);
int k = m + n;
for (int l = m; l < k; l++) {
appendHexPair(bytes[l], stringbuffer);
}
return stringbuffer.toString();
}
private static void appendHexPair(byte bt, StringBuffer stringbuffer) {
char c0 = hexDigits[(bt & 0xf0) >> 4];
char c1 = hexDigits[bt & 0xf];
stringbuffer.append(c0);
stringbuffer.append(c1);
}
}
......@@ -6,6 +6,7 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import pwc.taxtech.atms.common.util.FileUploadUtil;
import pwc.taxtech.atms.constant.enums.EnumServiceType;
import pwc.taxtech.atms.dao.OrganizationMapper;
import pwc.taxtech.atms.dao.ProjectMapper;
......@@ -16,6 +17,7 @@ import pwc.taxtech.atms.entity.OrganizationExample;
import pwc.taxtech.atms.entity.Project;
import pwc.taxtech.atms.entity.ProjectExample;
import pwc.taxtech.atms.service.impl.DataImportService;
import pwc.taxtech.atms.vat.dao.PwcReportAttachMapper;
import pwc.taxtech.atms.vat.entity.*;
import pwc.taxtech.atms.vat.service.impl.ReportServiceImpl;
......@@ -224,6 +226,21 @@ public class ReportController {
return reportService.deleteAttach(id);
}
@Autowired
private PwcReportAttachMapper pwcReportAttachMapper;
@RequestMapping("")
public OperationResultDto downLoadAttach(Long id){
OperationResultDto operationResultDto = new OperationResultDto();
PwcReportAttachExample example = new PwcReportAttachExample();
PwcReportAttachExample.Criteria criteria = example.createCriteria();
criteria.andIdEqualTo(id);
if(FileUploadUtil.downLoad(pwcReportAttachMapper.selectByExample(example).get(0).getFileUrl()) == true){
return operationResultDto.success();
};
operationResultDto.setResultMsg("附件导出失败");
return operationResultDto;
}
@Autowired
private OrganizationMapper organizationMapper;
......
......@@ -52,7 +52,7 @@ public class HttpFileService extends BaseService {
CloseableHttpClient httpClient = null;
String filePath = USER_TEMPLATE_PATH + fileName;
try {
String serverPath = config.getServerUrl() + config.getUploadUrl();
String serverPath = config.getUploadUrl();
httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(serverPath);
httpPost.addHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType());
......@@ -68,7 +68,7 @@ public class HttpFileService extends BaseService {
ApiResultDto resultDto = JSON.parseObject(IOUtils.toString(httpResponse.getEntity().getContent(), "UTF-8"), ApiResultDto.class);
if (resultDto.getCode() == ApiResultDto.SUCCESS) {
if(fullPath){
return config.getServerUrl() + "/" + filePath;
return config.getUploadUrl() + "/" + filePath;
}
return filePath;
}
......@@ -101,14 +101,14 @@ public class HttpFileService extends BaseService {
if (StringUtils.isBlank(filePath)) {
return null;
}
if (StringUtils.isNotBlank(config.getServerUrl())) {
if (StringUtils.isNotBlank(config.getDownloadUrl())) {
CloseableHttpClient client = HttpClients.createDefault();
//先判断下是否是全域名 全域名代表是didi服务器url
String url;
if(filePath.indexOf("http")>=0){
url = filePath;
}else{
url = StringUtils.appendIfMissing(config.getServerUrl(), "/") + filePath;
url = StringUtils.appendIfMissing(config.getDownloadUrl(), "/") + filePath;
}
HttpGet httpGet = new HttpGet(url);
CloseableHttpResponse response = null;
......
......@@ -238,8 +238,14 @@ public class TemplateGroupServiceImpl extends AbstractService {
ebitCellData.setRow(m);
ebitCellData.setCreateTime(now);
try {
if(sheet.getRow(m).getCell(j) != null)
if(sheet.getRow(m).getCell(j) != null){
if(CellType.STRING == sheet.getRow(m).getCell(j).getCellTypeEnum()){
ebitCellData.setData(sheet.getRow(m).getCell(j).getStringCellValue());
}else if (CellType.NUMERIC == sheet.getRow(m).getCell(j).getCellTypeEnum()){
ebitCellData.setData(String.valueOf(sheet.getRow(m).getCell(j).getNumericCellValue()));
}
}
}catch (Exception e){
//遇到空行,略过
}
......
......@@ -2096,7 +2096,7 @@ public class ReportServiceImpl extends BaseService {
fileDto.setRemarks(remarks);
}
fileDto.setFileUrl(FileUploadUtil.upload(file, true));
fileDto.setFileUrl(FileUploadUtil.upload(file, null));
//绑定
fileDto.setSize(String.valueOf(file.getSize() / 1024) + "KB");
fileDto.setUploadUser(authUserHelper.getCurrentAuditor().get());
......
analysisModule.controller('tableReportSheetController', ['$scope', '$rootScope', '$log', '$translate', '$timeout', '$q', '$compile', '$state', '$stateParams',
'apiInterceptor', 'vatExportService', 'SweetAlert', 'BSPLService', 'vatReportService', 'vatReportCacheService', 'vatSessionService',
'loginContext', 'enums', 'vatCommonService', 'vatWorkflowService', 'projectService', '$uibModal', '$cookies', 'Upload', 'vatImportService', 'vatApproveService','region',
'loginContext', 'enums', 'vatCommonService', 'vatWorkflowService', 'projectService', '$uibModal', '$cookies', 'Upload', 'vatImportService', 'vatApproveService','region','$http',
function ($scope, $rootScope, $log, $translate, $timeout, $q, $compile, $state, $stateParams, apiInterceptor, vatExportService, SweetAlert, BSPLService,
vatReportService, vatReportCacheService, vatSessionService, loginContext, enums, vatCommonService, vatWorkflowService, projectService,
$uibModal, $cookies, Upload, vatImportService, vatApproveService, region) {
$uibModal, $cookies, Upload, vatImportService, vatApproveService, region, $http) {
'use strict';
$log.debug('VatReportViewController.ctor()...');
......@@ -2883,7 +2883,7 @@
var date = new Date();
var year = date.getFullYear();
var mon = date.getMonth()+ 1;
$scope.selectedDate = new Date(year, date.getMonth() + 1, 1);
$scope.selectedDate = new Date(year, date.getMonth() , 1);
$scope.startDate = new Date(year - 20, 1, 1);
$scope.endDate = new Date(year + 20, 1, 1);
var ele1 = $("#ebitDatepacker");
......@@ -2925,6 +2925,8 @@
}).error(function(error){
});
}
//将spread保存到数据库
$scope.$watch('file', function (file) {
$scope.upload($scope.file);
......@@ -2952,7 +2954,6 @@
.progress(function (evt) {
})
.success(function (data, status, headers, config) {
debugger;
if(data.result){
frontImport(file);//前端导入
$('#busy-indicator-container').hide();
......@@ -2971,6 +2972,40 @@
SweetAlert.error(status + "上传失败")
})
};
//加载Ebit数据
$scope.relation.loadEbitCell = function (sheet) {
if(($scope.relation.data == null))
return;
for (var r = 37; r <= 43; r++) {
//sheet.setFormatter(r, 1, '# ??/??');//设置格式
if (r == 37) {
sheet.setValue(r, 1, PWC.tryParseStringToNum($scope.relation.data.ebitSubtraction != null ? $scope.relation.data.ebitSubtraction : ""));
}
if (r == 38) {
sheet.setValue(r, 1, PWC.tryParseStringToNum($scope.relation.data.specialConsiderations != null ? $scope.relation.data.specialConsiderations : ""));
}
if (r == 39) {
sheet.setValue(r, 1, PWC.tryParseStringToNum($scope.relation.data.specialFactors != null ? $scope.relation.data.specialFactors : ""));
}
if (r == 40) {
sheet.setValue(r, 1, PWC.tryParseStringToNum($scope.relation.data.ebitRate != null ? $scope.relation.data.ebitRate : ""));
}
if (r == 41) {
sheet.setValue(r, 1, PWC.tryParseStringToNum($scope.relation.data.transactionAmount != null ? $scope.relation.data.transactionAmount : ""));
}
if (r == 42) {
sheet.setValue(r, 1, PWC.tryParseStringToNum($scope.relation.data.sixAddTa != null ? $scope.relation.data.sixAddTa : ""));
}
if (r == 43) {
sheet.setValue(r, 1, PWC.tryParseStringToNum($scope.relation.data.totalAmountTax != null ? $scope.relation.data.totalAmountTax : ""));
}
sheet.setFormatter(r, 1, '# ?/?');
}
}
//前端导入
var frontImport = function(file){
......@@ -3000,7 +3035,7 @@
// here is excel IO API
excelIo.save(json, function (blob) {
saveAs(blob, $scope.relation.orgName != undefined ? $scope.relation.orgName : "" + $scope.relation.period + fileName);
saveAs(blob, ($scope.relation.orgName != undefined ? $scope.relation.orgName : "" + $scope.relation.period) + fileName);
}, function (e) {
// process error
console.log(e);
......@@ -3069,7 +3104,8 @@
searchEnabled: true,
noDataText: $translate.instant('RevenueNoOrgData'),
showSelectionControls: false,
onInitialized : function(){
onInitialized : function(e){
},
onItemClick: function (e) {
loadCellData($scope.relation.period, e.itemData.id,function(){
......@@ -3079,6 +3115,7 @@
}
};
$scope.$watch('relation._orgId', function(n, o){
if(n != undefined )
$scope.relation.orgId = n.pop();
});
......
......@@ -2487,7 +2487,7 @@
{
caption: '文件名', dataField: "fileName", cellTemplate: function (container, options) {
try {
$('<a href="' + options.data.fileUrl + '" target="_blank" style="cursor: pointer">"' + options.data.fileName + '"</a>&nbsp;&nbsp;')
$('<a href="javascript:;" onClick = "downLoadAttach('+options.data.id+')" target="_blank" style="cursor: pointer">"' + options.data.fileName + '"</a>&nbsp;&nbsp;')
.appendTo(container);
}
catch (e) {
......@@ -2526,26 +2526,23 @@
dataSource: '_gridData'
}
};
window.downLoadAttach = function(id){
vatReportService.downLoadAttach(id).success(function (res) {
if(res.result){
//导出成功
}else{
SweetAlert.error(res.resultMsg);
}
}).error();
}
window.deleteAttach = function (id, data) {
swal({
title: "warning!",
text: "确定删除该附件?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: $translate.instant('Yes'),
cancelButtonText: $translate.instant('No'),
closeOnConfirm: true,
closeOnCancel: true
},
function (tmpConfirm) {
PWC.warning("警告", "确定删除该附件?" , function (tmpConfirm) {
if (tmpConfirm) {
vatReportService.deleteAttach(id).success(function (res) {
if (res.resultMsg == "success") {
$scope.loadAttach();
}
});
}
});
}
......
......@@ -23,7 +23,7 @@
<span ng-show="detail.validationErrorList && detail.validationErrorList.length > 0" ng-model="tabType"
uib-btn-radio="3"><i class="fa fa-exclamation-circle red-color"></i>{{'ReportCheckResult' | translate}}</span>
<span ng-model="tabType" uib-btn-radio="4">{{'cellComment'|translate}}</span>
<span ng-model="tabType" uib-btn-radio="5" ng-click = "loadAttach()">{{'RelatedAttach'|translate}}</span>
<span ng-model="tabType" uib-btn-radio="5" ng-click = "loadAttach()">{{'RelatedAttach'|translate}} dsdsdsdssd</span>
</div>
<div class="content-info" ng-show="tabType === 1">
......
......@@ -1128,7 +1128,36 @@
}, {});
}
});
}
};
PWC.warning = function(title, text, callback){
swal({
title: title,
text: text,
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: $translate.instant('Yes'),
cancelButtonText: $translate.instant('No'),
closeOnConfirm: true,
closeOnCancel: true
},
callback);
};
PWC.alert = function(title, text, callback){
swal({
title: title,
text: text,
type: "info",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: $translate.instant('Yes'),
cancelButtonText: $translate.instant('No'),
closeOnConfirm: true,
closeOnCancel: true
},
callback);
};
/------------------------------------------------kevin insert -----------------------------------/
......
......@@ -242,6 +242,9 @@
},
saveEbitModule: function () {
},
downLoadAttach : function(id){
return $http.get('/Report/downLoadAttach?id=' + id);
}
};
......
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