@Component public class CreateCodeUtil { @Resource private JdbcTemplate jdbcTemplate; public String createCode(){ //查询数据库中最大的流水号 String sql = "select MAX(a.FILE_CODE+0) maxCode FROM t_file_info a"; List<Map<String,Object>> list; //调用templet方法 list = jdbcTemplate.queryForList(sql); String resultCode = ""; String maxCode = ""; Object object = list.get(0).get("maxCode"); if (list.size() > 0 && object!=null) { maxCode = new DecimalFormat("0").format((double)object); //Specify the generated time format } SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd"); String preCode = simpleDateFormat.format(new Date()); //If there is a code generated that day, add 1 to the end number directly; if a new code is not generated directly if (maxCode!=null&&maxCode.contains(preCode)){ Integer endCode = Integer.parseInt(maxCode.substring(8)); //Calculation result endCode = endCode+10000+1; resultCode = preCode+endCode.toString(). substring(1); }else { resultCode = preCode+"0001"; } return resultCode; } }
Serial number of tools
Guess you like
Origin blog.csdn.net/tonglei111/article/details/100763268
Ranking