Commit 162bb820 by HlQ

[add]

1.收款记录和发票记录创建时间排序
2.计算合同金额添加数据权限控制
1 parent f1f3590c
......@@ -25,7 +25,7 @@ public class ContractPaymentController {
@GetMapping("/contractPayment/{id}")
@SaCheckPermission(value = "contractPayment:query", orRole = "admin")
public List<ContractPaymentVO> getPaymentById(@PathVariable Long id) {
return converter.convert(contractPaymentService.lambdaQuery().eq(ContractPayment::getContractId, id).list(), ContractPaymentVO.class);
return converter.convert(contractPaymentService.lambdaQuery().eq(ContractPayment::getContractId, id).orderByAsc(ContractPayment::getPaymentType).list(), ContractPaymentVO.class);
}
@PostMapping("/contractPayment")
......
......@@ -4,6 +4,8 @@ import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.HttpUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
......@@ -11,19 +13,22 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import vion.Global;
import vion.dto.FileInfoDTO;
import vion.model.FileInfo;
import vion.service.IFileService;
import vion.model.*;
import vion.service.*;
import vion.utils.ResultUtil;
import vion.vo.ResultVO;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
@RestController
@RequestMapping(Global.BASE_URL)
@RequestMapping("/api")
@RequiredArgsConstructor
@Slf4j
public class FileController {
......@@ -31,8 +36,13 @@ public class FileController {
private final IFileService fileService;
private final Converter converter;
private final IDeliveryRecordService deliveryRecordService;
private final ITbDeliverGoodsService deliverGoodsService;
private final ITbAppendixService appendixService;
private final IContractService contractService;
@Value("${fileUrl:}")
private String fileurl;
private String fileUrl;
@GetMapping("/files")
public Page<FileInfo> getFiles(FileInfoDTO data) {
......@@ -51,7 +61,6 @@ public class FileController {
}
}
/*
* todo
* 手机端工单预处理提交
......@@ -64,7 +73,7 @@ public class FileController {
//上传url地址
String filename = infile.getOriginalFilename() + "_" + DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN);
// String path = fileurl + FileUtil.FILE_SEPARATOR + storeId + FileUtil.FILE_SEPARATOR + sourceId + FileUtil.FILE_SEPARATOR + filename;
String path = fileurl + FileUtil.FILE_SEPARATOR + filename;
String path = fileUrl + FileUtil.FILE_SEPARATOR + filename;
File file = FileUtil.touch(path);
infile.transferTo(file);
String sha256 = SecureUtil.sha256(file).toUpperCase();
......@@ -101,7 +110,7 @@ public class FileController {
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 + fileInfo.getStoreId() + FileUtil.FILE_SEPARATOR + fileInfo.getSourceId() + FileUtil.FILE_SEPARATOR + filename;
String path = fileUrl + FileUtil.FILE_SEPARATOR + fileInfo.getStoreId() + FileUtil.FILE_SEPARATOR + fileInfo.getSourceId() + FileUtil.FILE_SEPARATOR + filename;
File file = FileUtil.touch(path);
infile.transferTo(file);
......@@ -119,4 +128,64 @@ public class FileController {
}
return "文件保存成功";
}
@GetMapping("/tmpfile")
public String sync() {
// bDeliverGoodsId => tbAppendix
Map<String, List<TbAppendix>> id2UrlMap = appendixService.list(Wrappers.<TbAppendix>lambdaQuery().eq(TbAppendix::getBusinessTable, "tb_deliver_goods"))
.stream().collect(Collectors.groupingBy(TbAppendix::getBusinessUnid));
// bDeliverGoodsId => tbDeliverGoods
Map<Long, TbDeliverGoods> id2DeliverGoodsMap = deliverGoodsService.list().stream().collect(Collectors.toMap(TbDeliverGoods::getDeliverUnid, Function.identity()));
// contractNo => contract
Map<String, Long> no2ContractIdMap = contractService.list().stream().collect(Collectors.toMap(Contract::getContractNo, Contract::getId));
// contractNo => List<DeliveryRecord>
Map<String, List<DeliveryRecord>> no2IdMap = deliveryRecordService.list().stream().collect(Collectors.groupingBy(DeliveryRecord::getContractNo));
id2UrlMap.forEach((id, appendixList) -> appendixList.forEach(appendix -> {
TbDeliverGoods deliverGoods = id2DeliverGoodsMap.get(Long.valueOf(id));
String contractNo = deliverGoods.getContractUnid();
Long contractId = no2ContractIdMap.get(contractNo);
if (contractId == null) {
log.error("合同不存在:{}", contractNo);
return;
}
List<DeliveryRecord> deliveryIdList = no2IdMap.get(contractNo);
if (deliveryIdList.size() == 1) {
String path = fileUrl + FileUtil.FILE_SEPARATOR + "/delivery" + FileUtil.FILE_SEPARATOR + contractId + FileUtil.FILE_SEPARATOR + deliveryIdList.get(0).getId() + FileUtil.FILE_SEPARATOR + appendix.getAppendixName();
File file = HttpUtil.downloadFileFromUrl(appendix.getAppendixUrl().replace("192.168.9.110", "117.133.143.114"), FileUtil.file(path));
FileInfo fileInfo = new FileInfo();
fileInfo.setStoreId(-1L);
fileInfo.setSourceId(deliveryIdList.get(0).getId());
fileInfo.setSourceType(6);
fileInfo.setContractId(contractId);
fileInfo.setName(appendix.getAppendixName());
fileInfo.setUrl(path);
fileInfo.setType(FileUtil.extName(file));
fileInfo.setSha256(SecureUtil.sha256(file).toUpperCase());
fileInfo.setUploader("原合同平台");
fileService.save(fileInfo);
} else {
for (DeliveryRecord deliveryRecord : deliveryIdList) {
if (deliveryRecord.getSignDate().equals(id2DeliverGoodsMap.get(Long.valueOf(id)).getGoodsAcceptancDate()) && deliveryRecord.getShipDate().equals(id2DeliverGoodsMap.get(Long.valueOf(id)).getDeliverGoodsDate())) {
String path = fileUrl + FileUtil.FILE_SEPARATOR + "/delivery" + FileUtil.FILE_SEPARATOR + contractId + FileUtil.FILE_SEPARATOR + deliveryRecord.getId() + FileUtil.FILE_SEPARATOR + appendix.getAppendixName();
File file = HttpUtil.downloadFileFromUrl(appendix.getAppendixUrl().replace("192.168.9.110", "117.133.143.114"), FileUtil.file(path));
FileInfo fileInfo = new FileInfo();
fileInfo.setStoreId(-1L);
fileInfo.setSourceId(deliveryRecord.getId());
fileInfo.setSourceType(6);
fileInfo.setContractId(contractId);
fileInfo.setName(appendix.getAppendixName());
fileInfo.setUrl(path);
fileInfo.setType(FileUtil.extName(file));
fileInfo.setSha256(SecureUtil.sha256(file).toUpperCase());
fileInfo.setUploader("原合同平台");
fileService.save(fileInfo);
}
}
}
}));
return "success";
}
}
\ No newline at end of file
package vion.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import java.math.BigDecimal;
import java.util.Date;
@Getter
@Setter
......@@ -25,4 +27,10 @@ public class ContractPaymentDTO {
*/
private BigDecimal paymentRatio;
/**
* 节点日期,指合同到这一阶段时的时间
*/
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date nodeDate;
}
\ No newline at end of file
......@@ -167,7 +167,10 @@ public class Contract {
* 财务状态
*/
@TableField(value = "financial_status")
private Date financialStatus;
private Integer financialStatus;
@TableField(exist = false)
private Date originalModTime;
/**
* 合同签订付款比例
......
......@@ -157,7 +157,6 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
@Override
@Transactional(rollbackFor = Exception.class)
public String updateById(Long id, String contractNo, ContractDTO dto) {
// todo 合同状态变更时,添加 nodeDate,未上线待联调
Contract existContract = new Contract();
if (ObjUtil.isNotNull(id)) {
existContract = this.getById(id);
......@@ -242,7 +241,19 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
@Override
public JSONObject calAmount(ContractDTO dto) {
UserVO userVO = (UserVO) StpUtil.getTokenSession().get("curLoginUser");
String saleName = Opt.ofEmptyAble(userVO.getRoleVOList())
.map(l -> l.stream().map(RoleVO::getCode).collect(Collectors.toList()))
.map(roleCodeList -> {
if (!roleCodeList.contains("admin") && !roleCodeList.contains("shangwu") && !roleCodeList.contains("caiwu")) {
return userVO.getUsername();
} else {
return "";
}
}).orElse("未知");
List<Contract> contracts = this.list(Wrappers.lambdaQuery(converter.convert(dto, Contract.class))
.eq(StrUtil.isNotBlank(saleName), Contract::getSaleName, saleName)
.between(ArrayUtil.isAllNotNull(dto.getSignDateStart(), dto.getSignDateEnd()), Contract::getSignDate, dto.getSignDateStart(), dto.getSignDateEnd())
);
......@@ -301,9 +312,9 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
return;
}
BigDecimal paidAmount = c.getPaidAmount();
Map<Integer, Date> type2DateMap = contractPaymentList.stream().collect(HashMap::new, (m, v) -> m.put(v.getPaymentType(), v.getPaymentDate()), HashMap::putAll);
Map<Integer, Date> type2DateMap = contractPaymentList.stream().filter(cp -> cp.getPaymentType() < c.getStatus()).collect(HashMap::new, (m, v) -> m.put(v.getPaymentType(), v.getNodeDate()), HashMap::putAll);
Map<Integer, BigDecimal> type2AmountMap = contractPaymentList.stream().collect(Collectors.toMap(ContractPayment::getPaymentType, v -> NumberUtil.mul(v.getPaymentRatio(), totalAmount)));
Map<Integer, BigDecimal> type2AmountMap = contractPaymentList.stream().filter(cp -> cp.getPaymentType() < c.getStatus()).collect(Collectors.toMap(ContractPayment::getPaymentType, v -> NumberUtil.mul(v.getPaymentRatio(), totalAmount)));
TreeMap<Integer, BigDecimal> sortMap = MapUtil.sort(type2AmountMap, Comparator.comparingInt(Integer::intValue));
for (Map.Entry<Integer, BigDecimal> entry : sortMap.entrySet()) {
......@@ -321,11 +332,10 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
financialAgeVO.setContractName(c.getName());
financialAgeVO.setStatus(type);
financialAgeVO.setAmount(NumberUtil.equals(paidAmount, BigDecimal.ZERO) ? curAmount : BigDecimal.valueOf(Math.abs(paidAmount.doubleValue())));
Date payableDate = type2DateMap.get(type);
Opt.ofNullable(type2DateMap.get(type)).ifPresent(
date -> {
financialAgeVO.setPayableDate(date);
long age = DateUtil.between(new Date(), payableDate, DateUnit.DAY, false);
long age = DateUtil.between(new Date(), date, DateUnit.DAY, false);
financialAgeVO.setAge(((int) age));
}
);
......
......@@ -53,7 +53,8 @@ public class InvoiceServiceImpl extends MPJBaseServiceImpl<InvoiceMapper, Invoic
MPJLambdaWrapper<Invoice> wrapper = new MPJLambdaWrapper<>(converter.convert(dto, Invoice.class))
.selectAll(Invoice.class)
.leftJoin(Contract.class, Contract::getContractNo, Invoice::getContractNo)
.eq(StrUtil.isNotBlank(saleName), Contract::getSaleName, saleName);
.eq(StrUtil.isNotBlank(saleName), Contract::getSaleName, saleName)
.orderByDesc(Invoice::getCreateTime);
return this.selectJoinListPage(Page.of(dto.getPageNum(), dto.getPageSize()), InvoiceVO.class, wrapper);
}
......
......@@ -55,7 +55,8 @@ public class PaymentServiceImpl extends MPJBaseServiceImpl<PaymentMapper, Paymen
MPJLambdaWrapper<Payment> wrapper = new MPJLambdaWrapper<>(converter.convert(dto, Payment.class))
.selectAll(Payment.class)
.leftJoin(Contract.class, Contract::getContractNo, Payment::getContractNo)
.eq(StrUtil.isNotBlank(saleName), Contract::getSaleName, saleName);
.eq(StrUtil.isNotBlank(saleName), Contract::getSaleName, saleName)
.orderByDesc(Payment::getCreateTime);
return this.selectJoinListPage(Page.of(dto.getPageNum(), dto.getPageSize()), PaymentVO.class, wrapper);
}
......
......@@ -31,6 +31,18 @@ public class ContractPaymentVO {
private BigDecimal paymentRatio;
/**
* 收款日期
*/
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date paymentDate;
/**
* 节点日期,指合同到这一阶段时的时间
*/
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date nodeDate;
/**
* 创建者
*/
private Integer createUser;
......
......@@ -127,6 +127,11 @@ public class ContractVO {
private Date finalDate;
/**
* 财务状态
*/
private Integer financialStatus;
/**
* 开票金额
*/
private BigDecimal invoiceAmount;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!