|
@@ -0,0 +1,226 @@
|
|
|
|
|
+package com.ydtech.modules.order.service.impl;
|
|
|
|
|
+
|
|
|
|
|
+import cn.hutool.extra.qrcode.BufferedImageLuminanceSource;
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
|
|
+import com.github.pagehelper.page.PageMethod;
|
|
|
|
|
+import com.google.zxing.*;
|
|
|
|
|
+import com.google.zxing.client.j2se.MatrixToImageConfig;
|
|
|
|
|
+import com.google.zxing.client.j2se.MatrixToImageWriter;
|
|
|
|
|
+import com.google.zxing.common.BitMatrix;
|
|
|
|
|
+import com.google.zxing.common.HybridBinarizer;
|
|
|
|
|
+import com.google.zxing.qrcode.QRCodeWriter;
|
|
|
|
|
+import com.ydtech.components.OrderComponents;
|
|
|
|
|
+import com.ydtech.constants.InsuranceEnum;
|
|
|
|
|
+import com.ydtech.constants.enums.dict.InsOrderStatusEnum;
|
|
|
|
|
+import com.ydtech.core.page.HttpResult;
|
|
|
|
|
+import com.ydtech.exception.SystemException;
|
|
|
|
|
+import com.ydtech.modules.admin.model.SysDept;
|
|
|
|
|
+import com.ydtech.modules.admin.model.SysUser;
|
|
|
|
|
+import com.ydtech.modules.admin.service.SysDeptService;
|
|
|
|
|
+import com.ydtech.modules.admin.service.SysUserService;
|
|
|
|
|
+import com.ydtech.modules.fee.service.impl.FeeRuleSchemeServiceImpl;
|
|
|
|
|
+import com.ydtech.modules.ins.model.vo.CarInfoVo;
|
|
|
|
|
+import com.ydtech.modules.ins.model.ya.CarModelDTO;
|
|
|
|
|
+import com.ydtech.modules.ins.model.ya.ExtendInfoDto;
|
|
|
|
|
+import com.ydtech.modules.ins.model.ya.ResponseDataC2;
|
|
|
|
|
+import com.ydtech.modules.order.convert.CarModelDTOConvert;
|
|
|
|
|
+import com.ydtech.modules.order.convert.MapToYaExtendInfoDto;
|
|
|
|
|
+import com.ydtech.modules.order.dao.InsOrderQrCodeMapper;
|
|
|
|
|
+import com.ydtech.modules.order.dao.InsOrdersMapper;
|
|
|
|
|
+import com.ydtech.modules.order.entity.BasePageResult;
|
|
|
|
|
+import com.ydtech.modules.order.entity.InsAreaCompany;
|
|
|
|
|
+import com.ydtech.modules.order.entity.InsOrderQrCode;
|
|
|
|
|
+import com.ydtech.modules.order.entity.InsOrders;
|
|
|
|
|
+import com.ydtech.modules.order.entity.bo.UnderwritingRulesBo;
|
|
|
|
|
+import com.ydtech.modules.order.entity.dto.InsAreaCompanyQueryDto;
|
|
|
|
|
+import com.ydtech.modules.order.entity.vo.*;
|
|
|
|
|
+import com.ydtech.modules.order.entity.vo.ya.YaExtendInfoDto;
|
|
|
|
|
+import com.ydtech.modules.order.service.InsAreaCompanyService;
|
|
|
|
|
+import com.ydtech.modules.order.service.InsOrderQrCodeService;
|
|
|
|
|
+import com.ydtech.modules.order.service.InsOrdersService;
|
|
|
|
|
+import com.ydtech.modules.protocol.entity.dto.PtlAgreementInsCompanyDto;
|
|
|
|
|
+import com.ydtech.modules.protocol.service.PtlAgreementService;
|
|
|
|
|
+import com.ydtech.utils.idgen.IdGenerate;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
|
|
+
|
|
|
|
|
+import javax.imageio.ImageIO;
|
|
|
|
|
+import javax.validation.constraints.NotBlank;
|
|
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.net.URL;
|
|
|
|
|
+import java.nio.file.Paths;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
+import java.util.regex.Matcher;
|
|
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
|
|
+import static com.ydtech.modules.order.constants.OrderCacheConstant.*;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * @author wenkaisen
|
|
|
|
|
+ * @description 针对表【ins_orders(保险订单表)】的数据库操作Service实现
|
|
|
|
|
+ * @createDate 2023-01-31 15:44:29
|
|
|
|
|
+ */
|
|
|
|
|
+@Service
|
|
|
|
|
+public class InsOrderQrCodeServiceImpl extends ServiceImpl<InsOrderQrCodeMapper, InsOrderQrCode> implements InsOrderQrCodeService {
|
|
|
|
|
+
|
|
|
|
|
+ @Value("${upload.file.path}")
|
|
|
|
|
+ private String uploadFilePath;
|
|
|
|
|
+
|
|
|
|
|
+ @Value("${qrcode.genAddress}")
|
|
|
|
|
+ private String qrCodeGenAddress;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private InsAreaCompanyService insAreaCompanyService;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public InsOrderQrCode getOneOrSave(String companyId) {
|
|
|
|
|
+ //查询 ins_area_company数据
|
|
|
|
|
+ InsAreaCompany insAreaCompany = insAreaCompanyService.getOne(new LambdaQueryWrapper<InsAreaCompany>().eq(InsAreaCompany::getId, companyId));
|
|
|
|
|
+ //查询 是否有数据存在
|
|
|
|
|
+ InsOrderQrCode insOrderQrCode = baseMapper.selectOne(new LambdaQueryWrapper<InsOrderQrCode>()
|
|
|
|
|
+ .eq(InsOrderQrCode::getAreaCompanyId, companyId)
|
|
|
|
|
+ .eq(InsOrderQrCode::getQrcodeStatus, 1));
|
|
|
|
|
+ if(Objects.isNull(insOrderQrCode))
|
|
|
|
|
+ {
|
|
|
|
|
+ //如果订单状态等于 待缴费 或 撤销二维码
|
|
|
|
|
+ if(insAreaCompany.getOrderstatus().equals(InsOrderStatusEnum.WAIT_PAY.getCode())){
|
|
|
|
|
+ if(Objects.isNull(insAreaCompany.getPaymentLink())){
|
|
|
|
|
+ throw new SystemException("该订单没有缴费链接");
|
|
|
|
|
+ }
|
|
|
|
|
+ boolean save = save(insAreaCompany.getOrderno(), insAreaCompany.getId(), insAreaCompany.getPaymentLink());
|
|
|
|
|
+ insOrderQrCode = baseMapper.selectOne(new LambdaQueryWrapper<InsOrderQrCode>()
|
|
|
|
|
+ .eq(InsOrderQrCode::getAreaCompanyId, companyId)
|
|
|
|
|
+ .eq(InsOrderQrCode::getQrcodeStatus, 1));
|
|
|
|
|
+ }else{
|
|
|
|
|
+ throw new SystemException("该订单不是待缴费状态");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ return insOrderQrCode;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public InsOrderQrCode getOne(String companyId) {
|
|
|
|
|
+ //查询 ins_area_company数据
|
|
|
|
|
+// InsAreaCompany insAreaCompany = insAreaCompanyService.getOne(new LambdaQueryWrapper<InsAreaCompany>().eq(InsAreaCompany::getId, companyId));
|
|
|
|
|
+ //查询 是否有数据存在
|
|
|
|
|
+ InsOrderQrCode insOrderQrCode = baseMapper.selectOne(new LambdaQueryWrapper<InsOrderQrCode>()
|
|
|
|
|
+ .eq(InsOrderQrCode::getAreaCompanyId, companyId)
|
|
|
|
|
+ .eq(InsOrderQrCode::getQrcodeStatus, 1));
|
|
|
|
|
+ return insOrderQrCode;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private BufferedImage base64ToBufferedImage(String base64){
|
|
|
|
|
+ try {
|
|
|
|
|
+ byte[] bytes = Base64.getDecoder().decode(base64);
|
|
|
|
|
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
|
|
|
|
|
+ BufferedImage bi1 = ImageIO.read(bais);
|
|
|
|
|
+ return bi1;
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ throw new SystemException("base64转BufferedImage失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //获取二维码地址
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public String getQrCodeUrl(String base64) {
|
|
|
|
|
+
|
|
|
|
|
+ //base64字符串 提取二维码链接
|
|
|
|
|
+ BufferedImage bufferedImage = base64ToBufferedImage(base64);
|
|
|
|
|
+ BufferedImageLuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);
|
|
|
|
|
+ BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));
|
|
|
|
|
+ Hashtable hints = new Hashtable();
|
|
|
|
|
+ hints.put(com.google.zxing.DecodeHintType.CHARACTER_SET, "UTF-8");
|
|
|
|
|
+ hints.put(com.google.zxing.DecodeHintType.TRY_HARDER, Boolean.TRUE);
|
|
|
|
|
+ hints.put(com.google.zxing.DecodeHintType.PURE_BARCODE, Boolean.TRUE);
|
|
|
|
|
+ try {
|
|
|
|
|
+ Result decode = new MultiFormatReader().decode(binaryBitmap, hints);
|
|
|
|
|
+ return decode.getText();
|
|
|
|
|
+ } catch (NotFoundException e) {
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean isHttpUrl(String urls) {
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ URL url = new URL(urls);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }catch (java.net.MalformedURLException e){
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 保存二维码
|
|
|
|
|
+ * @param orderno
|
|
|
|
|
+ * @param companyId
|
|
|
|
|
+ * @param jumlUrl
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean save(String orderno, String companyId, String jumlUrl) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ InsOrderQrCode insOrderQrCode = new InsOrderQrCode();
|
|
|
|
|
+
|
|
|
|
|
+ String id = IdGenerate.nextId();
|
|
|
|
|
+ insOrderQrCode.setId(id);
|
|
|
|
|
+ insOrderQrCode.setOrderno(orderno);
|
|
|
|
|
+ insOrderQrCode.setAreaCompanyId(companyId);
|
|
|
|
|
+ //判断jumlUrl是base64 还是 url
|
|
|
|
|
+ if(isHttpUrl(jumlUrl)){
|
|
|
|
|
+ insOrderQrCode.setJumpUrl(jumlUrl);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ //base64 二维码图片
|
|
|
|
|
+ String qrCodeUrl = getQrCodeUrl(jumlUrl);
|
|
|
|
|
+ insOrderQrCode.setJumpUrl(qrCodeUrl);
|
|
|
|
|
+ }
|
|
|
|
|
+ insOrderQrCode.setQrcodeStatus(1);
|
|
|
|
|
+ insOrderQrCode.setCreatetime(new Date());
|
|
|
|
|
+ return this.save(insOrderQrCode);
|
|
|
|
|
+ }catch(Exception e){
|
|
|
|
|
+ throw new SystemException("查询二维码失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 更新二维码状态
|
|
|
|
|
+ * @param id
|
|
|
|
|
+ * @param status
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional
|
|
|
|
|
+ public boolean updateQrCode(String id, Integer status) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ InsOrderQrCode insOrderQrCode = new InsOrderQrCode();
|
|
|
|
|
+ insOrderQrCode.setQrcodeStatus(status);
|
|
|
|
|
+ insOrderQrCode.setDestructionCodeTime(new Date());
|
|
|
|
|
+ this.update(insOrderQrCode,new LambdaQueryWrapper<InsOrderQrCode>().eq(InsOrderQrCode::getAreaCompanyId,id));
|
|
|
|
|
+ //设置订单状态为撤销二维码
|
|
|
|
|
+ InsAreaCompany insAreaCompany = new InsAreaCompany();
|
|
|
|
|
+ insAreaCompany.setId(id);
|
|
|
|
|
+ insAreaCompany.setOrderstatus(InsOrderStatusEnum.QUOTE_ING.getCode());
|
|
|
|
|
+ insAreaCompanyService.updateCompanyAndOrders(insAreaCompany);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }catch(Exception e){
|
|
|
|
|
+ throw new SystemException("撤销二维码失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|