Administrator 2 年之前
父節點
當前提交
7f678f6114

+ 8 - 0
src/main/java/com/sysu/admin/controller/lz/area/LzArea.java

@@ -1,6 +1,7 @@
 package com.sysu.admin.controller.lz.area;
 
 import com.alibaba.fastjson.annotation.JSONField;
+import com.sysu.admin.controller.lz.period.LzPeriod;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
@@ -31,6 +32,13 @@ public class LzArea {
     @Column
     private String color;
 
+    /**
+     * 物候期
+     */
+    @ManyToOne(cascade= CascadeType.REFRESH)
+    @JoinColumn(name = "period_id")
+    private LzPeriod lzPeriod;
+
     @Transient
     private String wkt;
 

+ 5 - 1
src/main/java/com/sysu/admin/controller/lz/area/LzAreaService.java

@@ -14,7 +14,11 @@ public class LzAreaService extends BaseService<LzArea, Integer> {
     @Autowired
     LzAreaRepository lzAreaRepository;
 
-    public LzArea findByPoint(String wkt){
+    public LzArea findByWkt(Double[] point){
+        return lzAreaRepository.findByPoint("Point("+point[0]+" "+point[1]+")");
+    }
+
+    public LzArea findByWkt(String wkt){
         return lzAreaRepository.findByPoint(wkt);
     }
 

+ 50 - 13
src/main/java/com/sysu/admin/controller/lz/ns/site/NsTaskController.java

@@ -1,22 +1,28 @@
 package com.sysu.admin.controller.lz.ns.site;
 
+import com.querydsl.core.types.dsl.BooleanExpression;
 import com.sysu.admin.controller.lz.ns.NsActionRecordService;
 import com.sysu.admin.controller.lz.ns.NsActionTreeService;
 import com.sysu.admin.controller.lz.ns.NsTaskService;
 import com.sysu.admin.controller.lz.ns.NsTypeService;
-import com.sysu.admin.controller.lz.ns.bean.NsActionRecord;
-import com.sysu.admin.controller.lz.ns.bean.NsActionTree;
-import com.sysu.admin.controller.lz.ns.bean.NsTask;
-import com.sysu.admin.controller.lz.ns.bean.NsType;
+import com.sysu.admin.controller.lz.ns.bean.*;
+import com.sysu.admin.controller.lz.ns.site.vo.LzTaskVo;
 import com.sysu.admin.controller.lz.ns.site.vo.LzUserVo;
 import com.sysu.admin.site.CommonVo;
 import com.sysu.admin.support.system.user.User;
 import com.sysu.admin.support.system.user.UserService;
 import com.sysu.admin.support.system.user_role.UserRole;
 import com.sysu.admin.support.system.user_role.UserRoleService;
+import com.xiesx.fastboot.base.pagination.PaginationHelper;
+import com.xiesx.fastboot.base.pagination.PaginationResult;
+import com.xiesx.fastboot.base.pagination.PaginationVo;
 import com.xiesx.fastboot.base.result.BaseResult;
 import com.xiesx.fastboot.base.result.R;
+import org.apache.commons.lang3.ObjectUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
 import org.springframework.data.domain.Sort;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -43,13 +49,35 @@ public class NsTaskController {
     private NsActionTreeService actionTreeService;
 
     @RequestMapping("/list")
-    public BaseResult list(){
+    public PaginationResult list(@RequestBody LzTaskVo lzTaskVo){
         List<NsActionTree> nsActionTrees = actionTreeService.findAll();
+        // 分页
+        Pageable pageable = PageRequest.of(lzTaskVo.getPage(), lzTaskVo.getLimit(), Sort.by(Sort.Direction.DESC, User.FIELDS.createDate));
+
         Map<Integer, NsActionTree> integerNsActionTreeMap =  listToMap(nsActionTrees);
-        List<NsTask> nsTaskList = nsTaskService.findAll(Sort.by("id"));
+        QNsTask qNsTask = QNsTask.nsTask;
+        BooleanExpression expression = qNsTask.nsTypeId.eq(lzTaskVo.getTypeId());
+        if(lzTaskVo.getStatus() != null){
+            expression = expression.and(qNsTask.status.eq(lzTaskVo.getStatus()));
+        }
+        List<NsTask> nullTasks = new ArrayList<>();
+        Page<NsTask>  nsTaskList = get(expression, pageable, integerNsActionTreeMap, nullTasks);
+        if(nullTasks.size() > 0){
+            nsTaskService.deleteAll(nullTasks);
+            nsTaskList = get(expression, pageable, integerNsActionTreeMap, nullTasks);
+        }
+        return PaginationHelper.create(nsTaskList);
+    }
 
-        nsTaskList.forEach(nsTask -> {
-            nsTask.setRecordList(nsActionRecordService.findAllByTaskId(nsTask.getId()));
+    private Page<NsTask> get(BooleanExpression expression, Pageable pageable, Map<Integer, NsActionTree> integerNsActionTreeMap, List<NsTask> nullTasks){
+        Page<NsTask> nsTaskList = nsTaskService.findAll(expression, pageable);
+
+        nsTaskList.toList().forEach(nsTask -> {
+            List<NsActionRecord> nsActionRecordList = nsActionRecordService.findAllByTaskId(nsTask.getId());
+            if(nsActionRecordList.size() == 0){
+                nullTasks.add(nsTask);
+            }
+            nsTask.setRecordList(nsActionRecordList);
             StringBuffer ns = new StringBuffer();
             nsTask.getRecordList().stream().forEach(nsActionRecord -> {
                 NsActionTree a = integerNsActionTreeMap.get(nsActionRecord.getActionId());
@@ -60,8 +88,11 @@ public class NsTaskController {
             User user = userService.findOne(nsTask.getUserId().longValue());
             nsTask.setUserName(user.getNickname());
         });
-        return R.succ(nsTaskList);
+        return nsTaskList;
     }
+
+
+
     public Map<Integer, NsActionTree> listToMap(List<NsActionTree> nsActionTrees){
         Map<Integer, NsActionTree> map = new HashMap<>();
         nsActionTrees.forEach(nsActionTree -> {
@@ -83,9 +114,15 @@ public class NsTaskController {
 
     @RequestMapping("/audit")
     public BaseResult audit(@RequestBody CommonVo commonVo){
-        NsTask nsTask = nsTaskService.findOne(commonVo.getId().intValue());
-        nsTask.setStatus(2);
-        nsTaskService.save(nsTask);
-        return R.succ();
+        if(ObjectUtils.isNotEmpty(commonVo.getIds())){
+            commonVo.getIds().stream().forEach(aLong -> {
+                NsTask nsTask = nsTaskService.findOne(aLong.intValue());
+                nsTask.setStatus(3);
+                nsTaskService.save(nsTask);
+            });
+            return R.succ();
+        }
+        throw new RuntimeException("没有ids");
+
     }
 }

+ 12 - 0
src/main/java/com/sysu/admin/controller/lz/ns/site/vo/LzTaskVo.java

@@ -0,0 +1,12 @@
+package com.sysu.admin.controller.lz.ns.site.vo;
+
+import com.xiesx.fastboot.base.pagination.PaginationVo;
+import lombok.Data;
+
+@Data
+public class LzTaskVo extends PaginationVo {
+
+    private Integer typeId;
+    private Integer status;
+
+}

+ 4 - 1
src/main/java/com/sysu/admin/site/CommonVo.java

@@ -1,13 +1,16 @@
 package com.sysu.admin.site;
 
+import com.xiesx.fastboot.base.pagination.PaginationVo;
 import lombok.Data;
 
 
 import java.util.Date;
+import java.util.List;
 
 @Data
-public class CommonVo {
+public class CommonVo{
     private Long id;
+    private List<Long> ids;
     private String code;
     private Integer level;
     private Integer clazzId;

+ 22 - 16
src/main/java/com/sysu/admin/site/lz/LzAreaController.java

@@ -2,20 +2,18 @@ package com.sysu.admin.site.lz;
 
 import com.sysu.admin.controller.lz.area.LzArea;
 import com.sysu.admin.controller.lz.area.LzAreaService;
+import com.sysu.admin.controller.lz.period.LzPeriod;
 import com.sysu.admin.site.CommonVo;
 import com.sysu.admin.utils.shape.GeoCastUtil;
 import com.xiesx.fastboot.base.result.BaseResult;
 import com.xiesx.fastboot.base.result.R;
-import org.geotools.geometry.jts.JTSFactoryFinder;
-import org.locationtech.jts.geom.Coordinate;
-import org.locationtech.jts.geom.GeometryFactory;
 import org.locationtech.jts.geom.MultiPolygon;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Sort;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
-import java.util.Arrays;
 import java.util.List;
 
 @RequestMapping("/site/lz_area")
@@ -27,7 +25,7 @@ public class LzAreaController {
 
     @RequestMapping("/list")
     public BaseResult list(){
-        List<LzArea> list = lzAreaService.findAll();
+        List<LzArea> list = lzAreaService.findAll(Sort.by("id"));
         list.forEach(lzArea -> {
             lzArea.setWkt(GeoCastUtil.geomToWkt(lzArea.getGeom()));
             lzArea.setPointWkt(GeoCastUtil.geomToWkt(lzArea.getPoint()));
@@ -35,18 +33,26 @@ public class LzAreaController {
         return R.succ(list);
     }
 
-    @RequestMapping("/air_route")
-    public BaseResult airRoute(@RequestBody CommonVo commonVo){
-        LzArea area = lzAreaService.findOne(commonVo.getId().intValue());
-        Coordinate[] coordinates  = area.getGeom().getCoordinates();
-        Double[][] res = new Double[coordinates.length - 1][];
-        for(int i=0; i < coordinates.length - 1; i++){
-            Double [] temp = new Double[2];
-            temp[0] = coordinates[i].getX();
-            temp[1] = coordinates[i].getY();
-            res[i] = temp;
+    @RequestMapping("/findAreaByPoint")
+    public BaseResult findAreaByPoint(@RequestBody CommonVo commonVo){
+         return R.succ(lzAreaService.findByWkt(commonVo.getPoint()));
+    }
+
+    /**
+     * 改变物候期
+     * @return
+     */
+    @RequestMapping("/changePeriod")
+    public BaseResult changePeriod(@RequestBody CommonVo commonVo){
+        LzArea lzArea = lzAreaService.findByWkt(commonVo.getPoint());
+        if(lzArea == null){
+            return R.succ();
         }
-        return R.succ(res);
+        LzPeriod lzPeriod = new LzPeriod();
+        lzPeriod.setId(commonVo.getPeriodId());
+        lzArea.setLzPeriod(lzPeriod);
+        lzAreaService.save(lzArea);
+        return R.succ();
     }
 
     @RequestMapping("/save")

+ 2 - 2
src/main/java/com/sysu/admin/site/lz/LzTreeController.java

@@ -72,7 +72,7 @@ public class LzTreeController {
         Date now = new Date();
         Date start = getMonthBegin(DateUtils.addMonths(now, -1));
 
-        List<LzEveryday> lzEverydayList = everydayService.findListByTreeId(bean.getId(),start, now);
+        List<LzEveryday> lzEverydayList = everydayService.findListByTreeId(bean.getId(), start, now);
         bean.setLzEverydays(lzEverydayList);
         return R.succ(bean);
     }
@@ -80,7 +80,7 @@ public class LzTreeController {
     @RequestMapping("/save")
     public BaseResult save(@RequestBody LzTree bean){
         bean.setPoint((Point) GeoCastUtil.wktToGeom(bean.getWkt()));
-        LzArea lzArea = lzAreaService.findByPoint(bean.getWkt());
+        LzArea lzArea = lzAreaService.findByWkt(bean.getWkt());
         LzClazz clazz = lzClazzService.findOne(bean.getClazzId());
         bean.setClazz(clazz);
         bean.setCode(lzArea.getId() + clazz.getCode() +  bean.getCode());