|
@@ -0,0 +1,312 @@
|
|
|
|
+package com.jeeplus.pubmodules.serialNumTpl.service;
|
|
|
|
+
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
+import com.jeeplus.pubmodules.serialNumTpl.domain.SysSerialnumTpl;
|
|
|
|
+import com.jeeplus.pubmodules.serialNumTpl.mapper.SerialnumTplMapper;
|
|
|
|
+import com.jeeplus.sys.domain.Office;
|
|
|
|
+import com.jeeplus.sys.mapper.OfficeMapper;
|
|
|
|
+import com.jeeplus.sys.service.dto.UserDTO;
|
|
|
|
+import com.jeeplus.sys.utils.UserUtils;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.apache.http.client.utils.DateUtils;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
+import java.time.Month;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.regex.Matcher;
|
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
+
|
|
|
|
+@Service
|
|
|
|
+public class SerialnumTplService {
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private SerialnumTplMapper serialnumTplMapper;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private OfficeMapper officeMapper;
|
|
|
|
+
|
|
|
|
+ public IPage<SysSerialnumTpl> list(Page<SysSerialnumTpl> page, QueryWrapper<SysSerialnumTpl> sysSerialnumTplQueryWrapper) {
|
|
|
|
+ sysSerialnumTplQueryWrapper.eq("del_flag", 0);
|
|
|
|
+ IPage<SysSerialnumTpl> list = serialnumTplMapper.pageList(page, sysSerialnumTplQueryWrapper);
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public String remove(String id) {
|
|
|
|
+ serialnumTplMapper.deleteById(id);
|
|
|
|
+ return "操作成功";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public SysSerialnumTpl findById(String id) {
|
|
|
|
+ SysSerialnumTpl sysSerialnumTpl = serialnumTplMapper.selectById(id);
|
|
|
|
+ return sysSerialnumTpl;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public String save(SysSerialnumTpl sysSerialnumTpl) {
|
|
|
|
+ //获取当前登录人信息
|
|
|
|
+ UserDTO dto = UserUtils.getCurrentUserDTO();
|
|
|
|
+ //新增
|
|
|
|
+ if (StringUtils.isEmpty(sysSerialnumTpl.getId())) {
|
|
|
|
+ String id = UUID.randomUUID().toString().replace("-", "");
|
|
|
|
+ sysSerialnumTpl.setId(id);
|
|
|
|
+ sysSerialnumTpl.setCreateById(dto.getId());
|
|
|
|
+ sysSerialnumTpl.setCreateTime(new Date());
|
|
|
|
+ sysSerialnumTpl.setUpdateById(dto.getId());
|
|
|
|
+ sysSerialnumTpl.setUpdateTime(new Date());
|
|
|
|
+ sysSerialnumTpl.setDelFlag(0);
|
|
|
|
+ serialnumTplMapper.insert(sysSerialnumTpl);
|
|
|
|
+ }
|
|
|
|
+ //修改
|
|
|
|
+ if (StringUtils.isNotEmpty(sysSerialnumTpl.getId())) {
|
|
|
|
+ sysSerialnumTpl.setUpdateById(dto.getId());
|
|
|
|
+ sysSerialnumTpl.setUpdateTime(new Date());
|
|
|
|
+ serialnumTplMapper.updateById(sysSerialnumTpl);
|
|
|
|
+ }
|
|
|
|
+ return "操作完成";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional(readOnly = false,propagation = Propagation.REQUIRES_NEW)
|
|
|
|
+ public String genSerialNum(String companyId, String bizCode) throws Exception {
|
|
|
|
+ //获取当前登录人信息
|
|
|
|
+ UserDTO dto = UserUtils.getCurrentUserDTO();
|
|
|
|
+ Office office = officeMapper.selectById(companyId);
|
|
|
|
+ if (StringUtils.isBlank(bizCode)){
|
|
|
|
+ throw new Exception("生成编号失败,业务类型不能为空");
|
|
|
|
+ }
|
|
|
|
+ if (office != null) {
|
|
|
|
+ SysSerialnumTpl numTpl = this.querySerialTpl(office, bizCode);
|
|
|
|
+ if (numTpl == null) {
|
|
|
|
+ //查询编号模板 {brspnm}DZ-{year}-{serialNum}
|
|
|
|
+ SysSerialnumTpl serialNumTpl = serialnumTplMapper.queryByComAndBizCode(companyId, bizCode);
|
|
|
|
+ serialNumTpl.setCompanyId(companyId);
|
|
|
|
+ serialNumTpl.setSerialNum(0);
|
|
|
|
+ serialNumTpl.setCreateById(dto.getId());
|
|
|
|
+ serialNumTpl.setId(UUID.randomUUID().toString().replace("-", ""));
|
|
|
|
+ serialnumTplMapper.insert(serialNumTpl);
|
|
|
|
+ numTpl = serialNumTpl;
|
|
|
|
+ }
|
|
|
|
+ if (numTpl == null) {
|
|
|
|
+ throw new Exception("生成编号失败,请先设置相关业务编号模板");
|
|
|
|
+ }
|
|
|
|
+ String year = DateUtils.formatDate(new Date(), "yyyy");
|
|
|
|
+ if (!year.equals(numTpl.getYearBuilt())) {
|
|
|
|
+ serialnumTplMapper.resetSerialNum(numTpl.getId(), numTpl.getYearBuilt(), year);
|
|
|
|
+ }
|
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
|
+ String serialTpl = numTpl.getSerialTpl();
|
|
|
|
+ int i = serialnumTplMapper.updateSerialNum(numTpl);
|
|
|
|
+ if (i != 1) {
|
|
|
|
+ throw new Exception("生成编号失败,请稍后重试");
|
|
|
|
+ }
|
|
|
|
+ String num = String.valueOf(numTpl.getSerialNum() + 1);
|
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
|
+ for (int x = 0; x < (numTpl.getSerialNumLen() - num.length()); x++) {
|
|
|
|
+ sb.append("0");
|
|
|
|
+ }
|
|
|
|
+ sb.append(num);
|
|
|
|
+ //查询公司简称
|
|
|
|
+ if (serialTpl.contains("spnm")) {
|
|
|
|
+ String companyShortname = UserUtils.getSysParam("company_shortname");
|
|
|
|
+ map.put("spnm", StringUtils.isBlank(companyShortname) ? "" : companyShortname);
|
|
|
|
+ }
|
|
|
|
+ //查询分公司简称
|
|
|
|
+ if (serialTpl.contains("brspnm")) {
|
|
|
|
+ String branchShortname = UserUtils.getSysParam("branch_shortname");
|
|
|
|
+ map.put("brspnm", StringUtils.isBlank(branchShortname) ? "" : branchShortname);
|
|
|
|
+ }
|
|
|
|
+ //年份
|
|
|
|
+ if (serialTpl.contains("year")) {
|
|
|
|
+ map.put("year", year);
|
|
|
|
+ }
|
|
|
|
+ //月份
|
|
|
|
+ if (serialTpl.contains("month")) {
|
|
|
|
+ int month = new Date().getMonth() + 1;
|
|
|
|
+ map.put("month", month + "");
|
|
|
|
+ }
|
|
|
|
+ //序列号
|
|
|
|
+ if (serialTpl.contains("serialNum")) {
|
|
|
|
+ map.put("serialNum", sb.toString());
|
|
|
|
+ }
|
|
|
|
+ //日期
|
|
|
|
+ if (serialTpl.contains("day")) {
|
|
|
|
+ map.put("day", new Date().getDate() + "");
|
|
|
|
+ }
|
|
|
|
+ String serNum = renderString(serialTpl, map);
|
|
|
|
+ return serNum;
|
|
|
|
+ }
|
|
|
|
+ return "";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional(readOnly = false,propagation = Propagation.REQUIRES_NEW)
|
|
|
|
+ public String genSerialNumNoSort(String companyId, String bizCode) throws Exception {
|
|
|
|
+ //获取当前登录人信息
|
|
|
|
+ UserDTO dto = UserUtils.getCurrentUserDTO();
|
|
|
|
+ Office office = officeMapper.selectById(companyId);
|
|
|
|
+ if (StringUtils.isBlank(bizCode)){
|
|
|
|
+ throw new Exception("生成编号失败,业务类型不能为空");
|
|
|
|
+ }
|
|
|
|
+ if (office != null) {
|
|
|
|
+ SysSerialnumTpl numTpl = this.querySerialTpl(office, bizCode);
|
|
|
|
+ if (numTpl == null) {
|
|
|
|
+ //查询编号模板 {brspnm}DZ-{year}-{serialNum}
|
|
|
|
+ SysSerialnumTpl serialNumTpl = serialnumTplMapper.queryByComAndBizCode(companyId, bizCode);
|
|
|
|
+ serialNumTpl.setCompanyId(companyId);
|
|
|
|
+ serialNumTpl.setSerialNum(0);
|
|
|
|
+ serialNumTpl.setCreateById(dto.getId());
|
|
|
|
+ serialNumTpl.setId(UUID.randomUUID().toString().replace("-", ""));
|
|
|
|
+ serialnumTplMapper.insert(serialNumTpl);
|
|
|
|
+ numTpl = serialNumTpl;
|
|
|
|
+ }
|
|
|
|
+ if (numTpl == null) {
|
|
|
|
+ throw new Exception("生成编号失败,请先设置相关业务编号模板");
|
|
|
|
+ }
|
|
|
|
+ String year = DateUtils.formatDate(new Date(), "yyyy");
|
|
|
|
+ if (!year.equals(numTpl.getYearBuilt())) {
|
|
|
|
+ serialnumTplMapper.resetSerialNum(numTpl.getId(), numTpl.getYearBuilt(), year);
|
|
|
|
+ }
|
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
|
+ String serialTpl = numTpl.getSerialTpl();
|
|
|
|
+ int i = serialnumTplMapper.updateSerialNum(numTpl);
|
|
|
|
+ if (i != 1) {
|
|
|
|
+ throw new Exception("生成编号失败,请稍后重试");
|
|
|
|
+ }
|
|
|
|
+ String num = String.valueOf(numTpl.getSerialNum() + 1);
|
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
|
+ sb.append(num);
|
|
|
|
+ //查询公司简称
|
|
|
|
+ if (serialTpl.contains("spnm")) {
|
|
|
|
+ String companyShortname = UserUtils.getSysParam("company_shortname");
|
|
|
|
+ map.put("spnm", StringUtils.isBlank(companyShortname) ? "" : companyShortname);
|
|
|
|
+ }
|
|
|
|
+ //查询分公司简称
|
|
|
|
+ if (serialTpl.contains("brspnm")) {
|
|
|
|
+ String branchShortname = UserUtils.getSysParam("branch_shortname");
|
|
|
|
+ map.put("brspnm", StringUtils.isBlank(branchShortname) ? "" : branchShortname);
|
|
|
|
+ }
|
|
|
|
+ //年份
|
|
|
|
+ if (serialTpl.contains("year")) {
|
|
|
|
+ map.put("year", year);
|
|
|
|
+ }
|
|
|
|
+ //月份
|
|
|
|
+ if (serialTpl.contains("month")) {
|
|
|
|
+ int month = new Date().getMonth() + 1;
|
|
|
|
+ map.put("month", month + "");
|
|
|
|
+ }
|
|
|
|
+ //序列号
|
|
|
|
+ if (serialTpl.contains("serialNum")) {
|
|
|
|
+ map.put("serialNum", sb.toString());
|
|
|
|
+ }
|
|
|
|
+ //日期
|
|
|
|
+ if (serialTpl.contains("day")) {
|
|
|
|
+ map.put("day", new Date().getDate() + "");
|
|
|
|
+ }
|
|
|
|
+ String serNum = renderString(serialTpl, map);
|
|
|
|
+ return serNum;
|
|
|
|
+ }
|
|
|
|
+ return "";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional(readOnly = false,propagation = Propagation.REQUIRES_NEW)
|
|
|
|
+ public String genSerialReviewNum(String companyId, String bizCode) throws Exception {
|
|
|
|
+ //获取当前登录人信息
|
|
|
|
+ UserDTO dto = UserUtils.getCurrentUserDTO();
|
|
|
|
+ Office office = officeMapper.selectById(companyId);
|
|
|
|
+ if (StringUtils.isBlank(bizCode)){
|
|
|
|
+ throw new Exception("生成编号失败,业务类型不能为空");
|
|
|
|
+ }
|
|
|
|
+ if (office != null) {
|
|
|
|
+ SysSerialnumTpl numTpl = this.querySerialTpl(office, bizCode);
|
|
|
|
+ if (numTpl == null) {
|
|
|
|
+ //查询编号模板 {brspnm}DZ-{year}-{serialNum}
|
|
|
|
+ SysSerialnumTpl serialNumTpl = serialnumTplMapper.queryByComAndBizCode(companyId, bizCode);
|
|
|
|
+ serialNumTpl.setCompanyId(companyId);
|
|
|
|
+ serialNumTpl.setSerialNum(0);
|
|
|
|
+ serialNumTpl.setCreateById(dto.getId());
|
|
|
|
+ serialNumTpl.setId(UUID.randomUUID().toString().replace("-", ""));
|
|
|
|
+ serialnumTplMapper.insert(serialNumTpl);
|
|
|
|
+ numTpl = serialNumTpl;
|
|
|
|
+ }
|
|
|
|
+ if (numTpl == null) {
|
|
|
|
+ throw new Exception("生成编号失败,请先设置相关业务编号模板");
|
|
|
|
+ }
|
|
|
|
+ String year = DateUtils.formatDate(new Date(), "yyyy");
|
|
|
|
+ if (!year.equals(numTpl.getYearBuilt())) {
|
|
|
|
+ serialnumTplMapper.resetSerialNum(numTpl.getId(), numTpl.getYearBuilt(), year);
|
|
|
|
+ }
|
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
|
+ String serialTpl = numTpl.getSerialTpl();
|
|
|
|
+ int i = serialnumTplMapper.updateSerialNum(numTpl);
|
|
|
|
+ if (i != 1) {
|
|
|
|
+ throw new Exception("生成编号失败,请稍后重试");
|
|
|
|
+ }
|
|
|
|
+ String num = String.valueOf(numTpl.getSerialNum() + 1);
|
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
|
+// for (int x = 0; x < (numTpl.getSerialNumLen() - num.length()); x++) {
|
|
|
|
+// sb.append("0");
|
|
|
|
+// }
|
|
|
|
+ sb.append(num);
|
|
|
|
+ //查询公司简称
|
|
|
|
+ if (serialTpl.contains("spnm")) {
|
|
|
|
+ String companyShortname = UserUtils.getSysParam("company_shortname");
|
|
|
|
+ map.put("spnm", StringUtils.isBlank(companyShortname) ? "" : companyShortname);
|
|
|
|
+ }
|
|
|
|
+ //查询分公司简称
|
|
|
|
+ if (serialTpl.contains("brspnm")) {
|
|
|
|
+ String branchShortname = UserUtils.getSysParam("branch_shortname");
|
|
|
|
+ map.put("brspnm", StringUtils.isBlank(branchShortname) ? "" : branchShortname);
|
|
|
|
+ }
|
|
|
|
+ //年份
|
|
|
|
+ if (serialTpl.contains("year")) {
|
|
|
|
+ map.put("year", year);
|
|
|
|
+ }
|
|
|
|
+ //月份
|
|
|
|
+ if (serialTpl.contains("month")) {
|
|
|
|
+ int month = new Date().getMonth() + 1;
|
|
|
|
+ map.put("month", month + "");
|
|
|
|
+ }
|
|
|
|
+ //序列号
|
|
|
|
+ if (serialTpl.contains("serialNum")) {
|
|
|
|
+ map.put("serialNum", sb.toString());
|
|
|
|
+ }
|
|
|
|
+ //日期
|
|
|
|
+ if (serialTpl.contains("day")) {
|
|
|
|
+ map.put("day", new Date().getDate() + "");
|
|
|
|
+ }
|
|
|
|
+ String serNum = renderString(serialTpl, map);
|
|
|
|
+ return serNum;
|
|
|
|
+ }
|
|
|
|
+ return "";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private SysSerialnumTpl querySerialTpl(Office company, String bizCode) {
|
|
|
|
+ SysSerialnumTpl numTpl = serialnumTplMapper.queryByComAndBizCode(company.getId(), bizCode);
|
|
|
|
+ if (numTpl==null && company.getParentId()!=null && !"0".equals(company.getParentId())){
|
|
|
|
+ Office office = officeMapper.selectById(company.getParentId());
|
|
|
|
+ numTpl = this.querySerialTpl(office,bizCode);
|
|
|
|
+ }
|
|
|
|
+ return numTpl;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据键值对填充字符串,如("hello {name}",{name:"xiaoming"})
|
|
|
|
+ * 输出:
|
|
|
|
+ * @param content
|
|
|
|
+ * @param map
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static String renderString(String content, Map<String, String> map){
|
|
|
|
+ Set<Map.Entry<String, String>> sets = map.entrySet();
|
|
|
|
+ for(Map.Entry<String, String> entry : sets) {
|
|
|
|
+ String regex = "\\{" + entry.getKey() + "\\}";
|
|
|
|
+ Pattern pattern = Pattern.compile(regex);
|
|
|
|
+ Matcher matcher = pattern.matcher(content);
|
|
|
|
+ content = matcher.replaceAll(entry.getValue());
|
|
|
|
+ }
|
|
|
|
+ return content;
|
|
|
|
+ }
|
|
|
|
+}
|