Browse Source

7天自动清理OSS定时任务

suochencheng 7 years ago
parent
commit
5ea1a3b441

+ 2 - 0
src/main/java/com/izouma/awesomeadmin/dao/OrderImageMapper.java

@@ -31,5 +31,7 @@ public interface OrderImageMapper{
     List<OrderImage> query(OrderImage record);
 
     OrderImage getMemorySize(OrderImage record);
+
+    List<OrderImage> queryAutoCleanOrderImage(OrderImage record);
 }
 

+ 71 - 2
src/main/java/com/izouma/awesomeadmin/dao/OrderImageMapper.xml

@@ -21,6 +21,8 @@
         <result column="image_name" property="imageName" jdbcType="VARCHAR"/>
         <result column="original_artwork" property="originalArtwork" jdbcType="VARCHAR"/>
         <result column="finished_artwork" property="finishedArtwork" jdbcType="VARCHAR"/>
+        <result column="download_flag" property="downloadFlag" jdbcType="CHAR"/>
+        <result column="clean_flag" property="cleanFlag" jdbcType="CHAR"/>
     </resultMap>
     <sql id="Base_Column_List">
         <trim suffixOverrides=",">
@@ -62,6 +64,10 @@
 
             finished_artwork,
 
+            download_flag,
+
+            clean_flag,
+
         </trim>
     </sql>
     <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
@@ -265,6 +271,12 @@
             <if test="finishedArtwork != null">
                 finished_artwork= #{finishedArtwork,jdbcType=VARCHAR},
             </if>
+            <if test="downloadFlag != null">
+                download_flag= #{downloadFlag,jdbcType=CHAR},
+            </if>
+            <if test="cleanFlag != null">
+                clean_flag= #{cleanFlag,jdbcType=CHAR},
+            </if>
         </set>
         where id = #{id,jdbcType=INTEGER}
     </update>
@@ -304,6 +316,9 @@
             <if test="record.delFlag != null and !&quot;&quot;.equals(record.delFlag)">
                 and del_flag = #{record.delFlag}
             </if>
+            <if test="record.delFlag != null and !&quot;&quot;.equals(record.delFlag)">
+                and del_flag = #{record.delFlag}
+            </if>
             <if test="record.updateTime != null and !&quot;&quot;.equals(record.updateTime)">
                 and update_time = #{record.updateTime}
             </if>
@@ -357,6 +372,12 @@
                     and (finished_image is not null and finished_image != '')
                 </if>
             </if>
+            <if test="record.downloadFlag != null and !&quot;&quot;.equals(record.downloadFlag)">
+                and download_flag = #{record.downloadFlag}
+            </if>
+            <if test="record.cleanFlag != null and !&quot;&quot;.equals(record.cleanFlag)">
+                and clean_flag = #{record.cleanFlag}
+            </if>
             <if test="record.searchKey != null and !&quot;&quot;.equals(record.searchKey)">
                 <trim prefix="and (" suffix=")" prefixOverrides="OR">
                     OR order_id LIKE concat('%',#{record.searchKey},'%')
@@ -489,6 +510,12 @@
                     and (finished_image is not null and finished_image != '')
                 </if>
             </if>
+            <if test="downloadFlag != null and !&quot;&quot;.equals(downloadFlag)">
+                and download_flag = #{downloadFlag}
+            </if>
+            <if test="cleanFlag != null and !&quot;&quot;.equals(cleanFlag)">
+                and clean_flag = #{cleanFlag}
+            </if>
             <if test="searchKey != null and !&quot;&quot;.equals(searchKey)">
                 <trim prefix="and (" suffix=")" prefixOverrides="OR">
                     OR order_id LIKE concat('%',#{searchKey},'%')
@@ -619,8 +646,8 @@
     <select id="getMemorySize" parameterType="java.util.Map" resultType="com.izouma.awesomeadmin.model.OrderImage">
         SELECT
         store_id,
-        ROUND(SUM(original_size) / 1024  / 1024) AS original_size,
-        ROUND(SUM(finished_size) / 1024  / 1024) AS finished_size,
+        ROUND(SUM(original_size) / 1024 / 1024) AS original_size,
+        ROUND(SUM(finished_size) / 1024 / 1024) AS finished_size,
         ROUND(
         SUM(original_size) / 1024 / 1024 + SUM(finished_size) / 1024 / 1024
         ) AS total_size
@@ -679,6 +706,12 @@
             <if test="imageName != null and !&quot;&quot;.equals(imageName)">
                 and image_name = #{imageName}
             </if>
+            <if test="downloadFlag != null and !&quot;&quot;.equals(downloadFlag)">
+                and download_flag = #{downloadFlag}
+            </if>
+            <if test="cleanFlag != null and !&quot;&quot;.equals(cleanFlag)">
+                and clean_flag = #{cleanFlag}
+            </if>
 
         </where>
         GROUP BY
@@ -699,5 +732,41 @@
         </where>
         order by id desc
     </select>
+
+    <select id="queryAutoCleanOrderImage" parameterType="java.util.Map" resultType="com.izouma.awesomeadmin.model.OrderImage">
+        select
+        <include refid="Base_Column_List"/>
+        from order_image
+        <where>
+            and del_flag = 'N'
+            and download_flag = 'Y'
+            and clean_flag = 'N'
+            and order_id in (
+            SELECT
+            id
+            FROM
+            user_order
+            WHERE
+            del_flag = 'N'
+            AND status_flag >= 5
+            <![CDATA[AND confirm_time < DATE_ADD(NOW(), INTERVAL - 7 DAY)]]>
+            )
+            <if test="orderId != null and !&quot;&quot;.equals(orderId)">
+                and order_id = #{orderId}
+            </if>
+            <if test="userId != null and !&quot;&quot;.equals(userId)">
+                and user_id = #{userId}
+            </if>
+            <if test="storeId != null and !&quot;&quot;.equals(storeId)">
+                and store_id = #{storeId}
+            </if>
+            <if test="statusFlag != null and !&quot;&quot;.equals(statusFlag)">
+                and status_flag = #{statusFlag}
+            </if>
+            <if test="remark != null and !&quot;&quot;.equals(remark)">
+                and remark = #{remark}
+            </if>
+        </where>
+    </select>
 </mapper>
 

+ 13 - 0
src/main/java/com/izouma/awesomeadmin/dao/UserOrderMapper.xml

@@ -27,6 +27,11 @@
         <result column="show_flag" property="showFlag" jdbcType="CHAR"/>
         <result column="status_flag" property="statusFlag" jdbcType="INTEGER"/>
         <result column="fee" property="fee" jdbcType="DECIMAL"/>
+        <result column="coin" property="coin" jdbcType="DECIMAL"/>
+        <result column="point" property="point" jdbcType="DECIMAL"/>
+        <result column="cash" property="cash" jdbcType="DECIMAL"/>
+        <result column="cancel_reason" property="cancelReason" jdbcType="VARCHAR"/>
+        <result column="confirm_time" property="confirmTime" jdbcType="TIMESTAMP"/>
     </resultMap>
     <sql id="Base_Column_List">
         <trim suffixOverrides=",">
@@ -82,6 +87,8 @@
             coin,
             point,
             cash,
+            cancel_reason,
+            confirm_time,
 
         </trim>
     </sql>
@@ -358,6 +365,12 @@
             <if test="cash != null">
                 cash= #{cash,jdbcType=DECIMAL},
             </if>
+            <if test="cancelReason != null">
+                cancel_reason= #{cancelReason},
+            </if>
+            <if test="confirmTime != null">
+                confirm_time= #{confirmTime,jdbcType=TIMESTAMP},
+            </if>
         </set>
         where id = #{id,jdbcType=INTEGER}
     </update>

+ 26 - 0
src/main/java/com/izouma/awesomeadmin/model/OrderImage.java

@@ -42,6 +42,16 @@ public class OrderImage {
      */
     private String finishedArtwork;
 
+    /**
+     * 下载标识
+     */
+    private String downloadFlag;
+
+    /**
+     * 清理OSS标识
+     */
+    private String cleanFlag;
+
     /**
      * 图片备注
      */
@@ -302,5 +312,21 @@ public class OrderImage {
     public void setFinishedArtwork(String finishedArtwork) {
         this.finishedArtwork = finishedArtwork;
     }
+
+    public String getDownloadFlag() {
+        return downloadFlag;
+    }
+
+    public void setDownloadFlag(String downloadFlag) {
+        this.downloadFlag = downloadFlag;
+    }
+
+    public String getCleanFlag() {
+        return cleanFlag;
+    }
+
+    public void setCleanFlag(String cleanFlag) {
+        this.cleanFlag = cleanFlag;
+    }
 }
 

+ 13 - 0
src/main/java/com/izouma/awesomeadmin/model/UserOrder.java

@@ -39,6 +39,11 @@ public class UserOrder {
     private BigDecimal point;
     private BigDecimal cash;
 
+    /**
+     * 确认收货时间
+     */
+    private Date confirmTime;
+
     /**
      * 取消原因
      */
@@ -361,5 +366,13 @@ public class UserOrder {
     public void setUserInfo(UserInfo userInfo) {
         this.userInfo = userInfo;
     }
+
+    public Date getConfirmTime() {
+        return confirmTime;
+    }
+
+    public void setConfirmTime(Date confirmTime) {
+        this.confirmTime = confirmTime;
+    }
 }
 

+ 3 - 0
src/main/java/com/izouma/awesomeadmin/service/OrderImageService.java

@@ -3,6 +3,7 @@ package com.izouma.awesomeadmin.service;
 import java.util.*;
 
 import com.izouma.awesomeadmin.dto.Page;
+import com.izouma.awesomeadmin.dto.Result;
 import com.izouma.awesomeadmin.model.OrderImage;
 
 
@@ -34,5 +35,7 @@ public interface OrderImageService {
     boolean repair(OrderImage record);
 
     OrderImage getMemorySize(OrderImage record);
+
+    Result autoCleanOrderImage(OrderImage record);
 }
 

+ 45 - 0
src/main/java/com/izouma/awesomeadmin/service/impl/OrderImageServiceImpl.java

@@ -4,8 +4,12 @@ import java.util.*;
 
 import com.izouma.awesomeadmin.dao.OrderRepairDetailMapper;
 import com.izouma.awesomeadmin.dao.OrderRepairMapper;
+import com.izouma.awesomeadmin.dto.Result;
 import com.izouma.awesomeadmin.model.OrderRepair;
 import com.izouma.awesomeadmin.model.OrderRepairDetail;
+import com.izouma.awesomeadmin.service.OSSFileService;
+import com.izouma.awesomeadmin.util.PropertiesFileLoader;
+import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -31,6 +35,8 @@ public class OrderImageServiceImpl implements OrderImageService {
 
     @Autowired
     private OrderRepairDetailMapper orderRepairDetailMapper;
+    @Autowired
+    private OSSFileService OSSFileService;
 
 
     @Override
@@ -240,5 +246,44 @@ public class OrderImageServiceImpl implements OrderImageService {
 
         return null;
     }
+
+    @Override
+    public Result autoCleanOrderImage(OrderImage record) {
+
+        logger.info("autoCleanOrderImage");
+        try {
+
+            List<OrderImage> orderImageList = orderImageMapper.queryAutoCleanOrderImage(record);
+
+            for (OrderImage orderImage : orderImageList) {
+                orderImage.setCleanFlag("Y");
+
+                if (StringUtils.isNotEmpty(orderImage.getOriginalImage())) {
+                    String artwork = orderImage.getOriginalImage().replace(PropertiesFileLoader.getProperties("aliImageSever") + "/", "");
+                    OSSFileService.deleteObject(artwork);
+                }
+                if (StringUtils.isNotEmpty(orderImage.getOriginalArtwork())) {
+                    String artwork = orderImage.getOriginalArtwork().replace(PropertiesFileLoader.getProperties("aliImageSever") + "/", "");
+                    OSSFileService.deleteObject(artwork);
+                }
+                if (StringUtils.isNotEmpty(orderImage.getFinishedImage())) {
+                    String artwork = orderImage.getFinishedImage().replace(PropertiesFileLoader.getProperties("aliImageSever") + "/", "");
+                    OSSFileService.deleteObject(artwork);
+                }
+                if (StringUtils.isNotEmpty(orderImage.getFinishedArtwork())) {
+                    String artwork = orderImage.getFinishedArtwork().replace(PropertiesFileLoader.getProperties("aliImageSever") + "/", "");
+                    OSSFileService.deleteObject(artwork);
+                }
+
+                orderImageMapper.updateByPrimaryKeySelective(orderImage);
+            }
+
+            return new Result(true, "成功");
+        } catch (Exception e) {
+            logger.error("autoCleanOrderImage", e);
+        }
+
+        return null;
+    }
 }
 

+ 1 - 0
src/main/java/com/izouma/awesomeadmin/service/impl/UserOrderServiceImpl.java

@@ -625,6 +625,7 @@ public class UserOrderServiceImpl implements UserOrderService {
 
                 if (confirmFlag) {
 
+                    record.setConfirmTime(new Date());
                     userOrderMapper.updateByPrimaryKeySelective(record);
 
                     //结算商家

+ 24 - 2
src/main/java/com/izouma/awesomeadmin/web/OrderImageController.java

@@ -350,6 +350,12 @@ public class OrderImageController {
         return new Result(true, "保存成功");
     }
 
+    /**
+     * 获取店铺存储情况
+     *
+     * @param record
+     * @return
+     */
     @RequestMapping(value = "/getMemorySize", method = RequestMethod.GET)
     @ResponseBody
     public Result getMemorySize(OrderImage record) {
@@ -401,14 +407,18 @@ public class OrderImageController {
                         } else if ("finished".equals(typeFlag)) {
                             if (StringUtils.isNotEmpty(orderImage.getFinishedImage())) {
 
-                                if (StringUtils.isNotEmpty(orderImage.getOriginalArtwork())) {
-                                    String imageName = orderImage.getOriginalArtwork().replace(PropertiesFileLoader.getProperties("aliImageSever") + "/", "");
+                                if (StringUtils.isNotEmpty(orderImage.getFinishedArtwork())) {
+                                    String imageName = orderImage.getFinishedArtwork().replace(PropertiesFileLoader.getProperties("aliImageSever") + "/", "");
                                     keyList.add(imageName);
                                 } else {
 
                                     String imageName = orderImage.getFinishedImage().replace(PropertiesFileLoader.getProperties("aliImageSever") + "/", "");
                                     keyList.add(imageName);
                                 }
+
+                                //更新成已下载
+                                orderImage.setDownloadFlag("Y");
+                                orderImageService.updateOrderImage(orderImage);
                             }
                         }
                     }
@@ -469,6 +479,10 @@ public class OrderImageController {
                             String imageName = orderImage.getFinishedImage().replace(PropertiesFileLoader.getProperties("aliImageSever") + "/", "");
                             OSSFileService.singleFileDown(imageName, request, response);
                         }
+
+                        //更新成已下载
+                        orderImage.setDownloadFlag("Y");
+                        orderImageService.updateOrderImage(orderImage);
                     }
                 }
             }
@@ -481,5 +495,13 @@ public class OrderImageController {
     }
 
 
+    @RequestMapping(value = "/autoCleanOrderImage", method = RequestMethod.GET)
+    @ResponseBody
+    public Result autoCleanOrderImage() {
+
+        return orderImageService.autoCleanOrderImage(null);
+    }
+
+
 }