Commit 8ef39f9c by HlQ

[add] 添加发货记录管理模块

[chg] 代码优化
1 parent 3f2af6ff
......@@ -75,8 +75,8 @@ public class ResBodyAdvice implements ResponseBodyAdvice<Object> {
@ExceptionHandler(NotPermissionException.class)
public ResultVO notPermissionExceptionHandler(NotPermissionException e) {
log.error("无权限", e.getMessage());
return ResultUtil.error(500, "缺少权限:" + e.getPermission());
log.error("无权限:{}", e.getPermission());
return ResultUtil.error(500, "您没有该功能使用权限!");
}
}
package vion.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import vion.dto.DeliveryRecordDTO;
import vion.service.IDeliveryRecordService;
import vion.vo.DeliveryRecordVO;
/**
* 发货记录管理
*/
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class DeliveryRecordController {
private final IDeliveryRecordService deliveryRecordService;
private final Converter converter;
@GetMapping("/deliveryRecord")
@SaCheckPermission(value = "deliveryRecord:list", orRole = "admin")
public Page<DeliveryRecordVO> list(DeliveryRecordDTO dto) {
return deliveryRecordService.list(dto);
}
@GetMapping("/deliveryRecord/{id}")
@SaCheckPermission(value = "deliveryRecord:query", orRole = "admin")
public DeliveryRecordVO getById(@PathVariable Long id) {
return converter.convert(deliveryRecordService.getById(id), new DeliveryRecordVO());
}
@PostMapping("/deliveryRecord")
@SaCheckPermission(value = "deliveryRecord:save", orRole = "admin")
public String save(DeliveryRecordDTO dto) {
return deliveryRecordService.save(dto);
}
@PostMapping("/deliveryRecord/{id}")
@SaCheckPermission(value = "deliveryRecord:edit", orRole = "admin")
public String updateById(@PathVariable Long id, DeliveryRecordDTO dto) {
dto.setId(id);
return deliveryRecordService.updateById(dto);
}
@DeleteMapping("/deliveryRecord/{id}")
@SaCheckPermission(value = "deliveryRecord:remove", orRole = "admin")
public String delById(@PathVariable Long id) {
return deliveryRecordService.removeById(id) ? "删除成功" : "删除失败";
}
}
......@@ -8,13 +8,11 @@ import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import vion.dto.ServiceOrderDTO;
import vion.dto.StoreDTO;
import vion.model.Dictionary;
import vion.model.ServiceOrder;
import vion.service.IDictionaryService;
import vion.service.IServiceOrderService;
import vion.vo.ServiceOrderVO;
import vion.vo.StoreVO;
import java.util.List;
import java.util.Map;
......@@ -37,10 +35,11 @@ public class ServiceOrderController {
@GetMapping("/orders")
@SaCheckPermission(value = "order:list", orRole="admin")
@SaCheckPermission(value = "order:list", orRole = "admin")
public Page<ServiceOrderVO> getServiceOrderList(ServiceOrderDTO data) {
return serviceOrderService.getServiceOrderList(data);
}
@GetMapping("/order/{id}")
@SaCheckPermission(value = "order:query", orRole = "admin")
public ServiceOrder getOrderById(@PathVariable Long id) {
......@@ -85,7 +84,7 @@ public class ServiceOrderController {
/**
* 签字专用更新接口
*
* @param unid 服务单unid
* @param unid 服务单unid
* @param serviceOrderDTO dto
* @return java.lang.String
*/
......
package vion.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
......@@ -10,18 +11,12 @@ import org.springframework.web.bind.annotation.*;
import vion.Global;
import vion.dto.StatusDTO;
import vion.dto.StoreDTO;
import vion.model.Contract;
import vion.model.RContractStore;
import vion.model.Store;
import vion.service.IContractService;
import vion.service.IRContractStoreService;
import vion.service.IStoreService;
import vion.vo.ContractVO;
import vion.vo.StoreVO;
import vion.vo.UserVO;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@RequestMapping(Global.BASE_URL)
......@@ -30,8 +25,6 @@ import java.util.stream.Collectors;
public class StoreController {
private final IStoreService storeService;
private final IContractService contractService;
private final IRContractStoreService contractStoreService;
private final Converter converter;
......@@ -52,8 +45,8 @@ public class StoreController {
@SaCheckPermission(value = "store:list1", orRole = "admin")
public List<StoreVO> getStoreList(Integer accountId, String name, Integer limit) {
List<Store> storeList = storeService.lambdaQuery()
.eq(accountId != null, Store::getAccountId, accountId)
.like(StringUtils.isNotBlank(name), Store::getName, name)
.eq(ObjUtil.isNotNull(accountId), Store::getAccountId, accountId)
.like(StrUtil.isNotBlank(name), Store::getName, name)
.last(limit != null, "limit " + limit)
.list();
return converter.convert(storeList, StoreVO.class);
......@@ -79,15 +72,10 @@ public class StoreController {
return storeService.updateStoreStage(statusDTO, token);
}
// 未用到
// @GetMapping("/store/contract/{id}")
@SaCheckPermission(value = "store:contract", orRole = "admin")
public List<ContractVO> listContractById(@PathVariable Long id) {
List<RContractStore> contractStoreList = contractStoreService.lambdaQuery().eq(RContractStore::getStoreId, id).list();
List<Long> contractIdList = contractStoreList.stream().map(RContractStore::getContractId).collect(Collectors.toList());
List<Contract> contractList = contractService.lambdaQuery()
.select(Contract::getContractNo, Contract::getName, Contract::getSubject, Contract::getCustomerName, Contract::getSignDate, Contract::getType, Contract::getMaintainSdate, Contract::getMaintainEdate, Contract::getStatus)
.in(Contract::getId, contractIdList).list();
return converter.convert(contractList, ContractVO.class);
@PostMapping("/store/bindContract")
@SaCheckPermission(value = "store:bindContract", orRole = "admin")
// todo 权限未加
public String setMasterContract(@RequestBody StoreDTO dto) {
return storeService.updateById(converter.convert(dto, new Store())) ? "绑定主合同成功" : "绑定主合同失败";
}
}
......@@ -44,7 +44,7 @@ public class TaskController {
@GetMapping("/faultLogs")
@SaCheckPermission(value = "task:log:list", orRole = "admin")
public List<FaultLog> getFaultLogById(Integer storeId, Integer taskId) {
public List<FaultLog> getFaultLogById(Long storeId, Long taskId) {
List<FaultLog> faultLogList = faultLogService.lambdaQuery()
.eq(FaultLog::getStoreId, storeId)
......@@ -52,11 +52,12 @@ public class TaskController {
.orderByAsc(FaultLog::getCreateTime)
.list();
TaskVO taskVO = taskService.getTaskById(Long.valueOf(taskId));
TaskVO taskVO = taskService.getTaskById(taskId);
// 进行中的任务,在最后追加一条当前处理人正在处理的记录,仅做显示用
if (taskVO.getStatus() == 2) {
FaultLog faultLog = new FaultLog();
faultLog.setOperator(taskVO.getActiveUser());
faultLog.setContent("工单正在处理中");
faultLog.setCreateTime(new Date());
faultLogList.add(faultLog);
}
......
......@@ -6,6 +6,7 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.lang.Opt;
import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
......@@ -53,9 +54,16 @@ public class UserController {
return userService.getUserList(dto);
}
@GetMapping("/user/onlyName")
@SaCheckPermission(value = "user:listName", orRole = "admin")
// todo 权限未加
public List<UserVO> getNameList(UserDTO dto) {
return converter.convert(userService.list(Wrappers.lambdaQuery(converter.convert(dto, new User())).select(User::getId, User::getUsername)), UserVO.class);
}
@GetMapping("/user")
@SaCheckPermission(value = "user:query", orRole = "admin")
public User getUserByID(@RequestParam(name = "id") Integer id) {
public User getUserById(@RequestParam(name = "id") Integer id) {
return userService.getById(id);
}
......
package vion.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.multipart.MultipartFile;
import java.util.Date;
@Getter
@Setter
public class DeliveryRecordDTO extends BaseDTO {
private Long id;
/**
* 合同编号
*/
private String contractNo;
/**
* 项目id
*/
private Long storeId;
/**
* 客户名称
*/
private String customerName;
/**
* 发货日期
*/
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date shipDate;
/**
* 到货签收日期
*/
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date signDate;
private MultipartFile[] files;
}
\ No newline at end of file
package vion.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;
......@@ -17,19 +16,8 @@ public class StoreDTO extends BaseDTO {
private String storenum;
/** 门店名称 */
private String name ;
/** 流水号 */
private String number;
/** 合同编码 */
private String contractCode;
/** 合同金额 */
private Float amount;
/** 签订日期 */
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date orderdate;
/** 销售人 */
private Integer salesperson;
/** 质保期 */
private Integer warrantyPeriod;
/** 客户姓名 */
private String customerName;
/** 实施类型:0纯供货、1供货+安装、3续保、4维修 */
......@@ -52,4 +40,6 @@ public class StoreDTO extends BaseDTO {
private Date startdate;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date enddate;
/** 主合同id */
private Long masterContract;
}
package vion.mapper;
import com.github.yulichang.base.MPJBaseMapper;
import vion.model.DeliveryRecord;
/**
* @author HlQ
* @date 2023/12/5
*/
public interface DeliveryRecordMapper extends MPJBaseMapper<DeliveryRecord> {
}
\ No newline at end of file
......@@ -27,7 +27,7 @@ public class Contract {
/**
* 合同名称
*/
@TableField(value = "\"name\"")
@TableField(value = "\"name\"", condition = SqlCondition.LIKE)
private String name;
/**
......
package vion.model;
import com.baomidou.mybatisplus.annotation.*;
import io.github.linpeilie.annotations.AutoMapper;
import io.github.linpeilie.annotations.AutoMappers;
import lombok.Data;
import vion.dto.DeliveryRecordDTO;
import vion.vo.DeliveryRecordVO;
import java.util.Date;
/**
* 发货记录表
*/
@Data
@TableName(value = "tbl_delivery_record")
@AutoMappers({
@AutoMapper(target = DeliveryRecordVO.class),
@AutoMapper(target = DeliveryRecordDTO.class),
})
public class DeliveryRecord {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 合同编号
*/
@TableField(value = "contract_no")
private String contractNo;
/**
* 项目id
*/
@TableField(value = "store_id")
private Long storeId;
/**
* 客户名称
*/
@TableField(value = "customer_name")
private String customerName;
/**
* 发货日期
*/
@TableField(value = "ship_date")
private Date shipDate;
/**
* 到货签收日期
*/
@TableField(value = "sign_date")
private Date signDate;
/**
* 创建时间
*/
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
/**
* 修改时间
*/
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private Date updateTime;
}
\ No newline at end of file
......@@ -24,7 +24,7 @@ public class FileInfo {
private Long storeId;
/** 文件扩展名 */
private String type;
/** 文件来源(1项目、2工单预处理,3工单操作,4巡检,5合同) */
/** 文件来源(1项目、2工单预处理,3工单操作,4巡检,5合同,6发货记录) */
private Integer sourceType;
/** 文件来源id */
private Long sourceId;
......
......@@ -24,27 +24,16 @@ public class Store {
private Long id;
private String storenum;
/** 门店名称 */
@TableField(condition = SqlCondition.LIKE)
private String name;
/** 流水号 */
private String number;
/** 合同编码 */
private String contractCode;
/** 合同金额 */
private Float amount;
/** 签订日期 */
private Date orderdate;
/** 销售人 */
private Integer salesperson;
/** 质保期 */
private Integer warrantyPeriod;
/** 客户姓名 */
private String customerName;
/** 实施类型:0纯供货、1供货+安装、3续保、4维修 */
private Integer implementType;
/** 项目状态:0待确认、1进行中、2已完成、3挂起 */
private Integer projectState;
/** 联系人(多个联系人逗号隔开) */
private String contacts;
/** 创建者 */
private Long createUser;
/** 修改者 */
......@@ -67,4 +56,7 @@ public class Store {
private Integer projectStage;
/** 集团id */
private Long accountId;
/** 主合同id */
private Long masterContract;
}
package vion.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseService;
import vion.dto.DeliveryRecordDTO;
import vion.model.DeliveryRecord;
import vion.vo.DeliveryRecordVO;
/**
* @author HlQ
* @date 2023/12/5
*/
public interface IDeliveryRecordService extends MPJBaseService<DeliveryRecord> {
Page<DeliveryRecordVO> list(DeliveryRecordDTO dto);
String save(DeliveryRecordDTO dto);
String updateById(DeliveryRecordDTO dto);
}
package vion.service.impl;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
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.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.github.yulichang.base.MPJBaseServiceImpl;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
......@@ -17,15 +19,11 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import vion.dto.ContractDTO;
import vion.mapper.ContractMapper;
import vion.mapper.RContractStoreMapper;
import vion.mapper.StoreMapper;
import vion.model.Contract;
import vion.model.FileInfo;
import vion.model.RContractStore;
import vion.model.Store;
import vion.service.IContractPaymentService;
import vion.service.IContractService;
import vion.service.IFileService;
import vion.service.*;
import vion.vo.ContractVO;
import vion.vo.UserVO;
......@@ -47,9 +45,8 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
private final IFileService fileService;
private final IContractPaymentService contractPaymentService;
private final IRContractStoreService contractStoreService;
private final Converter converter;
private final RContractStoreMapper rContractStoreMapper;
private final StoreMapper storeMapper;
@Value("${fileUrl:}")
private String fileUrl;
......@@ -57,21 +54,13 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
@Override
public Page<ContractVO> list(ContractDTO dto) {
Contract contract = converter.convert(dto, new Contract());
String name = contract.getName();
contract.setName(null);
List<Long> ids = null;
if (dto.getStoreId() != null) {
ids = rContractStoreMapper.selectList(Wrappers.lambdaQuery(RContractStore.class)
.select(RContractStore::getContractId)
.eq(RContractStore::getStoreId, dto.getStoreId()))
.stream().map(RContractStore::getContractId).collect(Collectors.toList());
if (ids.isEmpty()) {
ids.add(-1L);
}
}
List<Long> ids = Opt.ofNullable(dto.getStoreId())
.map(storeId -> contractStoreService.listObjs(Wrappers.<RContractStore>lambdaQuery().select(RContractStore::getContractId).eq(RContractStore::getStoreId, dto.getStoreId()), o -> Long.valueOf(o.toString())))
.orElse(ListUtil.empty());
Page<Contract> contractList = this.lambdaQuery(contract)
.in(CollectionUtils.isNotEmpty(ids), Contract::getId, ids)
.like(StringUtils.isNotBlank(name), Contract::getName, name)
.in(CollUtil.isNotEmpty(ids), Contract::getId, ids)
.page(Page.of(dto.getPageNum(), dto.getPageSize()));
List<ContractVO> contractVOList = converter.convert(contractList.getRecords(), ContractVO.class);
// 查出合同关联的项目名
......@@ -80,25 +69,22 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
}
private void completeStoreName(List<ContractVO> contractVOList) {
if (CollectionUtils.isNotEmpty(contractVOList)) {
List<Long> contractIds = contractVOList.stream().map(ContractVO::getId).collect(Collectors.toList());
Map<Long, List<Long>> contractStoreIdsMap = rContractStoreMapper.selectList(Wrappers.lambdaQuery(RContractStore.class)
.in(RContractStore::getContractId, contractIds))
.stream().collect(Collectors.groupingBy(RContractStore::getContractId, Collectors.mapping(RContractStore::getStoreId, Collectors.toList())));
Map<Long, List<Long>> contractStoreIdsMap = Opt.ofEmptyAble(contractVOList)
.map(list -> list.stream().map(ContractVO::getId).collect(Collectors.toList()))
.map(contractIds -> contractStoreService.list(Wrappers.<RContractStore>lambdaQuery().in(RContractStore::getContractId, contractIds)))
.map(contractStoreList -> contractStoreList.stream().collect(Collectors.groupingBy(RContractStore::getContractId, Collectors.mapping(RContractStore::getStoreId, Collectors.toList()))))
.orElse(MapUtil.empty());
if (!contractStoreIdsMap.isEmpty()) {
List<Long> storeIds = contractStoreIdsMap.values().stream().flatMap(List::stream).collect(Collectors.toList());
Map<Long, String> storeIdNameMap = storeMapper.selectBatchIds(storeIds).stream().collect(Collectors.toMap(Store::getId, Store::getName));
if (!storeIdNameMap.isEmpty()) {
contractVOList.forEach(contractVO -> {
if (contractStoreIdsMap.containsKey(contractVO.getId())) {
contractVO.setStoreNames(contractStoreIdsMap.get(contractVO.getId()).stream().map(storeIdNameMap::get).collect(Collectors.toList()));
}
});
}
}
}
Opt.of(contractStoreIdsMap)
.filter(MapUtil::isNotEmpty)
.map(map -> map.values().stream().flatMap(List::stream).collect(Collectors.toList()))
.map(storeIds -> Db.listByIds(storeIds, Store.class))
.map(storeList -> storeList.stream().collect(Collectors.toMap(Store::getId, Store::getName)))
.ifPresent(storeIdNameMap -> contractVOList.forEach(contractVO -> {
if (contractStoreIdsMap.containsKey(contractVO.getId())) {
contractVO.setStoreNames(contractStoreIdsMap.get(contractVO.getId()).stream().map(storeIdNameMap::get).collect(Collectors.toList()));
}
}));
}
@Override
......
package vion.service.impl;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Opt;
import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import vion.dto.DeliveryRecordDTO;
import vion.mapper.DeliveryRecordMapper;
import vion.model.DeliveryRecord;
import vion.model.FileInfo;
import vion.model.Store;
import vion.service.IDeliveryRecordService;
import vion.service.IFileService;
import vion.vo.DeliveryRecordVO;
import vion.vo.UserVO;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Date;
/**
* @author HlQ
* @date 2023/12/5
*/
@Service
@RequiredArgsConstructor
public class DeliveryRecordServiceImpl extends MPJBaseServiceImpl<DeliveryRecordMapper, DeliveryRecord> implements IDeliveryRecordService {
private final IFileService fileService;
private final Converter converter;
@Value("${fileUrl:}")
private String fileUrl;
@Override
public Page<DeliveryRecordVO> list(DeliveryRecordDTO dto) {
MPJLambdaWrapper<DeliveryRecord> wrapper = new MPJLambdaWrapper<>(converter.convert(dto, new DeliveryRecord()))
.selectAll(DeliveryRecord.class)
.select(Store::getName)
.leftJoin(Store.class, Store::getId, DeliveryRecord::getStoreId);
return this.selectJoinListPage(Page.of(dto.getPageNum(), dto.getPageSize()), DeliveryRecordVO.class, wrapper);
}
@Override
public String save(DeliveryRecordDTO dto) {
DeliveryRecord record = converter.convert(dto, new DeliveryRecord());
if (this.save(record)) {
Opt.ofNullable(dto.getFiles())
.ifPresent(fileList -> {
UserVO userVO = (UserVO) StpUtil.getTokenSession().get("curLoginUser");
Arrays.stream(fileList).forEach(infile -> {
String orgName = infile.getOriginalFilename();
String fileName = orgName.substring(0, orgName.lastIndexOf("."));
String fileExt = orgName.substring(orgName.lastIndexOf("."));
String filename = fileName + "_" + DateUtil.format(new Date(), "yyyyMMdd_HHmmss") + fileExt;
String path = fileUrl + FileUtil.FILE_SEPARATOR + "/delivery" + FileUtil.FILE_SEPARATOR + dto.getStoreId() + 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(dto.getStoreId());
fileInfo.setSourceId(record.getId());
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 "新增失败";
}
}
@Override
public String updateById(DeliveryRecordDTO dto) {
DeliveryRecord record = converter.convert(dto, new DeliveryRecord());
if (this.updateById(record)) {
Opt.ofNullable(dto.getFiles())
.ifPresent(fileList -> {
UserVO userVO = (UserVO) StpUtil.getTokenSession().get("curLoginUser");
Arrays.stream(fileList).forEach(infile -> {
String orgName = infile.getOriginalFilename();
String fileName = orgName.substring(0, orgName.lastIndexOf("."));
String fileExt = orgName.substring(orgName.lastIndexOf("."));
String filename = fileName + "_" + DateUtil.format(new Date(), "yyyyMMdd_HHmmss") + fileExt;
String path = fileUrl + FileUtil.FILE_SEPARATOR + "/delivery" + FileUtil.FILE_SEPARATOR + dto.getStoreId() + 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(dto.getStoreId());
fileInfo.setSourceId(record.getId());
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 "更新失败";
}
}
}
package vion.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.lang.Opt;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.github.yulichang.base.MPJBaseServiceImpl;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
......@@ -21,7 +22,6 @@ import vion.third.WechatMod;
import vion.vo.ServiceOrderVO;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author HlQ
......@@ -54,18 +54,15 @@ public class ServiceOrderServiceImpl extends MPJBaseServiceImpl<ServiceOrderMapp
@Override
public Page<ServiceOrderVO> getServiceOrderList(ServiceOrderDTO data) {
ServiceOrder serviceOrder = converter.convert(data, new ServiceOrder());
List<Long> taskIds = null;
if (data.getStoreId() != null) {
taskIds = taskService.getBaseMapper().selectList(Wrappers.lambdaQuery(Task.class)
.select(Task::getId).eq(Task::getStoreId, data.getStoreId()))
.stream().map(Task::getId).collect(Collectors.toList());
}
List<Long> taskIds = Opt.ofNullable(data.getStoreId())
.map(storeId -> Db.listObjs(Wrappers.lambdaQuery(Task.class).eq(Task::getStoreId, storeId), Task::getId))
.orElse(ListUtil.empty());
Page<ServiceOrder> serviceOrderPage = this.lambdaQuery(serviceOrder)
.in(CollectionUtils.isNotEmpty(taskIds), ServiceOrder::getTaskId, taskIds)
.in(CollUtil.isNotEmpty(taskIds), ServiceOrder::getTaskId, taskIds)
.page(Page.of(data.getPageNum(), data.getPageSize()));
List<ServiceOrderVO> orderVOList = serviceOrderPage.getRecords().stream().map(order -> converter.convert(order, new ServiceOrderVO())).collect(Collectors.toList());
List<ServiceOrderVO> orderVOList = converter.convert(serviceOrderPage.getRecords(), ServiceOrderVO.class);
return Page.<ServiceOrderVO>of(data.getPageNum(), data.getPageSize(), serviceOrderPage.getTotal()).setRecords(orderVOList);
}
}
......@@ -6,11 +6,10 @@ 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.ArrayUtil;
import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.github.yulichang.base.MPJBaseServiceImpl;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
......@@ -20,16 +19,19 @@ import org.springframework.web.multipart.MultipartFile;
import vion.Global;
import vion.dto.StatusDTO;
import vion.dto.StoreDTO;
import vion.mapper.ServiceOrderMapper;
import vion.mapper.StoreMapper;
import vion.mapper.TaskMapper;
import vion.model.*;
import vion.service.*;
import vion.vo.ContractVO;
import vion.vo.StoreVO;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
......@@ -44,7 +46,6 @@ public class StoreServiceImpl extends MPJBaseServiceImpl<StoreMapper, Store> imp
private final Converter converter;
// 引入 taskService 会循环依赖
private final TaskMapper taskMapper;
private final ServiceOrderMapper serviceOrderMapper;
@Value("${fileUrl:}")
private String fileUrl;
......@@ -52,11 +53,7 @@ public class StoreServiceImpl extends MPJBaseServiceImpl<StoreMapper, Store> imp
@Override
public Page<StoreVO> getStoreList(StoreDTO data) {
Store store = converter.convert(data, new Store());
String name = store.getName();
store.setName(null);
Page<Store> storeList = this.lambdaQuery(store)
.like(StringUtils.isNotBlank(name), Store::getName, name)
.between(data.getStartdate() != null && data.getEnddate() != null, Store::getOrderdate, data.getStartdate(), data.getEnddate())
.page(Page.of(data.getPageNum(), data.getPageSize()));
// todo 缓存
List<Account> accountList = accountService.list();
......@@ -79,18 +76,16 @@ public class StoreServiceImpl extends MPJBaseServiceImpl<StoreMapper, Store> imp
})
.orElse(MapUtil.empty());
Map<Long, List<Long>> storeTaskIdMap = Opt.ofEmptyAble(storeIdList)
.map(l -> taskMapper.selectList(Wrappers.lambdaQuery(Task.class).in(Task::getStoreId, l))
.stream()
.collect(Collectors.groupingBy(Task::getStoreId, Collectors.mapping(Task::getId, Collectors.toList()))))
Map<Long, List<Long>> store2TaskIdMap = Opt.ofEmptyAble(storeIdList)
.map(l -> taskMapper.selectList(Wrappers.lambdaQuery(Task.class).in(Task::getStoreId, l)))
.map(taskList -> taskList.stream().collect(Collectors.groupingBy(Task::getStoreId, Collectors.mapping(Task::getId, Collectors.toList()))))
.orElse(MapUtil.empty());
List<Long> taskIds = storeTaskIdMap.values().stream()
List<Long> taskIds = store2TaskIdMap.values().stream()
.flatMap(List::stream)
.collect(Collectors.toList());
Map<Long, List<ServiceOrder>> taskServiceOrderMap = Opt.ofEmptyAble(taskIds)
.map(t -> serviceOrderMapper.selectList(Wrappers.lambdaQuery(ServiceOrder.class).in(ServiceOrder::getTaskId, taskIds))
.stream()
.collect(Collectors.groupingBy(ServiceOrder::getTaskId)))
.map(t -> Db.list(Wrappers.lambdaQuery(ServiceOrder.class).in(ServiceOrder::getTaskId, taskIds)))
.map(serviceOrderList -> serviceOrderList.stream().collect(Collectors.groupingBy(ServiceOrder::getTaskId)))
.orElse(MapUtil.empty());
......@@ -102,7 +97,10 @@ public class StoreServiceImpl extends MPJBaseServiceImpl<StoreMapper, Store> imp
Long storeId = item.getId();
List<RContractStore> contractStores = storeIdMap.get(storeId);
if (CollUtil.isEmpty(contractStores)) {
storeVO.setContractCount(Opt.ofEmptyAble(contractStores).map(List::size).orElse(0));
Contract masterContract = id2ContractMap.getOrDefault(item.getMasterContract(), null);
storeVO.setMainContract(Opt.ofNullable(masterContract).map(c -> converter.convert(c, new ContractVO())).orElse(null));
/*if (CollUtil.isEmpty(contractStores)) {
storeVO.setMaintainStatus("--");
} else {
List<Long> contractIds = contractStores.stream().map(RContractStore::getContractId).collect(Collectors.toList());
......@@ -116,17 +114,16 @@ public class StoreServiceImpl extends MPJBaseServiceImpl<StoreMapper, Store> imp
maintainStatusSet.add(isIn);
}
});
// todo 维保状态每天定时任务计算
storeVO.setMaintainStatus(CollUtil.isEmpty(maintainStatusSet) ? "--" : maintainStatusSet.contains(true) ? "在保" : "脱保");
storeVO.setContractCount(contractIds.size());
}
}*/
// 补充服务单
if (storeTaskIdMap.containsKey(item.getId())) {
List<ServiceOrder> serviceOrders = storeTaskIdMap.get(item.getId())
if (store2TaskIdMap.containsKey(item.getId())) {
List<ServiceOrder> serviceOrders = store2TaskIdMap.get(item.getId())
.stream().flatMap(taskId -> taskServiceOrderMap.getOrDefault(taskId, ListUtil.empty()).stream())
.collect(Collectors.toList());
storeVO.setServiceOrderCount(serviceOrders.size());
}
storeVOList.add(storeVO);
});
return Page.<StoreVO>of(data.getPageNum(), data.getPageSize(), storeList.getTotal()).setRecords(storeVOList);
......
......@@ -9,6 +9,7 @@ import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import io.github.linpeilie.Converter;
......@@ -16,7 +17,6 @@ import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import vion.dto.TaskTempDTO;
import vion.mapper.TaskMapper;
import vion.mapper.TaskTempMapper;
import vion.model.FileInfo;
import vion.model.Task;
......@@ -45,7 +45,6 @@ public class TaskTempServiceImpl extends MPJBaseServiceImpl<TaskTempMapper, Task
private final DingMod dingMod;
private final WechatMod wechatMod;
private final Converter converter;
private final TaskMapper taskMapper;
@Value("${fileUrl:}")
private String fileUrl;
......@@ -69,12 +68,12 @@ public class TaskTempServiceImpl extends MPJBaseServiceImpl<TaskTempMapper, Task
.eq(FileInfo::getSourceId, TaskTemp::getId)
.eq(FileInfo::getStoreId, 0L))
.eq(TaskTemp::getId, id);
TaskTempVO taskTempVO = this.selectJoinOne(TaskTempVO.class, wrapper);
List<Task> tasks = taskMapper.selectList(Wrappers.lambdaQuery(Task.class).eq(Task::getTaskTempId, id));
if (!tasks.isEmpty()) {
taskTempVO.setTask(tasks.get(0));
}
return taskTempVO;
return Opt.ofNullable(this.selectJoinOne(TaskTempVO.class, wrapper))
.ifPresent(taskTempVO -> {
Task task = Db.getOne(Wrappers.lambdaQuery(Task.class).eq(Task::getTaskTempId, id));
taskTempVO.setTask(task);
})
.orElse(null);
}
@Override
......
package vion.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import vion.model.FileInfo;
import java.util.Date;
import java.util.List;
@Getter
@Setter
public class DeliveryRecordVO {
private Long id;
/**
* 合同编号
*/
private String contractNo;
/**
* 项目id
*/
private Long storeId;
private String storeName;
/**
* 客户名称
*/
private String customerName;
/**
* 发货日期
*/
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date shipDate;
/**
* 到货签收日期
*/
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date signDate;
/**
* 创建时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
/**
* 修改时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;
private List<FileInfo> fileList;
}
\ No newline at end of file
package vion.vo;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import vion.model.Contract;
import vion.model.ServiceOrder;
import java.util.Date;
import java.util.List;
@Data
public class StoreVO {
......@@ -15,15 +11,6 @@ public class StoreVO {
private String storenum;
/** 门店名称 */
private String name;
/** 流水号 */
private String number;
/** 合同编码 */
private String contractCode;
/** 合同金额 */
private Float amount;
/** 签订日期 */
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date orderdate;
/** 销售人 */
private Integer salesperson;
/** 质保期 */
......@@ -51,26 +38,26 @@ public class StoreVO {
/** 集团id */
private Long accountId;
/** 收货名称 */
/* *//** 收货名称 *//*
private String consigneeName;
/** 收货手机号 */
*//** 收货手机号 *//*
private String consigneePhone;
/** 收货地址 */
*//** 收货地址 *//*
private String consigneeAddress;
/** 合同姓名 */
*//** 合同姓名 *//*
private String contractName;
/** 合同手机号 */
*//** 合同手机号 *//*
private String contractPhone;
/** 合同地址 */
*//** 合同地址 *//*
private String contractAddress;
/** 发票姓名 */
*//** 发票姓名 *//*
private String invoiceName ;
/** 发票手机号 */
*//** 发票手机号 *//*
private String invoicePhone;
/** 发票地址 */
*//** 发票地址 *//*
private String invoiceAddress;
/** 开票信息 */
private String invoiceInfo;
*//** 开票信息 *//*
private String invoiceInfo;*/
private String accountName;
private Long fileNum;
......@@ -87,4 +74,6 @@ public class StoreVO {
* 工单下的服务单
*/
private Integer serviceOrderCount;
private ContractVO mainContract;
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!