瀏覽代碼

fix:设备发货列表导出

caozixuan 1 年之前
父節點
當前提交
1376b98c7e

+ 19 - 0
sop-api/src/main/java/com/qmth/sop/server/api/TBDeviceDeliveryController.java

@@ -132,4 +132,23 @@ public class TBDeviceDeliveryController {
         tbDeviceDeliveryService.deviceDeliveryImport(file);
         return ResultUtil.ok();
     }
+
+    @ApiOperation(value = "设备发货导出")
+    @RequestMapping(value = "/export", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = ProjectExchangeResult.class)})
+    @OperationLog(logType = LogTypeEnum.EXPORT)
+    public Result export(@ApiParam(value = "服务单元id") @RequestParam(required = false) Long serviceId,
+                         @ApiParam(value = "用途类型") @RequestParam(required = false) DeviceUsageTypeEnum usageType,
+                         @ApiParam(value = "项目单号") @RequestParam(required = false) String crmNo,
+                         @ApiParam(value = "发货状态") @RequestParam(required = false) DeviceDeliveryStatusEnum status,
+                         @ApiParam(value = "发货人id") @RequestParam(required = false) Long deliverUserId,
+                         @ApiParam(value = "发货开始时间") @RequestParam(required = false) Long deliverStartTime,
+                         @ApiParam(value = "发货结束时间") @RequestParam(required = false) Long deliverEndTime,
+                         @ApiParam(value = "设备序列号") @RequestParam(required = false) String serialNo,
+                         @ApiParam(value = "供应商id") @RequestParam(required = false) Long supplierId,
+                         @ApiParam(value = "签收开始时间") @RequestParam(required = false) Long receiveStartTime,
+                         @ApiParam(value = "签收结束时间") @RequestParam(required = false) Long receiveEndTime) throws Exception {
+        tbDeviceDeliveryService.dataExport(serviceId, usageType, crmNo, status, deliverUserId, deliverStartTime, deliverEndTime, serialNo, supplierId, receiveStartTime, receiveEndTime);
+        return ResultUtil.ok();
+    }
 }

+ 28 - 0
sop-business/src/main/java/com/qmth/sop/business/mapper/TBDeviceDeliveryMapper.java

@@ -50,4 +50,32 @@ public interface TBDeviceDeliveryMapper extends BaseMapper<TBDeviceDelivery> {
                                        @Param("supplierId") Long supplierId,
                                        @Param("receiveStartTime") Long receiveStartTime,
                                        @Param("receiveEndTime") Long receiveEndTime);
+
+    /**
+     * 设备发货列表查询
+     *
+     * @param serviceId        serviceId
+     * @param usageType        usageType
+     * @param crmNo            crmNo
+     * @param status           status
+     * @param deliverUserId    deliverUserId
+     * @param deliverStartTime deliverStartTime
+     * @param deliverEndTime   deliverEndTime
+     * @param serialNo         serialNo
+     * @param supplierId       supplierId
+     * @param receiveStartTime receiveStartTime
+     * @param receiveEndTime   receiveEndTime
+     * @return 查询结果
+     */
+    List<TBDeviceDeliveryResult> list(@Param("serviceId") Long serviceId,
+                                      @Param("usageType") DeviceUsageTypeEnum usageType,
+                                      @Param("crmNo") String crmNo,
+                                      @Param("status") DeviceDeliveryStatusEnum status,
+                                      @Param("deliverUserId") Long deliverUserId,
+                                      @Param("deliverStartTime") Long deliverStartTime,
+                                      @Param("deliverEndTime") Long deliverEndTime,
+                                      @Param("serialNo") String serialNo,
+                                      @Param("supplierId") Long supplierId,
+                                      @Param("receiveStartTime") Long receiveStartTime,
+                                      @Param("receiveEndTime") Long receiveEndTime);
 }

+ 37 - 0
sop-business/src/main/java/com/qmth/sop/business/service/TBDeviceDeliveryService.java

@@ -10,6 +10,7 @@ import com.qmth.sop.common.enums.DeviceUsageTypeEnum;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -36,6 +37,7 @@ public interface TBDeviceDeliveryService extends IService<TBDeviceDelivery> {
      */
     void editDeviceDelivery(DeviceDeliveryParam deviceDeliveryParam);
 
+
     /**
      * 设备发货管理查询
      *
@@ -54,4 +56,39 @@ public interface TBDeviceDeliveryService extends IService<TBDeviceDelivery> {
      * @return 分页结果
      */
     IPage<TBDeviceDeliveryResult> page(IPage<Map> iPage, Long serviceId, DeviceUsageTypeEnum usageType, String crmNo, DeviceDeliveryStatusEnum status, Long deliverUserId, Long deliveryStartTime, Long deliveryEndTime, String serialNo, Long supplierId, Long receiveStartTime, Long receiveEndTime) throws Exception;
+
+    /**
+     * 设备发货管理列表
+     *
+     * @param serviceId         服务单元id
+     * @param usageType         用途类型
+     * @param crmNo             项目单号
+     * @param status            发货状态
+     * @param deliverUserId     发货人
+     * @param deliveryStartTime 发货开始时间
+     * @param deliveryEndTime   发货结束时间
+     * @param serialNo          设备序列号
+     * @param supplierId        供应商
+     * @param receiveStartTime  验收开始时间
+     * @param receiveEndTime    验收结束时间
+     * @return 分页结果
+     */
+    List<TBDeviceDeliveryResult> list(Long serviceId, DeviceUsageTypeEnum usageType, String crmNo, DeviceDeliveryStatusEnum status, Long deliverUserId, Long deliveryStartTime, Long deliveryEndTime, String serialNo, Long supplierId, Long receiveStartTime, Long receiveEndTime) throws Exception;
+
+    /**
+     * 设备发货管理导出
+     *
+     * @param serviceId         服务单元id
+     * @param usageType         用途类型
+     * @param crmNo             项目单号
+     * @param status            发货状态
+     * @param deliverUserId     发货人
+     * @param deliveryStartTime 发货开始时间
+     * @param deliveryEndTime   发货结束时间
+     * @param serialNo          设备序列号
+     * @param supplierId        供应商
+     * @param receiveStartTime  验收开始时间
+     * @param receiveEndTime    验收结束时间分页结果
+     */
+    void dataExport(Long serviceId, DeviceUsageTypeEnum usageType, String crmNo, DeviceDeliveryStatusEnum status, Long deliverUserId, Long deliveryStartTime, Long deliveryEndTime, String serialNo, Long supplierId, Long receiveStartTime, Long receiveEndTime) throws Exception;
 }

+ 49 - 4
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBDeviceDeliveryServiceImpl.java

@@ -8,17 +8,17 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.sop.business.bean.dto.DataPermissionDto;
 import com.qmth.sop.business.bean.dto.DeviceDeliveryImportDto;
 import com.qmth.sop.business.bean.dto.DeviceInfoDto;
+import com.qmth.sop.business.bean.dto.UserArchivesImportDto;
 import com.qmth.sop.business.bean.params.DeviceDeliveryParam;
+import com.qmth.sop.business.bean.query.UserArchivesQuery;
 import com.qmth.sop.business.bean.result.TBDeviceDeliveryResult;
-import com.qmth.sop.business.entity.SysDevice;
-import com.qmth.sop.business.entity.SysSupplier;
-import com.qmth.sop.business.entity.SysUser;
-import com.qmth.sop.business.entity.TBDeviceDelivery;
+import com.qmth.sop.business.entity.*;
 import com.qmth.sop.business.mapper.TBDeviceDeliveryMapper;
 import com.qmth.sop.business.service.*;
 import com.qmth.sop.business.util.excel.BasicExcelListener;
 import com.qmth.sop.common.contant.SystemConstant;
 import com.qmth.sop.common.enums.*;
+import com.qmth.sop.common.util.FileUtil;
 import com.qmth.sop.common.util.ServletUtil;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.time.DateFormatUtils;
@@ -28,6 +28,8 @@ import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.*;
@@ -206,6 +208,49 @@ public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMap
         return page;
     }
 
+    @Override
+    public List<TBDeviceDeliveryResult> list(Long serviceId, DeviceUsageTypeEnum usageType, String crmNo, DeviceDeliveryStatusEnum status, Long deliverUserId, Long deliveryStartTime, Long deliveryEndTime, String serialNo, Long supplierId, Long receiveStartTime, Long receiveEndTime) throws Exception {
+        if (crmNo != null && crmNo.length() > 0) {
+            crmNo = SystemConstant.translateSpecificSign(crmNo);
+        }
+        if (serialNo != null && serialNo.length() > 0) {
+            serialNo = SystemConstant.translateSpecificSign(serialNo);
+        }
+        SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
+        DataPermissionDto dpr = sysUserService.buildUserDataPermission(requestUser.getId());
+        if (dpr.getHasDeviceDelivery()) {
+            // 是设备管理员
+            Long userSupplierId = requestUser.getSupplierId();
+            if (userSupplierId == null || userSupplierId == 0) {
+                throw ExceptionResultEnum.ERROR.exception("请先在用户管理中绑定设备发货员对应的供应商");
+            }
+            supplierId = userSupplierId;
+        }
+        List<TBDeviceDeliveryResult> result = this.baseMapper.list(serviceId, usageType, crmNo, status, deliverUserId, deliveryStartTime, deliveryEndTime, serialNo, supplierId, receiveStartTime, receiveEndTime);
+        for (TBDeviceDeliveryResult e : result) {
+            this.fillResultInfo(e);
+        }
+        return result;
+    }
+
+    @Override
+    public void dataExport(Long serviceId, DeviceUsageTypeEnum usageType, String crmNo, DeviceDeliveryStatusEnum status, Long deliverUserId, Long deliveryStartTime, Long deliveryEndTime, String serialNo, Long supplierId, Long receiveStartTime, Long receiveEndTime) throws Exception {
+        List<TBDeviceDeliveryResult> datasource = this.list(serviceId, usageType, crmNo, status, deliverUserId, deliveryStartTime, deliveryEndTime, serialNo, supplierId, receiveStartTime, receiveEndTime);
+
+        File fileTemp = null;
+        try {
+            fileTemp = SystemConstant.getFileTempVar(SystemConstant.XLSX_PREFIX);
+            EasyExcel.write(fileTemp, TBDeviceDeliveryResult.class).sheet("设备发货管理列表").doWrite(datasource);
+            HttpServletResponse response = ServletUtil.getResponse();
+            FileUtil.outputFile(response, fileTemp, "设备发货管理列表导出");
+        } finally {
+            if (Objects.nonNull(fileTemp)) {
+                fileTemp.delete();
+            }
+        }
+    }
+
+
     /**
      * 补充结果信息
      *

+ 71 - 0
sop-business/src/main/resources/mapper/TBDeviceDeliveryMapper.xml

@@ -72,4 +72,75 @@
             </if>
         </where>
     </select>
+
+    <select id="list" resultType="com.qmth.sop.business.bean.result.TBDeviceDeliveryResult">
+        SELECT
+            tbdd.id,
+            tbs.name AS serviceName,
+            tbdd.crm_no AS crmNo,
+            tbdd.usage_type AS usageType,
+            tbdd.delivery_type AS deliveryType,
+            ss.name AS supplierName,
+            sd.device_code AS deviceNo,
+            sd.serial_no AS serialNo,
+            sd.brand,
+            sd.model,
+            tbdd.mailing_address AS mailingAddress,
+            tbdd.consignee,
+            tbdd.consignee_phone AS consigneePhone,
+            tbdd.express_no AS expressNo,
+            tbdd.express_photo_path AS expressPhotoPath,
+            tbdd.status,
+            tbdd.deliver_time AS deliverTime,
+            su.real_name AS deliverUserName,
+            tbdd.receive_time AS receiveTime
+        FROM
+            t_b_device_delivery tbdd
+        LEFT JOIN
+            t_b_crm tbc ON tbc.crm_no = tbdd.crm_no
+        LEFT JOIN
+            t_b_service tbs ON tbc.service_id = tbs.id
+        LEFT JOIN
+            sys_supplier ss ON ss.id = tbdd.supplier_id
+        LEFT JOIN
+            sys_device sd ON sd.serial_no = tbdd.serial_no
+        LEFT JOIN
+            sys_user su ON su.id = tbdd.deliver_user_id
+        <where>
+            AND tbdd.enable = 1
+            <if test="serviceId != null and serviceId != ''">
+                AND tbdd.service_id = #{serviceId}
+            </if>
+            <if test="usageType != null and usageType != ''">
+                AND tbdd.usage_type = #{usageType}
+            </if>
+            <if test="crmNo != null and crmNo != ''">
+                AND tbdd.crm_no = #{crmNo}
+            </if>
+            <if test="status != null and status != ''">
+                AND tbdd.status = #{status}
+            </if>
+            <if test="deliverUserId != null">
+                AND tbdd.deliver_user_id = #{deliverUserId}
+            </if>
+            <if test="deliverStartTime != null">
+                AND tbdd.deliver_time <![CDATA[ >= ]]> #{deliverStartTime}
+            </if>
+            <if test="deliverEndTime != null">
+                AND tbdd.deliver_time <![CDATA[ <= ]]> #{deliverEndTime}
+            </if>
+            <if test="serialNo != null and serialNo != ''">
+                AND tbdd.serial_no = #{serialNo}
+            </if>
+            <if test="supplierId != null">
+                AND tbdd.supplier_id = #{supplierId}
+            </if>
+            <if test="receiveStartTime != null and receiveStartTime != ''">
+                AND tbdd.receive_time <![CDATA[ >= ]]> #{receiveStartTime}
+            </if>
+            <if test="receiveEndTime != null and receiveEndTime != ''">
+                AND tbdd.receive_time <![CDATA[ <= ]]> #{receiveEndTime}
+            </if>
+        </where>
+    </select>
 </mapper>

+ 28 - 4
sop-common/src/main/java/com/qmth/sop/common/util/FileUtil.java

@@ -1,12 +1,14 @@
 package com.qmth.sop.common.util;
 
+import com.qmth.sop.common.contant.SystemConstant;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
+import java.net.URLEncoder;
 
 /**
  * @Description:
@@ -14,6 +16,8 @@ import java.io.InputStream;
  * @Date:
  */
 public class FileUtil {
+    private final static Logger log = LoggerFactory.getLogger(FileUtil.class);
+
     public static String fileToBase64(File imgFile) {
         String fileName=imgFile.getName();
         String suff=fileName.substring(fileName.lastIndexOf(".")+1).toLowerCase();
@@ -48,4 +52,24 @@ public class FileUtil {
             file.delete();
         }
     }
+
+    public static void outputFile(HttpServletResponse response, File file, String fileName) {
+        try {
+            if (!file.exists()) {
+                response.sendError(404, "File not found!");
+            }
+
+            BufferedInputStream br = new BufferedInputStream(new FileInputStream(file));
+            String fName = URLEncoder.encode(fileName, SystemConstant.CHARSET_NAME);
+
+            response.reset();
+            response.setContentType("application/x-msdownload");
+            response.setHeader("Content-Disposition", "attachment; filename=" + fName);
+            IOUtils.copy(br, response.getOutputStream());
+            br.close();
+//            outStream.close();
+        } catch (IOException e) {
+            log.error(SystemConstant.LOG_ERROR, e);
+        }
+    }
 }