① Ideas
1. Get the current time month date : 2018-01-15 00:00:00 2018-01-15 24:00:002. Whether the corresponding date field in the query table is within the time period of the day 3. If so, increment 4 from 0. If not, then find the Msgno maximum value, on this basis +1
② on the Code
Method of encapsulation in Controller tuning service
Integer msgid= Xxtzservice.getmsgid ();
Service
Public Integer Getmsgid () {//1. Gets the current time, in the format of month-day seconds string date = dateu.getdatetostring (new date (). GetTime ()); String senddate1 = date+ "00:00:00"; String Senddate2 = date+ "24:00:00";//2. The corresponding field in the query table has list<message> msglist = Xxtzmapper.findtime for the current time (senddate1, SENDDATE2); if (Msglist.size () ==0 | | msglist==null) {//3.1 If there is no match, increments from 1 to integer msgid=0;//daily up to 100,000 for (int i = 0; i < 100000; i++) {Msgid++;return msgid;}} else{//3.2 if matching, then find the maximum value of Msgno, on this basis +1integer MsgId = Xxtzmapper.findmaxmsgid (senddate1,senddate2); Msgid++;return MsgId;} return null;}
Mapper
List<message> Findtime (@Param ("senddate1") string senddate1, @Param ("Senddate2") string senddate2); Findmaxmsgid (@Param ("senddate1") string senddate1, @Param ("Senddate2") string senddate2);
Xxmapper.xml
<select id= "Findmaxmsgid" resulttype= "int" >select Max (MsgId) from Message where senddate between #{senddate1} and # {senddate2}</select><!--Query whether the corresponding field in the Message table has the time of day--><select id= "Findtime" resulttype= "Message" > SELECT * from Message where senddate between #{senddate1} and #{senddate2}</select>
Java controls a field increment on the day