开具发票
This commit is contained in:
parent
19710e3080
commit
a26dd232d7
6
pom.xml
6
pom.xml
@ -265,6 +265,12 @@
|
||||
<version>3.4.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.sun.mail</groupId>
|
||||
<artifactId>javax.mail</artifactId>
|
||||
<version>1.6.2</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.xkrs.allinpay;
|
||||
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.xkrs.allinpay.model.*;
|
||||
import com.xkrs.allinpay.utils.QRCodeUtils;
|
||||
import com.xkrs.allinpay.utils.SybConstants;
|
||||
import com.xkrs.allinpay.utils.SybUtil;
|
||||
import com.xkrs.allinpay.utils.*;
|
||||
import com.xkrs.common.encapsulation.PromptMessageEnum;
|
||||
import com.xkrs.common.tool.TokenUtil;
|
||||
import com.xkrs.dao.SysUserDao;
|
||||
@ -21,6 +21,7 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
@ -50,6 +51,12 @@ public class SybPayController {
|
||||
@Value("${qrCode.accessDirPath}")
|
||||
public String qrCodeAccessDirPath;
|
||||
|
||||
@Value("${invoice.saveDirPath}")
|
||||
public String invoiceSaveDirPath;
|
||||
|
||||
@Value("${invoice.accessDirPath}")
|
||||
public String invoiceAccessDirPath;
|
||||
|
||||
@Value("${pay.notifyUrl}")
|
||||
public String payNotifyUrl;
|
||||
|
||||
@ -102,6 +109,8 @@ public class SybPayController {
|
||||
SybPayService service = new SybPayService();
|
||||
Map<String, String> queryMap = service.query("", trxid);
|
||||
TranQueryEntity tranQueryEntity = TranQueryUtils.getEntityByMap(queryMap);
|
||||
tranQueryEntity.setInvoiceStatus(InvoiceStatus.unInvoiced.getValue());//默认未开具发票
|
||||
tranQueryEntity.setInvoicePath("");
|
||||
UnitOrderPayEntity unitOrderPay = getUnitOrderPayByTranQuery(tranQueryEntity);
|
||||
if (unitOrderPay != null) {
|
||||
tranQueryEntity.setOrderid(unitOrderPay.getId());
|
||||
@ -345,14 +354,14 @@ public class SybPayController {
|
||||
pageSizeInt = Integer.parseInt(pageSize);
|
||||
}
|
||||
//查询交易记录
|
||||
List<Map<String, String>> queryTranVoList = new LinkedList<>();
|
||||
List<Map<String, Object>> queryTranVoList = new LinkedList<>();
|
||||
if ("管理员".equals(sysUserEntity.getAccountType())) {
|
||||
System.out.println("管理员查" + (StrUtil.isEmpty(userName) ? "全部" : userName));
|
||||
List<Map<String, String>> list = tranQueryDao.queryTranByAdmin(StrUtil.isEmpty(userName) ? "" : userName, pageNumInt, pageSizeInt);
|
||||
List<Map<String, Object>> list = tranQueryDao.queryTranByAdmin(StrUtil.isEmpty(userName) ? "" : userName, pageNumInt, pageSizeInt);
|
||||
queryTranVoList.addAll(list);
|
||||
} else {
|
||||
System.out.println(sysUserEntity.getUserName() + "查自己");
|
||||
List<Map<String, String>> list = tranQueryDao.queryTran(sysUserEntity.getId(), pageNumInt, pageSizeInt);
|
||||
List<Map<String, Object>> list = tranQueryDao.queryTran(sysUserEntity.getId(), pageNumInt, pageSizeInt);
|
||||
queryTranVoList.addAll(list);
|
||||
}
|
||||
List<QueryTran> collect = queryTranVoList.stream().map(TranQueryUtils::transform).collect(Collectors.toList());
|
||||
@ -394,4 +403,59 @@ public class SybPayController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 申请开具发票
|
||||
*/
|
||||
@PostMapping("/apply_invoice")
|
||||
public String applyInvoice(@RequestBody ApplyInvoiceQo applyInvoiceQo) {
|
||||
try {
|
||||
Long id = applyInvoiceQo.getId();
|
||||
TranQueryEntity tranQueryEntity = tranQueryDao.findById(id).get();
|
||||
|
||||
tranQueryEntity.setInvoiceStatus(InvoiceStatus.inInvoicing.getValue());
|
||||
tranQueryDao.saveAndFlush(tranQueryEntity);
|
||||
|
||||
List<String> collect = tranQueryDao.queryTranById(id).stream()//
|
||||
.map(TranQueryUtils::transform)//
|
||||
.map(queryTran -> "姓名:" + queryTran.getReallyname() + "\n" +//
|
||||
"商品名称:" + queryTran.getBody() + "\n" +//
|
||||
"支付金额:" + queryTran.getTrxamt() + "\n" +//
|
||||
"支付时间:" + queryTran.getFintime() + "\n")//
|
||||
.collect(Collectors.toList());
|
||||
EmailUtils.sendEmail("全国火订单开具发票提醒邮件", CollUtil.join(collect, ","));
|
||||
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "申请开具发票提交成功", locale);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "申请开具发票提交失败", locale);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布发票
|
||||
*/
|
||||
@PostMapping("/publish_invoice")
|
||||
public String publishInvoice(PublishInvoiceQo publishInvoiceQo, @RequestParam(value = "file") MultipartFile file) throws IOException {
|
||||
|
||||
Long id = publishInvoiceQo.getId();
|
||||
TranQueryEntity tranQueryEntity = tranQueryDao.findById(id).get();
|
||||
|
||||
FileUploadPath uploadPath = new FileUploadPath(invoiceSaveDirPath, invoiceAccessDirPath);
|
||||
String reqsn = tranQueryEntity.getReqsn();
|
||||
String trxamt = tranQueryEntity.getTrxamt();
|
||||
String extName = FileUtil.extName(file.getOriginalFilename());
|
||||
String filePath = FileUploadUtils.uploadFile(file, uploadPath, null, reqsn + "_" + trxamt + "." + extName);
|
||||
|
||||
tranQueryEntity.setInvoiceStatus(InvoiceStatus.invoiced.getValue());
|
||||
tranQueryEntity.setInvoicePath(filePath);
|
||||
tranQueryDao.saveAndFlush(tranQueryEntity);
|
||||
|
||||
Long orderid = tranQueryEntity.getOrderid();
|
||||
Integer userId = unitOrderPayDao.findById(orderid).get().getUserId();
|
||||
SysUserEntity sysUserEntity = sysUserDao.findById(userId).get();
|
||||
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "上传发票成功", locale);
|
||||
}
|
||||
|
||||
}
|
||||
|
23
src/main/java/com/xkrs/allinpay/model/ApplyInvoiceQo.java
Normal file
23
src/main/java/com/xkrs/allinpay/model/ApplyInvoiceQo.java
Normal file
@ -0,0 +1,23 @@
|
||||
package com.xkrs.allinpay.model;
|
||||
|
||||
/**
|
||||
* 申请发票
|
||||
*/
|
||||
public class ApplyInvoiceQo {
|
||||
|
||||
/**
|
||||
* TranQueryEntity实体类的主键ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
public ApplyInvoiceQo() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
25
src/main/java/com/xkrs/allinpay/model/InvoiceStatus.java
Normal file
25
src/main/java/com/xkrs/allinpay/model/InvoiceStatus.java
Normal file
@ -0,0 +1,25 @@
|
||||
package com.xkrs.allinpay.model;
|
||||
|
||||
/**
|
||||
* 开具发票 状态枚举
|
||||
*/
|
||||
public enum InvoiceStatus {
|
||||
|
||||
unInvoiced("未开具发票"),
|
||||
|
||||
inInvoicing("开具发票中"),
|
||||
|
||||
invoiced("已开具发票"),
|
||||
|
||||
failure("开具发票失败");
|
||||
|
||||
private final String value;
|
||||
|
||||
InvoiceStatus(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
23
src/main/java/com/xkrs/allinpay/model/PublishInvoiceQo.java
Normal file
23
src/main/java/com/xkrs/allinpay/model/PublishInvoiceQo.java
Normal file
@ -0,0 +1,23 @@
|
||||
package com.xkrs.allinpay.model;
|
||||
|
||||
/**
|
||||
* 发布发票
|
||||
*/
|
||||
public class PublishInvoiceQo {
|
||||
|
||||
/**
|
||||
* TranQueryEntity实体类的主键ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
public PublishInvoiceQo() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
@ -2,8 +2,11 @@ package com.xkrs.allinpay.model;
|
||||
|
||||
public class QueryTran {
|
||||
|
||||
private Long id;
|
||||
private String trxid;
|
||||
private String reqsn;
|
||||
private String invoiceStatus;
|
||||
private String invoicePath;
|
||||
private String username;
|
||||
private String reallyname;
|
||||
private String body;
|
||||
@ -14,6 +17,14 @@ public class QueryTran {
|
||||
public QueryTran() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTrxid() {
|
||||
return trxid;
|
||||
}
|
||||
@ -30,6 +41,22 @@ public class QueryTran {
|
||||
this.reqsn = reqsn;
|
||||
}
|
||||
|
||||
public String getInvoiceStatus() {
|
||||
return invoiceStatus;
|
||||
}
|
||||
|
||||
public void setInvoiceStatus(String invoiceStatus) {
|
||||
this.invoiceStatus = invoiceStatus;
|
||||
}
|
||||
|
||||
public String getInvoicePath() {
|
||||
return invoicePath;
|
||||
}
|
||||
|
||||
public void setInvoicePath(String invoicePath) {
|
||||
this.invoicePath = invoicePath;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
@ -117,6 +117,14 @@ public class TranQueryEntity implements Serializable {
|
||||
* 通联渠道侧OPENID
|
||||
*/
|
||||
private String tlopenid;
|
||||
/**
|
||||
* 开具发票状态
|
||||
*/
|
||||
private String invoiceStatus;
|
||||
/**
|
||||
* 开具发票路径
|
||||
*/
|
||||
private String invoicePath;
|
||||
|
||||
public TranQueryEntity() {
|
||||
}
|
||||
@ -328,4 +336,20 @@ public class TranQueryEntity implements Serializable {
|
||||
public void setTlopenid(String tlopenid) {
|
||||
this.tlopenid = tlopenid;
|
||||
}
|
||||
|
||||
public String getInvoiceStatus() {
|
||||
return invoiceStatus;
|
||||
}
|
||||
|
||||
public void setInvoiceStatus(String invoiceStatus) {
|
||||
this.invoiceStatus = invoiceStatus;
|
||||
}
|
||||
|
||||
public String getInvoicePath() {
|
||||
return invoicePath;
|
||||
}
|
||||
|
||||
public void setInvoicePath(String invoicePath) {
|
||||
this.invoicePath = invoicePath;
|
||||
}
|
||||
}
|
||||
|
@ -71,16 +71,19 @@ public class TranQueryUtils {
|
||||
private static final SimpleDateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
private static final DecimalFormat decimalFormat = new DecimalFormat("0.00");
|
||||
|
||||
public static QueryTran transform(Map<String, String> queryTranVo) {
|
||||
public static QueryTran transform(Map<String, Object> queryTranVo) {
|
||||
|
||||
String trxid = queryTranVo.get("trxid");
|
||||
String reqsn = queryTranVo.get("reqsn");
|
||||
String username = queryTranVo.get("username");
|
||||
String reallyname = queryTranVo.get("reallyname");
|
||||
String body = queryTranVo.get("body");
|
||||
String trxamt = queryTranVo.get("trxamt");
|
||||
String fintime = queryTranVo.get("fintime");
|
||||
String trxstatus = queryTranVo.get("trxstatus");
|
||||
Long id = (Long) queryTranVo.get("id");
|
||||
String trxid = (String) queryTranVo.get("trxid");
|
||||
String reqsn = (String) queryTranVo.get("reqsn");
|
||||
String invoiceStatus = (String) queryTranVo.get("invoiceStatus");
|
||||
String invoicePath = (String) queryTranVo.get("invoicePath");
|
||||
String username = (String) queryTranVo.get("username");
|
||||
String reallyname = (String) queryTranVo.get("reallyname");
|
||||
String body = (String) queryTranVo.get("body");
|
||||
String trxamt = (String) queryTranVo.get("trxamt");
|
||||
String fintime = (String) queryTranVo.get("fintime");
|
||||
String trxstatus = (String) queryTranVo.get("trxstatus");
|
||||
|
||||
String finishTime = "";
|
||||
try {
|
||||
@ -91,15 +94,17 @@ public class TranQueryUtils {
|
||||
|
||||
QueryTran queryTran = new QueryTran();
|
||||
|
||||
queryTran.setId(id);
|
||||
queryTran.setTrxid(trxid);
|
||||
queryTran.setReqsn(reqsn);
|
||||
queryTran.setInvoiceStatus(invoiceStatus);
|
||||
queryTran.setInvoicePath(invoicePath);
|
||||
queryTran.setUsername(username);
|
||||
queryTran.setReallyname(reallyname);
|
||||
queryTran.setBody(body);
|
||||
queryTran.setTrxamt("¥" + decimalFormat.format(Long.parseLong(trxamt) / 100.0D));
|
||||
queryTran.setFintime(finishTime);
|
||||
queryTran.setTrxstatus("0000".equals(trxstatus) ? "支付成功" : "支付失败");
|
||||
|
||||
return queryTran;
|
||||
}
|
||||
|
||||
|
54
src/main/java/com/xkrs/allinpay/utils/EmailUtils.java
Normal file
54
src/main/java/com/xkrs/allinpay/utils/EmailUtils.java
Normal file
@ -0,0 +1,54 @@
|
||||
package com.xkrs.allinpay.utils;
|
||||
|
||||
import javax.mail.*;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* 发邮件工具类
|
||||
*/
|
||||
public class EmailUtils {
|
||||
|
||||
public static void sendEmail(String title, String content) {
|
||||
// 发件人邮箱
|
||||
final String fromEmail = "1248302679@qq.com";
|
||||
// 邮箱密码或授权码(视邮箱服务商要求)
|
||||
final String password = "cjuoxuycyxxzbaah";
|
||||
// 收件人邮箱
|
||||
// final String toEmail = "it@star-rising.com";
|
||||
final String toEmail = "liuchengqian@star-rising.com";
|
||||
|
||||
// 配置 SMTP 服务器属性
|
||||
Properties properties = new Properties();
|
||||
properties.put("mail.smtp.host", "smtp.qq.com"); // SMTP 主机名(如 Gmail: smtp.gmail.com)
|
||||
properties.put("mail.smtp.port", "587"); // SMTP 端口号
|
||||
properties.put("mail.smtp.auth", "true"); // 是否需要认证
|
||||
properties.put("mail.smtp.starttls.enable", "true"); // 启用 STARTTLS
|
||||
|
||||
// 创建会话
|
||||
Session session = Session.getInstance(properties, new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(fromEmail, password);
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
// 创建邮件内容
|
||||
Message message = new MimeMessage(session);
|
||||
message.setFrom(new InternetAddress(fromEmail)); // 设置发件人
|
||||
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toEmail)); // 设置收件人
|
||||
message.setSubject(title); // 设置邮件主题
|
||||
message.setText(content); // 设置邮件正文
|
||||
|
||||
// 发送邮件
|
||||
Transport.send(message);
|
||||
System.out.println("邮件发送成功!");
|
||||
} catch (MessagingException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("邮件发送失败!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -15,6 +15,11 @@ public class FileUploadPath {
|
||||
public FileUploadPath() {
|
||||
}
|
||||
|
||||
public FileUploadPath(String uploadPath, String accessPath) {
|
||||
this.uploadPath = uploadPath;
|
||||
this.accessPath = accessPath;
|
||||
}
|
||||
|
||||
public String getUploadPath() {
|
||||
return uploadPath;
|
||||
}
|
||||
|
@ -20,8 +20,8 @@ public interface TranQueryDao extends JpaRepository<TranQueryEntity, Long>, JpaS
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
@Query(value = "SELECT q.trxid, q.reqsn, u.user_name AS username, u.really_name AS reallyname, o.body, q.trxamt, q.fintime, q.trxstatus FROM tran_query AS q LEFT JOIN unit_order_pay AS o ON q.orderid = o.id LEFT JOIN sys_user AS u ON o.user_id = u.id WHERE u.id = ?1 ORDER BY q.fintime DESC LIMIT ?3 OFFSET (?2 - 1) * ?3", nativeQuery = true)
|
||||
List<Map<String, String>> queryTran(int userId, int pageNum, int pageSize);
|
||||
@Query(value = "SELECT q.id, q.trxid, q.reqsn, q.invoice_status AS invoiceStatus, q.invoice_path AS invoicePath, u.user_name AS username, u.really_name AS reallyname, o.body, q.trxamt, q.fintime, q.trxstatus FROM tran_query AS q LEFT JOIN unit_order_pay AS o ON q.orderid = o.id LEFT JOIN sys_user AS u ON o.user_id = u.id WHERE u.id = ?1 ORDER BY q.fintime DESC LIMIT ?3 OFFSET (?2 - 1) * ?3", nativeQuery = true)
|
||||
List<Map<String, Object>> queryTran(int userId, int pageNum, int pageSize);
|
||||
|
||||
/**
|
||||
* 管理员查询订单
|
||||
@ -31,7 +31,16 @@ public interface TranQueryDao extends JpaRepository<TranQueryEntity, Long>, JpaS
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
@Query(value = "SELECT q.trxid, q.reqsn, u.user_name AS username, u.really_name AS reallyname, o.body, q.trxamt, q.fintime, q.trxstatus FROM tran_query AS q LEFT JOIN unit_order_pay AS o ON q.orderid = o.id LEFT JOIN sys_user AS u ON o.user_id = u.id WHERE u.user_name LIKE %?1% ORDER BY q.fintime DESC LIMIT ?3 OFFSET (?2 - 1) * ?3", nativeQuery = true)
|
||||
List<Map<String, String>> queryTranByAdmin(String userName, int pageNum, int pageSize);
|
||||
@Query(value = "SELECT q.id, q.trxid, q.reqsn, q.invoice_status AS invoiceStatus, q.invoice_path AS invoicePath, u.user_name AS username, u.really_name AS reallyname, o.body, q.trxamt, q.fintime, q.trxstatus FROM tran_query AS q LEFT JOIN unit_order_pay AS o ON q.orderid = o.id LEFT JOIN sys_user AS u ON o.user_id = u.id WHERE u.user_name LIKE %?1% ORDER BY q.fintime DESC LIMIT ?3 OFFSET (?2 - 1) * ?3", nativeQuery = true)
|
||||
List<Map<String, Object>> queryTranByAdmin(String userName, int pageNum, int pageSize);
|
||||
|
||||
/**
|
||||
* 根据TranQueryEntity实体类的id查询订单
|
||||
*
|
||||
* @param id TranQueryEntity实体类的主键ID
|
||||
* @return 订单
|
||||
*/
|
||||
@Query(value = "SELECT q.id, q.trxid, q.reqsn, q.invoice_status AS invoiceStatus, q.invoice_path AS invoicePath, u.user_name AS username, u.really_name AS reallyname, o.body, q.trxamt, q.fintime, q.trxstatus FROM tran_query AS q LEFT JOIN unit_order_pay AS o ON q.orderid = o.id LEFT JOIN sys_user AS u ON o.user_id = u.id WHERE q.id = ?1", nativeQuery = true)
|
||||
List<Map<String, Object>> queryTranById(Long id);
|
||||
|
||||
}
|
||||
|
@ -81,7 +81,12 @@ logging.level.org.springframework.web.servlet.DispatcherServlet=DEBUG
|
||||
|
||||
qrCode.saveDirPath = /home/lcq/server/fire_point_allinpay/qrCode
|
||||
qrCode.accessDirPath = qrCode
|
||||
invoice.saveDirPath = /home/lcq/server/fire_point_allinpay/invoice
|
||||
invoice.accessDirPath = invoice
|
||||
pay.notifyUrl = http://8.142.26.238:7801/pay/notify
|
||||
|
||||
#qrCode.saveDirPath = C:\\Users\\ADMIN\\Desktop\\qrCode
|
||||
#qrCode.accessDirPath = qrCode
|
||||
#invoice.saveDirPath = C:\\Users\\ADMIN\\Desktop\\invoice
|
||||
#invoice.accessDirPath = invoice
|
||||
#pay.notifyUrl = http://localhost:7801/pay/notify
|
Loading…
x
Reference in New Issue
Block a user