Commit 2e88b2e6 by HlQ

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

1 parent ef11ee50
...@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil; ...@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Opt; import cn.hutool.core.lang.Opt;
import cn.hutool.core.map.MapUtil; import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.SecureUtil;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
...@@ -14,6 +15,7 @@ import com.github.yulichang.base.MPJBaseServiceImpl; ...@@ -14,6 +15,7 @@ import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper;
import io.github.linpeilie.Converter; import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -38,6 +40,7 @@ import java.util.stream.Collectors; ...@@ -38,6 +40,7 @@ import java.util.stream.Collectors;
* @date 2023/12/5 * @date 2023/12/5
*/ */
@Service @Service
@Slf4j
@RequiredArgsConstructor @RequiredArgsConstructor
public class DeliveryRecordServiceImpl extends MPJBaseServiceImpl<DeliveryRecordMapper, DeliveryRecord> implements IDeliveryRecordService { public class DeliveryRecordServiceImpl extends MPJBaseServiceImpl<DeliveryRecordMapper, DeliveryRecord> implements IDeliveryRecordService {
...@@ -76,40 +79,10 @@ public class DeliveryRecordServiceImpl extends MPJBaseServiceImpl<DeliveryRecord ...@@ -76,40 +79,10 @@ public class DeliveryRecordServiceImpl extends MPJBaseServiceImpl<DeliveryRecord
@Override @Override
public String save(DeliveryRecordDTO dto) { public String save(DeliveryRecordDTO dto) {
DeliveryRecord record = converter.convert(dto, DeliveryRecord.class); DeliveryRecord deliveryRecord = converter.convert(dto, DeliveryRecord.class);
if (this.save(record)) { if (this.save(deliveryRecord)) {
updStatusAndPushMsg(record); updStatusAndPushMsg(deliveryRecord);
saveFile(dto, 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 + 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);
});
});
return "新增成功"; return "新增成功";
} else { } else {
return "新增失败"; return "新增失败";
...@@ -127,10 +100,30 @@ public class DeliveryRecordServiceImpl extends MPJBaseServiceImpl<DeliveryRecord ...@@ -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) { private void updStatusAndPushMsg(DeliveryRecord record) {
ContractDTO contractDTO = new ContractDTO(); ContractDTO contractDTO = new ContractDTO();
contractDTO.setStatus(2); contractDTO.setStatus(2);
Contract existContract = contractService.lambdaQuery().eq(Contract::getContractNo, record.getContractNo()).one(); 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) { if (existContract.getStatus() < 2) {
contractService.updateById(null, record.getContractNo(), contractDTO); contractService.updateById(null, record.getContractNo(), contractDTO);
} }
...@@ -176,11 +169,7 @@ public class DeliveryRecordServiceImpl extends MPJBaseServiceImpl<DeliveryRecord ...@@ -176,11 +169,7 @@ public class DeliveryRecordServiceImpl extends MPJBaseServiceImpl<DeliveryRecord
return jsonObj; return jsonObj;
} }
@Override private void saveFile(DeliveryRecordDTO dto, DeliveryRecord deliveryRecord) {
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()) Opt.ofNullable(dto.getFiles())
.ifPresent(fileList -> { .ifPresent(fileList -> {
UserVO userVO = (UserVO) StpUtil.getTokenSession().get("curLoginUser"); UserVO userVO = (UserVO) StpUtil.getTokenSession().get("curLoginUser");
...@@ -190,7 +179,7 @@ public class DeliveryRecordServiceImpl extends MPJBaseServiceImpl<DeliveryRecord ...@@ -190,7 +179,7 @@ public class DeliveryRecordServiceImpl extends MPJBaseServiceImpl<DeliveryRecord
String mainName = FileUtil.mainName(orgName); String mainName = FileUtil.mainName(orgName);
String fileExt = FileUtil.extName(orgName); String fileExt = FileUtil.extName(orgName);
String filename = StrUtil.format("{}_{}.{}", mainName, DateUtil.format(new Date(), "yyyyMMdd_HHmmss"), fileExt); 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; 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); File file = FileUtil.touch(path);
try { try {
infile.transferTo(file); infile.transferTo(file);
...@@ -200,7 +189,7 @@ public class DeliveryRecordServiceImpl extends MPJBaseServiceImpl<DeliveryRecord ...@@ -200,7 +189,7 @@ public class DeliveryRecordServiceImpl extends MPJBaseServiceImpl<DeliveryRecord
FileInfo fileInfo = new FileInfo(); FileInfo fileInfo = new FileInfo();
fileInfo.setStoreId(0L); fileInfo.setStoreId(0L);
fileInfo.setSourceId(record.getId()); fileInfo.setSourceId(deliveryRecord.getId());
fileInfo.setContractId(deliveryRecord.getContractId()); fileInfo.setContractId(deliveryRecord.getContractId());
fileInfo.setSourceType(6); fileInfo.setSourceType(6);
fileInfo.setName(filename); fileInfo.setName(filename);
...@@ -211,9 +200,5 @@ public class DeliveryRecordServiceImpl extends MPJBaseServiceImpl<DeliveryRecord ...@@ -211,9 +200,5 @@ public class DeliveryRecordServiceImpl extends MPJBaseServiceImpl<DeliveryRecord
fileService.save(fileInfo); fileService.save(fileInfo);
}); });
}); });
return "更新成功";
} else {
return "更新失败";
}
} }
} }
...@@ -58,6 +58,36 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem ...@@ -58,6 +58,36 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
@Override @Override
public Page<TaskVO> getTaskList(TaskDTO data) { public Page<TaskVO> getTaskList(TaskDTO data) {
UserVO userVO = (UserVO) StpUtil.getTokenSession().get("curLoginUser"); 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(); Set<Long> taskIdSet = CollUtil.newHashSet();
Opt.ofEmptyAble(userVO.getRoleVOList()) Opt.ofEmptyAble(userVO.getRoleVOList())
.map(l -> l.stream().map(RoleVO::getCode).collect(Collectors.toList())) .map(l -> l.stream().map(RoleVO::getCode).collect(Collectors.toList()))
...@@ -85,26 +115,7 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem ...@@ -85,26 +115,7 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
} }
}) })
.ifPresent(logs -> taskIdSet.addAll(logs.stream().map(FaultLog::getTaskId).collect(Collectors.toSet()))); .ifPresent(logs -> taskIdSet.addAll(logs.stream().map(FaultLog::getTaskId).collect(Collectors.toSet())));
return taskIdSet;
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);
} }
@Override @Override
...@@ -138,7 +149,6 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem ...@@ -138,7 +149,6 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
* *
* @param data 前端传参 * @param data 前端传参
*/ */
private void handleTaskTemp(TaskDTO data) { private void handleTaskTemp(TaskDTO data) {
if (ObjUtil.isNotNull(data.getTaskTempId())) { if (ObjUtil.isNotNull(data.getTaskTempId())) {
Task existTask = this.lambdaQuery().eq(Task::getTaskTempId, data.getTaskTempId()).one(); 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!