ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TBillController.java
@@ -6,17 +6,19 @@ import com.ruoyi.common.exception.ServiceException; import com.ruoyi.system.dto.*; import com.ruoyi.system.model.TBill; import com.ruoyi.system.model.TBillDetail; import com.ruoyi.system.query.TBillQuery; import com.ruoyi.system.service.TBillDetailService; import com.ruoyi.system.service.TBillService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.*; import javax.validation.constraints.NotEmpty; import java.util.List; /** * <p> @@ -34,7 +36,8 @@ @Autowired TBillService tBillService; @Autowired TBillDetailService tBillDetailService; @PreAuthorize("@ss.hasPermi('system:bill:list')") @@ -52,6 +55,22 @@ tBillService.saveBill(bill); return R.ok(); } @ApiOperation("通过ID查找详情") @GetMapping("getDetailById") public R<TBillDto> getDetailById(@Validated @NotEmpty String id){ TBillDto dto = tBillService.getDetailByBillId(id); if (dto.getBillType().equals("3")){ List<TBillDetail> details = tBillDetailService.getByBillId(id); for (TBillDetail detail : details) { if (detail.getLiveType()==1)dto.setWater(detail); //水费 else dto.setElect(detail); //电费 } } return R.ok(dto); } @PreAuthorize("@ss.hasPermi('system:bill:checkOfflinePay')") @ApiOperation("确认线下缴费") @PostMapping("checkOfflinePay") @@ -85,5 +104,8 @@ } } ruoyi-common/pom.xml
@@ -200,7 +200,11 @@ <artifactId>hutool-all</artifactId> <version>5.8.4</version> </dependency> <dependency> <groupId>com.sun.mail</groupId> <artifactId>javax.mail</artifactId> <version>1.6.2</version> <!-- 请检查是否有更新的版本 --> </dependency> </dependencies> </project> ruoyi-common/src/main/java/com/ruoyi/common/config/MailProperties.java
New file @@ -0,0 +1,20 @@ package com.ruoyi.common.config; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; @Data @ConfigurationProperties(prefix = "mail") public class MailProperties { private String smtpHost="gz-smtp.qcloudmail.com"; private Integer smtpPort = 465; private String userAddr = "test@xzgtmail.591taxi.cn"; private String password = "CY20250226pass"; private String userName = "测试"; } ruoyi-common/src/main/java/com/ruoyi/common/config/SmsConfig.java
@@ -10,7 +10,7 @@ import org.springframework.context.annotation.Configuration; @Configuration @EnableConfigurationProperties(SmsProperties.class) @EnableConfigurationProperties({SmsProperties.class, MailProperties.class}) @ConditionalOnProperty(value = SmsProperties.ENABLE_KEY,matchIfMissing = true) public class SmsConfig { @@ -33,6 +33,5 @@ // 实例化要请求产品(sms)的client对象,第二个参数是地域信息,可以直接填写字符串ap-guangzhou,支持的地域列表参考 https://cloud.tencent.com/document/api/382/52071#.E5.9C.B0.E5.9F.9F.E5.88.97.E8.A1.A8 return new SmsClient(cred, "ap-guangzhou", clientProfile); } } ruoyi-common/src/main/java/com/ruoyi/common/utils/TencentMailUtil.java
New file @@ -0,0 +1,104 @@ package com.ruoyi.common.utils; import com.ruoyi.common.config.MailProperties; import com.ruoyi.common.exception.ServiceException; import com.sun.xml.internal.org.jvnet.mimepull.MIMEMessage; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; import java.util.Properties; import javax.mail.*; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; @Component @Slf4j public class TencentMailUtil { @Autowired MailProperties properties; /** * * @param emailAddress 邮件接收者email地址 * @param param 用户房屋地址参数 */ public void send(String emailAddress,String param){ // 配置发送邮件的环境属性 final Properties props = new Properties(); // 表示SMTP发送邮件,需要进行身份验证 props.put("mail.smtp.auth", "true"); props.put("mail.smtp.host", properties.getSmtpHost()); // 如果使用ssl,则去掉使用25端口的配置,进行如下配置, props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); props.put("mail.smtp.socketFactory.port", properties.getSmtpPort()); props.put("mail.smtp.port", properties.getSmtpPort()); // 发件人的账号,填写控制台配置的发信地址,比如xxx@xxx.com props.put("mail.user", properties.getUserAddr()); // 访问SMTP服务时需要提供的密码(在控制台选择发信地址进行设置) props.put("mail.password", properties.getPassword()); props.setProperty("mail.smtp.socketFactory.fallback", "false"); props.put("mail.smtp.ssl.enable", "false"); // 构建授权信息,用于进行SMTP进行身份验证 Authenticator authenticator = new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { // 用户名、密码 String userName = props.getProperty("mail.user"); String password = props.getProperty("mail.password"); return new PasswordAuthentication(userName, password); } }; // 使用环境属性和授权信息,创建邮件会话 Session mailSession = Session.getInstance(props, authenticator); // mailSession.setDebug(true); //UUID uuid = UUID.randomUUID(); //final String messageIDValue = "<" + uuid.toString() + ">"; // 创建邮件消息 MimeMessage message = new MimeMessage(mailSession) { //@Override //protected void updateMessageID() throws MessagingException { //设置自定义Message-ID值 //setHeader("Message-ID", messageIDValue); //} }; try { // 设置发件人邮件地址和名称。填写控制台配置的发信地址,比如xxx@xxx.com。和上面的mail.user保持一致。名称用户可以自定义填写。 InternetAddress from = new InternetAddress(properties.getUserAddr(), properties.getUserName()); message.setFrom(from); //可选。设置回信地址 // Address[] a = new Address[1]; // a[0] = new InternetAddress("***"); // message.setReplyTo(a); // 设置收件人邮件地址,比如yyy@yyy.com InternetAddress to = new InternetAddress(emailAddress); message.setRecipient(MimeMessage.RecipientType.TO, to); //如果同时发给多人,才将上面两行替换为如下(因为部分收信系统的一些限制,尽量每次投递给一个人;同时我们限制单次允许发送的人数是50人): // 设置邮件标题 message.setSubject("您的"+param+"账单提醒"); message.setHeader("Content-Transfer-Encoding", "base64"); // 设置邮件的内容体 type: text/plain(纯文本)text/html(HTML 文档) message.setContent("邻居您好!您"+param+",提醒您有账单需要处理,如已处理请忽略此短信,感谢您的支持!如有疑问请详询:4008888888。", "text/html;charset=UTF-8"); //发送邮件 Transport.send(message); } catch (MessagingException | UnsupportedEncodingException e) { log.error("发送邮件发生异常",e); throw new ServiceException("发送邮件失败,请检查"); } } // public static void main(String[] args) { // TencentMailUtil tencentMailUtil = new TencentMailUtil(); // MailProperties properties = new MailProperties(); // tencentMailUtil.properties = properties; // tencentMailUtil.send("214491528@qq.com","大学城揽院24栋"); // // } } ruoyi-system/src/main/java/com/ruoyi/system/dto/TBillDto.java
@@ -1,8 +1,10 @@ package com.ruoyi.system.dto; import com.ruoyi.system.model.TBill; import com.ruoyi.system.model.TBillDetail; import lombok.Data; import java.math.BigDecimal; import java.util.List; @Data @@ -17,6 +19,26 @@ private String account; private String houseName; /** * 合同信息 */ private String contractName; private String partyTwoName; private BigDecimal totalYear; private String payType; private BigDecimal deposit; /** * 水费 */ private TBillDetail water; /** * 电费 */ private TBillDetail elect; } ruoyi-system/src/main/java/com/ruoyi/system/mapper/TBillMapper.java
@@ -34,5 +34,5 @@ */ List<TBillDto> invoiceList(@Param("query")TBillQuery query, @Param("pageInfo")PageInfo<TBillDto> pageInfo); TBillDto selectTenentByBillId(@Param("billId") String billId); TBillDto selectDetailByBillId(@Param("billId") String billId); } ruoyi-system/src/main/java/com/ruoyi/system/service/TBillDetailService.java
@@ -3,6 +3,9 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.ruoyi.system.model.TBillDetail; import javax.validation.constraints.NotEmpty; import java.util.List; /** * <p> * 账单水电费子表 服务类 @@ -13,4 +16,7 @@ */ public interface TBillDetailService extends IService<TBillDetail> { List<TBillDetail> getByBillId(@NotEmpty String billId); } ruoyi-system/src/main/java/com/ruoyi/system/service/TBillService.java
@@ -10,6 +10,7 @@ import com.ruoyi.system.query.TBillQuery; import com.taxi591.bankapi.dto.ChargeBillRequest; import javax.validation.constraints.NotEmpty; import java.math.BigDecimal; import java.util.List; import java.util.function.Consumer; @@ -81,4 +82,6 @@ Integer sendSmsByBillIds(SmsByBillDto dto); Integer sendMailBatchByBillIds(SmsByBillDto dto); TBillDto getDetailByBillId(@NotEmpty String id); } ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBillDetailServiceImpl.java
@@ -1,10 +1,15 @@ package com.ruoyi.system.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.system.mapper.TBillDetailMapper; import com.ruoyi.system.model.TBillDetail; import com.ruoyi.system.model.TOrderBill; import com.ruoyi.system.service.TBillDetailService; import org.springframework.stereotype.Service; import javax.validation.constraints.NotEmpty; import java.util.List; /** * <p> @@ -17,4 +22,8 @@ @Service public class TBillDetailServiceImpl extends ServiceImpl<TBillDetailMapper, TBillDetail> implements TBillDetailService { @Override public List<TBillDetail> getByBillId(@NotEmpty String billId) { return list(new LambdaQueryWrapper<TBillDetail>().eq(TBillDetail::getBillId,billId)); } } ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBillServiceImpl.java
@@ -30,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import javax.validation.constraints.NotEmpty; import java.util.*; import java.util.stream.Collectors; import java.math.BigDecimal; @@ -359,7 +360,7 @@ public Integer sendSmsByBillIds(SmsByBillDto dto) { int failNum = 0; for (String billId : dto.getBillIds()) { TBillDto bill = getTenentByBillId(billId); TBillDto bill = getDetailByBillId(billId); if (bill.getSmsLastTime()!=null && (System.currentTimeMillis()-bill.getSmsLastTime().getTime()<smsUtil.getPro().getBillSmsDelayPeriod()*60*1000L)){ throw new ServiceException("有账单最近一次发送的时间是:"+DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,bill.getSmsLastTime())); @@ -388,7 +389,7 @@ public Integer sendMailBatchByBillIds(SmsByBillDto dto) { int failNum = 0; for (String billId : dto.getBillIds()) { TBillDto bill = getTenentByBillId(billId); TBillDto bill = getDetailByBillId(billId); if (bill.getSmsLastTime()!=null && (System.currentTimeMillis()-bill.getSmsLastTime().getTime()<smsUtil.getPro().getBillMailDelayPeriod()*60*1000L)){ throw new ServiceException("有账单最近一次发送的时间是:"+DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,bill.getSmsLastTime())); @@ -413,8 +414,8 @@ return failNum; } private TBillDto getTenentByBillId(String billId) { return getBaseMapper().selectTenentByBillId(billId); public TBillDto getDetailByBillId(@NotEmpty String billId) { return getBaseMapper().selectDetailByBillId(billId); } ruoyi-system/src/main/resources/mapper/system/TBillMapper.xml
@@ -130,14 +130,15 @@ order by b.pay_fees_time </select> <select id="selectTenentByBillId" resultType="com.ruoyi.system.dto.TBillDto"> <select id="selectDetailByBillId" resultType="com.ruoyi.system.dto.TBillDto"> SELECT b.*, t.resident_name as residentName, t.email, t.phone, t.account, h.house_name as houseName h.house_name as houseName, c.contract_name,c.pay_type,c.party_two_name,c.total_year,c.deposit FROM t_bill b LEFT JOIN t_contract c ON c.contract_number = b.contract_number and c.disabled=0