8 changed files with 258 additions and 45 deletions
-
11src/main/java/com/spring/modules/quotation/entity/QuotationInformationEntity.java
-
58src/main/java/com/spring/modules/quotation/entity/SeqRule.java
-
9src/main/java/com/spring/modules/quotation/mapper/SeqRuleMapper.java
-
14src/main/java/com/spring/modules/quotation/service/SeqRuleService.java
-
110src/main/java/com/spring/modules/quotation/service/impl/QuotationHeaderServerImpl.java
-
31src/main/java/com/spring/modules/quotation/service/impl/QuotationInformationServiceImpl.java
-
52src/main/java/com/spring/modules/quotation/service/impl/SeqRuleServiceImpl.java
-
18src/main/resources/mapper/quotation/QuotationInformationMapper.xml
@ -0,0 +1,58 @@ |
|||||
|
package com.spring.modules.quotation.entity; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
|
||||
|
@Data |
||||
|
@TableName("seq_rule") |
||||
|
public class SeqRule { |
||||
|
|
||||
|
@TableId(value = "id", type = IdType.AUTO) |
||||
|
private Long id; |
||||
|
private String type; |
||||
|
private String name; |
||||
|
private String prefix; |
||||
|
private Integer length; |
||||
|
private Long currentVal; |
||||
|
private Date createDate; |
||||
|
private String createBy; |
||||
|
private Date updateDate; |
||||
|
private String updateBy; |
||||
|
private String site; |
||||
|
|
||||
|
public SeqRule(){} |
||||
|
|
||||
|
/** |
||||
|
* 构造函数 |
||||
|
* @param site 工厂编号 |
||||
|
* @param type 类型 XJ/BJ... |
||||
|
* @param name 中文类型描述 |
||||
|
* @param prefix 前缀 |
||||
|
* @param length 序列长度 |
||||
|
*/ |
||||
|
public SeqRule(String site,String type,String name,String prefix,Integer length){ |
||||
|
this.site= site; |
||||
|
this.type = type; |
||||
|
this.name = name; |
||||
|
this.prefix = prefix; |
||||
|
this.length = length; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 构造函数 |
||||
|
* @param site 工厂编号 |
||||
|
* @param type 类型 XJ/BJ... |
||||
|
* @param name 中文类型描述 |
||||
|
* @param prefix 前缀 |
||||
|
* @param length 序列长度 |
||||
|
* @param currentVal 序列初始值 |
||||
|
*/ |
||||
|
public SeqRule(String site,String type,String name,String prefix,Integer length,Long currentVal){ |
||||
|
this(site,type,name,prefix,length); |
||||
|
this.currentVal = currentVal; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
package com.spring.modules.quotation.mapper; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.spring.modules.quotation.entity.SeqRule; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
|
||||
|
@Mapper |
||||
|
public interface SeqRuleMapper extends BaseMapper<SeqRule> { |
||||
|
} |
||||
@ -0,0 +1,14 @@ |
|||||
|
package com.spring.modules.quotation.service; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
import com.spring.modules.quotation.entity.SeqRule; |
||||
|
|
||||
|
public interface SeqRuleService extends IService<SeqRule> { |
||||
|
/** |
||||
|
* 获取序列号 |
||||
|
* @param type 类型 |
||||
|
* @param prefix 前缀 |
||||
|
* @return |
||||
|
*/ |
||||
|
String getSeqNo(String site,String type,String prefix); |
||||
|
} |
||||
@ -0,0 +1,52 @@ |
|||||
|
package com.spring.modules.quotation.service.impl; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
|
import com.spring.modules.quotation.entity.SeqRule; |
||||
|
import com.spring.modules.quotation.mapper.SeqRuleMapper; |
||||
|
import com.spring.modules.quotation.service.SeqRuleService; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.apache.commons.lang3.StringUtils; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
|
||||
|
@Service |
||||
|
@Slf4j |
||||
|
public class SeqRuleServiceImpl extends ServiceImpl<SeqRuleMapper, SeqRule> implements SeqRuleService { |
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
@Transactional |
||||
|
public String getSeqNo(String site,String type, String prefix) { |
||||
|
SeqRule seqRule = lambdaQuery().eq(SeqRule::getSite,site).eq(SeqRule::getType, type).eq(SeqRule::getPrefix, prefix).one(); |
||||
|
String seqNo = seqRuleValue(seqRule); |
||||
|
//生成完成直接递增 |
||||
|
seqRule.setCurrentVal(seqRule.getCurrentVal()+1); |
||||
|
if (!updateById(seqRule)) { |
||||
|
throw new RuntimeException("序列号修改失败!"); |
||||
|
} |
||||
|
return seqNo; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 通过序列号规则获取序列号 |
||||
|
* @param seqRule 序列号规则 |
||||
|
* @return |
||||
|
*/ |
||||
|
public String seqRuleValue(SeqRule seqRule){ |
||||
|
if (seqRule == null){ |
||||
|
throw new RuntimeException("序列号规则未定义"); |
||||
|
} |
||||
|
String prefix = seqRule.getPrefix(); |
||||
|
return prefix+"-"+getSeqNumber(seqRule.getCurrentVal(),seqRule.getLength()); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 返回组装的序列 |
||||
|
* @param currentVal 当前序列值 |
||||
|
* @param length 序列长度 |
||||
|
* @return |
||||
|
*/ |
||||
|
public String getSeqNumber(Long currentVal,Integer length){ |
||||
|
return StringUtils.leftPad(currentVal.toString(),length,"0"); |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue