Commit 2e88b2e6 by HlQ

[chg] 优化发货记录更新和工单列表代码

1 parent ef11ee50
......@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Opt;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.json.JSONObject;
......@@ -14,6 +15,7 @@ import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
......@@ -38,6 +40,7 @@ import java.util.stream.Collectors;
* @date 2023/12/5
*/
@Service
@Slf4j
@RequiredArgsConstructor
public class DeliveryRecordServiceImpl extends MPJBaseServiceImpl<DeliveryRecordMapper, DeliveryRecord> implements IDeliveryRecordService {
......@@ -76,40 +79,10 @@ public class DeliveryRecordServiceImpl extends MPJBaseServiceImpl<DeliveryRecord
@Override
public String save(DeliveryRecordDTO dto) {
DeliveryRecord record = converter.convert(dto, DeliveryRecord.class);
if (this.save(record)) {
updStatusAndPushMsg(record);
Opt.ofNullable(dto.getFiles())
.ifPresent(fileList -> {
UserVO userVO = (UserVO) StpUtil.getTokenSession().get("curLoginUser");
Arrays.stream(fileList).forEach(infile -> {
String orgName = infile.getOriginalFilename();
String mainName = FileUtil.mainName(orgName);
String fileExt = FileUtil.extName(orgName);
String filename = StrUtil.format("{}_{}.{}", mainName, DateUtil.format(new Date(), "yyyyMMdd_HHmmss"), fileExt);
String path = fileUrl + FileUtil.FILE_SEPARATOR + "delivery" + FileUtil.FILE_SEPARATOR + dto.getContractId() + FileUtil.FILE_SEPARATOR + record.getId() + FileUtil.FILE_SEPARATOR + filename;
File file = FileUtil.touch(path);
try {
infile.transferTo(file);
} catch (IOException e) {
log.error("保存文件出错", e);
}
FileInfo fileInfo = new FileInfo();
fileInfo.setStoreId(0L);
fileInfo.setSourceId(record.getId());
fileInfo.setContractId(dto.getContractId());
fileInfo.setSourceType(6);
fileInfo.setName(filename);
fileInfo.setUrl(path);
fileInfo.setType(FileUtil.extName(file));
fileInfo.setSha256(SecureUtil.sha256(file).toUpperCase());
fileInfo.setUploader(userVO.getUsername());
fileService.save(fileInfo);
});
});
DeliveryRecord deliveryRecord = converter.convert(dto, DeliveryRecord.class);
if (this.save(deliveryRecord)) {
updStatusAndPushMsg(deliveryRecord);
saveFile(dto, deliveryRecord);
return "新增成功";
} else {
return "新增失败";
......@@ -127,10 +100,30 @@ public class DeliveryRecordServiceImpl extends MPJBaseServiceImpl<DeliveryRecord
}
}
@Override
public String updateById(DeliveryRecordDTO dto) {
DeliveryRecord record = converter.convert(dto, DeliveryRecord.class);
if (this.updateById(record)) {
DeliveryRecord deliveryRecord = this.getById(dto.getId());
saveFile(dto, deliveryRecord);
return "更新成功";
} else {
return "更新失败";
}
}
/**
* 更新合同状态和点位设计记录状态,并推送发货消息提醒
*
* @param record 发货记录
*/
private void updStatusAndPushMsg(DeliveryRecord record) {
ContractDTO contractDTO = new ContractDTO();
contractDTO.setStatus(2);
Contract existContract = contractService.lambdaQuery().eq(Contract::getContractNo, record.getContractNo()).one();
if (ObjUtil.isNull(existContract) || ObjUtil.isNull(existContract.getStatus())) {
log.error("根据发货记录,更新合同状态出错,该合同不存在:{}", record.getContractNo());
}
if (existContract.getStatus() < 2) {
contractService.updateById(null, record.getContractNo(), contractDTO);
}
......@@ -176,44 +169,36 @@ public class DeliveryRecordServiceImpl extends MPJBaseServiceImpl<DeliveryRecord
return jsonObj;
}
@Override
public String updateById(DeliveryRecordDTO dto) {
DeliveryRecord record = converter.convert(dto, DeliveryRecord.class);
if (this.updateById(record)) {
DeliveryRecord deliveryRecord = this.getById(dto.getId());
Opt.ofNullable(dto.getFiles())
.ifPresent(fileList -> {
UserVO userVO = (UserVO) StpUtil.getTokenSession().get("curLoginUser");
Arrays.stream(fileList).forEach(infile -> {
String orgName = infile.getOriginalFilename();
String mainName = FileUtil.mainName(orgName);
String fileExt = FileUtil.extName(orgName);
String filename = StrUtil.format("{}_{}.{}", mainName, DateUtil.format(new Date(), "yyyyMMdd_HHmmss"), fileExt);
String path = fileUrl + FileUtil.FILE_SEPARATOR + "delivery" + FileUtil.FILE_SEPARATOR + deliveryRecord.getContractId() + FileUtil.FILE_SEPARATOR + record.getId() + FileUtil.FILE_SEPARATOR + filename;
File file = FileUtil.touch(path);
try {
infile.transferTo(file);
} catch (IOException e) {
log.error("保存文件出错", e);
}
FileInfo fileInfo = new FileInfo();
fileInfo.setStoreId(0L);
fileInfo.setSourceId(record.getId());
fileInfo.setContractId(deliveryRecord.getContractId());
fileInfo.setSourceType(6);
fileInfo.setName(filename);
fileInfo.setUrl(path);
fileInfo.setType(FileUtil.extName(file));
fileInfo.setSha256(SecureUtil.sha256(file).toUpperCase());
fileInfo.setUploader(userVO.getUsername());
fileService.save(fileInfo);
});
private void saveFile(DeliveryRecordDTO dto, DeliveryRecord deliveryRecord) {
Opt.ofNullable(dto.getFiles())
.ifPresent(fileList -> {
UserVO userVO = (UserVO) StpUtil.getTokenSession().get("curLoginUser");
Arrays.stream(fileList).forEach(infile -> {
String orgName = infile.getOriginalFilename();
String mainName = FileUtil.mainName(orgName);
String fileExt = FileUtil.extName(orgName);
String filename = StrUtil.format("{}_{}.{}", mainName, DateUtil.format(new Date(), "yyyyMMdd_HHmmss"), fileExt);
String path = fileUrl + FileUtil.FILE_SEPARATOR + "delivery" + FileUtil.FILE_SEPARATOR + deliveryRecord.getContractId() + FileUtil.FILE_SEPARATOR + deliveryRecord.getId() + FileUtil.FILE_SEPARATOR + filename;
File file = FileUtil.touch(path);
try {
infile.transferTo(file);
} catch (IOException e) {
log.error("保存文件出错", e);
}
FileInfo fileInfo = new FileInfo();
fileInfo.setStoreId(0L);
fileInfo.setSourceId(deliveryRecord.getId());
fileInfo.setContractId(deliveryRecord.getContractId());
fileInfo.setSourceType(6);
fileInfo.setName(filename);
fileInfo.setUrl(path);
fileInfo.setType(FileUtil.extName(file));
fileInfo.setSha256(SecureUtil.sha256(file).toUpperCase());
fileInfo.setUploader(userVO.getUsername());
fileService.save(fileInfo);
});
return "更新成功";
} else {
return "更新失败";
}
});
}
}
......@@ -58,6 +58,36 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
@Override
public Page<TaskVO> getTaskList(TaskDTO data) {
UserVO userVO = (UserVO) StpUtil.getTokenSession().get("curLoginUser");
Set<Long> taskIdSet = getTaskIdSet(userVO);
MPJLambdaWrapper<Task> wrapper = new MPJLambdaWrapper<>(converter.convert(data, Task.class))
.selectAll(Task.class)
.selectAs(Store::getName, TaskVO::getStoreName)
.selectAs(Account::getName, TaskVO::getAccountName)
.selectAssociation(ServiceOrder.class, TaskVO::getServiceOrder)
.leftJoin(Store.class, Store::getId, Task::getStoreId)
.leftJoin(Account.class, Account::getId, Task::getAccountId)
.leftJoin(ServiceOrder.class, ServiceOrder::getTaskId, Task::getId)
.between(ArrayUtil.isAllNotNull(data.getStartdate(), data.getEnddate()), Task::getRepairTime, data.getStartdate(), data.getEnddate())
.lt(data.getCurDate() != null, Task::getExpDate, data.getCurDate());
// todo 优化
if (taskIdSet.size() == 1 && CollUtil.get(taskIdSet, 0).equals(-99L)) {
// 不是管理员,并且第一次处理工单,但当前处理人是他
} else if (taskIdSet.size() == 1 && CollUtil.get(taskIdSet, 0).equals(0L)) {
// 管理员逻辑
} else {
wrapper.in(Task::getId, taskIdSet);
}
return this.selectJoinListPage(Page.of(data.getPageNum(), data.getPageSize()), TaskVO.class, wrapper);
}
/**
* 根据当前登录用户,判断其权限和其参与过的工单,获取工单id集合
*
* @param userVO 当前登录用户
* @return java.util.Set<java.lang.Long>
*/
private Set<Long> getTaskIdSet(UserVO userVO) {
Set<Long> taskIdSet = CollUtil.newHashSet();
Opt.ofEmptyAble(userVO.getRoleVOList())
.map(l -> l.stream().map(RoleVO::getCode).collect(Collectors.toList()))
......@@ -85,26 +115,7 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
}
})
.ifPresent(logs -> taskIdSet.addAll(logs.stream().map(FaultLog::getTaskId).collect(Collectors.toSet())));
MPJLambdaWrapper<Task> wrapper = new MPJLambdaWrapper<>(converter.convert(data, Task.class))
.selectAll(Task.class)
.selectAs(Store::getName, TaskVO::getStoreName)
.selectAs(Account::getName, TaskVO::getAccountName)
.selectAssociation(ServiceOrder.class, TaskVO::getServiceOrder)
.leftJoin(Store.class, Store::getId, Task::getStoreId)
.leftJoin(Account.class, Account::getId, Task::getAccountId)
.leftJoin(ServiceOrder.class, ServiceOrder::getTaskId, Task::getId)
.between(ArrayUtil.isAllNotNull(data.getStartdate(), data.getEnddate()), Task::getRepairTime, data.getStartdate(), data.getEnddate())
.lt(data.getCurDate() != null, Task::getExpDate, data.getCurDate());
// todo 优化
if (taskIdSet.size() == 1 && CollUtil.get(taskIdSet, 0).equals(-99L)) {
// 不是管理员,并且第一次处理工单,但当前处理人是他
} else if (taskIdSet.size() == 1 && CollUtil.get(taskIdSet, 0).equals(0L)) {
// 管理员逻辑
} else {
wrapper.in(Task::getId, taskIdSet);
}
return this.selectJoinListPage(Page.of(data.getPageNum(), data.getPageSize()), TaskVO.class, wrapper);
return taskIdSet;
}
@Override
......@@ -138,7 +149,6 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
*
* @param data 前端传参
*/
private void handleTaskTemp(TaskDTO data) {
if (ObjUtil.isNotNull(data.getTaskTempId())) {
Task existTask = this.lambdaQuery().eq(Task::getTaskTempId, data.getTaskTempId()).one();
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!