Преглед изворни кода

修改全局设置设计,优化其它代码

wanghaicheng пре 5 година
родитељ
комит
782eb146da

+ 2 - 3
lift-system-service/src/main/java/cn/com/ty/lift/system/faq/controller/FaqController.java

@@ -30,9 +30,8 @@ public class FaqController {
     @PostMapping("/child")
     public RestResponse child() {
         List<Faq> faqs = faqService.list(new QueryWrapper<Faq>()
-                .eq("type", 1)
-                .or()
-                .eq("type", 2));
+                .in("type", 1, 2)
+                .orderByAsc("parent_id", "type", "serial"));
         if (faqs.isEmpty()) {
             return RestResponse.success();
         }

+ 34 - 52
lift-system-service/src/main/java/cn/com/ty/lift/system/faq/service/impl/FaqServiceImpl.java

@@ -9,6 +9,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 
 /**
@@ -40,13 +42,10 @@ public class FaqServiceImpl extends ServiceImpl<FaqMapper, Faq> implements FaqSe
     public RestResponse add(Faq faq) {
         List<Faq> faqs = this.list(new QueryWrapper<Faq>()
                 .select("id", "serial")
-                .eq("type", faq.getType()).eq("parent_id", faq.getParentId())
+                .eq("type", faq.getType())
+                .eq("parent_id", faq.getParentId())
                 .orderByDesc("serial"));
-        if (faqs.isEmpty()) {
-            faq.setSerial(1);
-        } else {
-            faq.setSerial(faqs.get(0).getSerial() + 1);
-        }
+        faq.setSerial(faqs.size() + 1);
         if (this.save(faq)) {
             return RestResponse.success(null, "成功");
         }
@@ -83,61 +82,44 @@ public class FaqServiceImpl extends ServiceImpl<FaqMapper, Faq> implements FaqSe
     //type 1上移 0下移
     public RestResponse serial(Long id, Integer type) {
         Faq byId = this.getById(id);
-        if (byId == null) {
+        if (null == byId) {
             return RestResponse.success();
         }
-
-        List<Faq> faqs;
-        if (type == 1) {
-            faqs = this.list(new QueryWrapper<Faq>().eq("type", byId.getType())
-                    .eq("parent_id", byId.getParentId())
-                    .orderByDesc("serial"));
-        } else {
-            faqs = this.list(new QueryWrapper<Faq>().eq("type", byId.getType())
-                    .eq("parent_id", byId.getParentId())
-                    .orderByAsc(("serial")));
-        }
-
-        if (faqs.isEmpty()) {
-            byId.setSerial(1);
-            this.updateById(byId);
+        List<Faq> faqs = this.list(new QueryWrapper<Faq>()
+                .eq("parent_id", byId.getParentId())
+                .eq("type", byId.getType())
+                .orderByDesc("serial"));
+        if (faqs.size() == 1) {
             return RestResponse.success(null, "成功");
         }
-
-        Faq faq;
-        int i;
+        //type 0下移
+        //type 1上移
         if (type == 1) {
-            for (i = 0; i < faqs.size(); i++) {
-                if (faqs.get(i).getSerial() < byId.getSerial()) {
-                    break;
-                }
-            }
-        } else {
-            for (i = 0; i < faqs.size(); i++) {
-                if (faqs.get(i).getSerial() > byId.getSerial()) {
-                    break;
-                }
-            }
+            faqs.sort(Comparator.comparing(Faq::getSerial));
         }
-
-        if (i == faqs.size()) {
-            return RestResponse.success(null,"成功");
+        if (faqs.get(0).getSerial().equals(byId.getSerial())) {
+            return RestResponse.success(null, "成功");
         }
-
-        faq = faqs.get(i);
-
-
-        if (byId.getId().equals(faq.getId())) {
+        if (upOrDown(byId, faqs)) {
             return RestResponse.success(null, "成功");
         }
+        return RestResponse.fail();
+    }
 
-        Integer serial = faq.getSerial();
-        faq.setSerial(byId.getSerial());
-        byId.setSerial(serial);
-
-        this.updateById(faq);
-        this.updateById(byId);
-
-        return RestResponse.success(null, "成功");
+    private boolean upOrDown(Faq byId, List<Faq> faqs) {
+        System.out.println(faqs);
+        Faq f = new Faq();
+        for (Faq faq : faqs) {
+            if (faq.getSerial().equals(byId.getSerial())) {
+                Integer serial = f.getSerial();
+                f.setSerial(byId.getSerial());
+                byId.setSerial(serial);
+                if (this.updateById(byId) && this.updateById(f)) {
+                    return true;
+                }
+            }
+            f = faq;
+        }
+        return false;
     }
 }

+ 21 - 6
lift-system-service/src/main/java/cn/com/ty/lift/system/settings/controller/GlobalSetController.java

@@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
-import java.time.LocalDateTime;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -39,23 +39,38 @@ public class GlobalSetController {
     public RestResponse sets(@RequestBody GlobalSet globalSet) {
         List<Map<String, Object>> globalSets = globalSetService
                 .listMaps(new QueryWrapper<GlobalSet>()
-                        .select("id", "type", "value", "code", "company_id companyId")
+                        .select("code", "value")
                         .eq("company_id", globalSet.getCompanyId()));
         if (globalSets.isEmpty()) {
             return RestResponse.success();
         }
-        return RestResponse.success(globalSets, "成功");
+        HashMap<String, Object> result = new HashMap<>();
+        result.put("companyId", globalSet.getCompanyId());
+        HashMap<String, Object> tempMap = new HashMap<>();
+        globalSets.forEach(gs -> {
+            tempMap.put(gs.get("code").toString(), gs.get("value"));
+        });
+        result.put("sets", tempMap);
+        return RestResponse.success(result, "成功");
     }
 
     /**
-     * @param globalSets
+     * @param req
      * @return 操作结果
      * @description 根据id更新维保公司的全局设置
      * @date 2019/12/13 16:24
      */
     @PostMapping("/modify")
-    public RestResponse modify(@RequestBody List<GlobalSet> globalSets) {
-        globalSets.forEach(globalSet -> globalSet.setUpdateTime(LocalDateTime.now()));
+    public RestResponse modify(@RequestBody Map<String, Object> req) {
+        Long companyId = Long.valueOf(req.get("companyId").toString());
+        HashMap<String, Object> sets = (HashMap<String, Object>) req.get("sets");
+        List<GlobalSet> globalSets = globalSetService.list(new QueryWrapper<GlobalSet>().eq("company_id", companyId));
+        sets.forEach((k, v) -> {
+            for (GlobalSet globalSet : globalSets) {
+                if (globalSet.getCode().equals(k))
+                    globalSet.setValue(Integer.valueOf(v.toString()));
+            }
+        });
         if (globalSetService.updateBatchById(globalSets)) {
             return RestResponse.success(null, "成功");
         }

+ 1 - 32
lift-system-service/src/main/java/cn/com/ty/lift/system/settings/dao/entity/GlobalSet.java

@@ -31,18 +31,6 @@ public class GlobalSet implements Serializable {
     @TableId(value = "id",type = IdType.ID_WORKER)
     private Long id;
 
-    /**
-     * 设置名称
-     */
-    @TableField("name")
-    private String name;
-
-    /**
-     * 类型
-     */
-    @TableField("type")
-    private Integer type;
-
     /**
      * 设置值
      */
@@ -55,24 +43,6 @@ public class GlobalSet implements Serializable {
     @TableField("code")
     private String code;
 
-    /**
-     * 描述
-     */
-    @TableField("description")
-    private String description;
-
-    /**
-     * 创建时间
-     */
-    @TableField("create_time")
-    private LocalDateTime createTime;
-
-    /**
-     * 更新时间
-     */
-    @TableField("update_time")
-    private LocalDateTime updateTime;
-
     /**
      * 公司id
      */
@@ -81,11 +51,10 @@ public class GlobalSet implements Serializable {
 
     public GlobalSet(){}
 
-    public GlobalSet(Long companyId, int value, String code, Integer type){
+    public GlobalSet(Long companyId, int value, String code){
         this.companyId = companyId;
         this.value = value;
         this.code = code;
-        this.type = type;
     }
 
 }

+ 7 - 14
lift-system-service/src/main/java/cn/com/ty/lift/system/settings/service/impl/GlobalSetServiceImpl.java

@@ -34,8 +34,7 @@ public class GlobalSetServiceImpl extends ServiceImpl<GlobalSetMapper, GlobalSet
          */
         globalSetList.add(new GlobalSet(companyId,
                 ApiConstants.GlobalSetConstants.VALUE_YES,
-                ApiConstants.GlobalSetConstants.WORK_LIFT,
-                ApiConstants.GlobalSetConstants.TYPE_PROJECT));
+                ApiConstants.GlobalSetConstants.WORK_LIFT));
         /**
          * 名称:2.维保类型选项
          * 类型:电梯保养设置 值为2
@@ -45,8 +44,7 @@ public class GlobalSetServiceImpl extends ServiceImpl<GlobalSetMapper, GlobalSet
          */
         globalSetList.add(new GlobalSet(companyId,
                 ApiConstants.GlobalSetConstants.MT_CLERK_CHOOSE,
-                ApiConstants.GlobalSetConstants.MT_TYPE_OPTION,
-                ApiConstants.GlobalSetConstants.TYPE_LIFT));
+                ApiConstants.GlobalSetConstants.MT_TYPE_OPTION));
 
         /**
          * 名称:3.可同时签到保养的台量
@@ -56,8 +54,7 @@ public class GlobalSetServiceImpl extends ServiceImpl<GlobalSetMapper, GlobalSet
          */
         globalSetList.add(new GlobalSet(companyId,
                 1,
-                ApiConstants.GlobalSetConstants.MT_SAME_UNITS,
-                ApiConstants.GlobalSetConstants.TYPE_LIFT));
+                ApiConstants.GlobalSetConstants.MT_SAME_UNITS));
 
         /**
          * 名称:4.签退时,是否需要定位
@@ -68,8 +65,7 @@ public class GlobalSetServiceImpl extends ServiceImpl<GlobalSetMapper, GlobalSet
          */
         globalSetList.add(new GlobalSet(companyId,
                 ApiConstants.GlobalSetConstants.VALUE_NO,
-                ApiConstants.GlobalSetConstants.SIGN_OUT_LOCATE,
-                ApiConstants.GlobalSetConstants.TYPE_LIFT));
+                ApiConstants.GlobalSetConstants.SIGN_OUT_LOCATE));
         /**
          * 名称:5.保养单是否显示停梯时间和恢复时间
          * 类型:电梯保养设置 值为2
@@ -79,8 +75,7 @@ public class GlobalSetServiceImpl extends ServiceImpl<GlobalSetMapper, GlobalSet
          */
         globalSetList.add(new GlobalSet(companyId,
                 ApiConstants.GlobalSetConstants.VALUE_NO,
-                ApiConstants.GlobalSetConstants.SHOW_LIFT_TIME,
-                ApiConstants.GlobalSetConstants.TYPE_LIFT));
+                ApiConstants.GlobalSetConstants.SHOW_LIFT_TIME));
         /**
          * 名称:6.默认维保间隔
          * 类型:电梯保养设置 值为2
@@ -89,8 +84,7 @@ public class GlobalSetServiceImpl extends ServiceImpl<GlobalSetMapper, GlobalSet
          */
         globalSetList.add(new GlobalSet(companyId,
                 15,
-                ApiConstants.GlobalSetConstants.MT_INTERVAL,
-                ApiConstants.GlobalSetConstants.TYPE_LIFT));
+                ApiConstants.GlobalSetConstants.MT_INTERVAL));
         /**
          * 名称:7.补录权限
          * 类型:电梯保养设置 值为2
@@ -100,8 +94,7 @@ public class GlobalSetServiceImpl extends ServiceImpl<GlobalSetMapper, GlobalSet
          */
         globalSetList.add(new GlobalSet(companyId,
                 ApiConstants.GlobalSetConstants.CLERK_ADD,
-                ApiConstants.GlobalSetConstants.ADD_AUTHORITY,
-                ApiConstants.GlobalSetConstants.TYPE_LIFT));
+                ApiConstants.GlobalSetConstants.ADD_AUTHORITY));
         this.saveBatch(globalSetList);
     }
 }