|
|
@@ -0,0 +1,267 @@
|
|
|
+/*
|
|
|
+ * 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.billno.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 net.logstash.logback.encoder.org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.core.tool.utils.BeanUtil;
|
|
|
+import org.springblade.los.billno.entity.BillNoCenter;
|
|
|
+import org.springblade.los.billno.entity.BillNoSerial;
|
|
|
+import org.springblade.los.billno.entity.BusinessBillNo;
|
|
|
+import org.springblade.los.billno.mapper.BusinessBillNoMapper;
|
|
|
+import org.springblade.los.billno.service.IBillNoCenterService;
|
|
|
+import org.springblade.los.billno.service.IBillNoSerialService;
|
|
|
+import org.springblade.los.billno.service.IBusinessBillNoService;
|
|
|
+import org.springblade.los.billno.vo.BillNoSerialVO;
|
|
|
+import org.springblade.los.billno.vo.BusinessBillNoVO;
|
|
|
+import org.springblade.los.business.sea.entity.Bills;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 基础资料-业务类型编号格式 服务实现类
|
|
|
+ *
|
|
|
+ * @author BladeX
|
|
|
+ * @since 2023-10-20
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+public class BusinessBillNoServiceImpl extends ServiceImpl<BusinessBillNoMapper, BusinessBillNo> implements IBusinessBillNoService {
|
|
|
+
|
|
|
+
|
|
|
+ private final IBillNoSerialService billNoSerialService;
|
|
|
+
|
|
|
+ private final IBillNoCenterService billNoCenterService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<BusinessBillNoVO> selectBusinessBillNoPage(IPage<BusinessBillNoVO> page, BusinessBillNoVO businessBillNo) {
|
|
|
+ return page.setRecords(baseMapper.selectBusinessBillNoPage(page, businessBillNo));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R<String> getBillNoLos(BusinessBillNo businessBillNo) {
|
|
|
+ BusinessBillNo detail = baseMapper.selectOne(new LambdaQueryWrapper<BusinessBillNo>()
|
|
|
+ .eq(BusinessBillNo::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BusinessBillNo::getIsDeleted, 0)
|
|
|
+ .eq(BusinessBillNo::getBusinessTypeId, businessBillNo.getBusinessTypeId())
|
|
|
+ .eq(BusinessBillNo::getCode, businessBillNo.getCode())
|
|
|
+ .eq(BusinessBillNo::getStatus, 0));
|
|
|
+ if (detail == null) {
|
|
|
+ throw new RuntimeException("未找到可用生成编码规则");
|
|
|
+ }
|
|
|
+ Date date = new Date();
|
|
|
+ //编码开头
|
|
|
+ String head = "";
|
|
|
+ //编码日期格式
|
|
|
+ String yearMmDd = "";
|
|
|
+ //编码序列号
|
|
|
+ String tail = "";
|
|
|
+ //格式化后日期
|
|
|
+ String yyyyMM = "";
|
|
|
+ //编码
|
|
|
+ String billNo = null;
|
|
|
+ //判断编码格式是否为空
|
|
|
+ if (ObjectUtils.isNotNull(detail.getCodeFormat())) {
|
|
|
+ int index = detail.getCodeFormat().indexOf("%");
|
|
|
+ int indexLast = detail.getCodeFormat().indexOf("%", index + 1);
|
|
|
+ head = detail.getCodeFormat().substring(0, index);
|
|
|
+ yearMmDd = detail.getCodeFormat().substring(index + 1, indexLast);
|
|
|
+ tail = detail.getCodeFormat().substring(indexLast + 1);
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("编码格式为空");
|
|
|
+ }
|
|
|
+ //格式化日期
|
|
|
+ if (ObjectUtils.isNotNull(yearMmDd)) {
|
|
|
+ yyyyMM = DateFormatUtils.format(date, yearMmDd);
|
|
|
+ }
|
|
|
+ billNo = head + yyyyMM;
|
|
|
+ List<BillNoCenter> billNoCenterList = billNoCenterService.list(new LambdaQueryWrapper<BillNoCenter>()
|
|
|
+ .eq(BillNoCenter::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BillNoCenter::getIsDeleted, 0)
|
|
|
+ .eq(BillNoCenter::getBusinessTypeId, detail.getBusinessTypeId())
|
|
|
+ .eq(BillNoCenter::getBusinessType, detail.getBusinessType())
|
|
|
+ .eq(BillNoCenter::getPid, detail.getId())
|
|
|
+ .eq(BillNoCenter::getResetRule, detail.getResetRule())
|
|
|
+ .eq(BillNoCenter::getResetValue, billNo)
|
|
|
+ .orderByDesc(BillNoCenter::getCreateTime)
|
|
|
+ );
|
|
|
+ if (billNoCenterList.size() > 0) {
|
|
|
+ return R.data(billNoCenterList.get(0).getBillNo());
|
|
|
+ } else {
|
|
|
+ BillNoSerial billNoSerial1 = new BillNoSerialVO();
|
|
|
+ //判断是否有生成过编码记录
|
|
|
+ BillNoSerial billNoSerial = billNoSerialService.getOne(new LambdaQueryWrapper<BillNoSerial>()
|
|
|
+ .eq(BillNoSerial::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BillNoSerial::getIsDeleted, 0)
|
|
|
+ .eq(BillNoSerial::getBusinessTypeId, detail.getBusinessTypeId())
|
|
|
+ .eq(BillNoSerial::getPid, detail.getId())
|
|
|
+ .eq(BillNoSerial::getResetRule, detail.getResetRule())
|
|
|
+ .eq(BillNoSerial::getResetValue, billNo)
|
|
|
+ );
|
|
|
+ if (billNoSerial == null) {
|
|
|
+ billNoSerial1.setBusinessTypeId(detail.getBusinessTypeId());
|
|
|
+ billNoSerial1.setSerialNo(1L);
|
|
|
+ billNoSerial1.setPid(detail.getId());
|
|
|
+ billNoSerial1.setResetRule(detail.getResetRule());
|
|
|
+ billNoSerial1.setResetValue(billNo);
|
|
|
+ billNoSerial1.setBranchId(AuthUtil.getDeptId());
|
|
|
+ billNoSerial1.setCreateDept(AuthUtil.getDeptId());
|
|
|
+ billNoSerial1.setCreateTime(new Date());
|
|
|
+ billNoSerial1.setCreateUser(AuthUtil.getUserId());
|
|
|
+ billNoSerial1.setCreateUserName(AuthUtil.getUserName());
|
|
|
+ billNoSerial1.setTenantId(AuthUtil.getTenantId());
|
|
|
+ //生成序列号 循环赋0 最后一位赋1
|
|
|
+ if (tail.length() > 0) {
|
|
|
+ StringBuilder number = new StringBuilder();
|
|
|
+ for (int i = 0; i <= tail.length(); i++) {
|
|
|
+ if (i == tail.length()) {
|
|
|
+ number.append(number).append("1");
|
|
|
+ } else {
|
|
|
+ number.append(number).append("0");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ billNo = billNo + number.toString();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ BeanUtil.copyProperties(billNoSerial, billNoSerial1);
|
|
|
+ billNoSerial1.setSerialNo(billNoSerial.getSerialNo() + 1);
|
|
|
+ billNoSerial1.setUpdateTime(new Date());
|
|
|
+ billNoSerial1.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ billNoSerial1.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ String count = billNoSerial1.getSerialNo() + "";
|
|
|
+ if (tail.length() > 0) {
|
|
|
+ //判断最大序列号长度与序列号规则长度是否相等 相等不赋0
|
|
|
+ if (tail.length() == count.length()) {
|
|
|
+ billNo = billNo + count;
|
|
|
+ } else {
|
|
|
+ //不相等 序列号规则长度-最大序列号长度 之间赋0 然后拼接最大序列号
|
|
|
+ StringBuilder number = new StringBuilder();
|
|
|
+ for (int i = 0; i <= tail.length() - count.length(); i++) {
|
|
|
+ number.append(number).append("0");
|
|
|
+ }
|
|
|
+ billNo = billNo + number.toString() + count;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ billNoSerialService.saveOrUpdate(billNoSerial1);
|
|
|
+ return R.data(billNo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deteleBillNo(Bills item) {
|
|
|
+ String billNo = "";
|
|
|
+ String mbillNo = "";
|
|
|
+ if (ObjectUtils.isNotNull(item.getBillNo())) {
|
|
|
+ billNo = item.getBillNo().replaceAll("\\D", "");
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotNull(item.getMblno())) {
|
|
|
+ mbillNo = item.getMblno().replaceAll("\\D", "");
|
|
|
+ }
|
|
|
+ Date date = new Date();
|
|
|
+ //编码开头
|
|
|
+ String head = "";
|
|
|
+ //编码日期格式
|
|
|
+ String yearMmDd = "";
|
|
|
+ //格式化后日期
|
|
|
+ String yyyyMM = "";
|
|
|
+ List<BillNoSerial> billNoSerialList = billNoSerialService.list(new LambdaQueryWrapper<BillNoSerial>()
|
|
|
+ .eq(BillNoSerial::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BillNoSerial::getIsDeleted, 0)
|
|
|
+ .like(BillNoSerial::getResetValue, billNo));
|
|
|
+ if (billNoSerialList.size() > 0) {
|
|
|
+ BusinessBillNo detail = baseMapper.selectById(billNoSerialList.get(0).getPid());
|
|
|
+ //判断编码格式是否为空
|
|
|
+ if (ObjectUtils.isNotNull(detail.getCodeFormat())) {
|
|
|
+ int index = detail.getCodeFormat().indexOf("%");
|
|
|
+ int indexLast = detail.getCodeFormat().indexOf("%", index + 1);
|
|
|
+ head = detail.getCodeFormat().substring(0, index);
|
|
|
+ yearMmDd = detail.getCodeFormat().substring(index + 1, indexLast);
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("编码格式为空");
|
|
|
+ }
|
|
|
+ //格式化日期
|
|
|
+ if (ObjectUtils.isNotNull(yearMmDd)) {
|
|
|
+ yyyyMM = DateFormatUtils.format(date, yearMmDd);
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotNull(detail) && 1 == detail.getIsRecyclable()) {
|
|
|
+ BillNoCenter billNoCenter = new BillNoCenter();
|
|
|
+ billNoCenter.setBusinessType(detail.getBusinessType());
|
|
|
+ billNoCenter.setBusinessTypeId(detail.getBusinessTypeId());
|
|
|
+ billNoCenter.setPid(detail.getId());
|
|
|
+ billNoCenter.setBillId(item.getId());
|
|
|
+ billNoCenter.setBillNo(item.getBillNo());
|
|
|
+ billNoCenter.setResetRule(detail.getResetRule());
|
|
|
+ billNoCenter.setResetValue(head + yyyyMM);
|
|
|
+ billNoCenter.setTenantId(AuthUtil.getTenantId());
|
|
|
+ billNoCenter.setCreateTime(new Date());
|
|
|
+ billNoCenter.setCreateUser(AuthUtil.getUserId());
|
|
|
+ billNoCenter.setCreateUserName(AuthUtil.getUserName());
|
|
|
+ billNoCenter.setCreateDept(AuthUtil.getDeptId());
|
|
|
+ billNoCenterService.save(billNoCenter);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<BillNoSerial> billNoSerialList1 = billNoSerialService.list(new LambdaQueryWrapper<BillNoSerial>()
|
|
|
+ .eq(BillNoSerial::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BillNoSerial::getIsDeleted, 0)
|
|
|
+ .like(BillNoSerial::getResetValue, mbillNo));
|
|
|
+ if (billNoSerialList1.size() > 0) {
|
|
|
+ BusinessBillNo detail = baseMapper.selectById(billNoSerialList1.get(0).getPid());
|
|
|
+ if (ObjectUtils.isNotNull(detail) && 1 == detail.getIsRecyclable()) {
|
|
|
+ //判断编码格式是否为空
|
|
|
+ if (ObjectUtils.isNotNull(detail.getCodeFormat())) {
|
|
|
+ int index = detail.getCodeFormat().indexOf("%");
|
|
|
+ int indexLast = detail.getCodeFormat().indexOf("%", index + 1);
|
|
|
+ head = detail.getCodeFormat().substring(0, index);
|
|
|
+ yearMmDd = detail.getCodeFormat().substring(index + 1, indexLast);
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("编码格式为空");
|
|
|
+ }
|
|
|
+ //格式化日期
|
|
|
+ if (ObjectUtils.isNotNull(yearMmDd)) {
|
|
|
+ yyyyMM = DateFormatUtils.format(date, yearMmDd);
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotNull(detail) && 1 == detail.getIsRecyclable()) {
|
|
|
+ BillNoCenter billNoCenter = new BillNoCenter();
|
|
|
+ billNoCenter.setBusinessType(detail.getBusinessType());
|
|
|
+ billNoCenter.setBusinessTypeId(detail.getBusinessTypeId());
|
|
|
+ billNoCenter.setPid(detail.getId());
|
|
|
+ billNoCenter.setBillId(item.getId());
|
|
|
+ billNoCenter.setBillNo(item.getBillNo());
|
|
|
+ billNoCenter.setResetRule(detail.getResetRule());
|
|
|
+ billNoCenter.setResetValue(head + yyyyMM);
|
|
|
+ billNoCenter.setTenantId(AuthUtil.getTenantId());
|
|
|
+ billNoCenter.setCreateTime(new Date());
|
|
|
+ billNoCenter.setCreateUser(AuthUtil.getUserId());
|
|
|
+ billNoCenter.setCreateUserName(AuthUtil.getUserName());
|
|
|
+ billNoCenter.setCreateDept(AuthUtil.getDeptId());
|
|
|
+ billNoCenterService.save(billNoCenter);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|