|
|
@@ -0,0 +1,320 @@
|
|
|
+/*
|
|
|
+ * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
|
|
+ *
|
|
|
+ * Redistribution and use in source and binary forms, with or without
|
|
|
+ * modification, are permitted provided that the following conditions are met:
|
|
|
+ *
|
|
|
+ * Redistributions of source code must retain the above copyright notice,
|
|
|
+ * this list of conditions and the following disclaimer.
|
|
|
+ * Redistributions in binary form must reproduce the above copyright
|
|
|
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
+ * documentation and/or other materials provided with the distribution.
|
|
|
+ * Neither the name of the dreamlu.net developer nor the names of its
|
|
|
+ * contributors may be used to endorse or promote products derived from
|
|
|
+ * this software without specific prior written permission.
|
|
|
+ * Author: Chill 庄骞 (smallchill@163.com)
|
|
|
+ */
|
|
|
+package org.springblade.los.business.mktSlot.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.core.tool.utils.Func;
|
|
|
+import org.springblade.core.tool.utils.StringUtil;
|
|
|
+import org.springblade.los.Util.CurrencyUtils;
|
|
|
+import org.springblade.los.basic.business.entity.BusinessType;
|
|
|
+import org.springblade.los.basic.business.service.IBusinessTypeService;
|
|
|
+import org.springblade.los.billno.entity.BusinessBillNo;
|
|
|
+import org.springblade.los.billno.service.IBusinessBillNoService;
|
|
|
+import org.springblade.los.business.mktSlot.entity.MktSlot;
|
|
|
+import org.springblade.los.business.mktSlot.entity.MktSlotItem;
|
|
|
+import org.springblade.los.business.mktSlot.entity.MktSlotQuotation;
|
|
|
+import org.springblade.los.business.mktSlot.mapper.MktSlotMapper;
|
|
|
+import org.springblade.los.business.mktSlot.service.IMktSlotItemService;
|
|
|
+import org.springblade.los.business.mktSlot.service.IMktSlotQuotationService;
|
|
|
+import org.springblade.los.business.mktSlot.service.IMktSlotService;
|
|
|
+import org.springblade.los.business.mktSlot.vo.MktSlotVO;
|
|
|
+import org.springblade.system.feign.ISysClient;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
+
|
|
|
+import java.time.Duration;
|
|
|
+import java.time.Instant;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * mkt&slot表 服务实现类
|
|
|
+ *
|
|
|
+ * @author BladeX
|
|
|
+ * @since 2025-06-24
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+public class MktSlotServiceImpl extends ServiceImpl<MktSlotMapper, MktSlot> implements IMktSlotService {
|
|
|
+
|
|
|
+ private final ISysClient sysClient;
|
|
|
+
|
|
|
+ private final IBusinessBillNoService businessBillNoService;
|
|
|
+
|
|
|
+ private final IBusinessTypeService bBusinessTypeService;
|
|
|
+
|
|
|
+ private final CurrencyUtils currencyUtils;
|
|
|
+
|
|
|
+ private final IMktSlotItemService mktSlotItemService;
|
|
|
+
|
|
|
+ private final IMktSlotQuotationService mktSlotQuotationService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<MktSlotVO> selectMktSlotPage(IPage<MktSlotVO> page, MktSlotVO mktSlot) {
|
|
|
+ return page.setRecords(baseMapper.selectMktSlotPage(page, mktSlot));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public MktSlot detail(MktSlot mktSlot) {
|
|
|
+ if (mktSlot.getId() == null) {
|
|
|
+ throw new RuntimeException("缺少必要参数");
|
|
|
+ }
|
|
|
+ MktSlot detail = baseMapper.selectById(mktSlot.getId());
|
|
|
+ if (detail == null) {
|
|
|
+ throw new RuntimeException("未查到单据信息");
|
|
|
+ }
|
|
|
+ List<MktSlotItem> mktSlotItemList = mktSlotItemService.list(new LambdaQueryWrapper<MktSlotItem>()
|
|
|
+ .eq(MktSlotItem::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(MktSlotItem::getIsDeleted, 0)
|
|
|
+ .eq(MktSlotItem::getPid, detail.getId()));
|
|
|
+ if (!mktSlotItemList.isEmpty()) {
|
|
|
+ List<MktSlotQuotation> mktSlotQuotationList = mktSlotQuotationService.list(new LambdaQueryWrapper<MktSlotQuotation>()
|
|
|
+ .eq(MktSlotQuotation::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(MktSlotQuotation::getIsDeleted, 0)
|
|
|
+ .eq(MktSlotQuotation::getPid, detail.getId())
|
|
|
+ .in(MktSlotQuotation::getPpid, mktSlotItemList.stream().map(MktSlotItem::getId).collect(Collectors.toList())));
|
|
|
+ for (MktSlotItem item : mktSlotItemList) {
|
|
|
+ if (!mktSlotQuotationList.isEmpty()) {
|
|
|
+ List<MktSlotQuotation> mktSlotQuotations = mktSlotQuotationList.stream().filter(e -> e.getPpid().equals(item.getId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ item.setMktSlotQuotationList(mktSlotQuotations.isEmpty() ? new ArrayList<>() : mktSlotQuotations);
|
|
|
+ } else {
|
|
|
+ item.setMktSlotQuotationList(new ArrayList<>());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ detail.setMktSlotItemList(mktSlotItemList);
|
|
|
+ return detail;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R submit(MktSlot mktSlot) {
|
|
|
+ String branchId;
|
|
|
+ String deptName = "";
|
|
|
+ if (ObjectUtils.isNull(mktSlot.getBranchId())) {
|
|
|
+ branchId = AuthUtil.getDeptId();
|
|
|
+ } else {
|
|
|
+ branchId = mktSlot.getBranchId();
|
|
|
+ }
|
|
|
+ //获取部门ids对应中文名
|
|
|
+ R<String> res = sysClient.getDeptName(Long.parseLong(branchId));
|
|
|
+ if (res.isSuccess() && ObjectUtils.isNotNull(res.getData())) {
|
|
|
+ deptName = res.getData();
|
|
|
+ }
|
|
|
+ if (mktSlot.getId() == null) {
|
|
|
+ BusinessType businessType = bBusinessTypeService.getOne(new LambdaQueryWrapper<BusinessType>()
|
|
|
+ .select(BusinessType::getId)
|
|
|
+ .eq(BusinessType::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BusinessType::getIsDeleted, 0)
|
|
|
+ .eq(BusinessType::getStatus, 0)
|
|
|
+ .eq(BusinessType::getCode, "BJZX"));
|
|
|
+ if (businessType == null) {
|
|
|
+ throw new RuntimeException("未找到可用业务类型");
|
|
|
+ }
|
|
|
+ BusinessBillNo businessBillNo = new BusinessBillNo();
|
|
|
+ businessBillNo.setBusinessTypeId(businessType.getId());
|
|
|
+ businessBillNo.setCode("BJZX");
|
|
|
+ businessBillNo.setBranchId(mktSlot.getBranchId());
|
|
|
+ R clientBillNo = businessBillNoService.getBillNoLos(businessBillNo);
|
|
|
+ if (!clientBillNo.isSuccess()) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return R.fail(500, "生成订单编号失败");
|
|
|
+ }
|
|
|
+ mktSlot.setSysNo((String) clientBillNo.getData());
|
|
|
+ mktSlot.setBillDate(new Date());
|
|
|
+ mktSlot.setCreateTime(new Date());
|
|
|
+ mktSlot.setCreateUser(AuthUtil.getUserId());
|
|
|
+ mktSlot.setCreateUserName(AuthUtil.getUserName());
|
|
|
+ mktSlot.setTenantId(AuthUtil.getTenantId());
|
|
|
+ mktSlot.setBranchId(branchId);
|
|
|
+ mktSlot.setBranchName(deptName);
|
|
|
+ // 初始创建为1
|
|
|
+ mktSlot.setVersion("1");
|
|
|
+ this.save(mktSlot);
|
|
|
+ } else {
|
|
|
+ MktSlot dataSourceBill = baseMapper.selectOne(new LambdaQueryWrapper<MktSlot>().select(MktSlot::getId, MktSlot::getVersion).eq(MktSlot::getId, mktSlot.getId()));
|
|
|
+ if (!Objects.equals(dataSourceBill.getVersion(), mktSlot.getVersion())) {
|
|
|
+ return R.fail(601, "数据已被其他用户更新,请等待刷新后重试");
|
|
|
+ }
|
|
|
+ // 每更新一次往上累加一次版本
|
|
|
+ // 旧数据处理
|
|
|
+ int version = StringUtil.isBlank(dataSourceBill.getVersion()) ? 1 : Integer.parseInt(dataSourceBill.getVersion());
|
|
|
+ mktSlot.setVersion(String.valueOf(version + 1));
|
|
|
+ mktSlot.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ mktSlot.setUpdateTime(new Date());
|
|
|
+ mktSlot.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotNull(mktSlot.getMktSlotItemList()) && !mktSlot.getMktSlotItemList().isEmpty()) {
|
|
|
+ for (MktSlotItem item : mktSlot.getMktSlotItemList()) {
|
|
|
+ if (item.getId() == null) {
|
|
|
+ item.setCreateTime(new Date());
|
|
|
+ item.setCreateUser(AuthUtil.getUserId());
|
|
|
+ item.setCreateUserName(AuthUtil.getUserName());
|
|
|
+ item.setBranchId(branchId);
|
|
|
+ item.setBranchName(deptName);
|
|
|
+ } else {
|
|
|
+ item.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ item.setUpdateTime(new Date());
|
|
|
+ item.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ }
|
|
|
+ item.setPid(mktSlot.getId());
|
|
|
+ }
|
|
|
+ mktSlotItemService.saveOrUpdateBatch(mktSlot.getMktSlotItemList());
|
|
|
+ }
|
|
|
+ return R.data(mktSlot);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R submitMktSlot(String ids) {
|
|
|
+ if (ObjectUtils.isNull(ids)) {
|
|
|
+ throw new RuntimeException("缺少必要参数");
|
|
|
+ }
|
|
|
+ List<MktSlot> mktSlotList = baseMapper.selectList(new LambdaQueryWrapper<MktSlot>()
|
|
|
+ .eq(MktSlot::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(MktSlot::getIsDeleted, 0)
|
|
|
+ .in(MktSlot::getId, Func.toLongList(ids)));
|
|
|
+ if (mktSlotList.isEmpty()) {
|
|
|
+ throw new RuntimeException("未查到单据信息");
|
|
|
+ }
|
|
|
+ for (MktSlot item : mktSlotList) {
|
|
|
+ item.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ item.setUpdateTime(new Date());
|
|
|
+ item.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ item.setBillStatus("已提交");
|
|
|
+ }
|
|
|
+ this.updateBatchById(mktSlotList);
|
|
|
+ return R.data("操作成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R revokeMktSlot(String ids) {
|
|
|
+ if (ObjectUtils.isNull(ids)) {
|
|
|
+ throw new RuntimeException("缺少必要参数");
|
|
|
+ }
|
|
|
+ List<MktSlot> mktSlotList = baseMapper.selectList(new LambdaQueryWrapper<MktSlot>()
|
|
|
+ .eq(MktSlot::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(MktSlot::getIsDeleted, 0)
|
|
|
+ .in(MktSlot::getId, Func.toLongList(ids)));
|
|
|
+ if (mktSlotList.isEmpty()) {
|
|
|
+ throw new RuntimeException("未查到单据信息");
|
|
|
+ }
|
|
|
+ for (MktSlot item : mktSlotList) {
|
|
|
+ item.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ item.setUpdateTime(new Date());
|
|
|
+ item.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ item.setBillStatus("录入");
|
|
|
+ }
|
|
|
+ this.updateBatchById(mktSlotList);
|
|
|
+ return R.data("操作成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R generateQuotation(MktSlot mktSlot) {
|
|
|
+ if (mktSlot.getId() == null || ObjectUtils.isNull(mktSlot.getMktSlotItemList()) ||
|
|
|
+ mktSlot.getMktSlotItemList().isEmpty()) {
|
|
|
+ throw new RuntimeException("缺少必要请求参数");
|
|
|
+ }
|
|
|
+ List<MktSlotQuotation> mktSlotQuotationList = new ArrayList<>();
|
|
|
+ MktSlot detail = baseMapper.selectById(mktSlot.getId());
|
|
|
+ Instant instant1 = detail.getEffectiveStartDate().toInstant();
|
|
|
+ Instant instant2 = detail.getEffectiveEndDate().toInstant();
|
|
|
+ LocalDate date1 = instant1.atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
+ LocalDate date2 = instant2.atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
+ Duration duration = Duration.between(date1.atStartOfDay(), date2.atStartOfDay());
|
|
|
+ long days = duration.toDays();
|
|
|
+ for (MktSlotItem item : mktSlot.getMktSlotItemList()) {
|
|
|
+ for (int i = 0; i <= days; i++) {
|
|
|
+ MktSlotQuotation mktSlotQuotation = new MktSlotQuotation();
|
|
|
+ LocalDate tomorrow = date1.plusDays(i);
|
|
|
+ mktSlotQuotation.setPid(detail.getId());
|
|
|
+ mktSlotQuotation.setPpid(item.getId());
|
|
|
+ mktSlotQuotation.setCreateTime(new Date());
|
|
|
+ mktSlotQuotation.setCreateUser(AuthUtil.getUserId());
|
|
|
+ mktSlotQuotation.setCreateUserName(AuthUtil.getUserName());
|
|
|
+ mktSlotQuotation.setBranchId(item.getBranchId());
|
|
|
+ mktSlotQuotation.setBranchName(item.getBranchName());
|
|
|
+ mktSlotQuotation.setEtd(Date.from(tomorrow.atStartOfDay(ZoneId.systemDefault()).toInstant()));
|
|
|
+ mktSlotQuotation.setGp20(item.getGp20());
|
|
|
+ mktSlotQuotation.setGp40(item.getGp40());
|
|
|
+ mktSlotQuotation.setHc40(item.getHc40());
|
|
|
+ mktSlotQuotation.setCurCode(item.getCurCode());
|
|
|
+ mktSlotQuotation.setPolId(item.getPolId());
|
|
|
+ mktSlotQuotation.setPolCode(item.getPolCode());
|
|
|
+ mktSlotQuotation.setPolCnName(item.getPolCnName());
|
|
|
+ mktSlotQuotation.setPolEnName(item.getPolEnName());
|
|
|
+ mktSlotQuotation.setPodId(item.getPodId());
|
|
|
+ mktSlotQuotation.setPodCode(item.getPodCode());
|
|
|
+ mktSlotQuotation.setPodCnName(item.getPodCnName());
|
|
|
+ mktSlotQuotation.setPodEnName(item.getPodEnName());
|
|
|
+ mktSlotQuotationList.add(mktSlotQuotation);
|
|
|
+ }
|
|
|
+ item.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ item.setUpdateTime(new Date());
|
|
|
+ item.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ item.setWhetherQuotation("1");
|
|
|
+ }
|
|
|
+ if (!mktSlotQuotationList.isEmpty()) {
|
|
|
+ mktSlotQuotationService.saveBatch(mktSlotQuotationList);
|
|
|
+ }
|
|
|
+ mktSlotItemService.updateBatchById(mktSlot.getMktSlotItemList());
|
|
|
+ return R.data(mktSlot);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R revokeQuotation(MktSlot mktSlot) {
|
|
|
+ if (mktSlot.getId() == null || ObjectUtils.isNull(mktSlot.getMktSlotItemList()) ||
|
|
|
+ mktSlot.getMktSlotItemList().isEmpty()) {
|
|
|
+ throw new RuntimeException("缺少必要请求参数");
|
|
|
+ }
|
|
|
+ MktSlot detail = baseMapper.selectById(mktSlot.getId());
|
|
|
+ List<Long> idList = mktSlot.getMktSlotItemList().stream().map(MktSlotItem::getId).collect(Collectors.toList());
|
|
|
+ List<MktSlotQuotation> mktSlotQuotationList = mktSlotQuotationService.list(new LambdaQueryWrapper<MktSlotQuotation>()
|
|
|
+ .eq(MktSlotQuotation::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(MktSlotQuotation::getIsDeleted, 0)
|
|
|
+ .in(MktSlotQuotation::getPpid, idList)
|
|
|
+ .eq(MktSlotQuotation::getPid, detail.getId()));
|
|
|
+ if (!mktSlotQuotationList.isEmpty()) {
|
|
|
+ mktSlotQuotationService.removeByIds(mktSlotQuotationList.stream().map(MktSlotQuotation::getId).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ for (MktSlotItem item : mktSlot.getMktSlotItemList()) {
|
|
|
+ item.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ item.setUpdateTime(new Date());
|
|
|
+ item.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ item.setWhetherQuotation("0");
|
|
|
+ }
|
|
|
+ mktSlotItemService.updateBatchById(mktSlot.getMktSlotItemList());
|
|
|
+ return R.data(mktSlot);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|