x1ongzhu 6 년 전
부모
커밋
889a2502bb

+ 2 - 0
src/main/java/com/izouma/walkchina/domain/UserInfo.java

@@ -129,4 +129,6 @@ public class UserInfo {
     private List<Authority> authorities;
 
     private Boolean isNew;
+
+    private Boolean authorized;
 }

+ 1 - 0
src/main/java/com/izouma/walkchina/security/WebSecurityConfig.java

@@ -62,6 +62,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
                     .antMatchers("/admin/**").permitAll()
                     .antMatchers("/orderNotify/**").permitAll()
                     .antMatchers("/order/logistic").permitAll()
+                    .antMatchers("/systemVariable/all").permitAll()
                     // all other requests need to be authenticated
                     .anyRequest().authenticated().and()
                     // make sure we use stateless session; session won't be used to

+ 2 - 0
src/main/java/com/izouma/walkchina/service/JourneyService.java

@@ -96,6 +96,7 @@ public class JourneyService {
                                                 .distance(directionResponse.getResult().getRoutes().get(0)
                                                                            .getDistance())
                                                 .progress(.0)
+                                                .currentSteps(0L)
                                                 .steps(Math.round(distance / AppConstants.STEP_TO_DISTANCE_RATE))
                                                 .award(BigDecimal
                                                            .valueOf(Math.round(distance * AppConstants.DISTANCE_TO_COIN_RATE)))
@@ -144,6 +145,7 @@ public class JourneyService {
                                             .distance(route.getDistance())
                                             .steps((long) (route.getDistance() / AppConstants.STEP_TO_DISTANCE_RATE))
                                             .progress(.0)
+                                            .currentSteps(0L)
                                             .polyline(route.getPolyline())
                                             .routeSteps(route.getSteps())
                                             .build();

+ 2 - 0
src/main/java/com/izouma/walkchina/service/UserInfoService.java

@@ -154,6 +154,7 @@ public class UserInfoService {
                                .price(AppConstants.MIN_PRICE)
                                .active(true)
                                .isNew(true)
+                               .authorized(true)
                                .authorities(Collections.singletonList(authorityRepository.findByName(AuthorityName.ROLE_USER)))
                                .build();
             uploadUserMarker(userInfo);
@@ -167,6 +168,7 @@ public class UserInfoService {
             userInfo.setCountry(wxUserInfo.getCountry());
             userInfo.setProvince(wxUserInfo.getProvince());
             userInfo.setCity(wxUserInfo.getCity());
+            userInfo.setAuthorized(true);
             uploadUserMarker(userInfo);
             userInfo = userInfoRepository.save(userInfo);
         }

+ 43 - 3
src/main/java/com/izouma/walkchina/web/SystemVariableController.java

@@ -1,17 +1,22 @@
 package com.izouma.walkchina.web;
 
 import com.izouma.walkchina.constant.AppConstants;
+import com.izouma.walkchina.domain.SystemVariable;
 import com.izouma.walkchina.dto.Result;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import com.izouma.walkchina.repo.SystemVariableRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
+import java.util.regex.Pattern;
 
 @RestController
 @RequestMapping("/systemVariable")
 public class SystemVariableController {
+    @Autowired
+    private SystemVariableRepository systemVariableRepository;
 
     @GetMapping("/conversionFactor")
     public Result getConversionFactor() {
@@ -20,4 +25,39 @@ public class SystemVariableController {
         map.put("DISTANCE_TO_COIN_RATE", AppConstants.DISTANCE_TO_COIN_RATE);
         return Result.ok(map);
     }
+
+    @GetMapping("/all")
+    public Result all() {
+        List<SystemVariable> list = systemVariableRepository.findAll();
+        Map<String, Object> map = new HashMap<>();
+        for (SystemVariable systemVariable : list) {
+            if (Pattern.matches("(?i)(true|false)", systemVariable.getValue())) {
+                map.put(systemVariable.getName(), Boolean.parseBoolean(systemVariable.getValue()));
+            } else if (Pattern.matches("\\d+", systemVariable.getValue())) {
+                map.put(systemVariable.getName(), Long.parseLong(systemVariable.getValue()));
+            } else if (Pattern.matches("\\d+\\.\\d+", systemVariable.getValue())) {
+                map.put(systemVariable.getName(), Double.parseDouble(systemVariable.getValue()));
+            } else {
+                map.put(systemVariable.getName(), systemVariable.getValue());
+            }
+        }
+        return Result.ok(map);
+    }
+
+    @PostMapping("/save")
+    public Result save(@RequestBody Map<String, String> body) {
+        body.forEach((name, value) -> {
+            SystemVariable systemVariable = systemVariableRepository.findByName(name);
+            if (systemVariable == null) {
+                systemVariable = SystemVariable.builder()
+                                               .name(name)
+                                               .value(value)
+                                               .build();
+            } else {
+                systemVariable.setValue(value);
+            }
+            systemVariableRepository.save(systemVariable);
+        });
+        return Result.ok();
+    }
 }

+ 5 - 0
src/main/walk-china-admin/src/router.js

@@ -61,6 +61,11 @@ const router = new Router({
                     name: 'orderEdit',
                     component: () => import(/* webpackChunkName: "orderEdit" */ './views/OrderEdit.vue'),
                 },
+                {
+                    path: '/config',
+                    name: 'config',
+                    component: () => import(/* webpackChunkName: "config" */ './views/Config.vue'),
+                },
             ],
         },
     ],

+ 51 - 0
src/main/walk-china-admin/src/views/Config.vue

@@ -0,0 +1,51 @@
+<template>
+    <div>
+        <el-form label-position="left" label-width="120px" size="small">
+            <el-form-item label="强制登录">
+                <el-switch v-model="config.forceLogin"></el-switch>
+            </el-form-item>
+            <el-form-item label="强制获取步数">
+                <el-switch v-model="config.forceGetSteps"></el-switch>
+            </el-form-item>
+            <el-form-item label="强制获取位置">
+                <el-switch v-model="config.forceGetLocation"></el-switch>
+            </el-form-item>
+            <el-form-item>
+                <el-button @click="save" type="primary">保存</el-button>
+            </el-form-item>
+        </el-form>
+    </div>
+</template>
+<script>
+export default {
+    data() {
+        return {
+            config: {},
+        };
+    },
+    created() {
+        this.$http.get('/systemVariable/all').then(res => {
+            if (res.success) {
+                this.config = res.data;
+            }
+        });
+    },
+    methods: {
+        save() {
+            this.$confirm('确认保存?', '提示')
+                .then(_ => {
+                    this.$axios.post('/systemVariable/save', this.config).then(res => {
+                        if (res.data.success) {
+                            this.$message.success('保存成功');
+                        } else {
+                            this.$message.error(res.error);
+                        }
+                    });
+                })
+                .catch();
+        },
+    },
+};
+</script>
+<style lang="less" scoped>
+</style>

+ 7 - 0
src/test/java/com/izouma/walkchina/CommonTest.java

@@ -30,6 +30,7 @@ import java.text.MessageFormat;
 import java.time.Instant;
 import java.time.ZoneId;
 import java.util.*;
+import java.util.regex.Pattern;
 import java.util.stream.Stream;
 
 public class CommonTest {
@@ -241,4 +242,10 @@ public class CommonTest {
         }
         System.out.println(i);
     }
+
+    @Test
+    public void testPattern() {
+        System.out.println(Pattern.matches("(?i)(true|false)", "False"));
+        System.out.println(Pattern.matches("\\d+|\\d\\.\\d+", ".1"));
+    }
 }