소스 검색

无车优化,自有车接口返回

Administrator 1 년 전
부모
커밋
821ba72377

+ 23 - 1
src/main/java/com/jkcredit/invoice/controller/business/NoCarController.java

@@ -510,7 +510,8 @@ public class NoCarController {
                noCarWayBillFileInfo.setBatchNum(batchNumber);
                noCarWayBillFileInfo.setUpdateTime(DateUtil.getCurrentDateStr());
                noCarWayBillFileInfo.setBase64Str( Base64Utils.fileToBase64Str(fileTemp));
-               noCarWayBillFileInfo.setWayBillNum(fileTemp.getName());
+               noCarWayBillFileInfo.setWayBillNum(fileTemp.getName().replaceAll(".pdf","").replaceAll(".PDF",""));
+               noCarWayBillFileInfo.setFileName(fileTemp.getName());
                wayBillFileService.insert(noCarWayBillFileInfo);
             }
             return new RespR(true);
@@ -834,7 +835,28 @@ public class NoCarController {
         }
         return new RespR(false);
     }
+    @GetMapping("/downloadWayBillFile")
+    @ApiOperation(value = "运单文件下载", notes = "运单文件下载")
+    public RespR downloadWayBillFile(@NotNull(message = "运单文件下载,运单号") String wayBillNum, HttpServletResponse response) {
+        OutputStream outputStream = null;
+        InputStream inputStream = null;
+        try {
+            NoCarWayBillFileInfo noCarWayBillFileInfo = wayBillFileService.selectFileInfo(null,wayBillNum);
+            byte[] bytes = Base64Utils.DECODER_64.decode(noCarWayBillFileInfo.getBase64Str());
+            ByteArrayInputStream byteInputStream = new ByteArrayInputStream(bytes);
+            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(noCarWayBillFileInfo.getFileName(), "UTF-8"));
+            outputStream = response.getOutputStream();
+            IOUtils.copy(byteInputStream, outputStream);
+            response.flushBuffer();
+            return new RespR(true);
+        } catch (IOException e) {
 
+        } finally {
+            IOUtils.closeQuietly(inputStream);
+            IOUtils.closeQuietly(outputStream);
+        }
+        return new RespR(false);
+    }
     public void setTimeDue1(NoCarCalculateInfor carCalculateInfor) {
         if (!StringUtils.isEmpty(carCalculateInfor.getInvoiceMakeTime()) && !NULL.equals(carCalculateInfor.getInvoiceMakeTime())) {
             String[] res = carCalculateInfor.getInvoiceMakeTime().split(",");

+ 1 - 0
src/main/java/com/jkcredit/invoice/credit/SimpleCoreFilter.java

@@ -142,6 +142,7 @@ public class SimpleCoreFilter implements Filter {
             "/noCar/findNocarCalculateInfoStatis",
             "/noCar/findNocarCalculateInfo",
             "/noCar/templateDownload",
+            "/noCar/downloadWayBillFile",
             "/noCar/batchImportNocarInvoices",
             "/noCar/batchImportNocarBillWay",
 

+ 34 - 7
src/main/java/com/jkcredit/invoice/credit/interserver/NoCarInterServiceImpl.java

@@ -14,6 +14,7 @@ import com.jkcredit.invoice.model.entity.customer.CustomerRec;
 import com.jkcredit.invoice.model.entity.invoice.BillInvoice;
 import com.jkcredit.invoice.model.entity.manager.Param;
 import com.jkcredit.invoice.model.entity.waybill.NoCarWayBill;
+import com.jkcredit.invoice.model.entity.waybill.NoCarWayBillFileInfo;
 import com.jkcredit.invoice.service.customer.CustomerRecService;
 import com.jkcredit.invoice.service.lowerservice.NoCarService;
 import com.jkcredit.invoice.service.lowerservice.vo.HcInvoiceQueryVo;
@@ -29,7 +30,7 @@ import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
 import java.util.List;
-
+import com.jkcredit.invoice.service.nocar.WayBillFileService;
 import static com.jkcredit.invoice.common.CommonConst.*;
 import static java.util.stream.Collectors.toList;
 
@@ -58,6 +59,8 @@ public class NoCarInterServiceImpl implements NoCarInterService {
     ParamService paramService;
     @Autowired
     private NoCarService noCarService;
+    @Autowired
+    private WayBillFileService wayBillFileService;
 
     public static void main(String[] args) {
         List<String> list1 = new ArrayList<String>();
@@ -311,9 +314,9 @@ public class NoCarInterServiceImpl implements NoCarInterService {
                     || null == fee
                     || null == titleType
                     || StringUtils.isEmpty(taxplayerCode)
-                    || StringUtils.isEmpty(base64Str)
+                    /*|| StringUtils.isEmpty(base64Str)
                     || StringUtils.isEmpty(waybillFileName)
-                    || null == contractType
+                    || null == contractType*/
 
             ) {
                 result.setMsg("必传参数有空值");
@@ -339,7 +342,18 @@ public class NoCarInterServiceImpl implements NoCarInterService {
             noCarWayBill.setWaybillFileName(waybillFileName);
             noCarWayBill.setBase64Str(base64Str);
             noCarWayBill.setContractType(contractType);
-            return getDataResult(appKey, data, costtimestart, result, customerRec, noCarWayBill);
+           DataResult dataResult = getDataResult(appKey, data, costtimestart, result, customerRec, noCarWayBill);
+            if(dataResult.getCode() == 0){
+                NoCarWayBillFileInfo noCarWayBillFileInfo = new NoCarWayBillFileInfo();
+                noCarWayBillFileInfo.setBase64Str(base64Str);
+                noCarWayBillFileInfo.setFileName(waybillFileName);
+                noCarWayBillFileInfo.setWayBillNum(num);
+                noCarWayBillFileInfo.setCustomerId(appKey);
+                noCarWayBillFileInfo.setCompanyName(noCarWayBill.getCompanyName());
+                noCarWayBillFileInfo.setUpdateTime(DateUtil.getCurrentDateStr());
+                wayBillFileService.insert(noCarWayBillFileInfo);
+            }
+            return dataResult;
         } catch (Exception e) {
             log.error("[-NoCarInterServiceImpl.noCarBillStart-] get httpclient exception is "
                     + e + ", request is " + data);
@@ -518,9 +532,9 @@ public class NoCarInterServiceImpl implements NoCarInterService {
                     || null == fee
                     || null == titleType
                     || StringUtils.isEmpty(taxplayerCode)
-                    || StringUtils.isEmpty(base64Str)
+                    /*|| StringUtils.isEmpty(base64Str)
                     || StringUtils.isEmpty(waybillFileName)
-                    || null == contractType
+                    || null == contractType*/
             ) {
                 result.setMsg("有空的必填运单要素,请检查");
                 return result;
@@ -561,7 +575,20 @@ public class NoCarInterServiceImpl implements NoCarInterService {
             if (checkCustomerCarRecQueryResult(result, noCarWayBill, customerCarRecs, customerCarRec)) {
                 return result;
             }
-            return getDataResultss(data, costtimestart, result, noCarService.noCarHisWaybillStart(noCarWayBill), "[-NoCarInterServiceImpl.noCarHisWaybillStart-] result is ");
+            RespR respR = noCarService.noCarHisWaybillStart(noCarWayBill);
+            if(respR.getCode() == 0){
+                //上传成功后文件入库
+                NoCarWayBillFileInfo noCarWayBillFileInfo = new NoCarWayBillFileInfo();
+                noCarWayBillFileInfo.setBase64Str(base64Str);
+                noCarWayBillFileInfo.setFileName(waybillFileName);
+                noCarWayBillFileInfo.setBatchNum("接口运单");
+                noCarWayBillFileInfo.setWayBillNum(num);
+                noCarWayBillFileInfo.setUpdateTime(DateUtil.getCurrentDateStr());
+                noCarWayBillFileInfo.setCustomerId(appKey);
+                noCarWayBillFileInfo.setCompanyName(noCarWayBill.getCompanyName());
+                wayBillFileService.insert(noCarWayBillFileInfo);
+            }
+            return getDataResultss(data, costtimestart, result, respR, "[-NoCarInterServiceImpl.noCarHisWaybillStart-] result is ");
         } catch (Exception e) {
             log.error("[-NoCarInterServiceImpl.noCarHisWaybillStart-] get httpclient exception is "
                     + e + ", request is " + data);

+ 6 - 0
src/main/java/com/jkcredit/invoice/mapper/waybill/WayBillFileMapper.java

@@ -18,4 +18,10 @@ public interface WayBillFileMapper  extends BaseMapper<NoCarWayBillFileInfo> {
 
     NoCarWayBillFileInfo selectFileInfoNoFile(@Param("batchNum") String batchNum, @Param("wayBillNum") String wayBillNum);
 
+    NoCarWayBillFileInfo selectFileInfoNoBatch( @Param("wayBillNum") String wayBillNum);
+
+    NoCarWayBillFileInfo selectFileInfoNoFileNoBatch(@Param("wayBillNum") String wayBillNum);
+
+    int deleteFileByTime(String yesTime);
+
 }

+ 10 - 0
src/main/java/com/jkcredit/invoice/model/entity/waybill/NoCarWayBillFileInfo.java

@@ -13,6 +13,8 @@ public class NoCarWayBillFileInfo {
      * 运单号
      */
     private String wayBillNum;
+
+    private String fileName;
     /**
      * 批次号
      */
@@ -75,4 +77,12 @@ public class NoCarWayBillFileInfo {
     public void setCompanyName(String companyName) {
         this.companyName = companyName;
     }
+
+    public String getFileName() {
+        return fileName;
+    }
+
+    public void setFileName(String fileName) {
+        this.fileName = fileName;
+    }
 }

+ 1 - 1
src/main/java/com/jkcredit/invoice/service/lowerservice/impl/NoCarServiceImpl.java

@@ -298,7 +298,7 @@ public class NoCarServiceImpl implements NoCarService {
         }
     }
     @Autowired
-    private WayBillFileMapper wayBillFileMapper;
+    private com.jkcredit.invoice.service.nocar.WayBillFileService wayBillFileMapper;
     /**
      * 组装指令报文
      */

+ 9 - 0
src/main/java/com/jkcredit/invoice/service/nocar/impl/WayBillFileServiceImpl.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.jkcredit.invoice.mapper.waybill.WayBillFileMapper;
 import com.jkcredit.invoice.model.entity.waybill.NoCarWayBillFileInfo;
 import com.jkcredit.invoice.service.nocar.WayBillFileService;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -25,11 +26,19 @@ public class WayBillFileServiceImpl extends ServiceImpl<WayBillFileMapper, NoCar
 
     @Override
     public NoCarWayBillFileInfo selectFileInfo(String batchNum,String wayBillNum) {
+        if(StringUtils.isEmpty(batchNum)){
+            return wayBillFileMapper.selectFileInfoNoBatch(wayBillNum);
+        }
         return wayBillFileMapper.selectFileInfo(batchNum,wayBillNum);
     }
 
     @Override
     public NoCarWayBillFileInfo selectFileInfoNoFile(String batchNum,String wayBillNum) {
+        if(StringUtils.isEmpty(batchNum)){
+            return wayBillFileMapper.selectFileInfoNoFileNoBatch(wayBillNum);
+        }
         return wayBillFileMapper.selectFileInfoNoFile(batchNum,wayBillNum);
     }
+
+
 }

+ 17 - 0
src/main/java/com/jkcredit/invoice/task/ScheduledBillTask.java

@@ -155,6 +155,23 @@ public class ScheduledBillTask {
         }
     }
     @Autowired
+    com.jkcredit.invoice.mapper.waybill.WayBillFileMapper wayBillFileMapper;
+    @Scheduled(cron = "0 0 1 * * ?", zone = "Asia/Shanghai")
+    public void deleteFile()throws Exception{
+        InetAddress addr = InetAddress.getLocalHost();
+        String ip = paramService.getParamsByParamName("CURR_SELF_IP").getParamValue();
+
+        log.info("CURR_SELF_IP" + ip + ",address:" + addr);
+        if (!addr.getHostAddress().equals(ip)) {
+            log.info("!shanchufile");
+            return;
+        } else {
+            log.info("shanchufile");
+        }
+        String yesdate = DateUtil.getDateAfterDayTime(DateUtil.getCurrentDateStr(),-1);
+        wayBillFileMapper.deleteFileByTime(yesdate);
+    }
+    @Autowired
     SelfCarInterface selfCarInterface;
     /**
      * @Scheduled(cron = "0 0 23 * * ?", zone = "Asia/Shanghai")

+ 2 - 2
src/main/java/com/jkcredit/invoice/util/Base64Utils.java

@@ -14,8 +14,8 @@ public class Base64Utils {
     /**
      * Base64 编码与解码
      */
-    private static final Base64.Decoder DECODER_64 = Base64.getDecoder();
-    private static final Base64.Encoder ENCODER_64 = Base64.getEncoder();
+    public static final Base64.Decoder DECODER_64 = Base64.getDecoder();
+    public static final Base64.Encoder ENCODER_64 = Base64.getEncoder();
 
     /**
      * dpi越大转换后的图片越清晰,相对转换速度越慢

+ 23 - 1
src/main/java/com/jkcredit/invoice/util/DateUtil.java

@@ -329,7 +329,28 @@ public class DateUtil {
         return format.format(now.getTime());
 
     }
+    /**
+     * 得到几天前的时间
+     */
+
+    public static String getDateAfterDayTime(String date, int day) {
+
+        DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Date dateR = null;
+        try {
+            dateR = format.parse(date);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        Calendar now = Calendar.getInstance();
+        now.setTime(dateR);
 
+        now.set(Calendar.DATE, now.get(Calendar.DATE) + day);
+
+        return format.format(now.getTime());
+
+    }
     /**
      * 判断给定时间与给定时间相差多少小时
      *
@@ -368,7 +389,8 @@ public class DateUtil {
         System.out.println(isValidDate("2022-11-31T23:59:59"));
         System.out.println(getMouthDays("2022-5"));*/
         // System.out.println(DateUtil.getDistanceHoursTwo("2022-02-26 09:02:26","2022-03-01 09:02:58"));
-        System.out.print(getSplitTimeOver96("2023-01-04 12:28:11","2023-01-09 12:28:10"));
+        //System.out.print(getSplitTimeOver96("2023-01-04 12:28:11","2023-01-09 12:28:10"));
+        System.out.print(getDateAfterDayTime(getCurrentDateStr(),-1));
     }
     public static String[] getMouthDays(String mounth){
         DateFormat format = new SimpleDateFormat("yyyy-MM");

+ 2 - 1
src/main/java/com/jkcredit/invoice/util/ZipUtils.java

@@ -138,7 +138,8 @@ public class ZipUtils {
 
    try {
 
-     ZipUtils.unZipFiles("E:\\test\\test.zip", "E:\\test\\out\\");
+     //ZipUtils.unZipFiles("E:\\test\\test.zip", "E:\\test\\out\\");
+       System.out.print("123.pdf".replace(".pdf",""));
    } catch (Exception e) {
      e.printStackTrace();
    }

+ 17 - 5
src/main/resources/mapper/waybill/WayBillFileMapper.xml

@@ -3,6 +3,7 @@
 <mapper namespace="com.jkcredit.invoice.mapper.waybill.WayBillFileMapper">
     <!-- 通用查询映射结果 -->
     <resultMap id="BaseResultMap" type="com.jkcredit.invoice.model.entity.waybill.NoCarWayBillFileInfo">
+        <result column="fileName" property="fileName"/>
         <result column="wayBillNum" property="wayBillNum"/>
         <result column="batchNum" property="batchNum"/>
         <result column="updateTime" property="updateTime"/>
@@ -17,7 +18,8 @@
          companyName,
          batchNum,
          wayBillNum,
-         updateTime
+         updateTime,
+         fileName
     </sql>
 
     <select id="selectAllFiles" resultMap="BaseResultMap">
@@ -44,17 +46,27 @@
             batchNum,
             wayBillNum,
             updateTime,
-            base64Str
+            base64Str,
+            filename
         )
         values( #{customerId,jdbcType=VARCHAR}, #{companyName,jdbcType=VARCHAR}, #{batchNum,jdbcType=VARCHAR}, #{wayBillNum,jdbcType=VARCHAR},
-            #{updateTime,jdbcType=VARCHAR}, #{base64Str,jdbcType=VARCHAR})
+            #{updateTime,jdbcType=VARCHAR}, #{base64Str,jdbcType=VARCHAR},#{fileName,jdbcType=VARCHAR})
     </insert>
 
 
   <select id="selectFileInfo" parameterType="java.lang.String" resultMap="BaseResultWithFileMap">
-      select <include refid="baseSql" />,base64Str from t_waybill_File where batchNum=#{batchNum,jdbcType=VARCHAR} and wayBillNum like concat(#{wayBillNum,jdbcType=VARCHAR},'%')
+      select <include refid="baseSql" />,base64Str from t_waybill_File where batchNum=#{batchNum,jdbcType=VARCHAR} and wayBillNum =#{wayBillNum,jdbcType=VARCHAR}
   </select>
     <select id="selectFileInfoNoFile" parameterType="java.util.HashMap" resultMap="BaseResultMap">
-        select <include refid="baseSql" /> from t_waybill_File where batchNum=#{batchNum,jdbcType=VARCHAR} and wayBillNum like concat(#{wayBillNum,jdbcType=VARCHAR},'%')
+        select <include refid="baseSql" /> from t_waybill_File where batchNum=#{batchNum,jdbcType=VARCHAR} and wayBillNum =#{wayBillNum,jdbcType=VARCHAR}
     </select>
+    <select id="selectFileInfoNoBatch" parameterType="java.lang.String" resultMap="BaseResultWithFileMap">
+        select <include refid="baseSql" />,base64Str from t_waybill_File where  wayBillNum =#{wayBillNum,jdbcType=VARCHAR}
+    </select>
+    <select id="selectFileInfoNoFileNoBatch" parameterType="java.util.HashMap" resultMap="BaseResultMap">
+        select <include refid="baseSql" /> from t_waybill_File where wayBillNum =#{wayBillNum,jdbcType=VARCHAR}
+    </select>
+    <delete id="deleteFileByTime">
+        DELETE  from t_waybill_File t where  #{deleteFileByTime,jdbcType=VARCHAR}> t.updateTime
+    </delete>
 </mapper>