代码提交

master
yqy 3 years ago
parent accabed021
commit 4e248c5324

@ -76,4 +76,11 @@ public class ClueDto implements Serializable {
@ApiModelProperty(value = "任务名")
private String taskName;
@ApiModelProperty(value = "组呼叫方式0:双呼 1:点呼 2:AXB")
private Integer callMode;
@ApiModelProperty(value = "版本号")
private Integer optimisticVersion;
}

@ -40,6 +40,11 @@ public class Organize implements Serializable {
@Column(name = "organize_name")
private String organizeName;
@ApiModelProperty(value = "组呼叫方式0:双呼 1:点呼 2:AXB")
@NotNull(message = "请选择呼叫方式")
@Column(name = "call_mode")
private Integer callMode;
@ApiModelProperty(value = "创建人")
@Column(name = "create_by")
private Long createBy;

@ -21,6 +21,8 @@ public class OrganizeDto implements Serializable {
private String organizeName;
private Integer callMode;
private Long createBy;
private Date createTime;

@ -23,7 +23,6 @@ import com.google.common.collect.Lists;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
@ -292,6 +291,7 @@ public class OrganizeServiceImpl implements OrganizeService {
//发送通知
// userIdList.add(SecurityUtils.getCurrentUserId());
MessageNotification messageNotification = new MessageNotification();
messageNotification.setMessageTitle("分配通知");
messageNotification.setMessageType(2);
messageNotification.setMessageContext("接收到" + organizeSaveDTO.getOrganizeTaskName() + "任务分配");
userMessageService.createUserMessage(userIdList, messageNotification, DefaultNumberConstants.TWO_NUMBER);
@ -436,6 +436,7 @@ public class OrganizeServiceImpl implements OrganizeService {
// userIds.add(SecurityUtils.getCurrentUserId());
List<Long> userIdList = new ArrayList<>(userIds);
MessageNotification messageNotification = new MessageNotification();
messageNotification.setMessageTitle("分配通知");
messageNotification.setMessageType(2);
messageNotification.setMessageContext("接收到" + updateTaskOrganize.getOrganizeTaskName() + "任务分配");
userMessageService.createUserMessage(userIdList, messageNotification, DefaultNumberConstants.TWO_NUMBER);
@ -505,6 +506,7 @@ public class OrganizeServiceImpl implements OrganizeService {
list.add(taskOrganizeDto.getOrganizeTaskName());
map.put("taskName", list);
}
return map;
}
map.put("organizeLabel", taskOrganizeDto.getOrganizeLabel());
Task task = taskRepository.findById(taskId).orElseGet(Task::new);

@ -6,6 +6,7 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
/**
* @author YQY
@ -15,6 +16,7 @@ import org.springframework.scheduling.annotation.EnableAsync;
@EnableJpaAuditing
@EnableFeignClients
@EnableDiscoveryClient
@EnableScheduling
public class AdPlatformSourceApplication {
public static void main(String[] args) {
SpringApplication.run(AdPlatformSourceApplication.class, args);

@ -1,9 +1,12 @@
package com.baiye.feign;
import com.baiye.feign.fallback.OrganizeClientFallback;
import com.baiye.model.dto.OrganizeQueryCriteria;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@ -22,4 +25,8 @@ public interface OrganizeClient {
*/
@GetMapping(PAY_PREFIX + "/getLabel")
ResponseEntity<Map<String, List<String>>> getLabel(@RequestParam("taskId") Long taskId,@RequestParam("organizeId") Long organizeId);
@ApiOperation("查询组")
@GetMapping(PAY_PREFIX + "/query")
ResponseEntity<Object> query(@RequestParam("id") Long organizeId);
}

@ -1,6 +1,7 @@
package com.baiye.feign.fallback;
import com.baiye.feign.OrganizeClient;
import com.baiye.model.dto.OrganizeQueryCriteria;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
@ -13,4 +14,9 @@ public class OrganizeClientFallback implements OrganizeClient {
public ResponseEntity<Map<String, List<String>>> getLabel(Long taskId, Long organizeId) {
return null;
}
@Override
public ResponseEntity<Object> query(Long organizeId) {
return null;
}
}

@ -38,7 +38,8 @@ public class ClueJpa {
public List<ClueDto> getClueList(ClueQueryCriteria clueQueryCriteria, Pageable pageable) {
StringBuilder sql = new StringBuilder();
sql.append("select c.id as id,c.name as name,c.nid as nid,c.wx as wx,c.origin as origin,c.collect_time as collectTime,c.address as address,c.record_id as recordId," +
"c.create_time as createTime,cm.remark as remark,cm.member_status as memberStatus,cm.organize_id as organizeId,cm.member_id as memberId,cm.source_label as sourceLabel,cm.task_id as taskId " +
"c.create_time as createTime,cm.remark as remark,cm.member_status as memberStatus,cm.organize_id as organizeId,cm.member_id as memberId," +
"cm.optimistic_version as optimisticVersion,cm.source_label as sourceLabel,cm.task_id as taskId " +
"from tb_clue as c LEFT JOIN tb_clue_middle as cm on c.id = cm.clue_id where 1=1 ");
List confirmReceipt = getConfirmReceipt(clueQueryCriteria, sql, pageable);
return getTradeInfo(confirmReceipt);
@ -149,6 +150,7 @@ public class ClueJpa {
clueDto.setMemberId(memberId.longValue());
BigInteger taskId = (BigInteger) row.get("taskId");
clueDto.setTaskId(taskId.longValue());
clueDto.setOptimisticVersion((Integer) row.get("optimisticVersion"));
clueDtoList.add(clueDto);
}
return clueDtoList;

@ -85,4 +85,12 @@ public interface ClueMiddleRepository extends JpaRepository<ClueMiddle, Long>, J
* @return
*/
List<ClueMiddle> findByTaskIdAndOrganizeId(Long taskId, Long organizeId);
/**
*
* @param clueId
* @return
*/
@Query(value = " select optimistic_version from tb_clue_middle where clue_id = ?1 ", nativeQuery = true)
Integer lookUpOptimisticVersion(Long clueId);
}

@ -57,4 +57,9 @@ public class ClueMiddle{
@ApiModelProperty(value = "备注")
@Column(name = "remark")
private String remark;
@ApiModelProperty(value = "版本号")
@NotNull(message = "版本号不能为空")
@Column(name = "optimistic_version")
private Integer optimisticVersion;
}

@ -6,7 +6,6 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import javax.persistence.Column;
import java.io.Serializable;
import java.util.List;
@ -35,4 +34,7 @@ public class ClueMiddleDto implements Serializable {
@ApiModelProperty(value = "备注")
private String remark;
@ApiModelProperty(value = "版本号")
private Integer optimisticVersion;
}

@ -1,5 +1,8 @@
package com.baiye.module.service.impl;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baiye.constant.DefaultNumberConstants;
import com.baiye.exception.BadRequestException;
import com.baiye.feign.OrganizeClient;
@ -54,6 +57,7 @@ public class ClueServiceImpl implements ClueService {
clueMiddle.setClueId(clue.getId());
clueMiddle.setTaskId(taskId);
clueMiddle.setMemberStatus(DefaultNumberConstants.ZERO_NUMBER);
clueMiddle.setOptimisticVersion(DefaultNumberConstants.ZERO_NUMBER);
clueMiddleRepository.save(clueMiddle);
}
}
@ -163,6 +167,12 @@ public class ClueServiceImpl implements ClueService {
// id查询(详情查询)时返回标签信息
if (clueQueryCriteria.getId() != null) {
for (ClueDto clueDto : clueDtoList) {
//循环查库ID查询只一次循环
// String organizeStr = organizeClient.query(clueDto.getOrganizeId()).getBody().toString();
// String str = organizeStr.replaceAll("=", ":");
// JSONArray jsonArray = JSONUtil.parseArray(str);
// JSONObject jsonObject = JSONUtil.parseObj(jsonArray.get(0));
// clueDto.setCallMode((Integer)jsonObject.get("callMode"));
Map<String, List<String>> mapList = organizeClient.getLabel(clueDto.getTaskId(), clueDto.getOrganizeId()).getBody();
clueDto.setBaseLabel(mapList.get("baseLabel"));
clueDto.setOrganizeLabel(mapList.get("organizeLabel"));
@ -202,6 +212,13 @@ public class ClueServiceImpl implements ClueService {
@Override
@Transactional(rollbackFor = Exception.class)
public void update(ClueMiddle clueMiddle) {
//乐观锁,不用jpa查询(jpa有缓存这个坑)
if (clueMiddle.getOptimisticVersion() != null){
Integer version = clueMiddleRepository.lookUpOptimisticVersion(clueMiddle.getClueId());
if (version != clueMiddle.getOptimisticVersion()){
throw new BadRequestException("刷新后重试");
}
}
ClueMiddle clueMiddleOne = clueMiddleRepository.findById(clueMiddle.getClueId()).orElseGet(ClueMiddle::new);
if (clueMiddle.getSourceLabel() != null) {
List<String> sourceLabelList = clueMiddle.getSourceLabel();
@ -215,6 +232,7 @@ public class ClueServiceImpl implements ClueService {
if (StringUtils.isNotBlank(clueMiddle.getRemark())) {
clueMiddleOne.setRemark(clueMiddle.getRemark());
}
clueMiddleOne.setOptimisticVersion(clueMiddle.getOptimisticVersion() + 1);
clueMiddleRepository.save(clueMiddleOne);
}

@ -1,5 +1,8 @@
package com.baiye.module.service.impl;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.text.csv.CsvData;
import cn.hutool.core.text.csv.CsvRow;
import cn.hutool.core.text.csv.CsvUtil;
@ -16,11 +19,13 @@ import com.baiye.module.entity.Task;
import com.baiye.module.service.UploadFileService;
import com.baiye.task.FileAnalysisTask;
import com.baiye.module.constant.FileConstant;
import com.baiye.util.FileZipUtil;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
@ -266,6 +271,21 @@ public class UploadFileServiceImpl implements UploadFileService {
return true;
}
/**
* (3)
* @throws Exception
*/
@Scheduled(cron = "0 0 3 * * ? *")
public void compress() throws Exception {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
DateTime date = DateUtil.yesterday();
String path = URL + dateFormat.format(date);
boolean directory = FileUtil.isDirectory(path);
if (directory){
FileZipUtil.zipFile(new File(path),"zip");
}
}
/**
* +
*

@ -0,0 +1,170 @@
package com.baiye.util;
import cn.hutool.core.io.FileUtil;
import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
* ziprar
*/
public class FileZipUtil {
/**
* @param path
* @param format ziprard
*/
public static void generateFile(String path, String format) throws Exception {
File file = new File(path);
// 压缩文件的路径不存在
if (!file.exists()) {
throw new Exception("路径 " + path + " 不存在文件,无法进行压缩...");
}
// 用于存放压缩文件的文件夹
String generateFile = file.getParent() + File.separator;
File compress = new File(generateFile);
// 如果文件夹不存在,进行创建
if (!compress.exists()) {
compress.mkdirs();
}
// 目的压缩文件
String generateFileName = compress.getAbsolutePath() + File.separator + file.getName() + "." + format;
// 输入流 表示从一个源读取数据
// 输出流 表示向一个目标写入数据
// 输出流
FileOutputStream outputStream = new FileOutputStream(generateFileName);
// 压缩输出流
ZipOutputStream zipOutputStream = new ZipOutputStream(new BufferedOutputStream(outputStream));
generateFile(zipOutputStream, file, "");
System.out.println("源文件位置:" + file.getAbsolutePath() + ",目的压缩文件生成位置:" + generateFileName);
//删除源文件
file.delete();
// 关闭 输出流
zipOutputStream.close();
}
/**
* @param out
* @param file
* @param dir
* @throws Exception
*/
private static void generateFile(ZipOutputStream out, File file, String dir) throws Exception {
// 当前的是文件夹,则进行一步处理
if (file.isDirectory()) {
//得到文件列表信息
File[] files = file.listFiles();
//将文件夹添加到下一级打包目录
out.putNextEntry(new ZipEntry(dir + "/"));
dir = dir.length() == 0 ? "" : dir + "/";
//循环将文件夹中的文件打包
for (int i = 0; i < files.length; i++) {
generateFile(out, files[i], dir + files[i].getName());
}
} else { // 当前是文件
// 输入流
FileInputStream inputStream = new FileInputStream(file);
// 标记要打包的条目
out.putNextEntry(new ZipEntry(dir));
// 进行写操作
int len = 0;
byte[] bytes = new byte[1024];
while ((len = inputStream.read(bytes)) > 0) {
out.write(bytes, 0, len);
}
// 关闭输入流
inputStream.close();
}
}
/**
*
*
* @param output ZipOutputStream
* @param file
* @param childPath
*/
private static void zip(ZipOutputStream output, File file, String childPath) {
FileInputStream input = null;
try {
// 文件为目录
if (file.isDirectory()) {
// 得到当前目录里面的文件列表
File list[] = file.listFiles();
childPath = childPath + (childPath.length() == 0 ? "" : "/")
+ file.getName();
// 循环递归压缩每个文件
for (File f : list) {
zip(output, f, childPath);
}
} else {
// 压缩文件
childPath = (childPath.length() == 0 ? "" : childPath + "/")
+ file.getName();
output.putNextEntry(new ZipEntry(childPath));
input = new FileInputStream(file);
int readLen = 0;
byte[] buffer = new byte[1024 * 8];
while ((readLen = input.read(buffer, 0, 1024 * 8)) != -1) {
output.write(buffer, 0, readLen);
}
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
// 关闭流
if (input != null) {
try {
input.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
/**
*
*
* @param path
* @param format zip | rar
* @throws Exception
*/
public static String zipFile(File path, String format) throws Exception {
String generatePath = "";
if (path.isDirectory()) {
generatePath = path.getParent().endsWith("/") == false ? path.getParent() + File.separator + path.getName() + "." + format : path.getParent() + path.getName() + "." + format;
} else {
generatePath = path.getParent().endsWith("/") == false ? path.getParent() + File.separator : path.getParent();
generatePath += path.getName().substring(0, path.getName().lastIndexOf(".")) + "." + format;
}
// 输出流
FileOutputStream outputStream = new FileOutputStream(generatePath);
// 压缩输出流
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(outputStream));
zip(out, path, "");
//删除源文件夹
FileUtil.del(path);
out.flush();
out.close();
return generatePath;
}
}
Loading…
Cancel
Save