Quellcode durchsuchen

20220907
系统管理-编号模板管理

sunruiqi vor 2 Jahren
Ursprung
Commit
96fd6fc516

+ 1 - 1
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/mould/mapper/xml/TemplateMapper.xml

@@ -19,7 +19,7 @@
 	<select id="queryByComAndBizCode" resultType="com.jeeplus.test.mould.domain.SysSerialnumTpl">
 		select	a.*
 		 from sys_serialnum_tpl a
-			where a.company_id = #{companyId} and a.biz_code = #{bizCode}
+			where a.company_id = #{id} and a.biz_code = #{bizCode}
 	</select>
 
 	<update id="resetSerialNum">

+ 31 - 15
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/mould/service/SerialnumTplService.java

@@ -16,6 +16,8 @@ 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.Date;
 import java.util.HashMap;
 import java.util.Map;
@@ -71,20 +73,12 @@ public class SerialnumTplService {
 
     @Transactional(readOnly = false,propagation = Propagation.REQUIRES_NEW)
     public String genSerialNumNotNum(String companyId, String bizCode) throws Exception {
-//        String branchOffice = UserUtils.getSelectOffice().getBranchOffice();
-//        if(StringUtils.isNotBlank(branchOffice)){
-//            company = officeService.get(branchOffice);
-//        }
-//        if (company==null||StringUtils.isBlank(company.getId())){
-//            throw new Exception("生成编号失败,公司信息不能为空");
-//        }
         //获取当前登录人信息
         UserDTO dto = UserUtils.getCurrentUserDTO();
         Office office = officeMapper.selectById(companyId);
         if (StringUtils.isBlank(bizCode)){
             throw new Exception("生成编号失败,业务类型不能为空");
         }
-
         SysSerialnumTpl numTpl = this.querySerialTpl(office, bizCode);
         if (numTpl==null){
             //查询编号模板   {brspnm}DZ-{year}-{serialNum}
@@ -99,8 +93,6 @@ public class SerialnumTplService {
         if (numTpl==null){
             throw new Exception("生成编号失败,请先设置相关业务编号模板");
         }
-        if ("0".equals(office.getParentId()))
-            office.setParentId(null);
         String year = DateUtils.formatDate(new Date(), "yyyy");
         if(!year.equals(numTpl.getYearBuilt())){
             serialnumTplMapper.resetSerialNum(numTpl.getId(),numTpl.getYearBuilt(),year);
@@ -111,11 +103,35 @@ public class SerialnumTplService {
         if (i!=1){
             throw new Exception("生成编号失败,请稍后重试");
         }
-        String companyShortname = UserUtils.getSysParam("company_shortname", dto.getCompanyDTO().getId());
-        map.put("spnm",StringUtils.isBlank(companyShortname)?"":companyShortname);
-        String branchShortname = UserUtils.getSysParam("branch_shortname", dto.getCompanyDTO().getId());
-        map.put("brspnm", StringUtils.isBlank(branchShortname)?"":branchShortname);
-        map.put("year",year);
+        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());
+        }
         String serNum = StringUtils.renderString(serialTpl, map);
         return serNum;
     }

+ 24 - 26
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/utils/UserUtils.java

@@ -20,6 +20,7 @@ import com.jeeplus.sys.service.UserService;
 import com.jeeplus.sys.service.dto.*;
 import com.jeeplus.sys.service.mapstruct.MenuWrapper;
 
+import javax.validation.constraints.NotNull;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -31,7 +32,7 @@ import java.util.Set;
  */
 public class UserUtils {
 
-	private static OfficeMapper officeMapper;
+	private static OfficeMapper officeMapper = SpringContextHolder.getBean(OfficeMapper.class);
 
 	/**
 	 * 根据ID获取用户
@@ -170,34 +171,31 @@ public class UserUtils {
 	 * branchOffice 分公司Id 分公司id为空传公司id
 	 * @return
 	 */
-	public static String getSysParam(String parameter,String companyId) {
-		Office office = officeMapper.selectById(companyId);
-		SysParameter SysParameter = officeMapper.findIsforce(parameter);
-		if(office!=null&&SysParameter!=null&&"1".equals(SysParameter.getIsForce())){//公司必须自己定义参数
-			if (!"0".equals(office.getParentId()) && "1".equals(office.getType())) {//分公司的人
-				SysParameterValue sysParameterValue = officeMapper.findValueByParameter(parameter, office.getId());
-				if (sysParameterValue != null) {
-					return sysParameterValue.getValue();
-				}else{
-					return "";
-				}
-			}else{
-				SysParameterValue sysComValue = officeMapper.findValueByParameter(parameter, companyId);
-				if (sysComValue != null) {
-					return sysComValue.getValue();
-				} else {
-					return "";
-				}
+	public static String getSysParam(String parameter) {
+		//查询当前登录人公司信息
+		UserDTO userDTO = UserUtils.getCurrentUserDTO();
+		OfficeDTO companyDTO = userDTO.getCompanyDTO();
+		//当前登录人所属公司是子公司
+		if (!"0".equals(companyDTO.getParentId()) && "1".equals(companyDTO.getType())) {
+			//查询子公司简称
+			if ("branch_shortname".equals(parameter)) {
+				SysParameterValue sysParameterValue = officeMapper.findValueByParameter(parameter, companyDTO.getId());
+				return sysParameterValue == null ? "" : sysParameterValue.getValue();
 			}
-		}else{
-			SysParameterValue sysComValue = officeMapper.findValueByParameter(parameter, companyId);
-			if (sysComValue == null) {
-				SysParameterValue sysValue = officeMapper.findSysValue(parameter);
-				return sysValue.getValue();
-			} else {
-				return sysComValue.getValue();
+			//查询公司简称
+			if ("company_shortname".equals(parameter)) {
+				SysParameterValue sysParameterValue = officeMapper.findValueByParameter(parameter, companyDTO.getParentId());
+				return sysParameterValue == null ? "" : sysParameterValue.getValue();
+			}
+		} else {
+			//当前登录人所属公司是总公司
+			//查询公司简称
+			if ("company_shortname".equals(parameter)) {
+				SysParameterValue sysParameterValue = officeMapper.findValueByParameter(parameter, companyDTO.getId());
+				return sysParameterValue == null ? "" : sysParameterValue.getValue();
 			}
 		}
+		return "";
 	}