| | |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.system.model.Project; |
| | | import com.ruoyi.system.model.ProjectInfo; |
| | | import com.ruoyi.system.mapper.ProjectInfoMapper; |
| | | import com.ruoyi.system.model.Record; |
| | | import com.ruoyi.system.query.ProjectDangerousTrendQuery; |
| | | import com.ruoyi.system.query.ProjectHiddenDangerTrendListQuery; |
| | | import com.ruoyi.system.service.ProjectCategoryCalculator; |
| | | import com.ruoyi.system.service.ProjectInfoService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.system.service.ProjectService; |
| | | import com.ruoyi.system.service.RecordService; |
| | | import com.ruoyi.system.vo.ProjectDangerousTrendVo; |
| | | import com.ruoyi.system.vo.ProjectHiddenDangerList; |
| | | import com.ruoyi.system.vo.ProjectHiddenDangerNextList; |
| | | import com.ruoyi.system.vo.ProjectHiddenDangerTrendVo; |
| | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.time.YearMonth; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.time.temporal.TemporalAdjusters; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | import static java.util.stream.Collectors.groupingBy; |
| | | |
| | |
| | | public class ProjectInfoServiceImpl extends ServiceImpl<ProjectInfoMapper, ProjectInfo> implements ProjectInfoService { |
| | | |
| | | |
| | | @Autowired |
| | | private ProjectCategoryCalculator projectCategoryCalculator; |
| | | |
| | | @Autowired |
| | | private ProjectService projectService; |
| | | |
| | | @Override |
| | | public List<ProjectHiddenDangerTrendVo> getProjectHiddenDangerTrend(Integer projectId) { |
| | | // 获取上月第一天的时间 |
| | |
| | | for (Record record : list) { |
| | | String hierarchyNames = record.getHierarchyNames(); |
| | | JSONArray jsonArray = JSONArray.parseArray(hierarchyNames); |
| | | if(record.getDeviceId()!=null){ |
| | | // 取出倒数第3个 |
| | | String name = jsonArray.getString(jsonArray.size()-3); |
| | | |
| | | record.setHierarchyName( name); |
| | | }else { |
| | | // 取出倒数第4个 |
| | | String name = jsonArray.getString(jsonArray.size()-4); |
| | | |
| | | record.setHierarchyName( name); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | LocalDate thisMonth = LocalDate.now().minusMonths(0).with(TemporalAdjusters.firstDayOfMonth()); |
| | |
| | | for (Record record : list) { |
| | | String hierarchyNames = record.getHierarchyNames(); |
| | | JSONArray jsonArray = JSONArray.parseArray(hierarchyNames); |
| | | if(record.getDeviceId()!=null){ |
| | | // 取出倒数第3个 |
| | | String name = jsonArray.getString(jsonArray.size()-3); |
| | | |
| | | record.setHierarchyName( name); |
| | | }else { |
| | | // 取出倒数第4个 |
| | | String name = jsonArray.getString(jsonArray.size()-4); |
| | | |
| | | record.setHierarchyName( name); |
| | | } |
| | | |
| | | } |
| | | |
| | | // 算出跨度几个月 |
| | |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public List<ProjectDangerousTrendVo> getProjectDangerousTrend(ProjectDangerousTrendQuery query) { |
| | | List<ProjectDangerousTrendVo> list = new ArrayList<>(); |
| | | Project project = projectService.getById(query.getProjectId()); |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | // 算出跨度几个月 |
| | | int months = calculateMonthsBetween(query.getStartTime(),query.getEndTime()); |
| | | ArrayList<Project> projects = new ArrayList<>(); |
| | | projects.add( project); |
| | | String temp=null; |
| | | try { |
| | | for (int i = 0; i < months; i++) { |
| | | ProjectDangerousTrendVo vo = new ProjectDangerousTrendVo(); |
| | | LocalDate localDate = getMonthBoundaries(query.getStartTime(), true).plusMonths(i); |
| | | String dateStr = localDate.toString().substring(0, 7); |
| | | String start = localDate+" 00:00:00"; |
| | | String end = getMonthBoundaries(query.getStartTime(), false).plusMonths(i)+" 23:59:59"; |
| | | Date startDate = simpleDateFormat.parse(start); |
| | | Date endDate = simpleDateFormat.parse(end); |
| | | vo.setTime(dateStr); |
| | | |
| | | if(project.getType()==2){ |
| | | Map<Integer, String> integerStringMap = projectCategoryCalculator.calculateFixedAssetCategories(projects, Long.valueOf(project.getClientId()), startDate, endDate); |
| | | String s = integerStringMap.get(query.getProjectId()); |
| | | vo.setLevel(s); |
| | | }else { |
| | | Map<Integer, String> integerStringMap = projectCategoryCalculator.calculateOngoingProjectCategories(projects, Long.valueOf(project.getClientId()), startDate, endDate); |
| | | String s = integerStringMap.get(query.getProjectId()); |
| | | vo.setLevel(s); |
| | | } |
| | | // 如果没有则沿用上次的 |
| | | if(vo.getLevel()!=null){ |
| | | temp=vo.getLevel(); |
| | | }else { |
| | | vo.setLevel(temp); |
| | | } |
| | | list.add( vo); |
| | | } |
| | | }catch (ParseException e){ |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | |
| | | public static LocalDate getMonthBoundaries(String yearMonthStr,boolean isInclusive) { |
| | | // 解析字符串为YearMonth |