liriming
2024-09-23 5c60072c51928a5c8a0732191b1df17a88c68b99
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/SequenceNumServiceImpl.java
@@ -5,25 +5,29 @@
import com.iailab.module.model.mcs.pre.dao.SequenceNumDao;
import com.iailab.module.model.mcs.pre.entity.SequenceNumEntity;
import com.iailab.module.model.mcs.pre.service.SequenceNumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * @author PanZhibao
 * @date 2021年05月06日 13:20
 */
@Service("sequenceNumService")
@Service
public class SequenceNumServiceImpl extends ServiceImpl<SequenceNumDao, SequenceNumEntity> implements SequenceNumService {
    @Autowired
    private SequenceNumDao sequenceNumDao;
    @Override
    public synchronized SequenceNumEntity getAndIncreaseByCode (String code) {
        QueryWrapper queryWrapper = new QueryWrapper<SequenceNumEntity>();
        queryWrapper.eq("code", code);
        SequenceNumEntity sequenceNumEntity =  this.getOne(queryWrapper);
        SequenceNumEntity sequenceNumEntity =  sequenceNumDao.selectOne(queryWrapper);
        SequenceNumEntity sequenceNumUpdate = new SequenceNumEntity();
        sequenceNumUpdate.setId(sequenceNumEntity.getId());
        sequenceNumUpdate.setSequenceNum(sequenceNumEntity.getSequenceNum() + 1);
        this.updateById(sequenceNumUpdate);
        sequenceNumDao.updateById(sequenceNumUpdate);
        return sequenceNumEntity;
    }
}