diff --git a/src/main/java/com/sqx/modules/artificer/service/impl/ArtificerTimeServiceImpl.java b/src/main/java/com/sqx/modules/artificer/service/impl/ArtificerTimeServiceImpl.java index b615807..864f057 100644 --- a/src/main/java/com/sqx/modules/artificer/service/impl/ArtificerTimeServiceImpl.java +++ b/src/main/java/com/sqx/modules/artificer/service/impl/ArtificerTimeServiceImpl.java @@ -28,6 +28,7 @@ import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.*; +import java.util.stream.Collectors; @Service @@ -101,28 +102,30 @@ public class ArtificerTimeServiceImpl extends ServiceImpl dateMap = new HashMap(); - for(String times:idleTime.split(",")){ - String[] datetime = times.split(" "); - if(datetime!=null && datetime.length>0) { - baseMapper.delete(new QueryWrapper().eq("artificer_date", datetime[0]).eq("artificer_id", artificer.getArtificerId()).eq("artificer_time", datetime[1])); - if(dateMap.get(datetime[0])!=null){ - List timeList = dateMap.get(datetime[0]); - timeList.add(datetime[1]); - }else{ - List timeList = new ArrayList<>(); - timeList.add(datetime[1]); - dateMap.put(datetime[0],timeList); - } - } - } - Map busyMap = getBusyMap(dateMap); + String[] idelTimes = idleTime.split(","); + String[] datetime1 = idelTimes[0].split(" "); + String startDay = datetime1[0]; + String startTime = datetime1[1]; + String[] datetime2 = idelTimes[1].split(" "); + String endDay = datetime2[0]; + String endTime = datetime2[1]; + QueryWrapper qw = new QueryWrapper(); + qw.eq("artificer_id", artificer.getArtificerId()); + qw.ge("artificer_date", startDay); + qw.le("artificer_date", endDay); + qw.ge("artificer_time", startTime); + qw.le("artificer_time", endTime); + baseMapper.delete(qw); + + Map dateMap = getIdelMap(idelTimes[0],idelTimes[1]); + + Map busyMap = getBusyMap(dateMap); for (String key : busyMap.keySet()) { - Map busyTimeMap = busyMap.get(key); - for (String timeKey : busyTimeMap.keySet()) { + List busyTimeList = busyMap.get(key); + for(String time : busyTimeList){ ArtificerTime artificerTime=new ArtificerTime(); artificerTime.setArtificerDate(key); - artificerTime.setArtificerTime(busyTimeMap.get(timeKey)); + artificerTime.setArtificerTime(time); artificerTime.setArtificerId(artificer.getArtificerId()); artificerTime.setClassify(2); artificerTime.setCreateTime(DateUtils.format(new Date())); @@ -150,18 +153,41 @@ public class ArtificerTimeServiceImpl extends ServiceImpl getBusyMap(Map dateMap){ - Map map = new HashMap(); + private Map getIdelMap(String startDateStr,String endDateStr){ + Map map = new HashMap(); + Date startDate = DateUtils.stringToDate(startDateStr,"yyyy-MM-dd HH:mm"); + Date endDate = DateUtils.stringToDate(endDateStr,"yyyy-MM-dd HH:mm"); + Date current = startDate; + while(current.getTime()<=endDate.getTime()){ + String day = DateUtils.format(current,"yyyy-MM-dd"); + String time = DateUtils.format(current,"HH:mm"); + if(map.get(day)!=null){ + List timeList = map.get(day); + timeList.add(time); + }else{ + List timeList = new ArrayList<>(); + timeList.add(time); + map.put(day,timeList); + } + DateUtils.addDateMinutes(current,30); + } + return map; + } + + private Map getBusyMap(Map dateMap){ + Map map = new HashMap(); for (String key : dateMap.keySet()) { List timeList = dateMap.get(key); - Map allTimes = getTimeMap(); + Map allTimes = getTimeMap(); for(int i=0; i < timeList.size();i++){ String time = timeList.get(i); if(allTimes.get(time)!=null){ allTimes.remove(time); } } - map.put(key,allTimes); + List keyList = allTimes.keySet().stream().collect(Collectors.toList()); + Collections.sort(keyList); + map.put(key,keyList); } return map; } @@ -183,24 +209,28 @@ public class ArtificerTimeServiceImpl extends ServiceImpl dateMap = new HashMap(); - for(String times:idleTime.split(",")){ - String[] datetime = times.split(" "); - if(datetime!=null && datetime.length>0) { - if(dateMap.get(datetime[0])!=null){ - List timeList = dateMap.get(datetime[0]); - timeList.add(datetime[1]); - }else{ - List timeList = new ArrayList<>(); - timeList.add(datetime[1]); - dateMap.put(datetime[0],timeList); - } + Date startDate = DateUtils.stringToDate(idelTimes[0],"yyyy-MM-dd HH:mm"); + Date endDate = DateUtils.stringToDate(idelTimes[1],"yyyy-MM-dd HH:mm"); + Date current = startDate; + while(current.getTime()<=endDate.getTime()){ + String day = DateUtils.format(current,"yyyy-MM-dd"); + String time = DateUtils.format(current,"HH:mm"); + if(dateMap.get(day)!=null){ + List timeList = dateMap.get(day); + timeList.add(time); + }else{ + List timeList = new ArrayList<>(); + timeList.add(time); + dateMap.put(day,timeList); } + current = DateUtils.addDateMinutes(current,30); } - Map map = new HashMap(); + Map map = new HashMap(); for (String key : dateMap.keySet()) { List timeList = dateMap.get(key); Map allTimes = new HashMap(); @@ -220,19 +250,20 @@ public class ArtificerTimeServiceImpl extends ServiceImpl keyList = allTimes.keySet().stream().collect(Collectors.toList()); + Collections.sort(keyList); + map.put(key,keyList); } for (String key : map.keySet()) { - Map busyTimeMap = map.get(key); - for (String timeKey : busyTimeMap.keySet()) { + List busyTimeList = map.get(key); + for(String time : busyTimeList){ System.out.print(key); System.out.print(" "); - System.out.print(busyTimeMap.get(timeKey)); + System.out.print(time); System.out.println(""); } } - } @Override diff --git a/src/main/resources/mapper/shipinquan/ShipinquanDao.xml b/src/main/resources/mapper/shipinquan/ShipinquanDao.xml index 20cb132..c886ac7 100644 --- a/src/main/resources/mapper/shipinquan/ShipinquanDao.xml +++ b/src/main/resources/mapper/shipinquan/ShipinquanDao.xml @@ -37,7 +37,7 @@ if(c.id is null,0,1) as sfdz FROM bl_shipinquan a left join artificer b on a.create_by = b.user_id - left join bl_shipinquan_dianzan c on a.id = c.shipinquan_id + left join bl_shipinquan_dianzan c on a.id = c.shipinquan_id and c.create_by = #{params.createBy} and c.create_by = #{params.userId} left join collect_artificer d on b.artificer_id = d.artificer_id and d.user_id = #{params.userId}