Преглед на файлове

小程序相关业务开发

潘海瑞 преди 10 месеца
родител
ревизия
3aab1debd0
променени са 19 файла, в които са добавени 534 реда и са изтрити 1 реда
  1. 8 0
      sky-server/src/main/java/com/sky/config/WebMvcConfiguration.java
  2. 24 1
      sky-server/src/main/java/com/sky/controller/admin/DishController.java
  3. 33 0
      sky-server/src/main/java/com/sky/controller/user/CategoryController.java
  4. 53 0
      sky-server/src/main/java/com/sky/controller/user/DishController.java
  5. 54 0
      sky-server/src/main/java/com/sky/controller/user/SetmealController.java
  6. 55 0
      sky-server/src/main/java/com/sky/controller/user/UserController.java
  7. 61 0
      sky-server/src/main/java/com/sky/interceptor/JwtTokenUserIterceptor.java
  8. 19 0
      sky-server/src/main/java/com/sky/mapper/SetmealMapper.java
  9. 24 0
      sky-server/src/main/java/com/sky/mapper/UserMapper.java
  10. 7 0
      sky-server/src/main/java/com/sky/service/DishService.java
  11. 16 0
      sky-server/src/main/java/com/sky/service/SetmealService.java
  12. 14 0
      sky-server/src/main/java/com/sky/service/UserService.java
  13. 26 0
      sky-server/src/main/java/com/sky/service/impl/DishServiceImpl.java
  14. 22 0
      sky-server/src/main/java/com/sky/service/impl/SetmealServiceImpl.java
  15. 83 0
      sky-server/src/main/java/com/sky/service/impl/UserServiceImp.java
  16. 3 0
      sky-server/src/main/resources/application-dev.yml
  17. 6 0
      sky-server/src/main/resources/application.yml
  18. 15 0
      sky-server/src/main/resources/mapper/SetmealMapper.xml
  19. 11 0
      sky-server/src/main/resources/mapper/UserMapper.xml

+ 8 - 0
sky-server/src/main/java/com/sky/config/WebMvcConfiguration.java

@@ -1,6 +1,7 @@
 package com.sky.config;
 
 import com.sky.interceptor.JwtTokenAdminInterceptor;
+import com.sky.interceptor.JwtTokenUserIterceptor;
 import com.sky.json.JacksonObjectMapper;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -29,6 +30,8 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
 
     @Autowired
     private JwtTokenAdminInterceptor jwtTokenAdminInterceptor;
+    @Autowired
+    private JwtTokenUserIterceptor jwtTokenUserIterceptor;
 
     /**
      * 注册自定义拦截器
@@ -40,6 +43,11 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
         registry.addInterceptor(jwtTokenAdminInterceptor)
                 .addPathPatterns("/admin/**")
                 .excludePathPatterns("/admin/employee/login");
+
+        registry.addInterceptor(jwtTokenUserIterceptor)
+                .addPathPatterns("/user/**")
+                .excludePathPatterns("/user/user/login")
+                .excludePathPatterns("/user/user/status");
     }
 
     /**

+ 24 - 1
sky-server/src/main/java/com/sky/controller/admin/DishController.java

@@ -9,19 +9,23 @@ import com.sky.service.DishService;
 import com.sky.vo.DishVO;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
+import java.util.Set;
 
 /**
  * 菜品管理
  */
-@RestController
+@RestController("adminDishController")
 @RequestMapping("/admin/dish")
 @Slf4j
 public class DishController {
     @Autowired
     private DishService dishService;
+    @Autowired
+    private RedisTemplate redisTemplate;
     /**
      * 添加菜品
      * @param dishDTO
@@ -31,6 +35,9 @@ public class DishController {
     public Result save(@RequestBody DishDTO dishDTO){
         log.info("新增菜品:{}",dishDTO);
         dishService.saveWithFlavor(dishDTO);
+        //清理缓存数据
+        String key = "dish" + dishDTO.getCategoryId();
+        cleanCache(key);
         return Result.success();
     }
 
@@ -54,6 +61,8 @@ public class DishController {
     @DeleteMapping
     public Result delete(@RequestParam List<Long> ids){
         log.info("批量删除菜品{}",ids);
+        //将所有菜品缓存数据清理掉,所有以dish_开头的key
+        cleanCache("dish*");
         dishService.deleteBatch(ids);
         return Result.success();
     }
@@ -79,6 +88,9 @@ public class DishController {
     public Result update(@RequestBody DishDTO dishDTO){
         log.info("修改菜品信息{}",dishDTO);
         dishService.updateWithFlavor(dishDTO);
+
+        //将所有菜品缓存数据清理掉,所有以dish_开头的key
+        cleanCache("dish*");
         return Result.success();
     }
 
@@ -92,6 +104,9 @@ public class DishController {
     public Result isSole(@PathVariable Integer status,Long id){
         log.info("菜品起售停售:{}{}",status,id);
         dishService.isSole(status,id);
+
+        //将所有菜品缓存数据清理掉,所有以dish_开头的key
+        cleanCache("dish*");
         return Result.success();
     }
 
@@ -107,4 +122,12 @@ public class DishController {
 
         return Result.success(list);
     }
+
+    /**
+     * 清理缓存数据
+     */
+    private void cleanCache(String patten){
+        Set keys = redisTemplate.keys(patten);
+        redisTemplate.delete(keys);
+    }
 }

+ 33 - 0
sky-server/src/main/java/com/sky/controller/user/CategoryController.java

@@ -0,0 +1,33 @@
+package com.sky.controller.user;
+
+import com.sky.entity.Category;
+import com.sky.result.Result;
+import com.sky.service.CategoryService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+@RestController("userCategoryController")
+@RequestMapping("/user/category")
+@Slf4j
+public class CategoryController {
+    @Autowired
+    private CategoryService categoryService;
+
+    /**
+     * 查询分类
+     * @param type
+     * @return
+     */
+    @GetMapping("/list")
+    public Result<List<Category>> list(Integer type){
+
+        List<Category> list = categoryService.list(type);
+
+        return Result.success(list);
+    }
+}

+ 53 - 0
sky-server/src/main/java/com/sky/controller/user/DishController.java

@@ -0,0 +1,53 @@
+package com.sky.controller.user;
+
+import com.sky.constant.StatusConstant;
+import com.sky.entity.Dish;
+import com.sky.result.Result;
+import com.sky.service.DishService;
+import com.sky.vo.DishVO;
+import io.swagger.annotations.Api;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+@RestController("UserDishController")
+@RequestMapping("/user/dish")
+@Slf4j
+
+public class DishController {
+
+    @Autowired
+    private DishService dishService;
+    @Autowired
+    private RedisTemplate redisTemplate;
+    /**
+     * 查询菜品分类
+     * @param categoryId
+     * @return
+     */
+    @GetMapping("/list")
+    public Result<List<DishVO>> list(Long categoryId){
+        //构造redis中的key,规则:dish_分类id
+        String key = "dish" + categoryId;
+        List<DishVO> list = (List<DishVO>) redisTemplate.opsForValue().get(key);//存进去什么类型,取出来就是什么类型
+        if (list != null && list.size() > 0){
+            //如果存在,直接返回无需查询页面
+            return Result.success(list);
+        }
+
+        Dish dish = new Dish();
+        dish.setCategoryId(categoryId);
+        dish.setStatus(StatusConstant.ENABLE);
+
+        //如果不存在,查询数据库,将查询到的数据放到redis
+        list = dishService.listWithFlavor(dish);
+        redisTemplate.opsForValue().set(key,list);
+
+        return Result.success(list);
+    }
+}

+ 54 - 0
sky-server/src/main/java/com/sky/controller/user/SetmealController.java

@@ -0,0 +1,54 @@
+package com.sky.controller.user;
+
+import com.sky.constant.StatusConstant;
+import com.sky.entity.Setmeal;
+import com.sky.result.Result;
+import com.sky.service.SetmealService;
+import com.sky.vo.DishItemVO;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+@RestController("userSetmealController")
+@RequestMapping("/user/setmeal")
+@Slf4j
+public class SetmealController {
+    @Autowired
+    private SetmealService setmealService;
+
+    /**
+     * 条件查询
+     *
+     * @param categoryId
+     * @return
+     */
+    @GetMapping("/list")
+    @ApiOperation("根据分类id查询套餐")
+    public Result<List<Setmeal>> list(Long categoryId) {
+        Setmeal setmeal = new Setmeal();
+        setmeal.setCategoryId(categoryId);
+        setmeal.setStatus(StatusConstant.ENABLE);
+
+        List<Setmeal> list = setmealService.list(setmeal);
+        return Result.success(list);
+    }
+
+    /**
+     * 根据套餐id查询包含的菜品列表
+     *
+     * @param id
+     * @return
+     */
+    @GetMapping("/dish/{id}")
+    @ApiOperation("根据套餐id查询包含的菜品列表")
+    public Result<List<DishItemVO>> dishList(@PathVariable("id") Long id) {
+        List<DishItemVO> list = setmealService.getDishItemById(id);
+        return Result.success(list);
+    }
+}

+ 55 - 0
sky-server/src/main/java/com/sky/controller/user/UserController.java

@@ -0,0 +1,55 @@
+package com.sky.controller.user;
+
+import com.sky.constant.JwtClaimsConstant;
+import com.sky.dto.UserLoginDTO;
+import com.sky.entity.User;
+import com.sky.properties.JwtProperties;
+import com.sky.result.Result;
+import com.sky.service.UserService;
+import com.sky.utils.JwtUtil;
+import com.sky.vo.UserLoginVO;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@RestController
+@RequestMapping("/user/user")
+@Slf4j
+public class UserController {
+
+    @Autowired
+    private UserService userService;
+    @Autowired
+    private JwtProperties jwtProperties;
+
+    /**
+     * 用户微信登录
+     * @param userLoginDTO
+     * @return
+     */
+    @PostMapping("/login")
+    public Result<UserLoginVO> login(@RequestBody UserLoginDTO userLoginDTO){
+        log.info("用户微信登录:",userLoginDTO.getCode());
+
+        //微信登录
+        User user = userService.wxLogin(userLoginDTO);
+
+        //为微信用户添加JWT令牌
+        Map<String, Object> claims = new HashMap<>();
+        claims.put(JwtClaimsConstant.USER_ID,user.getId());
+        String token = JwtUtil.createJWT(jwtProperties.getUserSecretKey(),jwtProperties.getUserTtl(),claims);
+
+        UserLoginVO userLoginVO = UserLoginVO.builder()
+                .id(user.getId())
+                .openid(user.getOpenid())
+                .token(token)
+                .build();
+        return Result.success(userLoginVO);
+    }
+}

+ 61 - 0
sky-server/src/main/java/com/sky/interceptor/JwtTokenUserIterceptor.java

@@ -0,0 +1,61 @@
+package com.sky.interceptor;
+
+import com.sky.constant.JwtClaimsConstant;
+import com.sky.context.BaseContext;
+import com.sky.properties.JwtProperties;
+import com.sky.utils.JwtUtil;
+import io.jsonwebtoken.Claims;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.web.method.HandlerMethod;
+import org.springframework.web.servlet.HandlerInterceptor;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * jwt令牌校验的拦截器
+ */
+@Component
+@Slf4j
+public class JwtTokenUserIterceptor implements HandlerInterceptor {
+
+    @Autowired
+    private JwtProperties jwtProperties;
+
+    /**
+     * 校验jwt
+     *
+     * @param request
+     * @param response
+     * @param handler
+     * @return
+     * @throws Exception
+     */
+    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+        //判断当前拦截到的是Controller的方法还是其他资源
+        if (!(handler instanceof HandlerMethod)) {
+            //当前拦截到的不是动态方法,直接放行
+            return true;
+        }
+
+        //1、从请求头中获取令牌
+        String token = request.getHeader(jwtProperties.getUserTokenName());
+
+        //2、校验令牌
+        try {
+            log.info("jwt校验:{}", token);
+            Claims claims = JwtUtil.parseJWT(jwtProperties.getUserSecretKey(), token);
+            Long userId = Long.valueOf(claims.get(JwtClaimsConstant.USER_ID).toString());
+            log.info("当前用户id:", userId);
+            BaseContext.setCurrentId(userId);
+            //3、通过,放行
+            return true;
+        } catch (Exception ex) {
+            //4、不通过,响应401状态码
+            response.setStatus(401);
+            return false;
+        }
+    }
+}

+ 19 - 0
sky-server/src/main/java/com/sky/mapper/SetmealMapper.java

@@ -6,12 +6,15 @@ import com.sky.dto.SetmealPageQueryDTO;
 import com.sky.entity.Setmeal;
 import com.sky.enumeration.OperationType;
 import com.sky.result.Result;
+import com.sky.vo.DishItemVO;
 import com.sky.vo.SetmealVO;
 import org.apache.ibatis.annotations.Delete;
 import org.apache.ibatis.annotations.Insert;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Select;
 
+import java.util.List;
+
 @Mapper
 public interface SetmealMapper {
 
@@ -59,4 +62,20 @@ public interface SetmealMapper {
     @AutoFill(value = OperationType.UPDATE)
     void update(Setmeal setmeal);
 
+    /**
+     * 条件查询
+     * @param setmeal
+     * @return
+     */
+    List<Setmeal> list(Setmeal setmeal);
+
+    /**
+     * 根据套餐id查询菜品选项
+     * @param setmealId
+     * @return
+     */
+    @Select("select sd.name, sd.copies, d.image, d.description " +
+            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
+            "where sd.setmeal_id = #{setmealId}")
+    List<DishItemVO> getDishItemBySetmealId(Long setmealId);
 }

+ 24 - 0
sky-server/src/main/java/com/sky/mapper/UserMapper.java

@@ -0,0 +1,24 @@
+package com.sky.mapper;
+
+import com.sky.entity.User;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Select;
+
+@Mapper
+public interface UserMapper {
+
+    /**
+     * 根据openid查询是否有用户
+     * @param openid
+     * @return
+     */
+    @Select("select * from user where openid = #{openid}")
+    User getById(String openid);
+
+
+    /**
+     * 主动插入数据
+     * @param user
+     */
+    void insert(User user);
+}

+ 7 - 0
sky-server/src/main/java/com/sky/service/DishService.java

@@ -56,4 +56,11 @@ public interface DishService {
      * @return
      */
     List<Dish> list(Long categoryId);
+
+    /**
+     * 条件查询菜品和口味
+     * @param dish
+     * @return
+     */
+    List<DishVO> listWithFlavor(Dish dish);
 }

+ 16 - 0
sky-server/src/main/java/com/sky/service/SetmealService.java

@@ -2,7 +2,9 @@ package com.sky.service;
 
 import com.sky.dto.SetmealDTO;
 import com.sky.dto.SetmealPageQueryDTO;
+import com.sky.entity.Setmeal;
 import com.sky.result.PageResult;
+import com.sky.vo.DishItemVO;
 import com.sky.vo.SetmealVO;
 
 import java.util.List;
@@ -46,4 +48,18 @@ public interface SetmealService {
      * @param id
      */
     void startOrStop(Integer status, Long id);
+
+    /**
+     * 条件查询
+     * @param setmeal
+     * @return
+     */
+    List<Setmeal> list(Setmeal setmeal);
+
+    /**
+     * 根据套餐id查询包含的菜品列表
+     * @param id
+     * @return
+     */
+    List<DishItemVO> getDishItemById(Long id);
 }

+ 14 - 0
sky-server/src/main/java/com/sky/service/UserService.java

@@ -0,0 +1,14 @@
+package com.sky.service;
+
+import com.sky.dto.UserLoginDTO;
+import com.sky.entity.User;
+
+public interface UserService {
+
+    /**
+     * 微信登录
+     * @param userLoginDTO
+     * @return
+     */
+    User wxLogin(UserLoginDTO userLoginDTO);
+}

+ 26 - 0
sky-server/src/main/java/com/sky/service/impl/DishServiceImpl.java

@@ -21,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.ArrayList;
 import java.util.List;
 
 @Service
@@ -169,5 +170,30 @@ public class DishServiceImpl implements DishService {
         return dishMapper.list(dish);
     }
 
+    /**
+     * 条件查询菜品和口味
+     * @param dish
+     * @return
+     */
+    @Override
+    public List<DishVO> listWithFlavor(Dish dish) {
+        List<Dish> dishList = dishMapper.list(dish);
+
+        List<DishVO> dishVOList = new ArrayList<>();
+
+        for (Dish d : dishList) {
+            DishVO dishVO = new DishVO();
+            BeanUtils.copyProperties(d,dishVO);
+
+            //根据菜品id查询对应的口味
+            List<DishFlavor> flavors = dishFlavorsMapper.getByDishId(d.getId());
+
+            dishVO.setFlavors(flavors);
+            dishVOList.add(dishVO);
+        }
+
+        return dishVOList;
+    }
+
 
 }

+ 22 - 0
sky-server/src/main/java/com/sky/service/impl/SetmealServiceImpl.java

@@ -16,6 +16,7 @@ import com.sky.mapper.SetmealDishMapper;
 import com.sky.mapper.SetmealMapper;
 import com.sky.result.PageResult;
 import com.sky.service.SetmealService;
+import com.sky.vo.DishItemVO;
 import com.sky.vo.SetmealVO;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
@@ -172,4 +173,25 @@ public class SetmealServiceImpl implements SetmealService {
                 .build();
         setmealMapper.update(setmeal);
     }
+
+    /**
+     * 条件查询
+     * @param setmeal
+     * @return
+     */
+    @Override
+    public List<Setmeal> list(Setmeal setmeal) {
+        List<Setmeal> list = setmealMapper.list(setmeal);
+        return list;
+    }
+
+    /**
+     * 根据id查询菜品选项
+     * @param id
+     * @return
+     */
+    @Override
+    public List<DishItemVO> getDishItemById(Long id) {
+        return setmealMapper.getDishItemBySetmealId(id);
+    }
 }

+ 83 - 0
sky-server/src/main/java/com/sky/service/impl/UserServiceImp.java

@@ -0,0 +1,83 @@
+package com.sky.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.sky.constant.MessageConstant;
+import com.sky.dto.UserLoginDTO;
+import com.sky.entity.User;
+import com.sky.exception.LoginFailedException;
+import com.sky.mapper.UserMapper;
+import com.sky.properties.WeChatProperties;
+import com.sky.service.UserService;
+import com.sky.utils.HttpClientUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.time.LocalDateTime;
+import java.util.HashMap;
+import java.util.Map;
+
+@Service
+@Slf4j
+public class UserServiceImp implements UserService {
+
+    @Autowired
+    private UserMapper userMapper;
+    //微信服务接口地址
+    public static final String WX_LOGIN = "https://api.weixin.qq.com/sns/jscode2session";
+
+    @Autowired
+    private WeChatProperties weChatProperties;
+
+
+    /**
+     * 微信登陆
+     * @param userLoginDTO
+     * @return
+     */
+    @Override
+    public User wxLogin(UserLoginDTO userLoginDTO) {
+
+
+        String openid = getOpenId(userLoginDTO.getCode());
+
+        //判断openid是否为空,如果为空表示登陆失败,抛出业务异常
+        if (openid == null){
+            throw new LoginFailedException(MessageConstant.LOGIN_FAILED);
+        }
+
+        //判断当前用户是否为新用户
+        User user =  userMapper.getById(openid);
+
+        //如果是新用户,则自动完成注册
+        if (user == null){
+            //自己构造用户信息
+            user = User.builder()
+                    .openid(openid)
+                    .createTime(LocalDateTime.now())
+                    .build();
+            userMapper.insert(user);
+        }
+        return user;
+    }
+
+    /**
+     * 调用微信接口服务,获取微信用户的openid
+     * @param code
+     * @return
+     */
+    private String getOpenId(String code){
+        //调用微信接口服务,获得当前微信用户的openid
+        Map<String, String> map = new HashMap<>();
+        map.put("appid",weChatProperties.getAppid());
+        map.put("secret",weChatProperties.getSecret());
+        map.put("js_code",code);
+        map.put("grant_type","authorization_code");
+        String json = HttpClientUtil.doGet(WX_LOGIN,map);
+
+        JSONObject jsonObject = JSON.parseObject(json);//将数据转为json格式
+        String openid = jsonObject.getString("openid");
+        return openid;
+    }
+}

+ 3 - 0
sky-server/src/main/resources/application-dev.yml

@@ -16,3 +16,6 @@ sky:
     port: 6379
     password: 1234
     database: 10
+  wechat:
+    appid: wxf00d8b3f53a027a8
+    secret: c17c4c425b6a51cbdb573d2785b57c81

+ 6 - 0
sky-server/src/main/resources/application.yml

@@ -42,9 +42,15 @@ sky:
     admin-ttl: 43200000
     # 设置前端传递过来的令牌名称
     admin-token-name: token
+    user-secret-key: itheima
+    user-ttl: 43200000
+    user-token-name: authentication
 
   alioss:
     endpoint: ${sky.alioss.endpoint}
     access-key-id: ${sky.alioss.access-key-id}
     access-key-secret: ${sky.alioss.access-key-secret}
     bucket-name: ${sky.alioss.bucket-name}
+  wechat:
+    appid: ${sky.wechat.appid}
+    secret: ${sky.wechat.secret}

+ 15 - 0
sky-server/src/main/resources/mapper/SetmealMapper.xml

@@ -54,4 +54,19 @@
         </where>
         order by s.create_time desc
     </select>
+    <!--条件查询-->
+    <select id="list" resultType="com.sky.entity.Setmeal">
+        select * from setmeal
+        <where>
+            <if test="name != null">
+                and name like concat('%',#{name},'%')
+            </if>
+            <if test="categoryId != null">
+                and category_id = #{categoryId}
+            </if>
+            <if test="status != null">
+                and status = #{status}
+            </if>
+        </where>
+    </select>
 </mapper>

+ 11 - 0
sky-server/src/main/resources/mapper/UserMapper.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.sky.mapper.UserMapper">
+
+    <insert id="insert" useGeneratedKeys="true" keyProperty="id">
+        insert into user(openid, name, phone, sex, id_number, avatar, create_time)
+        VALUES
+            (#{openid},#{name},#{phone},#{sex},#{idNumber},#{avatar},#{createTime})
+    </insert>
+</mapper>