添加性别代码
parent
59997acf8f
commit
6fdc5024eb
@ -0,0 +1,23 @@
|
|||||||
|
package me.zhengjie.common.convert;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
|
||||||
|
import javax.persistence.AttributeConverter;
|
||||||
|
import javax.persistence.Converter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Enzo
|
||||||
|
* @date : 2021/12/28
|
||||||
|
*/
|
||||||
|
@Converter
|
||||||
|
public class JpaConverterListJson implements AttributeConverter<Object, String> {
|
||||||
|
@Override
|
||||||
|
public String convertToDatabaseColumn(Object obj) {
|
||||||
|
return JSONUtil.toJsonStr(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object convertToEntityAttribute(String s) {
|
||||||
|
return JSONUtil.parseArray(s);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package me.zhengjie.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Enzo
|
||||||
|
* @date : 2022/3/3
|
||||||
|
*/
|
||||||
|
public class MailConstant {
|
||||||
|
private MailConstant() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求类型
|
||||||
|
*/
|
||||||
|
public static final String MAIL_TYPE = "GS";
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,85 @@
|
|||||||
|
package me.zhengjie.utils;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.CharsetUtil;
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import net.lingala.zip4j.core.ZipFile;
|
||||||
|
import net.lingala.zip4j.exception.ZipException;
|
||||||
|
import net.lingala.zip4j.model.ZipParameters;
|
||||||
|
import net.lingala.zip4j.util.Zip4jConstants;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Enzo
|
||||||
|
* @date : 2022/10/24
|
||||||
|
*/
|
||||||
|
public class CompressUtil {
|
||||||
|
private CompressUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param zipPath 压缩文件路径
|
||||||
|
* @param filepath 文件路径
|
||||||
|
* @param password 压缩密码
|
||||||
|
*/
|
||||||
|
public static void decryptionCompression(String zipPath, String filepath, String password) {
|
||||||
|
try {
|
||||||
|
//创建压缩文件
|
||||||
|
ZipFile zipFile = new ZipFile(zipPath);
|
||||||
|
ArrayList<File> files = new ArrayList<>();
|
||||||
|
files.add(new File(filepath));
|
||||||
|
|
||||||
|
//设置压缩文件参数
|
||||||
|
ZipParameters parameters = new ZipParameters();
|
||||||
|
//设置压缩方法
|
||||||
|
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
|
||||||
|
|
||||||
|
//设置压缩级别
|
||||||
|
//DEFLATE_LEVEL_FASTEST - Lowest compression level but higher speed of compression
|
||||||
|
//DEFLATE_LEVEL_FAST - Low compression level but higher speed of compression
|
||||||
|
//DEFLATE_LEVEL_NORMAL - Optimal balance between compression level/speed
|
||||||
|
//DEFLATE_LEVEL_MAXIMUM - High compression level with a compromise of speed
|
||||||
|
//DEFLATE_LEVEL_ULTRA - Highest compression level but low speed
|
||||||
|
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
|
||||||
|
|
||||||
|
|
||||||
|
//设置加密方法
|
||||||
|
parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);
|
||||||
|
|
||||||
|
//设置aes加密强度
|
||||||
|
parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(password)) {
|
||||||
|
//设置压缩文件加密
|
||||||
|
parameters.setEncryptFiles(Boolean.TRUE);
|
||||||
|
//设置密码
|
||||||
|
parameters.setPassword(password);
|
||||||
|
}
|
||||||
|
|
||||||
|
//添加文件到压缩文件
|
||||||
|
zipFile.addFiles(files, parameters);
|
||||||
|
} catch (ZipException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String unzipFiles(String fileUrl, String zipPath, String password) throws ZipException {
|
||||||
|
File file = new File(zipPath);
|
||||||
|
ZipFile zipFile = new ZipFile(file);
|
||||||
|
//设置文件编码,根据实际场景
|
||||||
|
zipFile.setFileNameCharset(CharsetUtil.GBK);
|
||||||
|
if (zipFile.isEncrypted()) {
|
||||||
|
zipFile.setPassword(password);
|
||||||
|
}
|
||||||
|
String uuid = IdUtil.randomUUID();
|
||||||
|
String filePath
|
||||||
|
= fileUrl.concat(StrUtil.SLASH).concat(uuid);
|
||||||
|
zipFile.extractAll(filePath);
|
||||||
|
return filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package me.zhengjie.modules.gender.config.properties;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Enzo
|
||||||
|
* @date : 2022/10/18
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "gender")
|
||||||
|
public class DeliveryProperties {
|
||||||
|
|
||||||
|
@ApiModelProperty("文件地址")
|
||||||
|
private String fileUrl;
|
||||||
|
|
||||||
|
@ApiModelProperty("压缩密码")
|
||||||
|
private String zipPassword;
|
||||||
|
|
||||||
|
@ApiModelProperty("下载地址")
|
||||||
|
private String downPath;
|
||||||
|
|
||||||
|
@ApiModelProperty("emailAddress")
|
||||||
|
private String emailAddress;
|
||||||
|
|
||||||
|
@ApiModelProperty("genderEmailAddress")
|
||||||
|
private String genderEmailAddress;
|
||||||
|
|
||||||
|
|
||||||
|
@ApiModelProperty("emailPassword")
|
||||||
|
private String emailPassword;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ApiModelProperty("toGenderEmailAddress")
|
||||||
|
private String toGenderEmailAddress;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019-2020 Zheng Jie
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package me.zhengjie.modules.gender.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import cn.hutool.core.bean.copier.CopyOptions;
|
||||||
|
import me.zhengjie.common.convert.JpaConverterListJson;
|
||||||
|
import org.hibernate.annotations.CreationTimestamp;
|
||||||
|
import org.hibernate.annotations.UpdateTimestamp;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import javax.validation.constraints.*;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @website https://el-admin.vip
|
||||||
|
* @description /
|
||||||
|
* @author Enzo
|
||||||
|
* @date 2023-06-01
|
||||||
|
**/
|
||||||
|
@Entity
|
||||||
|
@Data
|
||||||
|
@Table(name="tb_delivery_gender")
|
||||||
|
public class DeliveryGender implements Serializable {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "id")
|
||||||
|
@ApiModelProperty(value = "id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "task_name")
|
||||||
|
@ApiModelProperty(value = "名称")
|
||||||
|
private String taskName;
|
||||||
|
|
||||||
|
@Column(name = "num")
|
||||||
|
@ApiModelProperty(value = "数量")
|
||||||
|
private Integer num;
|
||||||
|
|
||||||
|
@Column(name = "status")
|
||||||
|
@ApiModelProperty(value = "状态")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
@Column(name = "down_url")
|
||||||
|
@ApiModelProperty(value = "下载地址")
|
||||||
|
private String downUrl;
|
||||||
|
|
||||||
|
@Column(name = "down_path")
|
||||||
|
@ApiModelProperty(value = "文件地址")
|
||||||
|
private String downPath;
|
||||||
|
|
||||||
|
@Column(name = "mail_name")
|
||||||
|
@ApiModelProperty(value = "文件地址")
|
||||||
|
private String mailName;
|
||||||
|
|
||||||
|
@Column(name = "type")
|
||||||
|
@ApiModelProperty(value = "类型")
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
|
@CreationTimestamp
|
||||||
|
@Column(name = "create_time")
|
||||||
|
@ApiModelProperty(value = "创建时间")
|
||||||
|
private Timestamp createTime;
|
||||||
|
|
||||||
|
@UpdateTimestamp
|
||||||
|
@Column(name = "update_time")
|
||||||
|
@ApiModelProperty(value = "更新时间")
|
||||||
|
private Timestamp updateTime;
|
||||||
|
|
||||||
|
@Column(name = "task_num_str")
|
||||||
|
@ApiModelProperty(value = "标识")
|
||||||
|
@Convert(converter = JpaConverterListJson.class)
|
||||||
|
private List<String> taskNumStr;
|
||||||
|
|
||||||
|
public void copy(DeliveryGender source){
|
||||||
|
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019-2020 Zheng Jie
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package me.zhengjie.modules.gender.repository;
|
||||||
|
|
||||||
|
import me.zhengjie.modules.gender.domain.DeliveryGender;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Enzo
|
||||||
|
* @website https://el-admin.vip
|
||||||
|
* @date 2023-06-01
|
||||||
|
**/
|
||||||
|
public interface DeliveryGenderRepository extends JpaRepository<DeliveryGender, Long>, JpaSpecificationExecutor<DeliveryGender> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务查找记录
|
||||||
|
*
|
||||||
|
* @param taskName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Query(value = "from DeliveryGender where taskName = ?1 order by id desc ")
|
||||||
|
List<DeliveryGender> findByTaskName(String taskName);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送邮件查找记录
|
||||||
|
*
|
||||||
|
* @param taskName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Query(value = "from DeliveryGender where mailName = ?1 order by id desc ")
|
||||||
|
List<DeliveryGender> findByMailName(String taskName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改状态
|
||||||
|
*
|
||||||
|
* @param num
|
||||||
|
* @param taskName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Modifying
|
||||||
|
@Query("UPDATE DeliveryGender d set d.status = ?1 where d.taskName = ?2")
|
||||||
|
int updateStatusAndDecryptNum(Integer num, String taskName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改状态
|
||||||
|
* @param downUrl
|
||||||
|
* @param zipPath
|
||||||
|
* @param number
|
||||||
|
* @param taskName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Modifying
|
||||||
|
@Query("UPDATE DeliveryGender d set d.status = ?3,d.downUrl = ?1,d.downPath = ?2 where d.taskName = ?4")
|
||||||
|
int updateStatusAndDownUrlByTaskName(String downUrl, String zipPath, Integer number, String taskName);
|
||||||
|
}
|
@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019-2020 Zheng Jie
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package me.zhengjie.modules.gender.rest;
|
||||||
|
|
||||||
|
import me.zhengjie.annotation.Log;
|
||||||
|
import me.zhengjie.modules.gender.domain.DeliveryGender;
|
||||||
|
import me.zhengjie.modules.gender.service.DeliveryGenderService;
|
||||||
|
import me.zhengjie.modules.gender.service.dto.DeliveryGenderQueryCriteria;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import io.swagger.annotations.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @website https://el-admin.vip
|
||||||
|
* @author Enzo
|
||||||
|
* @date 2023-06-01
|
||||||
|
**/
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/api/deliveryGender")
|
||||||
|
public class DeliveryGenderController {
|
||||||
|
|
||||||
|
private final DeliveryGenderService deliveryGenderService;
|
||||||
|
|
||||||
|
@Log("导出数据")
|
||||||
|
@ApiOperation("导出数据")
|
||||||
|
@GetMapping(value = "/download")
|
||||||
|
@PreAuthorize("@el.check('deliveryGender:list')")
|
||||||
|
public void download(HttpServletResponse response, DeliveryGenderQueryCriteria criteria) throws IOException {
|
||||||
|
deliveryGenderService.download(deliveryGenderService.queryAll(criteria), response);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
@ApiOperation("查询")
|
||||||
|
@PreAuthorize("@el.check('deliveryGender:list')")
|
||||||
|
public ResponseEntity<Object> query(DeliveryGenderQueryCriteria criteria, Pageable pageable){
|
||||||
|
return new ResponseEntity<>(deliveryGenderService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
@ApiOperation("新增")
|
||||||
|
@PreAuthorize("@el.check('deliveryGender:add')")
|
||||||
|
public ResponseEntity<Object> create(@Validated @RequestBody DeliveryGender resources){
|
||||||
|
return new ResponseEntity<>(deliveryGenderService.create(resources),HttpStatus.CREATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping
|
||||||
|
@ApiOperation("修改")
|
||||||
|
@PreAuthorize("@el.check('deliveryGender:edit')")
|
||||||
|
public ResponseEntity<Object> update(@Validated @RequestBody DeliveryGender resources){
|
||||||
|
deliveryGenderService.update(resources);
|
||||||
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("删除")
|
||||||
|
@PreAuthorize("@el.check('deliveryGender:del')")
|
||||||
|
@DeleteMapping
|
||||||
|
public ResponseEntity<Object> delete(@RequestBody Long[] ids) {
|
||||||
|
deliveryGenderService.deleteAll(ids);
|
||||||
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation("上传文件发送邮件")
|
||||||
|
@PostMapping("/upload/files")
|
||||||
|
public ResponseEntity<Object> uploadFile(@RequestParam("file") MultipartFile[] files, @RequestParam(value = "taskName") String taskName) {
|
||||||
|
return new ResponseEntity<>(deliveryGenderService.uploadFile(files, taskName), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,110 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019-2020 Zheng Jie
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package me.zhengjie.modules.gender.service;
|
||||||
|
|
||||||
|
import me.zhengjie.modules.gender.domain.DeliveryGender;
|
||||||
|
import me.zhengjie.modules.gender.service.dto.DeliveryGenderDto;
|
||||||
|
import me.zhengjie.modules.gender.service.dto.DeliveryGenderQueryCriteria;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.List;
|
||||||
|
import java.io.IOException;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @website https://el-admin.vip
|
||||||
|
* @description 服务接口
|
||||||
|
* @author Enzo
|
||||||
|
* @date 2023-06-01
|
||||||
|
**/
|
||||||
|
public interface DeliveryGenderService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询数据分页
|
||||||
|
* @param criteria 条件
|
||||||
|
* @param pageable 分页参数
|
||||||
|
* @return Map<String,Object>
|
||||||
|
*/
|
||||||
|
Map<String,Object> queryAll(DeliveryGenderQueryCriteria criteria, Pageable pageable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有数据不分页
|
||||||
|
* @param criteria 条件参数
|
||||||
|
* @return List<DeliveryGenderDto>
|
||||||
|
*/
|
||||||
|
List<DeliveryGenderDto> queryAll(DeliveryGenderQueryCriteria criteria);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询
|
||||||
|
* @param id ID
|
||||||
|
* @return DeliveryGenderDto
|
||||||
|
*/
|
||||||
|
DeliveryGenderDto findById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建
|
||||||
|
* @param resources /
|
||||||
|
* @return DeliveryGenderDto
|
||||||
|
*/
|
||||||
|
DeliveryGenderDto create(DeliveryGender resources);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编辑
|
||||||
|
* @param resources /
|
||||||
|
*/
|
||||||
|
void update(DeliveryGender resources);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多选删除
|
||||||
|
* @param ids /
|
||||||
|
*/
|
||||||
|
void deleteAll(Long[] ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出数据
|
||||||
|
* @param all 待导出的数据
|
||||||
|
* @param response /
|
||||||
|
* @throws IOException /
|
||||||
|
*/
|
||||||
|
void download(List<DeliveryGenderDto> all, HttpServletResponse response) throws IOException;
|
||||||
|
/**
|
||||||
|
* 上传文件发送邮件
|
||||||
|
*
|
||||||
|
* @param files
|
||||||
|
* @param taskName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Boolean uploadFile(MultipartFile[] files, String taskName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 名称查找
|
||||||
|
* @param substring
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
DeliveryGender findByMailName(String substring);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改下载地址
|
||||||
|
*
|
||||||
|
* @param downUrl
|
||||||
|
* @param zipPath
|
||||||
|
* @param number
|
||||||
|
* @param taskName
|
||||||
|
*/
|
||||||
|
Boolean updateStatusByTaskName(String downUrl, String zipPath, Integer number, String taskName);
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019-2020 Zheng Jie
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package me.zhengjie.modules.gender.service.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @website https://el-admin.vip
|
||||||
|
* @description /
|
||||||
|
* @author Enzo
|
||||||
|
* @date 2023-06-01
|
||||||
|
**/
|
||||||
|
@Data
|
||||||
|
public class DeliveryGenderDto implements Serializable {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/** 名称 */
|
||||||
|
private String taskName;
|
||||||
|
|
||||||
|
/** 数量 */
|
||||||
|
private Integer num;
|
||||||
|
|
||||||
|
/** 状态 */
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
/** 类型 */
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
|
/** 创建时间 */
|
||||||
|
private Timestamp createTime;
|
||||||
|
|
||||||
|
/** 更新时间 */
|
||||||
|
private Timestamp updateTime;
|
||||||
|
|
||||||
|
/** 标识 */
|
||||||
|
private List<String> taskNumStr;
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019-2020 Zheng Jie
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package me.zhengjie.modules.gender.service.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import me.zhengjie.annotation.Query;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Enzo
|
||||||
|
* @website https://el-admin.vip
|
||||||
|
* @date 2023-06-01
|
||||||
|
**/
|
||||||
|
@Data
|
||||||
|
public class DeliveryGenderQueryCriteria {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模糊
|
||||||
|
*/
|
||||||
|
@Query(type = Query.Type.INNER_LIKE)
|
||||||
|
private String taskName;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,207 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019-2020 Zheng Jie
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package me.zhengjie.modules.gender.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import me.zhengjie.exception.BadRequestException;
|
||||||
|
import me.zhengjie.modules.constant.FileConstant;
|
||||||
|
import me.zhengjie.modules.gender.config.properties.DeliveryProperties;
|
||||||
|
import me.zhengjie.modules.gender.domain.DeliveryGender;
|
||||||
|
import me.zhengjie.modules.gender.repository.DeliveryGenderRepository;
|
||||||
|
import me.zhengjie.modules.gender.service.DeliveryGenderService;
|
||||||
|
import me.zhengjie.modules.gender.service.dto.DeliveryGenderDto;
|
||||||
|
import me.zhengjie.modules.gender.service.dto.DeliveryGenderQueryCriteria;
|
||||||
|
import me.zhengjie.modules.gender.service.mapstruct.DeliveryGenderMapper;
|
||||||
|
import me.zhengjie.modules.uploadnew.util.AESUtils;
|
||||||
|
import me.zhengjie.modules.uploadnew.util.ToolExcelUtils;
|
||||||
|
import me.zhengjie.modules.uploadnew.util.TxtUtils;
|
||||||
|
import me.zhengjie.modules.uploadnew.util.ZipUtils;
|
||||||
|
import me.zhengjie.utils.*;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Enzo
|
||||||
|
* @website https://el-admin.vip
|
||||||
|
* @description 服务实现
|
||||||
|
* @date 2023-06-01
|
||||||
|
**/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class DeliveryGenderServiceImpl implements DeliveryGenderService {
|
||||||
|
|
||||||
|
private final DeliveryGenderRepository deliveryGenderRepository;
|
||||||
|
|
||||||
|
private final DeliveryGenderMapper deliveryGenderMapper;
|
||||||
|
|
||||||
|
private final DeliveryProperties deliveryProperties;
|
||||||
|
|
||||||
|
private final RedisUtils redisUtils;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> queryAll(DeliveryGenderQueryCriteria criteria, Pageable pageable) {
|
||||||
|
Page<DeliveryGender> page = deliveryGenderRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
|
||||||
|
return PageUtil.toPage(page.map(deliveryGenderMapper::toDto));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DeliveryGenderDto> queryAll(DeliveryGenderQueryCriteria criteria) {
|
||||||
|
return deliveryGenderMapper.toDto(deliveryGenderRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public DeliveryGenderDto findById(Long id) {
|
||||||
|
DeliveryGender deliveryGender = deliveryGenderRepository.findById(id).orElseGet(DeliveryGender::new);
|
||||||
|
ValidationUtil.isNull(deliveryGender.getId(), "DeliveryGender", "id", id);
|
||||||
|
return deliveryGenderMapper.toDto(deliveryGender);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public DeliveryGenderDto create(DeliveryGender resources) {
|
||||||
|
return deliveryGenderMapper.toDto(deliveryGenderRepository.save(resources));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void update(DeliveryGender resources) {
|
||||||
|
DeliveryGender deliveryGender = deliveryGenderRepository.findById(resources.getId()).orElseGet(DeliveryGender::new);
|
||||||
|
ValidationUtil.isNull(deliveryGender.getId(), "DeliveryGender", "id", resources.getId());
|
||||||
|
deliveryGender.copy(resources);
|
||||||
|
deliveryGenderRepository.save(deliveryGender);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteAll(Long[] ids) {
|
||||||
|
for (Long id : ids) {
|
||||||
|
DeliveryGender deliveryGender = deliveryGenderRepository.findById(id).orElseGet(DeliveryGender::new);
|
||||||
|
if (ObjectUtil.isNotNull(deliveryGender)){
|
||||||
|
FileUtil.del(deliveryGender.getDownPath());
|
||||||
|
}
|
||||||
|
deliveryGenderRepository.deleteById(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void download(List<DeliveryGenderDto> all, HttpServletResponse response) throws IOException {
|
||||||
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
|
for (DeliveryGenderDto genderDto : all) {
|
||||||
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
|
map.put("名称", genderDto.getTaskName());
|
||||||
|
map.put("数量", genderDto.getNum());
|
||||||
|
map.put("状态", genderDto.getStatus());
|
||||||
|
map.put("类型", genderDto.getType());
|
||||||
|
map.put("创建时间", genderDto.getCreateTime());
|
||||||
|
map.put("更新时间", genderDto.getUpdateTime());
|
||||||
|
map.put("标识", genderDto.getTaskNumStr());
|
||||||
|
list.add(map);
|
||||||
|
}
|
||||||
|
FileUtil.downloadExcel(list, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SneakyThrows
|
||||||
|
public Boolean uploadFile(MultipartFile[] files, String taskName) {
|
||||||
|
if (files.length > 0) {
|
||||||
|
List<String> arrayList = Lists.newArrayList();
|
||||||
|
for (MultipartFile file : files) {
|
||||||
|
String originalFilename = file.getOriginalFilename();
|
||||||
|
File filePath = FileUtil.multiToFile(file);
|
||||||
|
if (StringUtils.isNotBlank(originalFilename)) {
|
||||||
|
arrayList = originalFilename.contains(FileConstant.TXT_FILE_SUB_NAME)
|
||||||
|
? TxtUtils.txtParseListVyUrl(filePath.getPath()) :
|
||||||
|
originalFilename.contains(FileConstant.CSV_FILE_SUB_NAME)
|
||||||
|
? ToolExcelUtils.csvParseListByUrl(filePath.getPath())
|
||||||
|
: ToolExcelUtils.excelParseListByUrl(filePath.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (CollUtil.isNotEmpty(arrayList)) {
|
||||||
|
// 去除重复数据
|
||||||
|
List<String> dtoArrayList = Lists.newArrayList(Sets.newHashSet(arrayList));
|
||||||
|
// 加密
|
||||||
|
List<String> stringList = dtoArrayList.stream().filter
|
||||||
|
(StringUtils::isNotBlank).map
|
||||||
|
(source -> AESUtils.dbEncrypt(FileConstant.AES_PASSWORD, source))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (stringList.size() < 100) {
|
||||||
|
throw new BadRequestException("上传条数不能小于100条");
|
||||||
|
}
|
||||||
|
// 每次500000 数据
|
||||||
|
List<List<String>> partition = Lists.partition(stringList, 500000);
|
||||||
|
for (List<String> list : partition) {
|
||||||
|
String uuid = IdUtil.fastSimpleUUID();
|
||||||
|
String sendMailName = redisUtils.acquisitionBatch(CacheKey.GR_REQUEST_TYPE);
|
||||||
|
String file = FileUtil.SYS_TEM_DIR.concat(StrUtil.SLASH).concat(uuid);
|
||||||
|
// 保存文件下载地址
|
||||||
|
ZipUtils.zipFileAndSendGenderMail(list, file, sendMailName, deliveryProperties);
|
||||||
|
this.saveDeliveryRecord(taskName, sendMailName, list.size(), 1);
|
||||||
|
}
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Boolean.FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean saveDeliveryRecord(String taskImeiName, String sendMailName, Integer num, Integer type) {
|
||||||
|
DeliveryGender deliveryRecord = new DeliveryGender();
|
||||||
|
deliveryRecord.setNum(num);
|
||||||
|
deliveryRecord.setStatus(0);
|
||||||
|
deliveryRecord.setType(type);
|
||||||
|
deliveryRecord.setMailName(sendMailName);
|
||||||
|
deliveryRecord.setTaskName(taskImeiName);
|
||||||
|
return deliveryGenderRepository.save(deliveryRecord).getId() != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeliveryGender findByMailName(String taskName) {
|
||||||
|
// 防止重复提交数据
|
||||||
|
List<DeliveryGender> byTaskName =
|
||||||
|
deliveryGenderRepository.findByMailName(taskName);
|
||||||
|
return CollUtil.isNotEmpty(byTaskName) ? byTaskName.get(0) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean updateStatusByTaskName(String downUrl, String zipPath, Integer number, String taskName) {
|
||||||
|
return deliveryGenderRepository.updateStatusAndDownUrlByTaskName(downUrl, zipPath, number, taskName) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019-2020 Zheng Jie
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package me.zhengjie.modules.gender.service.mapstruct;
|
||||||
|
|
||||||
|
import me.zhengjie.base.BaseMapper;
|
||||||
|
import me.zhengjie.modules.gender.domain.DeliveryGender;
|
||||||
|
import me.zhengjie.modules.gender.service.dto.DeliveryGenderDto;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.ReportingPolicy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @website https://el-admin.vip
|
||||||
|
* @author Enzo
|
||||||
|
* @date 2023-06-01
|
||||||
|
**/
|
||||||
|
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||||
|
public interface DeliveryGenderMapper extends BaseMapper<DeliveryGenderDto, DeliveryGender> {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,135 @@
|
|||||||
|
package me.zhengjie.modules.gender.task;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.text.csv.CsvData;
|
||||||
|
import cn.hutool.core.text.csv.CsvReader;
|
||||||
|
import cn.hutool.core.text.csv.CsvUtil;
|
||||||
|
import cn.hutool.core.text.csv.CsvWriter;
|
||||||
|
import cn.hutool.core.util.CharsetUtil;
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.google.common.base.Joiner;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import me.zhengjie.constant.MailConstant;
|
||||||
|
import me.zhengjie.modules.constant.FileConstant;
|
||||||
|
import me.zhengjie.modules.gender.config.properties.DeliveryProperties;
|
||||||
|
import me.zhengjie.modules.gender.domain.DeliveryGender;
|
||||||
|
import me.zhengjie.modules.gender.service.DeliveryGenderService;
|
||||||
|
import me.zhengjie.modules.uploadnew.util.AESUtils;
|
||||||
|
import me.zhengjie.utils.*;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.mail.Message;
|
||||||
|
import javax.mail.internet.MimeMessage;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Enzo
|
||||||
|
* @date : 2023/5/15
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class GenderConversionTask {
|
||||||
|
|
||||||
|
|
||||||
|
private final RedisUtils redisUtils;
|
||||||
|
|
||||||
|
private final DeliveryProperties deliveryProperties;
|
||||||
|
|
||||||
|
private final DeliveryGenderService deliveryGenderService;
|
||||||
|
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
@Scheduled(cron = "0 0/10 * * * ? ")
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void receiveMail() {
|
||||||
|
// 获取邮件内容
|
||||||
|
List<Message> list = MailUtil.readMailByIMAP
|
||||||
|
(deliveryProperties.getGenderEmailAddress(), deliveryProperties.getEmailPassword());
|
||||||
|
if (CollUtil.isNotEmpty(list)) {
|
||||||
|
for (Message message : list) {
|
||||||
|
// 获取未读的邮件内容 且与之对应
|
||||||
|
if (deliveryProperties.getToGenderEmailAddress().equalsIgnoreCase
|
||||||
|
(MailUtil.getFrom((MimeMessage) message))) {
|
||||||
|
String taskName = message.getSubject();
|
||||||
|
Object objCache = redisUtils.get(taskName);
|
||||||
|
if (ObjectUtil.isNotNull(objCache)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 设置十分钟缓存
|
||||||
|
redisUtils.set(taskName, taskName, 10, TimeUnit.MINUTES);
|
||||||
|
if (taskName.startsWith(MailConstant.MAIL_TYPE)) {
|
||||||
|
String substring = taskName.substring(0, taskName.lastIndexOf(StrUtil.DASHED));
|
||||||
|
DeliveryGender byTaskName = deliveryGenderService.findByMailName(substring);
|
||||||
|
if (ObjectUtil.isNotNull(byTaskName)
|
||||||
|
&& !byTaskName.getTaskNumStr().contains(taskName)) {
|
||||||
|
List<String> taskNumStr = byTaskName.getTaskNumStr();
|
||||||
|
taskNumStr.add(taskName);
|
||||||
|
log.info("================ the gender mail taskName as {} ==============", taskName);
|
||||||
|
List<String> joinList = Lists.newArrayList();
|
||||||
|
CsvReader reader = CsvUtil.getReader();
|
||||||
|
// 解析附件内容并保存文件
|
||||||
|
String path = MailUtil.saveAttachMent
|
||||||
|
(message, deliveryProperties.getFileUrl());
|
||||||
|
// 解压文件
|
||||||
|
String unzipPath =
|
||||||
|
CompressUtil.unzipFiles(deliveryProperties.getFileUrl(),
|
||||||
|
path, deliveryProperties.getZipPassword());
|
||||||
|
File file = new File(unzipPath);
|
||||||
|
File parseFile = Objects.requireNonNull
|
||||||
|
(file.listFiles())[0];
|
||||||
|
// 解析文件
|
||||||
|
CsvData data = reader.read(parseFile);
|
||||||
|
// csv通配
|
||||||
|
data.getRows().forEach(clue -> {
|
||||||
|
String decrypt = AESUtils.dbDecrypt
|
||||||
|
(FileConstant.AES_PASSWORD, clue.get(0));
|
||||||
|
String aesEncrypt = EncryptUtil.aesEncrypt(decrypt, FileConstant.PLAT_DECRYPTION);
|
||||||
|
List<String> collect = Stream.of(aesEncrypt, clue.get(1)).collect(Collectors.toList());
|
||||||
|
String join = Joiner.on(StrUtil.COMMA).skipNulls().join(collect);
|
||||||
|
joinList.add(join);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(byTaskName.getDownPath())) {
|
||||||
|
FileUtil.writeToCsv(joinList, parseFile.getPath(), Boolean.TRUE);
|
||||||
|
deliveryGenderService.update(byTaskName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String down = deliveryProperties.getFileUrl().concat(StrUtil.SLASH).concat(IdUtil.fastSimpleUUID());
|
||||||
|
// 首次加载
|
||||||
|
String csvPath = down.concat(StrUtil.DOT).concat(FileConstant.CSV_FILE_SUB_NAME);
|
||||||
|
String zipPath = down.concat(StrUtil.DOT).concat(FileConstant.ZIP_FILE_SUB_NAME);
|
||||||
|
CsvWriter writer = CsvUtil.getWriter(csvPath, CharsetUtil.CHARSET_UTF_8);
|
||||||
|
writer.write(joinList);
|
||||||
|
writer.close();
|
||||||
|
// 设置压缩文件
|
||||||
|
CompressUtil.decryptionCompression(zipPath, csvPath, null);
|
||||||
|
String filePath = zipPath.substring
|
||||||
|
(zipPath.lastIndexOf(StrUtil.SLASH) + 1);
|
||||||
|
String downUrl = deliveryProperties.getDownPath().concat(filePath);
|
||||||
|
byTaskName.setStatus(1);
|
||||||
|
byTaskName.setDownUrl(downUrl);
|
||||||
|
byTaskName.setDownPath(zipPath);
|
||||||
|
deliveryGenderService.update(byTaskName);
|
||||||
|
log.info("================ change down url {} zip url {} ================", zipPath, filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue