|
@@ -0,0 +1,66 @@
|
|
|
+package com.huimv.guowei.admin.controller;
|
|
|
+
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.huimv.guowei.admin.common.utils.Result;
|
|
|
+import com.huimv.guowei.admin.common.utils.ResultCode;
|
|
|
+import com.huimv.guowei.admin.entity.EggProduction;
|
|
|
+import com.huimv.guowei.admin.entity.dto.EggProductionDto;
|
|
|
+import com.huimv.guowei.admin.service.IEggProductionService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.time.LocalTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 前端控制器
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author newspaper
|
|
|
+ * @since 2023-11-28
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/egg-production")
|
|
|
+@CrossOrigin
|
|
|
+public class EggProductionController {
|
|
|
+ @Autowired
|
|
|
+ private IEggProductionService eggProductionService;
|
|
|
+
|
|
|
+ @PostMapping("/list")
|
|
|
+ public Result add(@RequestBody Map<String,String> paramsMap){
|
|
|
+ String farmId = paramsMap.get("farmId");
|
|
|
+ List<EggProduction> eggProductions = eggProductionService.list(new QueryWrapper<EggProduction>().eq("farm_id", farmId).orderByAsc("event_type"));
|
|
|
+ if (CollUtil.isEmpty(eggProductions)){
|
|
|
+ return new Result(ResultCode.SUCCESS,new ArrayList());
|
|
|
+ }
|
|
|
+ return new Result(ResultCode.SUCCESS,eggProductions);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/update")
|
|
|
+ public Result add(@RequestBody EggProductionDto eggProductionDto){
|
|
|
+ List<EggProduction> list = eggProductionDto.getList();
|
|
|
+ EggProduction eggProduction1 = list.stream().filter(eggProduction -> eggProduction.getEventType().equals(0)).findFirst().orElse(null);
|
|
|
+ if (eggProduction1.getStartTime().isAfter(eggProduction1.getEndTime())){
|
|
|
+ return new Result(10001,"起始时间不能晚于结束时间",false);
|
|
|
+ }
|
|
|
+ EggProduction eggProduction2 = list.stream().filter(eggProduction -> eggProduction.getEventType().equals(1)).findFirst().orElse(null);
|
|
|
+ if (eggProduction2.getStartTime().isAfter(eggProduction2.getEndTime())){
|
|
|
+ return new Result(10001,"起始时间不能晚于结束时间",false);
|
|
|
+ }
|
|
|
+ if (isTimeOverlap(eggProduction1.getStartTime(),eggProduction1.getEndTime(),eggProduction2.getStartTime(),eggProduction2.getEndTime())) {
|
|
|
+ return new Result(10001,"存在时间重叠",false);
|
|
|
+ }
|
|
|
+ eggProductionService.saveOrUpdateBatch(list);
|
|
|
+ return Result.SUCCESS();
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean isTimeOverlap(LocalTime start1, LocalTime end1, LocalTime start2, LocalTime end2) {
|
|
|
+ return !(end1.isBefore(start2) || start1.isAfter(end2));
|
|
|
+ }
|
|
|
+}
|