|
@@ -0,0 +1,81 @@
|
|
|
+package cn.com.ty.lift.business.maintenance.service;
|
|
|
+
|
|
|
+import cn.com.ty.lift.business.maintenance.dao.entity.model.dto.MaintenancePlanMonthTaskNum;
|
|
|
+import cn.com.ty.lift.business.maintenance.dao.entity.model.request.PropertyMaintenanceVO;
|
|
|
+import cn.com.ty.lift.business.maintenance.dao.entity.model.response.PropertyCalendarResponse;
|
|
|
+import cn.com.ty.lift.business.maintenance.dao.mapper.PropertyMaintenanceMapper;
|
|
|
+import cn.com.xwy.boot.web.dto.RestResponse;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+@Slf4j
|
|
|
+public class PropertyMaintenanceService {
|
|
|
+ private final PropertyMaintenanceMapper propertyMaintenanceMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param propertyMaintenanceVO userId用户id,yearMonth年月 例202005即2020年5月
|
|
|
+ * @return 日历
|
|
|
+ */
|
|
|
+ public RestResponse<?> queryMaintenancePlanMonth(PropertyMaintenanceVO propertyMaintenanceVO) {
|
|
|
+ List<MaintenancePlanMonthTaskNum> planNums = propertyMaintenanceMapper.queryMaintenancePlanMonth(propertyMaintenanceVO.getUserId(), propertyMaintenanceVO.getYearMonth());
|
|
|
+ if (planNums.isEmpty()) {
|
|
|
+ return RestResponse.success();
|
|
|
+ }
|
|
|
+ log.info(planNums.toString());
|
|
|
+ List<PropertyCalendarResponse> calendar = new ArrayList<>();
|
|
|
+ //循环每日,每种状态的维保计划
|
|
|
+ for (MaintenancePlanMonthTaskNum planNum : planNums) {
|
|
|
+ numToCalendar(calendar, planNum);
|
|
|
+ }
|
|
|
+ return RestResponse.success(calendar);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 维保计划每日每个状态的数量转前端日历所需格式
|
|
|
+ *
|
|
|
+ * @param calendar 日历
|
|
|
+ * @param planNum 计划数量
|
|
|
+ */
|
|
|
+ private void numToCalendar(List<PropertyCalendarResponse> calendar, MaintenancePlanMonthTaskNum planNum) {
|
|
|
+ boolean hasDay = false;
|
|
|
+ boolean hasStatus = false;
|
|
|
+ //遍历每日
|
|
|
+ for (PropertyCalendarResponse day : calendar) {
|
|
|
+ if (day.getKey().equals(planNum.getDay())) {
|
|
|
+ hasDay = true;
|
|
|
+ //遍历每日的每个状态
|
|
|
+ for (PropertyCalendarResponse.Values status : day.getValue()) {
|
|
|
+ if (status.getKey().equals(planNum.getStatus())) {
|
|
|
+ hasStatus = true;
|
|
|
+ status.setValue(planNum.getCount());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //如果遍历到的日期,没有这个状态,新增这个状态
|
|
|
+ if (!hasStatus) {
|
|
|
+ PropertyCalendarResponse.Values status = new PropertyCalendarResponse.Values();
|
|
|
+ status.setKey(planNum.getStatus());
|
|
|
+ status.setValue(planNum.getCount());
|
|
|
+ day.getValue().add(status);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //如果日历中没有这个日期,新增这个日期
|
|
|
+ if (!hasDay) {
|
|
|
+ PropertyCalendarResponse day = new PropertyCalendarResponse();
|
|
|
+ day.setKey(planNum.getDay());
|
|
|
+ List<PropertyCalendarResponse.Values> statuses = day.getValue();
|
|
|
+ PropertyCalendarResponse.Values status = new PropertyCalendarResponse.Values();
|
|
|
+ status.setKey(planNum.getStatus());
|
|
|
+ status.setValue(planNum.getCount());
|
|
|
+ statuses.add(status);
|
|
|
+ day.setValue(statuses);
|
|
|
+ calendar.add(day);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|