52 lines
1.9 KiB
Java
52 lines
1.9 KiB
Java
|
|
package com.gunshi.project.ss.service;
|
||
|
|
|
||
|
|
|
||
|
|
import com.gunshi.project.ss.model.MentenceFarmerRecord;
|
||
|
|
import com.gunshi.project.ss.model.MentenceStDetail;
|
||
|
|
import lombok.extern.slf4j.Slf4j;
|
||
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
||
|
|
import org.springframework.stereotype.Service;
|
||
|
|
|
||
|
|
import java.time.LocalDateTime;
|
||
|
|
import java.util.HashMap;
|
||
|
|
import java.util.List;
|
||
|
|
import java.util.Map;
|
||
|
|
import java.util.stream.Collectors;
|
||
|
|
|
||
|
|
@Service
|
||
|
|
@Slf4j
|
||
|
|
public class ScreenMfrService {
|
||
|
|
|
||
|
|
@Autowired
|
||
|
|
private MentenceFarmerRecordService mentenceFarmerRecordService;
|
||
|
|
|
||
|
|
@Autowired
|
||
|
|
private MentenceStDetailService mentenceStDetailService;
|
||
|
|
|
||
|
|
public Map<String, Long> get(Long year) {
|
||
|
|
Map<String, Long> map = new HashMap<>();
|
||
|
|
Map<Long,String> idMapToName = new HashMap<>();
|
||
|
|
LocalDateTime start = LocalDateTime.of(year.intValue(),1,1,0,0,0);
|
||
|
|
LocalDateTime end = LocalDateTime.of(year.intValue(),12,31,23,59,59);
|
||
|
|
List<MentenceFarmerRecord> farmerRecords = mentenceFarmerRecordService.lambdaQuery()
|
||
|
|
.ge(MentenceFarmerRecord::getMentenceTimeBegin, start)
|
||
|
|
.le(MentenceFarmerRecord::getMentenceTimeBegin, end)
|
||
|
|
.list();
|
||
|
|
if(farmerRecords.isEmpty()){
|
||
|
|
return map;
|
||
|
|
}
|
||
|
|
List<Long> stDetailId = farmerRecords.stream().map(o -> o.getMentenceStDetailId()).distinct().collect(Collectors.toList());
|
||
|
|
List<MentenceStDetail> mentenceStDetail = mentenceStDetailService.lambdaQuery()
|
||
|
|
.in(MentenceStDetail::getId, stDetailId).list();
|
||
|
|
for (MentenceStDetail stDetail : mentenceStDetail) {
|
||
|
|
idMapToName.put(stDetail.getId(),stDetail.getStDetailName());
|
||
|
|
}
|
||
|
|
|
||
|
|
for (MentenceFarmerRecord record : farmerRecords) {
|
||
|
|
String name = idMapToName.get(record.getMentenceStDetailId());
|
||
|
|
map.put(name,map.getOrDefault(name,0L)+1L);
|
||
|
|
}
|
||
|
|
return map;
|
||
|
|
}
|
||
|
|
}
|