Houjie
2025-06-30 c34fc83655b146b40802e1fce22db37b7367c83d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package org.jeecg.modules.system.service.impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.system.entity.SysIdentity;
import org.jeecg.modules.system.mapper.SysIdentityMapper;
import org.jeecg.modules.system.service.SysIdentityService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.text.SimpleDateFormat;
import java.util.List;
 
@Service
public class SysIdentityServiceImpl extends ServiceImpl<SysIdentityMapper, SysIdentity>
    implements SysIdentityService {
  /*@Autowired
  @Lazy
  private SerialNumberMapService serialNumberMapService;*/
 
  /**
   * 通过type获取mom_sys_identity表实例,实现方法
   *
   * @param type 业务类型
   * @return SysIdentity mom_sys_identity表实例对象
   */
  @Override
  public SysIdentity findIdentityByType(String type) {
    String yearValue = DateUtils.date2Str(new SimpleDateFormat("yyyy"));
    String monthValue = DateUtils.date2Str(new SimpleDateFormat("MM"));
    SysIdentity identityByType = super.getBaseMapper().findIdentityByType(type, yearValue, monthValue);
    return identityByType;
  }
 
  @Override
  @Transactional(rollbackFor = {Exception.class})
  public String getNumByTypeAndLength(String type, Integer length) {
    String currentDate = DateUtils.getCurrentDateStr();
    String yearValue = currentDate.split("-")[0];
    String monthValue = currentDate.split("-")[1];
    List<SysIdentity> systemIdentityList =
            lambdaQuery()
                    .eq(SysIdentity::getType, type)
                    .eq(SysIdentity::getYearValue, yearValue)
                    .eq(SysIdentity::getMonthValue, monthValue)
                    .list();
    SysIdentity mesSysIdentity =
            systemIdentityList.size() > 0 ? systemIdentityList.get(0) : new SysIdentity();
    Integer num = 1;
    if (StringUtils.isBlank(mesSysIdentity.getId())) {
      mesSysIdentity.setType(type);
      mesSysIdentity.setMonthValue(monthValue);
      mesSysIdentity.setYearValue(yearValue);
      mesSysIdentity.setNum(num);
      super.saveOrUpdate(mesSysIdentity);
    } else {
      num = mesSysIdentity.getNum() + 1;
      mesSysIdentity.setNum(num);
      super.saveOrUpdate(mesSysIdentity);
    }
    String serialNum = StringUtils.leftPad(String.valueOf(num), length, "0");
    return serialNum;
    }
 
 
}