From a81b9fc7dc055874d501becd1862b4ff581c0d4a Mon Sep 17 00:00:00 2001
From: cuijian <cuijian@xalxzn.com>
Date: 星期二, 29 八月 2023 13:12:06 +0800
Subject: [PATCH] 编码规则

---
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/entity/SerialNumberMap.java                  |   43 ++++
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/IdentityService.java                 |   16 +
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/SerialNumberMapController.java    |   88 +++++++++
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/IdentityController.java           |   27 +++
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/SerialNumberMapServiceImpl.java |  127 ++++++++++++++
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/SerialNumberMapService.java          |   16 +
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/mapper/SerialNumberMapMapper.java            |   25 ++
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/mapper/xml/SerialNumberMapMapper.xml         |    8 
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/entity/Identity.java                         |   34 +++
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/IdentityServiceImpl.java        |   81 +++++++++
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/mapper/IdentityMapper.java                   |   27 +++
 11 files changed, 492 insertions(+), 0 deletions(-)

diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/IdentityController.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/IdentityController.java
new file mode 100644
index 0000000..173f8de
--- /dev/null
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/IdentityController.java
@@ -0,0 +1,27 @@
+package org.jeecg.modules.eam.controller;
+
+import io.swagger.annotations.Api;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.modules.eam.service.IdentityService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/eam/sysIdentity")
+@Api(value = "鍗曞彿鐢熸垚鍣� 鍓嶇鎺у埗鍣�")
+public class IdentityController {
+  @Autowired
+  @Lazy
+  private IdentityService sysIdentityService;
+  // 鏂板
+  @GetMapping("/getNumNew")
+  public Result<?> getNum(@RequestParam(name="type",required = true)String type,
+                          @RequestParam(name="length",defaultValue = "4")Integer length) {
+    String serialNum = sysIdentityService.getNumByTypeAndLength(type, length);
+    return Result.ok(serialNum);
+  }
+}
diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/SerialNumberMapController.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/SerialNumberMapController.java
new file mode 100644
index 0000000..81c4e29
--- /dev/null
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/SerialNumberMapController.java
@@ -0,0 +1,88 @@
+package org.jeecg.modules.eam.controller;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import io.swagger.annotations.Api;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.base.controller.JeecgController;
+import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.modules.eam.entity.SerialNumberMap;
+import org.jeecg.modules.eam.service.SerialNumberMapService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Arrays;
+
+@RestController
+@RequestMapping("/eam/serialNumber")
+@Api(value = "鍗曞彿瑙勫垯鏄犲皠鍏崇郴 鍓嶇鎺у埗鍣�")
+public class SerialNumberMapController extends JeecgController<SerialNumberMap, SerialNumberMapService> {
+
+    @Autowired
+    @Lazy
+    private SerialNumberMapService serialNumberMapService;
+
+    @GetMapping(value = "/list")
+    public Result<?> list(SerialNumberMap serialNumberMap,
+                          @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+                          @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
+        QueryWrapper<SerialNumberMap> queryWrapper = QueryGenerator.initQueryWrapper(serialNumberMap, req.getParameterMap());
+        Page<SerialNumberMap> page = new Page<SerialNumberMap>(pageNo, pageSize);
+        IPage<SerialNumberMap> pageList = serialNumberMapService.page(page, queryWrapper);
+        return Result.ok(pageList);
+    }
+
+    // 鏂板
+    @PostMapping("/add")
+    public Result<?> add (@RequestBody SerialNumberMap snm){
+        snm.setYearFormat("yy");
+        snm.setMonthFormat("MM");
+        snm.setDayFormat("dd");
+        serialNumberMapService.save(snm);
+        return Result.ok();
+    }
+
+    @PutMapping(value = "/edit")
+    public Result<?> edit(@RequestBody SerialNumberMap snm) {
+        serialNumberMapService.updateById(snm);
+        return Result.ok("鏇存柊鎴愬姛锛�");
+    }
+
+    // 鍒犻櫎
+    @DeleteMapping("/delete")
+    public Result<?> delete (@RequestParam(name="id",required = true) String id){
+        serialNumberMapService.removeById(id);
+        return Result.ok("鍒犻櫎鎴愬姛");
+    }
+
+    @DeleteMapping(value = "/deleteBatch")
+    public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
+        serialNumberMapService.removeByIds(Arrays.asList(ids.split(",")));
+        return Result.ok("鎵归噺鍒犻櫎鎴愬姛锛�");
+    }
+
+    /**
+     * 閫氳繃绫诲瀷鑾峰彇瀹屾暣缂栧彿 銆愯捣濮嬪浐瀹氬瓧绗�+浼佷笟浠g爜(5)+骞�(2)+鏈�(2)+鏃�(2)+娴佹按鍙�(4)銆�
+     * @param type 绫诲瀷
+     * @return Result
+     */
+    @GetMapping("/getSerialNumber")
+    public Result<?> getSerialNumber(@RequestParam(name="type",required = true) String type){
+        Result purchaseRequest = serialNumberMapService.getSerialNumber(type);
+        return purchaseRequest;
+    }
+
+    /**
+     * 閫氳繃绫诲瀷鑾峰彇缂栧彿鍓嶇紑銆愯捣濮嬪浐瀹氬瓧绗�+浼佷笟浠g爜(5)+骞�(2)+鏈�(2)+鏃�(2)銆�
+     * @param type 绫诲瀷
+     * @return Result
+     */
+    @GetMapping("/getSerial")
+    public Result<?> getSerial(@RequestParam(name="type",required = true) String type){
+        Result purchaseRequest = serialNumberMapService.getSerial(type);
+        return purchaseRequest;
+    }
+}
diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/entity/Identity.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/entity/Identity.java
new file mode 100644
index 0000000..42d6fb1
--- /dev/null
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/entity/Identity.java
@@ -0,0 +1,34 @@
+package org.jeecg.modules.eam.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.jeecg.common.system.base.entity.JeecgEntity;
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@TableName("mom_sys_identity")
+@ApiModel(value = "鍗曟嵁娴佹按鍙风敓鎴愯〃")
+public class Identity extends JeecgEntity {
+
+	// private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "娴佹按鍙�")
+    private int num;
+
+    @ApiModelProperty(value = "鏈堜唤")
+    private String monthValue;
+
+    @ApiModelProperty(value = "骞翠唤")
+    private String yearValue;
+
+    @ApiModelProperty(value = "涓氬姟绫诲瀷")
+    private String type;
+
+    @ApiModelProperty(value = "涓氬姟绫诲瀷璇存槑")
+    private String remark;
+}
diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/entity/SerialNumberMap.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/entity/SerialNumberMap.java
new file mode 100644
index 0000000..7a9bc2a
--- /dev/null
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/entity/SerialNumberMap.java
@@ -0,0 +1,43 @@
+package org.jeecg.modules.eam.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.jeecg.common.system.base.entity.JeecgEntity;
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@TableName("mom_serial_number_map")
+@ApiModel(value = "鍗曞彿瑙勫垯鏄犲皠鍏崇郴")
+public class SerialNumberMap extends JeecgEntity {
+
+	// private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "鍔熻兘鍗曟嵁鍚嶇О")
+    private String functionName;
+
+    @ApiModelProperty(value = "璧峰鍥哄畾瀛楃")
+    private String beginSymbol;
+
+    @ApiModelProperty(value = "浼佷笟浠g爜")
+    private String enterpriseCode;
+
+    @ApiModelProperty(value = "骞�")
+    private String yearFormat;
+
+    @ApiModelProperty(value = "鏈�")
+    private String monthFormat;
+
+    @ApiModelProperty(value = "鏃�")
+    private String dayFormat;
+
+    @ApiModelProperty(value = "鍔熻兘绫诲瀷")
+    private String type;
+
+    @ApiModelProperty(value = "鐢熶骇杩囩▼妫�楠岃〃ID")
+    private String identityId;
+}
diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/mapper/IdentityMapper.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/mapper/IdentityMapper.java
new file mode 100644
index 0000000..e1b2eb5
--- /dev/null
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/mapper/IdentityMapper.java
@@ -0,0 +1,27 @@
+package org.jeecg.modules.eam.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+import org.jeecg.modules.eam.entity.Identity;
+
+public interface IdentityMapper extends BaseMapper<Identity> {
+//    @Select("select id," +
+//            "num," +
+//            "month_value," +
+//            "year_value," +
+//            "type," +
+//            "remark " +
+//            " from mes_sys_identity t1 where t1.type = #{type}")
+//    public MesSysIdentity findIdentityByType(@Param("type")String type);
+
+
+    @Select("select id," +
+            "num," +
+            "month_value," +
+            "year_value," +
+            "type," +
+            "remark " +
+            " from mom_sys_identity t1 where t1.type = #{type} and t1.year_value = #{yearValue} and t1.month_value =#{monthValue}")
+    public Identity findIdentityByType(@Param("type") String type, @Param("yearValue") String yearValue, @Param("monthValue") String monthValue);
+}
diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/mapper/SerialNumberMapMapper.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/mapper/SerialNumberMapMapper.java
new file mode 100644
index 0000000..cadcea6
--- /dev/null
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/mapper/SerialNumberMapMapper.java
@@ -0,0 +1,25 @@
+package org.jeecg.modules.eam.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+import org.jeecg.modules.eam.entity.SerialNumberMap;
+
+public interface SerialNumberMapMapper extends BaseMapper<SerialNumberMap> {
+    @Select("select id," +
+            "function_name," +
+            "begin_symbol," +
+            "enterprise_code," +
+            "year_format," +
+            "month_format," +
+            "day_format," +
+            "type," +
+            "identity_id" +
+            " from mom_serial_number_map t1 where t1.type = #{type}")
+    public SerialNumberMap getByType(@Param("type") String type);
+
+    @Select("<script> select F_GET_SEQ_ID(#{type}) </script>")
+    public String getNum(@Param("type") String type);
+
+    boolean  updateBatchByEnterpriseCode(@Param("enterpriseCode") String enterpriseCode);
+}
diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/mapper/xml/SerialNumberMapMapper.xml b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/mapper/xml/SerialNumberMapMapper.xml
new file mode 100644
index 0000000..01c61aa
--- /dev/null
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/mapper/xml/SerialNumberMapMapper.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.jeecg.modules.eam.mapper.SerialNumberMapMapper">
+
+	<update id="updateBatchByEnterpriseCode">
+		update mom_serial_number_map set enterprise_code = #{enterpriseCode}
+	</update>
+</mapper>
diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/IdentityService.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/IdentityService.java
new file mode 100644
index 0000000..c820be7
--- /dev/null
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/IdentityService.java
@@ -0,0 +1,16 @@
+package org.jeecg.modules.eam.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.modules.eam.entity.Identity;
+
+public interface IdentityService extends IService<Identity> {
+
+    public Identity findIdentityByType(String type);
+
+    /**
+     * 鏍规嵁绫诲瀷鍜岄暱搴﹁幏鍙栨祦姘村彿
+     * @param type
+     * @return
+     */
+    public String getNumByTypeAndLength(String type, Integer length);
+}
diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/SerialNumberMapService.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/SerialNumberMapService.java
new file mode 100644
index 0000000..19ae6bc
--- /dev/null
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/SerialNumberMapService.java
@@ -0,0 +1,16 @@
+package org.jeecg.modules.eam.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.modules.eam.entity.SerialNumberMap;
+
+public interface SerialNumberMapService extends IService<SerialNumberMap> {
+
+    public Result<?> getSerialNumber(String type);
+
+    public Result<?> getSerial(String type);
+
+    public SerialNumberMap getByType(String type);
+
+    boolean  updateBatchByEnterpriseCode(String creditCode);
+}
diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/IdentityServiceImpl.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/IdentityServiceImpl.java
new file mode 100644
index 0000000..b9e338f
--- /dev/null
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/IdentityServiceImpl.java
@@ -0,0 +1,81 @@
+package org.jeecg.modules.eam.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.apache.commons.lang.StringUtils;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.util.DateUtils;
+import org.jeecg.modules.eam.entity.Identity;
+import org.jeecg.modules.eam.entity.SerialNumberMap;
+import org.jeecg.modules.eam.mapper.IdentityMapper;
+import org.jeecg.modules.eam.service.IdentityService;
+import org.jeecg.modules.eam.service.SerialNumberMapService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.text.SimpleDateFormat;
+import java.util.List;
+
+@Service
+public class IdentityServiceImpl extends ServiceImpl<IdentityMapper, Identity>
+    implements IdentityService {
+  @Autowired
+  @Lazy
+  private SerialNumberMapService serialNumberMapService;
+
+  /**
+   * 閫氳繃type鑾峰彇mes_sys_identity琛ㄥ疄渚嬶紝瀹炵幇鏂规硶
+   *
+   * @param type 涓氬姟绫诲瀷
+   * @return MesSysIdentity mes_sys_identity琛ㄥ疄渚嬪璞�
+   */
+  @Override
+  public Identity findIdentityByType(String type) {
+    String yearValue = DateUtils.date2Str(new SimpleDateFormat("yyyy"));
+    String monthValue = DateUtils.date2Str(new SimpleDateFormat("MM"));
+    Identity identityByType = super.getBaseMapper().findIdentityByType(type, yearValue, monthValue);
+    return identityByType;
+  }
+
+  @Override
+  @Transactional(rollbackFor = {Exception.class})
+  public String getNumByTypeAndLength(String type, Integer length) {
+    SerialNumberMap serialNumberMap = serialNumberMapService.getByType(type);
+    Result<?> result = serialNumberMapService.getSerial(type);
+    String prefix = result.getMessage().toString();
+    String identityId = serialNumberMap.getIdentityId();
+    String currentDate = DateUtils.getCurrentDateStr();
+    String yearValue = currentDate.split("-")[0];
+    String monthValue = currentDate.split("-")[1];
+    List<Identity> systemIdentityList =
+            lambdaQuery()
+                    .eq(Identity::getId, identityId)
+                    .eq(Identity::getType, type)
+                    .eq(Identity::getYearValue, yearValue)
+                    .eq(Identity::getMonthValue, monthValue)
+                    .list();
+    Identity mesSysIdentity =
+            systemIdentityList.size() > 0 ? systemIdentityList.get(0) : new Identity();
+    Integer num = 1;
+    if (StringUtils.isBlank(mesSysIdentity.getId())) {
+      mesSysIdentity.setId(identityId);
+      mesSysIdentity.setType(type);
+      mesSysIdentity.setMonthValue(monthValue);
+      mesSysIdentity.setYearValue(yearValue);
+      mesSysIdentity.setNum(num);
+      super.saveOrUpdate(mesSysIdentity);
+
+      serialNumberMap.setIdentityId(mesSysIdentity.getId());
+      serialNumberMapService.updateById(serialNumberMap);
+    } else {
+      num = mesSysIdentity.getNum() + 1;
+      mesSysIdentity.setNum(num);
+      super.saveOrUpdate(mesSysIdentity);
+    }
+    String serialNum = prefix + StringUtils.leftPad(String.valueOf(num), length, "0");
+    return serialNum;
+    }
+
+
+}
diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/SerialNumberMapServiceImpl.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/SerialNumberMapServiceImpl.java
new file mode 100644
index 0000000..8853bba
--- /dev/null
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/SerialNumberMapServiceImpl.java
@@ -0,0 +1,127 @@
+package org.jeecg.modules.eam.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.util.DateUtils;
+import org.jeecg.common.util.StrUtils;
+import org.jeecg.modules.eam.entity.Identity;
+import org.jeecg.modules.eam.entity.SerialNumberMap;
+import org.jeecg.modules.eam.mapper.SerialNumberMapMapper;
+import org.jeecg.modules.eam.service.IdentityService;
+import org.jeecg.modules.eam.service.SerialNumberMapService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.text.SimpleDateFormat;
+
+@Service
+public class SerialNumberMapServiceImpl extends ServiceImpl<SerialNumberMapMapper, SerialNumberMap> implements SerialNumberMapService {
+
+    @Autowired
+    private IdentityService mesSysIdentityService;
+//    @Autowired
+//    private IEnterpriseService enterpriseService;
+
+    /**
+     * 鐢熸垚瀹屾暣鍗曞彿銆愯捣濮嬪浐瀹氬瓧绗�+浼佷笟浠g爜(5)+骞�(2)+鏈�(2)+鏃�(2)+娴佹按鍙�(4)銆�
+     * @param type 涓氬姟绫诲瀷
+     * @return
+     */
+    @Override
+    public Result<?> getSerialNumber(String type) {
+        String serialNumber = "";
+        if(StrUtils.isNotBlankOrNull(type)){
+            // 鑾峰彇鏄犲皠琛ㄥ璞�
+            SerialNumberMap byType = getByType(type);
+            if(byType!=null){
+                // 鍒ゆ柇mes_sys_identity琛ㄦ槸鍚︽湁褰撳墠type
+                boolean b = checkIdentityByType(type);
+                if(b){
+                    // 鍗曞彿鐢熶骇瑙勫垯 璧峰鍥哄畾瀛楃+浼佷笟浠g爜(5)+骞�(2)+鏈�(2)+鏃�(2)+娴佹按鍙�(4)
+                    String num = super.baseMapper.getNum(type);
+                    String substring = num.substring(2, num.length());
+                    serialNumber = byType.getBeginSymbol() +
+                            byType.getEnterpriseCode()+
+                            DateUtils.date2Str(new SimpleDateFormat(byType.getYearFormat()+byType.getMonthFormat()+byType.getDayFormat()))
+                            +substring;
+                }else{
+                    return Result.error("鐢熸垚鍗曞彿澶辫触锛�");
+                }
+            }else{
+                return Result.error("绫诲瀷涓嶅瓨鍦紝璇锋坊鍔犲悗閲嶈瘯锛�");
+            }
+        }else{
+            return Result.error("鍙傛暟閿欒,绫诲瀷涓嶈兘涓虹┖锛�");
+        }
+        return Result.ok(serialNumber);
+    }
+
+    /**
+     * 鐢熸垚鍗曞彿鍓嶇紑 銆愯捣濮嬪浐瀹氬瓧绗�+浼佷笟浠g爜(5)+骞�(2)+鏈�(2)+鏃�(2)銆�
+     * @param type 涓氬姟绫诲瀷
+     * @return
+     */
+    @Override
+    public Result<?> getSerial(String type) {
+        String serialNumber = "";
+//        Enterprise enterprise = enterpriseService.gerCurrentEnterprise();
+//       String  enterpriseCode =  enterprise.getCode().substring(0,5);
+        if(StrUtils.isNotBlankOrNull(type)){
+            // 鑾峰彇鏄犲皠琛ㄥ璞�
+            SerialNumberMap byType = getByType(type);
+            if(byType!=null){
+                // 鍒ゆ柇mes_sys_identity琛ㄦ槸鍚︽湁褰撳墠type
+//                boolean b = checkIdentityByType(type);
+//                if(b){
+                    // 鍗曞彿鐢熶骇瑙勫垯 璧峰鍥哄畾瀛楃+浼佷笟浠g爜(5)+骞�(2)+鏈�(2)+鏃�(2)+娴佹按鍙�(4)
+                serialNumber = byType.getBeginSymbol()  +
+                        DateUtils.date2Str(new SimpleDateFormat(byType.getYearFormat()+byType.getMonthFormat()));
+//                    serialNumber = byType.getBeginSymbol()  + enterpriseCode +
+//                            DateUtils.date2Str(new SimpleDateFormat(byType.getYearFormat()+byType.getMonthFormat()+byType.getDayFormat()));
+//                }else {
+//                    return Result.error("鐢熸垚鍗曞彿鍓嶇紑澶辫触锛�");
+//                }
+            }else{
+                return Result.error("绫诲瀷涓嶅瓨鍦紝璇锋坊鍔犲悗閲嶈瘯锛�");
+            }
+        }else{
+            return Result.error("鍙傛暟閿欒,绫诲瀷涓嶈兘涓虹┖锛�");
+        }
+        return Result.ok(serialNumber);
+    }
+
+    @Override
+    public SerialNumberMap getByType(String type) {
+        SerialNumberMap byType = super.getBaseMapper().getByType(type);
+        return byType;
+    }
+
+    @Override
+    public boolean updateBatchByEnterpriseCode(String enterpriseCode) {
+        return  super.baseMapper.updateBatchByEnterpriseCode(enterpriseCode);
+    }
+
+    /**
+     * 鍒ゆ柇mes_sys_identity琛ㄦ槸鍚︽湁褰撳墠type,濡傛灉娌℃湁鏂板涓�鏉�
+     * @param type 涓氬姟绫诲瀷
+     * @return
+     */
+    public boolean checkIdentityByType(String type){
+        boolean b = false;
+        // 閫氳繃type鑾峰彇mes_sys_identity琛ㄥ疄渚�
+        Identity identityByType = mesSysIdentityService.findIdentityByType(type);
+        if(identityByType!=null){
+            b = true;
+        }else{
+            Identity mesSysIdentity = new Identity();
+            mesSysIdentity.setType(type);
+            mesSysIdentity.setMonthValue(DateUtils.date2Str(new SimpleDateFormat("MM")));
+            mesSysIdentity.setYearValue(DateUtils.date2Str(new SimpleDateFormat("yyyy")));
+            mesSysIdentity.setNum(0);
+            mesSysIdentity.setRemark("鑷姩娣诲姞");
+            boolean save = mesSysIdentityService.save(mesSysIdentity);
+            b = save;
+        }
+        return b;
+    }
+}

--
Gitblit v1.9.3