|
|
@@ -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();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|