Browse Source

シーケンス做成

zdsong 2 weeks ago
parent
commit
2341e28362

+ 52 - 0
farm-common/src/main/java/jp/yamoto/farm/common/core/domain/entity/RangedSeq.java

@@ -0,0 +1,52 @@
+package jp.yamoto.farm.common.core.domain.entity;
+
+import lombok.Data;
+
+/**
+ * シーケンス ranged_seq
+ *
+ * @author nextosd
+ */
+@Data
+public class RangedSeq {
+
+    /**
+     * Id
+     */
+    private String id;
+
+    /**
+     * キー1
+     */
+    private String key1;
+
+    /**
+     * 値1
+     */
+    private String value1;
+
+    /**
+     * キー2
+     */
+    private String key2;
+
+    /**
+     * 値2
+     */
+    private String value2;
+
+
+    /**
+     * キー3
+     */
+    private String key3;
+
+    /**
+     * 値3
+     */
+    private String value3;
+
+    private Integer seq;
+
+
+}

+ 37 - 0
farm-common/src/main/java/jp/yamoto/farm/common/core/service/IRangedSeqService.java

@@ -0,0 +1,37 @@
+package jp.yamoto.farm.common.core.service;
+
+/**
+ * シーケンス状況情報サービス層処理
+ *
+ * @author nextosd
+ */
+public interface IRangedSeqService {
+
+    /**
+     * 顧客シリアル
+     */
+    public static final String SERIAL_TYPE_CUSTOMER = "customer";
+    /**
+     * 顧客シリアルキー1
+     */
+    public static final String SERIAL_PREFIX_CUSTOMER = "C";
+
+    /**
+     * RangedSeqを見つけてシーケンスを上げて返します
+     * @param key1 キー1
+     * @param value1 値1
+     * @param key2 キー2
+     * @param value2 値2
+     * @param key3 キー3
+     * @param value3 値3
+     * @return シーケンス
+     */
+    public Integer increaseSequence(String key1, String value1, String key2, String value2, String key3, String value3);
+
+    /**
+     * シリアル取得済
+     * @param serialType シリアルタイプ
+     * @return シリアル
+     */
+    public String generateSerialNo(String serialType);
+}

+ 88 - 0
farm-common/src/main/java/jp/yamoto/farm/common/core/service/impl/RangedSeqServiceImpl.java

@@ -0,0 +1,88 @@
+package jp.yamoto.farm.common.core.service.impl;
+
+import jp.yamoto.farm.common.core.domain.entity.RangedSeq;
+import jp.yamoto.farm.common.core.service.IRangedSeqService;
+import jp.yamoto.farm.common.exception.ServiceException;
+import jp.yamoto.farm.common.mapper.RangedSeqMapper;
+import jp.yamoto.farm.common.utils.StringUtils;
+import jp.yamoto.farm.common.utils.ValueUtils;
+import jp.yamoto.farm.common.utils.uuid.IdUtils;
+import org.apache.logging.log4j.LogManager;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * シーケンス状況情報サービス層処理
+ *
+ * @author nextosd
+ */
+@Service
+public class RangedSeqServiceImpl implements IRangedSeqService {
+
+    @Autowired
+    private RangedSeqMapper rangedSeqMapper;
+
+    /**
+     * シリアル取得済
+     * @param serialType シリアルタイプ
+     * @return シリアル
+     */
+    @Override
+    public String generateSerialNo(String serialType) {
+        Integer seq = 0;
+        String result = "";
+        if(ValueUtils.isEqual(SERIAL_TYPE_CUSTOMER, serialType)) {
+            seq = this.increaseSequence(SERIAL_PREFIX_CUSTOMER,SERIAL_PREFIX_CUSTOMER,SERIAL_TYPE_CUSTOMER,SERIAL_TYPE_CUSTOMER,null,null);
+            String serialNo = StringUtils.leftPad(String.valueOf(seq), 5, '0');
+            result = SERIAL_PREFIX_CUSTOMER + serialNo;
+        }
+
+        return result;
+    }
+
+    /**
+     * RangedSeqを見つけてシーケンスを上げて返します
+     * @param key1 キー1
+     * @param value1 値1
+     * @param key2 キー2
+     * @param value2 値2
+     * @param key3 キー3
+     * @param value3 値3
+     * @return シーケンス
+     */
+    @Override
+    public  Integer increaseSequence( String key1, String value1, String key2, String value2, String key3, String value3) {
+        RangedSeq condition = new RangedSeq();
+        condition.setKey1(key1);
+        condition.setValue1(value1);
+        condition.setKey2(key2);
+        condition.setValue2(value2);
+        condition.setKey3(key3);
+        condition.setValue3(value3);
+        return this.increaseSequence(condition);
+    }
+
+    /**
+     * RangedSeqを見つけてシーケンスを上げて返します
+     *
+     * @param condition シーケンス
+     * @return シーケンス結果
+     */
+    private  Integer increaseSequence(RangedSeq condition) {
+
+        RangedSeq rs = rangedSeqMapper.selectRangedSeq(condition);
+
+        if(rs == null) {
+            rs = condition;
+            rs.setId(IdUtils.nextIdStr());
+            rs.setSeq(1);
+            rangedSeqMapper.insert(rs);
+        } else {
+            rs.setSeq(rs.getSeq() + 1);
+            rangedSeqMapper.update(rs);
+        }
+
+        return rs.getSeq();
+    }
+
+}

+ 34 - 0
farm-common/src/main/java/jp/yamoto/farm/common/mapper/RangedSeqMapper.java

@@ -0,0 +1,34 @@
+package jp.yamoto.farm.common.mapper;
+
+import jp.yamoto.farm.common.core.domain.entity.RangedSeq;
+
+/**
+ * シリアルナンバー状況情報
+ *
+ * @author nextosd
+ */
+public interface RangedSeqMapper
+{
+    /**
+     * シリアルナンバー追加
+     *
+     * @param rangeSeq ログ・オブジェクトへのアクセス
+     */
+    public void insert(RangedSeq rangeSeq);
+
+    /**
+     * シリアルナンバー更新
+     *
+     * @param rangeSeq ログ・オブジェクトへのアクセス
+     */
+    public void update(RangedSeq rangeSeq);
+
+    /**
+     * シリアルナンバーを検索リスト
+     *
+     * @param rangeSeq ID List
+     * @return シリアルナンバー
+     */
+    public RangedSeq selectRangedSeq(RangedSeq rangeSeq);
+
+}

+ 70 - 0
farm-common/src/main/resources/mapper/common/RangedSeqMapper.xml

@@ -0,0 +1,70 @@
+<?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="jp.yamoto.farm.common.mapper.RangedSeqMapper">
+
+    <resultMap type="RangedSeq" id="RangedSeqResult">
+        <id property="id" column="id"/>
+        <result property="key1" column="title"/>
+        <result property="value1" column="value1"/>
+        <result property="key2" column="key2"/>
+        <result property="value2" column="value2"/>
+        <result property="key3" column="key3"/>
+        <result property="value3" column="value3"/>
+        <result property="seq" column="seq"/>
+        <result property="costTime" column="cost_time"/>
+    </resultMap>
+
+	<sql id="selectSeq">
+        select id,key1,value1,key2,value2,key3,value3,seq
+        from ranged_seq
+
+    </sql>
+
+    <select id="selectRangedSeq" parameterType="RangedSeq"  resultMap="RangedSeqResult">
+        <include refid="selectSeq"/>
+        <where>
+            <if test="id != null  and id != ''">
+                and id = #{id}
+            </if>
+            <if test="key1 != null  and key1 != ''">
+                and key1 = #{key1}
+            </if>
+            <if test="value1 != null  and value1 != ''">
+                and value1 = #{value1}
+            </if>
+            <if test="key2 != null  and key2 != ''">
+                and key2 = #{key2}
+            </if>
+            <if test="value2 != null  and value2 != ''">
+                and value2 = #{value2}
+            </if>
+            <if test="key3 != null  and key3 != ''">
+                and key3 = #{key3}
+            </if>
+            <if test="value3 != null  and value3 != ''">
+                and value3 = #{value3}
+            </if>
+
+        </where>
+    </select>
+    
+	<insert id="insert" parameterType="RangedSeq">
+		insert into ranged_seq(id, key1, value1, key2, value2, key3, value3,seq,update_time)
+        values (#{id}, #{key1}, #{value1}, #{key2}, #{value2}, #{key3}, #{value3}, #{seq}, now())
+	</insert>
+
+    <update id="update" parameterType="RangedSeq">
+        update ranged_seq
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="seq != null">
+                seq = #{seq},
+            </if>
+
+        </trim>
+        where
+        id = #{id}
+    </update>
+
+</mapper>