|
|
@@ -0,0 +1,214 @@
|
|
|
+package org.dromara.customer.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.dromara.common.core.enums.FormatsType;
|
|
|
+import org.dromara.common.core.utils.DateUtils;
|
|
|
+import org.dromara.common.core.utils.MapstructUtils;
|
|
|
+import org.dromara.common.core.utils.StringUtils;
|
|
|
+import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.dromara.customer.domain.bo.PartnerPreparedBo;
|
|
|
+import org.dromara.customer.domain.vo.PartnerPreparedVo;
|
|
|
+import org.dromara.customer.domain.PartnerPrepared;
|
|
|
+import org.dromara.customer.mapper.PartnerPreparedMapper;
|
|
|
+import org.dromara.customer.service.IPartnerPreparedService;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Collection;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 伙伴商备货单Service业务层处理
|
|
|
+ *
|
|
|
+ * @author LionLi
|
|
|
+ * @date 2026-01-21
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Service
|
|
|
+public class PartnerPreparedServiceImpl extends ServiceImpl<PartnerPreparedMapper, PartnerPrepared> implements IPartnerPreparedService {
|
|
|
+
|
|
|
+ private final PartnerPreparedMapper baseMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询伙伴商备货单
|
|
|
+ *
|
|
|
+ * @param id 主键
|
|
|
+ * @return 伙伴商备货单
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public PartnerPreparedVo queryById(Long id){
|
|
|
+ return baseMapper.selectVoById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询伙伴商备货单列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @param pageQuery 分页参数
|
|
|
+ * @return 伙伴商备货单分页列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<PartnerPreparedVo> queryPageList(PartnerPreparedBo bo, PageQuery pageQuery) {
|
|
|
+ LambdaQueryWrapper<PartnerPrepared> lqw = buildQueryWrapper(bo);
|
|
|
+ Page<PartnerPreparedVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
|
+ return TableDataInfo.build(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询符合条件的伙伴商备货单列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @return 伙伴商备货单列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<PartnerPreparedVo> queryList(PartnerPreparedBo bo) {
|
|
|
+ LambdaQueryWrapper<PartnerPrepared> lqw = buildQueryWrapper(bo);
|
|
|
+ return baseMapper.selectVoList(lqw);
|
|
|
+ }
|
|
|
+
|
|
|
+ private LambdaQueryWrapper<PartnerPrepared> buildQueryWrapper(PartnerPreparedBo bo) {
|
|
|
+ Map<String, Object> params = bo.getParams();
|
|
|
+ LambdaQueryWrapper<PartnerPrepared> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.orderByAsc(PartnerPrepared::getId);
|
|
|
+ lqw.eq(bo.getPartnerId() != null, PartnerPrepared::getPartnerId, bo.getPartnerId());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getPreparedNo()), PartnerPrepared::getPreparedNo, bo.getPreparedNo());
|
|
|
+ lqw.eq(bo.getCooperationCode() != null, PartnerPrepared::getCooperationCode, bo.getCooperationCode());
|
|
|
+ lqw.like(StringUtils.isNotBlank(bo.getCustomerName()), PartnerPrepared::getCustomerName, bo.getCustomerName());
|
|
|
+ lqw.like(StringUtils.isNotBlank(bo.getPurchasingUnitName()), PartnerPrepared::getPurchasingUnitName, bo.getPurchasingUnitName());
|
|
|
+ lqw.eq(bo.getAmount() != null, PartnerPrepared::getAmount, bo.getAmount());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getArea()), PartnerPrepared::getArea, bo.getArea());
|
|
|
+ lqw.eq(bo.getEstimatedTime() != null, PartnerPrepared::getEstimatedTime, bo.getEstimatedTime());
|
|
|
+ lqw.eq(bo.getDueDate() != null, PartnerPrepared::getDueDate, bo.getDueDate());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getInvoiceAttachment()), PartnerPrepared::getInvoiceAttachment, bo.getInvoiceAttachment());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getPurchasingUnit()), PartnerPrepared::getPurchasingUnit, bo.getPurchasingUnit());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getPerson()), PartnerPrepared::getPerson, bo.getPerson());
|
|
|
+ lqw.like(StringUtils.isNotBlank(bo.getDeptName()), PartnerPrepared::getDeptName, bo.getDeptName());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getPhone()), PartnerPrepared::getPhone, bo.getPhone());
|
|
|
+ lqw.eq(bo.getPreparedStatus() != null, PartnerPrepared::getPreparedStatus, bo.getPreparedStatus());
|
|
|
+ lqw.eq(bo.getDealStatus() != null, PartnerPrepared::getDealStatus, bo.getDealStatus());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getReject()), PartnerPrepared::getReject, bo.getReject());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getStatus()), PartnerPrepared::getStatus, bo.getStatus());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getPlatformCode()), PartnerPrepared::getPlatformCode, bo.getPlatformCode());
|
|
|
+ return lqw;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增伙伴商备货单
|
|
|
+ *
|
|
|
+ * @param bo 伙伴商备货单
|
|
|
+ * @return 是否新增成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean insertByBo(PartnerPreparedBo bo) {
|
|
|
+ PartnerPrepared add = MapstructUtils.convert(bo, PartnerPrepared.class);
|
|
|
+
|
|
|
+ // TODO: 【重要】partner_id 用于关联当前登录的伙伴商用户
|
|
|
+ // 应该从当前登录用户的 token/session 中获取其关联的伙伴商ID(partner_info.id)
|
|
|
+ // 伙伴商用户登录后,其创建的所有订单报备都应自动绑定到该伙伴商
|
|
|
+ // 临时方案:这里暂时硬编码为 1,需要根据实际登录用户动态获取
|
|
|
+ if (add.getPartnerId() == null) {
|
|
|
+ add.setPartnerId(1L);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 自动生成备货单编号
|
|
|
+ if (StringUtils.isBlank(add.getPreparedNo())) {
|
|
|
+ add.setPreparedNo(generatePreparedNo());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置必填字段的默认值(避免数据库约束错误)
|
|
|
+ if (StringUtils.isBlank(add.getPurchasingUnitName())) {
|
|
|
+ add.setPurchasingUnitName("");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(add.getDeptName())) {
|
|
|
+ add.setDeptName("");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(add.getInvoiceAttachment())) {
|
|
|
+ add.setInvoiceAttachment("");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置初始状态:新建订单默认为待审核、未处理
|
|
|
+ if (add.getPreparedStatus() == null) {
|
|
|
+ add.setPreparedStatus(0L); // 0=待审核
|
|
|
+ }
|
|
|
+ if (add.getDealStatus() == null) {
|
|
|
+ add.setDealStatus(0L); // 0=未处理
|
|
|
+ }
|
|
|
+
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ boolean flag = baseMapper.insert(add) > 0;
|
|
|
+ if (flag) {
|
|
|
+ bo.setId(add.getId());
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成备货单编号
|
|
|
+ * 格式:BH + yyyyMMdd + 6位流水号
|
|
|
+ * 例如:BH202601220000001
|
|
|
+ */
|
|
|
+ private String generatePreparedNo() {
|
|
|
+ String dateStr = DateUtils.dateTimeNow(FormatsType.YYYYMMDD);
|
|
|
+ String prefix = "BH" + dateStr;
|
|
|
+
|
|
|
+ // 查询当天最大的流水号
|
|
|
+ LambdaQueryWrapper<PartnerPrepared> wrapper = Wrappers.lambdaQuery();
|
|
|
+ wrapper.likeRight(PartnerPrepared::getPreparedNo, prefix)
|
|
|
+ .orderByDesc(PartnerPrepared::getPreparedNo)
|
|
|
+ .last("LIMIT 1");
|
|
|
+ PartnerPrepared lastOrder = baseMapper.selectOne(wrapper);
|
|
|
+
|
|
|
+ int sequence = 1;
|
|
|
+ if (lastOrder != null && StringUtils.isNotBlank(lastOrder.getPreparedNo())) {
|
|
|
+ String lastNo = lastOrder.getPreparedNo();
|
|
|
+ if (lastNo.length() >= prefix.length() + 6) {
|
|
|
+ String lastSequence = lastNo.substring(prefix.length());
|
|
|
+ sequence = Integer.parseInt(lastSequence) + 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return prefix + String.format("%06d", sequence);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改伙伴商备货单
|
|
|
+ *
|
|
|
+ * @param bo 伙伴商备货单
|
|
|
+ * @return 是否修改成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean updateByBo(PartnerPreparedBo bo) {
|
|
|
+ PartnerPrepared update = MapstructUtils.convert(bo, PartnerPrepared.class);
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ return baseMapper.updateById(update) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(PartnerPrepared entity){
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验并批量删除伙伴商备货单信息
|
|
|
+ *
|
|
|
+ * @param ids 待删除的主键集合
|
|
|
+ * @param isValid 是否进行有效性校验
|
|
|
+ * @return 是否删除成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if(isValid){
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return baseMapper.deleteByIds(ids) > 0;
|
|
|
+ }
|
|
|
+}
|