package com.zy.crm.manager.service.impl; import com.baomidou.mybatisplus.plugins.Page; import com.core.common.Cools; import com.zy.crm.manager.mapper.CstmrMapper; import com.zy.crm.manager.entity.Cstmr; import com.zy.crm.manager.service.CstmrService; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import org.springframework.stereotype.Service; @Service("cstmrService") public class CstmrServiceImpl extends ServiceImpl implements CstmrService { @Override public Cstmr selectByUuid(Long hostId, String uuid) { return this.baseMapper.selectByUuid(hostId, uuid); } @Override public synchronized String getUuid(Long hostId) { String uuid = null; int times = 0; while (Cools.isEmpty(uuid)) { if (times > 100) { break; } String nextUuid = getNextUuid(hostId); if (selectByUuid(hostId, nextUuid) == null) { uuid = nextUuid; } times ++; } return uuid; } private String getNextUuid(Long hostId) { Cstmr cstmr = this.baseMapper.selectCstmrByNewestUuid(hostId); if (cstmr == null) { return "0001"; } return zerofill(String.valueOf(Integer.parseInt(cstmr.getUuid()) + 1), 4); } @Override public Page getPage(Page page, Long hostId, String deptId, Long userId, String condition) { return page.setRecords(baseMapper.listByPage(page, hostId, deptId, userId, condition)); } @Override public int updateDeptIdByUserId(Long userId, Long deptId) { return this.baseMapper.updateDeptIdByUserId(userId, deptId); } public static String zerofill(String msg, Integer count){ if (msg.length() == count){ return msg; } else if (msg.length() > count){ return msg.substring(0, 16); } else { StringBuilder msgBuilder = new StringBuilder(msg); for (int i = 0; i