自动生成编号

后台

Date date = new Date();
            SimpleDateFormat dmDate = new SimpleDateFormat("yyyyMMdd"); // 获取当前时间
            String dateran = dmDate.format(date);
            String sql = " select case when main_number is null then '0001' else substr(max(substr(main_number,7))+1,7) end main_number " +
                         "  from aviation_info where DATE_FORMAT(create_date,'%Y%m%d') = DATE_FORMAT(now(),'%Y%m%d')  ";
            String maxnum = jdbcTemplate.queryForObject(sql,String.class);
            String mainNumber = "HKZD"+dateran+maxnum;
            aviationInfo.setMainNumber(mainNumber);
            aviationInfoService.save(aviationInfo);

 

posted @ 2021-06-28 16:43  薛柏梁  阅读(62)  评论(0编辑  收藏  举报