Commit 4655491f by kangxiaoshan

pd 附件上传

parent 81170a96
......@@ -177,6 +177,13 @@
<redis.event.port>6379</redis.event.port>
<redis.event.database>13</redis.event.database>
<!--Redis setting//end-->
<ddb.accesskey>AKIAOS2UEXIFNVER2O6A</ddb.accesskey>
<ddb.secretkey>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</ddb.secretkey>
<ddb.region>cn-north-1</ddb.region>
<ddb.upload.path>ry_manager_attach_dir</ddb.upload.path>
<ddb.bucket>reyundownload-test</ddb.bucket>
</properties>
</profile>
......@@ -278,6 +285,12 @@
<redis.event.port>6379</redis.event.port>
<redis.event.database>13</redis.event.database>
<!--Redis setting//end-->
<ddb.accesskey>AKIA3XXNRTS2KXU632MD</ddb.accesskey>
<ddb.secretkey>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</ddb.secretkey>
<ddb.region>cn-north-1</ddb.region>
<ddb.upload.path>ry_manager_attach_dir</ddb.upload.path>
<ddb.bucket>reyundownload</ddb.bucket>
</properties>
</profile>
</profiles>
......@@ -835,11 +848,11 @@
<artifactId>jcommander</artifactId>
<version>1.48</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.mchange</groupId>-->
<!-- <artifactId>c3p0</artifactId>-->
<!-- <version>0.9.5.2</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.mchange</groupId>-->
<!-- <artifactId>c3p0</artifactId>-->
<!-- <version>0.9.5.2</version>-->
<!-- </dependency>-->
</dependencies>
<!-- 配置构建 -->
......
package common.controller;
import common.model.PdIncome;
import common.model.User;
import common.service.DmpIncomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import security.annotation.CurrentAccount;
import util.ResultModel;
//私有化项目管理
@RestController
@RequestMapping("pd")
public class PdController {
@Autowired
DmpIncomeService dmpIncomeService;
//收入记录
@GetMapping("/income/list/bycode")
public ResultModel listByContract(String code) {
//按合同查询
return ResultModel.OK(dmpIncomeService.listpdIncomeByCode(code));
}
//录入收入
@PostMapping("/income/save")
public ResultModel create(@RequestBody PdIncome income, @CurrentAccount User account) {
//按合同查询
return ResultModel.OK(dmpIncomeService.pdCreate(income, account));
}
//更新
@PostMapping("/income/update")
public ResultModel update(@RequestBody PdIncome income, @CurrentAccount User account) {
//按合同查询
return ResultModel.OK(dmpIncomeService.pdUpdate(income));
}
//删除
@PostMapping("/income/delete")
public ResultModel delete(@RequestBody PdIncome income) {
//按合同查询
return ResultModel.OK(dmpIncomeService.pdDelete(income));
}
//上传附件
@PostMapping("/upload/attachment")
public ResultModel uploadAttach(@RequestParam("file") MultipartFile file, String contractCode, @CurrentAccount User user) {
return ResultModel.OK(dmpIncomeService.uploadPdAttach(file, contractCode, user));
}
//下载附加
@RequestMapping(value = "download/attachment/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<byte[]> getDownloadResponseEntity(@PathVariable Long id) {
return dmpIncomeService.downloadAttach(id);
}
//删除附件
@PostMapping("/delete/load/attachment/{id}")
public ResultModel deleteAttach(@PathVariable Long id) {
return ResultModel.OK(dmpIncomeService.deleteAttach(id));
}
}
......@@ -110,6 +110,9 @@ public class Contract {
private String businessTypeName; //业务类型 1 VIP 2 共管
private String agreementTypeName; //协议类型 1 普通协议 2 框架协议
private String productType; //产品类型
@Id
@GeneratedValue
public Long getId() {
......@@ -811,4 +814,12 @@ public class Contract {
public void setAgreementTypeName(String agreementTypeName) {
this.agreementTypeName = agreementTypeName;
}
public String getProductType() {
return productType;
}
public void setProductType(String productType) {
this.productType = productType;
}
}
package common.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.util.Date;
@Entity
public class PdAttachment {
private Long id;// ID
private String contractCode;//合同编号
private String fileOrginName;//原始文件名
private String fileName;//文件名
private String fileType;//文件类型
private Date uploadDate;//上传日期
private String uploadUser;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getContractCode() {
return contractCode;
}
public void setContractCode(String contractCode) {
this.contractCode = contractCode;
}
public String getFileOrginName() {
return fileOrginName;
}
public void setFileOrginName(String fileOrginName) {
this.fileOrginName = fileOrginName;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public Date getUploadDate() {
return uploadDate;
}
public void setUploadDate(Date uploadDate) {
this.uploadDate = uploadDate;
}
public String getUploadUser() {
return uploadUser;
}
public void setUploadUser(String uploadUser) {
this.uploadUser = uploadUser;
}
public String getFileType() {
return fileType;
}
public void setFileType(String fileType) {
this.fileType = fileType;
}
}
package common.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Transient;
import java.util.Date;
@Entity
public class PdIncome {
private Long id;// ID
private String contractCode;//合同编号
private String inputDate; //录入日期
private String settlementDate;//结算日期
private String incomeType;//收入类型
private String acceptanceAmount;//验收金额
private String taxRate;//税率
private String confirmIncome;//确认收入
private Date createTime;
private Date modifyTime;
private String inputUser;//录入人
//contract_code, my_body_name, customer_body, customer_short, business_type, agreement_type
private String myBodyName,
customerBody,
customerShort,
businessType,
agreementType;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getContractCode() {
return contractCode;
}
public void setContractCode(String contractCode) {
this.contractCode = contractCode;
}
public String getInputDate() {
return inputDate;
}
public void setInputDate(String inputDate) {
this.inputDate = inputDate;
}
public String getSettlementDate() {
return settlementDate;
}
public void setSettlementDate(String settlementDate) {
this.settlementDate = settlementDate;
}
public String getIncomeType() {
return incomeType;
}
public void setIncomeType(String incomeType) {
this.incomeType = incomeType;
}
public String getAcceptanceAmount() {
return acceptanceAmount;
}
public void setAcceptanceAmount(String acceptanceAmount) {
this.acceptanceAmount = acceptanceAmount;
}
public String getTaxRate() {
return taxRate;
}
public void setTaxRate(String taxRate) {
this.taxRate = taxRate;
}
public String getConfirmIncome() {
return confirmIncome;
}
public void setConfirmIncome(String confirmIncome) {
this.confirmIncome = confirmIncome;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getModifyTime() {
return modifyTime;
}
public void setModifyTime(Date modifyTime) {
this.modifyTime = modifyTime;
}
public String getInputUser() {
return inputUser;
}
public void setInputUser(String inputUser) {
this.inputUser = inputUser;
}
@Transient
public String getMyBodyName() {
return myBodyName;
}
public void setMyBodyName(String myBodyName) {
this.myBodyName = myBodyName;
}
@Transient
public String getCustomerBody() {
return customerBody;
}
public void setCustomerBody(String customerBody) {
this.customerBody = customerBody;
}
@Transient
public String getCustomerShort() {
return customerShort;
}
public void setCustomerShort(String customerShort) {
this.customerShort = customerShort;
}
@Transient
public String getBusinessType() {
return businessType;
}
public void setBusinessType(String businessType) {
this.businessType = businessType;
}
@Transient
public String getAgreementType() {
return agreementType;
}
public void setAgreementType(String agreementType) {
this.agreementType = agreementType;
}
}
package common.repository;
import common.model.PdAttachment;
import org.springframework.data.jpa.repository.JpaRepository;
public interface PdAttachmentRepository extends JpaRepository<PdAttachment, Long> {
}
package common.repository;
import common.model.PdIncome;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
public interface PdIncomeRepository extends JpaRepository<PdIncome, Long> {
@Query(value = "select * from pd_income where contract_code = ? order by input_date desc ",nativeQuery = true)
List<PdIncome> findByContractCode(String code);
}
package common.service;
import common.model.DmpIncome;
import common.model.PdAttachment;
import common.model.PdIncome;
import common.model.User;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.http.ResponseEntity;
import org.springframework.web.multipart.MultipartFile;
import tkio.model.Account;
import util.ResultModel;
import java.util.List;
......@@ -23,4 +27,18 @@ public interface DmpIncomeService {
ResultModel uploadFile(MultipartFile file, String platform, User loginAccount);
ResultModel contractUploadFile(MultipartFile file, String platform, User loginAccount);
List listpdIncomeByCode(String code);
PdIncome pdCreate(PdIncome income, User account);
PdIncome pdUpdate(PdIncome income);
int pdDelete(PdIncome income);
PdAttachment uploadPdAttach(MultipartFile file, String contractCode, User user);
ResponseEntity<byte[]> downloadAttach(Long id);
PdAttachment deleteAttach(Long id);
}
......@@ -4,6 +4,7 @@ package common.service.impl;
import common.model.*;
import common.repository.*;
import common.service.DmpIncomeService;
import org.apache.commons.io.IOUtils;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
......@@ -12,10 +13,14 @@ import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.StopWatch;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import util.AwsS3Util;
import util.Constant;
import util.ResultModel;
import java.io.IOException;
......@@ -57,6 +62,12 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
@Autowired
ContractBodyRepository contractBodyRepository;
@Autowired
PdIncomeRepository pdIncomeRepository;
@Autowired
PdAttachmentRepository pdAttachmentRepository;
public static final Map<String, String> SHEET_NAMES = new HashMap();
private static final Map<String, String> CONTRACT_TYPE_NAME = new HashMap();
......@@ -533,5 +544,102 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
return ResultModel.ERROR("第" + line + "行,[" + title + "]错误");
}
@Override
public List listpdIncomeByCode(String code) {
return pdIncomeRepository.findByContractCode(code);
}
@Override
public PdIncome pdCreate(PdIncome income, User user) {
income.setCreateTime(new Date());
income.setInputUser(user.getName());
return pdIncomeRepository.save(income);
}
@Override
public PdIncome pdUpdate(PdIncome income) {
PdIncome item = pdIncomeRepository.findOne(income.getId());
item.setModifyTime(new Date());
item.setAcceptanceAmount(income.getAcceptanceAmount());
item.setConfirmIncome(income.getConfirmIncome());
item.setInputDate(income.getInputDate());
item.setIncomeType(income.getIncomeType());
item.setTaxRate(income.getTaxRate());
pdIncomeRepository.save(item);
return item;
}
@Override
public int pdDelete(PdIncome income) {
pdIncomeRepository.delete(income.getId());
return 1;
}
@Override
public PdAttachment uploadPdAttach(MultipartFile file, String contractCode, User user) {
InputStream inputStream = null;
try {
inputStream = file.getInputStream();
PdAttachment attachment = new PdAttachment();
attachment.setUploadDate(new Date());
attachment.setUploadUser(user.getName());
attachment.setFileOrginName(file.getOriginalFilename());
attachment.setFileName(contractCode + "_" + file.getOriginalFilename());
attachment.setContractCode(contractCode);
attachment.setFileType(file.getContentType());
// 上传文件
String s3key = Constant.uploadPath + attachment.getFileName();
String contentType = file.getContentType();
AwsS3Util.getInstance().uploadStreamToS3(Constant.bucket, s3key,
inputStream, contentType, file.getSize());
pdAttachmentRepository.save(attachment);
return attachment;
} catch (IOException e) {
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
}
}
}
return null;
}
@Override
public ResponseEntity<byte[]> downloadAttach(Long id) {
PdAttachment attachment = pdAttachmentRepository.findOne(id);
final String s3key = Constant.uploadPath + attachment.getFileName();
String fileName = attachment.getFileOrginName();
InputStream in = null;
byte[] content;
String fileType = attachment.getFileType();
try {
in = AwsS3Util.getInstance().downloadStreamFromS3(Constant.bucket, s3key);
content = IOUtils.toByteArray(in);
HttpHeaders headers = new HttpHeaders();
headers.set("filename", fileName);
headers.add("content-disposition", "attachment; filename=" + fileName);
headers.add("Content-Type", fileType);
return new ResponseEntity<>(content, headers, org.springframework.http.HttpStatus.CREATED);
} catch (Exception e) {
logger.error("s3key:" + s3key + " bucket:" + Constant.bucket, e);
} finally {
IOUtils.closeQuietly(in);
}
return null;
}
@Override
public PdAttachment deleteAttach(Long id) {
PdAttachment attachment = pdAttachmentRepository.findOne(id);
final String s3key = Constant.uploadPath + attachment.getFileName();
AwsS3Util.getInstance().deleteS3Object(Constant.bucket, s3key);
pdAttachmentRepository.delete(id);
return attachment;
}
}
......@@ -71,6 +71,7 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter {
|| requestURL.indexOf("user/forget") != -1
|| requestURL.indexOf("user/code") != -1
|| requestURL.indexOf("txt2db") != -1
|| requestURL.indexOf("/open/account") != -1
|| requestURL.indexOf("/test/contract/flow") != -1
|| requestURL.indexOf("contract/build") != -1
|| requestURL.indexOf("accountmng/findSaleInfo") != -1) {
......
......@@ -32,8 +32,11 @@ public class AwsS3Util
private AmazonS3 s3;
private AwsS3Util() {
String accessKey = "AKIAPSKINGJFIZHEFNWQ";
String secretKey = "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";
/* String accessKey = "AKIAPSKINGJFIZHEFNWQ";
String secretKey = "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";*/
String accessKey = Constant.accessKey;
String secretKey = Constant.secretKey;
if ((accessKey != null) && (secretKey != null)) {
AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
......@@ -49,7 +52,7 @@ public class AwsS3Util
if (s3 == null)
s3 = new AmazonS3Client(credentials, config);
s3.setRegion(com.amazonaws.regions.Region.getRegion(Regions.CN_NORTH_1));
s3.setRegion(com.amazonaws.regions.Region.getRegion(Regions.fromName(Constant.ddbregion)));
}
}
......
......@@ -8,38 +8,43 @@ import java.util.ResourceBundle;
public class Constant {
public static String CURRENT_ACCOUNT = "$CURRENT_ACCOUNT$";
public static ResourceBundle mailBundle = ResourceBundle.getBundle("mail");
public static String mailHost = mailBundle.getString("mail.host");
public static String mailUsername = mailBundle.getString("mail.username");
public static String mailPassword = mailBundle.getString("mail.password");
public static String mailContentType = mailBundle.getString("mail.content_type");
public static String mailList = mailBundle.getString("mail.list");
public static String mailprod = mailBundle.getString("mail.prod");
public static String mailtestUser = mailBundle.getString("mail.test");
public static List<String> mlist = Arrays.asList(mailList.split(","));
public static String mailValidTime = mailBundle.getString("mail.valid_time");
public static ResourceBundle commonBundle = ResourceBundle.getBundle("common");
public static String reportUrl = commonBundle.getString("report.url");
public static String importTempUrl = commonBundle.getString("import.temp.url");
public static String adiUrl = commonBundle.getString("adi.url");
public static ResourceBundle redis = ResourceBundle.getBundle("redis");
public static String REDIS_KEY_VALID_TIME = redis.getString("redis.key.validtime");
public static String REDIS_IP_REQUEST_TIMES = redis.getString("redis.ip.requesttimes");
public static String REDIS_IP_UNKNOWN_REQUEST_TIMES = redis.getString("redis.ip.unknown.requesttimes");
public static ResourceBundle resourceBundle = ResourceBundle.getBundle("db");
public static String dburl = resourceBundle.getString("db.url");
public static String dbusername = resourceBundle.getString("db.username");
public static String dbpassword = resourceBundle.getString("db.password");
public static String dbdriver = resourceBundle.getString("db.driver");
public static Long tkioPriceLevelNotLimit = 20L;
public static String CURRENT_ACCOUNT = "$CURRENT_ACCOUNT$";
public static ResourceBundle mailBundle = ResourceBundle.getBundle("mail");
public static String mailHost = mailBundle.getString("mail.host");
public static String mailUsername = mailBundle.getString("mail.username");
public static String mailPassword = mailBundle.getString("mail.password");
public static String mailContentType = mailBundle.getString("mail.content_type");
public static String mailList = mailBundle.getString("mail.list");
public static String mailprod = mailBundle.getString("mail.prod");
public static String mailtestUser = mailBundle.getString("mail.test");
public static List<String> mlist = Arrays.asList(mailList.split(","));
public static String mailValidTime = mailBundle.getString("mail.valid_time");
public static ResourceBundle commonBundle = ResourceBundle.getBundle("common");
public static String reportUrl = commonBundle.getString("report.url");
public static String importTempUrl = commonBundle.getString("import.temp.url");
public static String adiUrl = commonBundle.getString("adi.url");
public static ResourceBundle redis = ResourceBundle.getBundle("redis");
public static String REDIS_KEY_VALID_TIME = redis.getString("redis.key.validtime");
public static String REDIS_IP_REQUEST_TIMES = redis.getString("redis.ip.requesttimes");
public static String REDIS_IP_UNKNOWN_REQUEST_TIMES = redis.getString("redis.ip.unknown.requesttimes");
public static ResourceBundle resourceBundle = ResourceBundle.getBundle("db");
public static String dburl = resourceBundle.getString("db.url");
public static String dbusername = resourceBundle.getString("db.username");
public static String dbpassword = resourceBundle.getString("db.password");
public static String dbdriver = resourceBundle.getString("db.driver");
public static Long tkioPriceLevelNotLimit = 20L;
public static ResourceBundle ddbBundle = ResourceBundle.getBundle("ddb");
public static String accessKey = ddbBundle.getString("ddb.accesskey");
public static String secretKey = ddbBundle.getString("ddb.secretkey");
public static String ddbregion = ddbBundle.getString("ddb.region");
public static String bucket = ddbBundle.getString("ddb.bucket");
public static String uploadPath = ddbBundle.getString("ddb.upload.path");
}
ddb.accesskey=${ddb.accesskey}
ddb.secretkey=${ddb.secretkey}
ddb.region=${ddb.region}
ddb.bucket=${ddb.bucket}
ddb.upload.path=${ddb.upload.path}
\ No newline at end of file
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