xuhy
2025-03-12 5706757a0bcec3318c8c460d34c1827788065d7c
Merge branch 'xizang-changyun' of https://gitee.com/xiaochen991015/xizang
7个文件已修改
293 ■■■■■ 已修改文件
generator/src/test/java/com/xizang/CodeGeneratorTests.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TInvoiceController.java 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-common/src/main/java/com/ruoyi/common/utils/TencentMailUtil.java 126 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/dto/OfflinePayCheckDto.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/service/TInvoiceService.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBillServiceImpl.java 46 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TInvoiceServiceImpl.java 99 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
generator/src/test/java/com/xizang/CodeGeneratorTests.java
@@ -35,9 +35,9 @@
        // 全局配置
        GlobalConfig gc = new GlobalConfig();
        String projectPath = "F:\\workSpace\\xizang\\generator";
        String projectPath = "D:\\workspaces\\Project\\company\\changyun\\xizang\\xizang\\generator";
        gc.setOutputDir(projectPath + "/src/main/java")
                .setAuthor("xiaochen")
                .setAuthor("yupeng")
                .setMapperName("%sMapper")
                .setXmlName("%sMapper")
                .setServiceName("%sService")
@@ -144,7 +144,7 @@
//         strategy.setTablePrefix(pc.getModuleName() + "");
//        strategy.setLikeTable(new LikeTable("room"));
        //strategy.setLikeTable(new LikeTable("member"));
        strategy.setLikeTable(new LikeTable("t_bank_flow"));// 生成表名
        strategy.setLikeTable(new LikeTable("sys_file"));// 生成表名
//        strategy.setLikeTable(new LikeTable("t_hotel"));// 生成表名
//        strategy.setLikeTable(new LikeTable("t_scan_message"));// 生成表名
//        strategy.setNotLikeTable(new LikeTable("hotel_info"));// 不生成表名
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TInvoiceController.java
@@ -5,6 +5,7 @@
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.TencentMailUtil;
import com.ruoyi.system.dto.TBillDto;
import com.ruoyi.system.model.TBill;
import com.ruoyi.system.model.TInvoice;
@@ -57,13 +58,7 @@
    @PostMapping("/uploadVoucher")
    @PreAuthorize("@ss.hasPermi('invoice:list:payment')")
    public R<Boolean> uploadVoucher(@RequestBody TInvoiceQuery query) {
        TInvoice tInvoice = new TInvoice();
        tInvoice.setId(query.getId());
        tInvoice.setInvoiceVoucher(query.getInvoiceVoucher());
        tInvoice.setInvoiceVoucherName(query.getInvoiceVoucherName());
        tInvoice.setInvoiceTime(query.getInvoiceTime());
        tInvoice.setStatus(2);
        return R.ok(invoiceService.updateById(tInvoice));
        return R.ok(invoiceService.uploadVoucher(query));
    }
}
ruoyi-common/src/main/java/com/ruoyi/common/utils/TencentMailUtil.java
@@ -6,11 +6,20 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import java.net.URLEncoder;
import javax.activation.URLDataSource;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.*;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.concurrent.CompletableFuture;
@Component
@Slf4j
@@ -43,7 +52,8 @@
        // 访问SMTP服务时需要提供的密码(在控制台选择发信地址进行设置)
        props.put("mail.password", properties.getPassword());
        props.setProperty("mail.smtp.socketFactory.fallback", "false");
        props.put("mail.smtp.ssl.enable", "false");
        props.put("mail.smtp.ssl.enable", "true");
        props.put("mail.smtp.ssl.protocols", "TLSv1.2");
        // 构建授权信息,用于进行SMTP进行身份验证
        Authenticator authenticator = new Authenticator() {
            @Override
@@ -94,17 +104,113 @@
            e.printStackTrace();
            log.error("发送邮件发生异常",e);
        }
    }
    public static void main(String[] args) {
    public void sendInvoice(String emailAddress, List<Map<String, String>> list) {
        // 异步发送邮件
        CompletableFuture.runAsync(() -> {
            try {
                sendEmail(emailAddress, list);
            } catch (ServiceException e) {
                log.error("邮件发送失败", e);
            }
        });
    }
    private void sendEmail(String emailAddress, List<Map<String, String>> list) throws ServiceException {
        try {
            // 创建邮件会话
            Session mailSession = Session.getInstance(getMailProperties(), getAuthenticator());
            // 创建邮件消息
            MimeMessage message = new MimeMessage(mailSession);
            // 设置发件人
            InternetAddress from = new InternetAddress(properties.getUserAddr(), properties.getUserName());
            message.setFrom(from);
            // 设置收件人
            InternetAddress to = new InternetAddress(emailAddress);
            message.setRecipient(MimeMessage.RecipientType.TO, to);
            // 设置邮件标题
            message.setSubject("发票");
            // 创建邮件内容
            Multipart multipart = createMultipart(list);
            // 设置邮件内容
            message.setContent(multipart);
            // 发送邮件
            Transport.send(message);
        } catch (MessagingException | UnsupportedEncodingException | MalformedURLException e) {
            log.error("发送邮件发生异常", e);
            throw new ServiceException("发送邮件失败, 请检查");
        }
    }
    private Properties getMailProperties() {
        Properties props = new Properties();
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.host", properties.getSmtpHost());
        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());
        props.put("mail.user", properties.getUserAddr());
        props.put("mail.password", properties.getPassword());
        props.setProperty("mail.smtp.socketFactory.fallback", "false");
        props.put("mail.smtp.ssl.enable", "false");
        return props;
    }
    private Authenticator getAuthenticator() {
        return new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                String userName = properties.getUserAddr();
                String password = properties.getPassword();
                return new PasswordAuthentication(userName, password);
            }
        };
    }
    private Multipart createMultipart(List<Map<String, String>> list) throws MessagingException, UnsupportedEncodingException, MalformedURLException {
        Multipart multipart = new MimeMultipart();
        // 添加文本消息部分
        BodyPart messageBodyPart = new MimeBodyPart();
        messageBodyPart.setHeader("Content-Type", "text/plain;charset=utf-8");
        multipart.addBodyPart(messageBodyPart);
        // 添加附件部分
        for (Map<String, String> map : list) {
            messageBodyPart = new MimeBodyPart();
            String url = map.get("url");
            String fileName = map.get("fileName");
            URLDataSource source = new URLDataSource(new URL(url));
            messageBodyPart.setDataHandler(new DataHandler(source));
            String filenameEncode = MimeUtility.encodeText(fileName, "UTF-8", "base64");
            messageBodyPart.setFileName(filenameEncode);
            messageBodyPart.setHeader("Content-Transfer-Encoding", "base64");
            messageBodyPart.setHeader("Content-Disposition", "attachment");
            messageBodyPart.setHeader("Content-Type", "application/octet-stream;name=\"" + filenameEncode + "\"");
            multipart.addBodyPart(messageBodyPart);
        }
        return multipart;
    }
   public static void main(String[] args) throws UnsupportedEncodingException {
        TencentMailUtil tencentMailUtil = new TencentMailUtil();
        MailProperties properties = new MailProperties();
        tencentMailUtil.properties = properties;
        tencentMailUtil.send("214491528@qq.com","大学城揽院24栋");
       tencentMailUtil.send("645025773@qq.com","大学城揽院24栋");
    }
}
ruoyi-system/src/main/java/com/ruoyi/system/dto/OfflinePayCheckDto.java
@@ -38,7 +38,11 @@
    @ApiModelProperty("支付凭证")
    private String voucher;
    @ApiModelProperty("银行流水ID")
    @NotEmpty(message = "银行流水ID不能为空")
    private String flowId;
    @ApiModelProperty("支付类型")
    @NotEmpty(message = "支付类型不能为空")
    private Integer payType;
}
ruoyi-system/src/main/java/com/ruoyi/system/service/TInvoiceService.java
@@ -19,4 +19,5 @@
public interface TInvoiceService extends IService<TInvoice> {
    PageInfo<TInvoice> pageList(TInvoiceQuery query);
    List<TInvoice> makeQuery(TInvoiceQuery query);
    Boolean uploadVoucher(TInvoiceQuery query);
}
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBillServiceImpl.java
@@ -241,8 +241,12 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean checkOfflinePay(OfflinePayCheckDto dto) {
        TBankFlow bankflow = tBankFlowService.getById(dto.getFlowId());
        TBillDto bill = getDetailByBillId(dto.getBillId());
        if (dto.getPayType()==1){ //银行
            if (StringUtils.isEmpty(dto.getFlowId())){
                throw new ServiceException("银行流水ID不能为空");
            }
            TBankFlow bankflow = tBankFlowService.getById(dto.getFlowId());
        if (bankflow.getRemainingMoney().compareTo(BigDecimal.ZERO)<=0){
            throw new ServiceException("该流水已无可抵扣剩余金额");
        }
@@ -253,7 +257,6 @@
        if (dto.getAmount().compareTo(bill.getOutstandingMoney())>0){
            throw new ServiceException("实付金额不能高于该账单欠费金额");
        }
        TBill billSave = new TBill();
        billSave.setId(bill.getId());
        billSave.setPayFeesMoney(dto.getAmount());
@@ -262,13 +265,17 @@
        billSave.setVoucher(dto.getVoucher());
        billSave.setPayFeesType(2);
        TBill back = lockAndUpdateInfo(billSave, 2);
        //更新银行流水的已抵扣金额和剩余可抵扣金额
        TBankFlow saveBankFlow = new TBankFlow();
        saveBankFlow.setId(bankflow.getId());
        saveBankFlow.setDeductionMoney(bankflow.getDeductionMoney().add(dto.getAmount()));
        saveBankFlow.setRemainingMoney(bankflow.getRemainingMoney().subtract(dto.getAmount()));
            BigDecimal subtract = bankflow.getRemainingMoney().subtract(dto.getAmount());
            saveBankFlow.setRemainingMoney(subtract);
            if (BigDecimal.ZERO.compareTo(subtract) == 0){
                saveBankFlow.setFlowStatus(1);
            }
        tBankFlowService.updateById(saveBankFlow);
            //更新银行流水的已抵扣金额和剩余可抵扣金额
        //存流水
        TFlowManagement save = new TFlowManagement();
        save.setPayType(3);
@@ -277,6 +284,29 @@
        save.setSysSerialNumber(OrderNos.getDid(30));
        save.setBankSerialNumber(bankflow.getBankSerialNumber());
        save.setFlowType(2);
            save.setPaymentBillId(back.getId());
            save.setDeductionMoney(back.getDeductionMoney());
            save.setFlowMoney(dto.getAmount());
            save.setRemainingMoney(back.getOutstandingMoney());
            save.setPreOutstand(back.getPreOutstand());
            tFlowManagementService.save(save);
            return true;
        }
        //现金支付
        TBill billSave = new TBill();
        billSave.setId(bill.getId());
        billSave.setPayFeesMoney(dto.getAmount());
        billSave.setPayFeesTime(dto.getPayTime()!=null?dto.getPayTime():DateUtils.dateToLocalDateTime(new Date()));
        billSave.setVoucher(dto.getVoucher());
        billSave.setPayFeesType(2);
        TBill back = lockAndUpdateInfo(billSave, 2);
        TFlowManagement save = new TFlowManagement();
        save.setPayType(3);
        save.setPayer(dto.getPayer());
        save.setPayTime(billSave.getPayFeesTime());
        save.setSysSerialNumber(OrderNos.getDid(30));
        save.setFlowType(1);
        save.setPaymentBillId(back.getId());
        save.setDeductionMoney(back.getDeductionMoney());
        save.setFlowMoney(dto.getAmount());
@@ -483,7 +513,11 @@
            TBankFlow saveBankFlow = new TBankFlow();
            saveBankFlow.setId(bankflow.getId());
            saveBankFlow.setDeductionMoney(bankflow.getDeductionMoney().add(dto.getAmount()));
            saveBankFlow.setRemainingMoney(bankflow.getRemainingMoney().subtract(dto.getAmount()));
            BigDecimal subtract = bankflow.getRemainingMoney().subtract(dto.getAmount());
            saveBankFlow.setRemainingMoney(subtract);
            if (BigDecimal.ZERO.compareTo(subtract) == 0){
                saveBankFlow.setFlowStatus(1);
            }
            tBankFlowService.updateById(saveBankFlow);
        }
        //存流水
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TInvoiceServiceImpl.java
@@ -3,7 +3,9 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.TencentMailUtil;
import com.ruoyi.system.mapper.TInvoiceMapper;
import com.ruoyi.system.model.TInvoice;
import com.ruoyi.system.query.TInvoiceQuery;
@@ -12,7 +14,10 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import javax.annotation.Resource;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
/**
 * <p>
@@ -28,6 +33,8 @@
    TInvoiceToBillServiceImpl tInvoiceToBillService;
    @Autowired
    TBillService tBillService;
    @Resource
    TencentMailUtil mailUtil;
    @Override
    public PageInfo<TInvoice> pageList(TInvoiceQuery query) {
@@ -49,4 +56,94 @@
                .orderByDesc(TInvoice::getCreateTime);
        return this.baseMapper.selectList(queryWrapper);
    }
    @Override
    public Boolean uploadVoucher(TInvoiceQuery query) {
        // 检查是否存在对应的发票记录
        TInvoice preexist = getById(query.getId());
        if (preexist == null) {
            log.error("未找到对应的发票记录,ID: {}"+query.getId());
            return false;
        }
        // 更新发票信息
        TInvoice tInvoice = new TInvoice();
        tInvoice.setId(query.getId());
        tInvoice.setInvoiceVoucher(query.getInvoiceVoucher());
        tInvoice.setInvoiceVoucherName(query.getInvoiceVoucherName());
        tInvoice.setInvoiceTime(query.getInvoiceTime());
        tInvoice.setStatus(2);
        // 处理附件信息
        List<Map<String, String>> attachments = buildAttachments(query.getInvoiceVoucher(), query.getInvoiceVoucherName());
        if (attachments.isEmpty()) {
            log.warn("未找到有效的附件信息");
            return updateById(tInvoice);
        }
        // 异步发送邮件
        CompletableFuture.runAsync(() -> {
            try {
                mailUtil.sendInvoice(preexist.getEmail(), attachments);
            } catch (ServiceException e) {
                log.error("邮件发送失败", e);
            }
        });
        // 更新数据库
        return updateById(tInvoice);
    }
    private List<Map<String, String>> buildAttachments(String invoiceVoucher, String invoiceVoucherName) {
        if (invoiceVoucher == null || invoiceVoucherName == null) {
            return Collections.emptyList();
        }
        String[] voucherUrls = invoiceVoucher.split(",");
        String[] voucherNames = invoiceVoucherName.split(",");
        // 确保两个数组长度一致
        int length = Math.min(voucherUrls.length, voucherNames.length);
        if (length == 0) {
            return Collections.emptyList();
        }
        // 构建附件列表
        List<Map<String, String>> attachments = new ArrayList<>(length);
        for (int i = 0; i < length; i++) {
            Map<String, String> attachment = new HashMap<>(2); // 初始容量为2,避免扩容
            attachment.put("url", voucherUrls[i]);
            attachment.put("fileName", voucherNames[i]);
            attachments.add(attachment);
        }
        return attachments;
    }
    // @Override
    // public Boolean uploadVoucher(TInvoiceQuery query) {
    //     TInvoice preexist = getById(query.getId());
    //     if (preexist == null){
    //         return false;
    //     }
    //     TInvoice tInvoice = new TInvoice();
    //     tInvoice.setId(query.getId());
    //     tInvoice.setInvoiceVoucher(query.getInvoiceVoucher());
    //     tInvoice.setInvoiceVoucherName(query.getInvoiceVoucherName());
    //     tInvoice.setInvoiceTime(query.getInvoiceTime());
    //     tInvoice.setStatus(2);
    //     List<Map<String, String>> mapArrayList = new ArrayList<>();
    //     String invoiceVoucher = query.getInvoiceVoucher();
    //     String invoiceVoucherName = query.getInvoiceVoucherName();
    //
    //     List<String> list = Arrays.stream(invoiceVoucher.split(",")).collect(Collectors.toList());
    //     for (int i = 0; i < list.size()-1; i++) {
    //         Map<String, String> map = new HashMap<>();
    //         map.put("url", list.get(i));
    //         map.put("fileName",invoiceVoucherName.split(",")[i]);
    //         mapArrayList.add(map);
    //     }
    //     mailUtil.sendInvoice(preexist.getEmail(),mapArrayList);
    //     return updateById(tInvoice);
    // }
}