3 Коммиты eb27a93786 ... 1e3113951e

Автор SHA1 Сообщение Дата
  zhang 1e3113951e mybatis plus 插件测试 лет назад: 2
  zhang e9ae4d4dd9 Merge branch 'doudian' of http://git.semsx.com/zhangxiaoyu/baseJapi into doudian лет назад: 2
  zhang 5fe5afc8d5 mybatis plus 插件测试 лет назад: 2

+ 1 - 3
src/main/java/com/api/controller/ApiRegisterController.java

@@ -30,7 +30,7 @@ import java.util.Date;
30 30
  * @author Mark sunlightcs@gmail.com
31 31
  */
32 32
 @RestController
33
-@RequestMapping("/api")
33
+@RequestMapping("/apiRegister")
34 34
 @Api(tags="注册接口")
35 35
 public class ApiRegisterController {
36 36
     @Autowired
@@ -41,14 +41,12 @@ public class ApiRegisterController {
41 41
     public R register(@RequestBody RegisterForm form){
42 42
         //表单校验
43 43
         ValidatorUtils.validateEntity(form);
44
-
45 44
         UserEntity user = new UserEntity();
46 45
         user.setMobile(form.getMobile());
47 46
         user.setUsername(form.getMobile());
48 47
         user.setPassword(DigestUtils.sha256Hex(form.getPassword()));
49 48
         user.setCreateTime(new Date());
50 49
         userService.save(user);
51
-
52 50
         return R.ok();
53 51
     }
54 52
 }

+ 16 - 8
src/main/java/com/api/controller/ApiTestController.java

@@ -10,10 +10,14 @@ package com.api.controller;
10 10
 
11 11
 import com.api.dao.TokenDao;
12 12
 import com.api.service.DoudianTokenService;
13
+import com.api.service.TokenService;
13 14
 import com.common.utils.R;
14 15
 import com.api.annotation.Login;
15 16
 import com.api.annotation.LoginUser;
16 17
 import com.api.entity.UserEntity;
18
+import com.doudian.open.api.token_create.TokenCreateRequest;
19
+import com.doudian.open.core.DoudianOpClient;
20
+import com.doudian.open.core.GlobalConfig;
17 21
 import io.swagger.annotations.Api;
18 22
 import io.swagger.annotations.ApiOperation;
19 23
 import org.springframework.beans.factory.BeanFactory;
@@ -44,6 +48,8 @@ public class ApiTestController extends AbsctactController {
44 48
     @Autowired
45 49
     TokenDao tokenDao;
46 50
     @Autowired
51
+    TokenService tokenService;
52
+    @Autowired
47 53
     DoudianTokenService doudianTokenService;
48 54
     @Login
49 55
     @GetMapping("userInfo")
@@ -68,12 +74,14 @@ public class ApiTestController extends AbsctactController {
68 74
 //        return R.ok().put("msg", "无需token也能访问。。。");
69 75
         return R.ok().put( "无需token也能访问。。。");
70 76
     }
71
-    @GetMapping("douToken")
72
-    @ApiOperation("忽略Token验证测试")
73
-    public R douToken(HttpServletRequest request, HttpSession httpSession){
74
-//        doudianTokenService.getShopAccessToken(19855808L);
75
-        doudianTokenService.getAddressList(19855808L);
76
-//        return R.ok().put("msg", "无需token也能访问。。。");
77
-        return R.ok().put( "无需token也能访问。。。");
78
-    }
77
+
78
+//    @GetMapping("notToken")
79
+//    @ApiOperation("忽略Token验证测试")
80
+//    public R createToken(HttpServletRequest request, HttpSession httpSession){
81
+//        tokenService.testCreateToken(request);
82
+////        return R.ok().put("msg", "无需token也能访问。。。");
83
+//        return R.ok().put( "无需token也能访问。。。");
84
+//    }
85
+
86
+
79 87
 }

+ 14 - 0
src/main/java/com/api/dao/AccountMapper.java

@@ -0,0 +1,14 @@
1
+package com.api.dao;
2
+
3
+import com.api.entity.AccountEntity;
4
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
+import org.apache.ibatis.annotations.Mapper;
7
+import org.apache.ibatis.annotations.Param;
8
+
9
+@Mapper
10
+public interface AccountMapper extends BaseMapper<AccountEntity> {
11
+    Page<AccountEntity> getPageVO(
12
+            @Param("page") Page<AccountEntity> page,
13
+            @Param("dep_id") Integer depId);
14
+}

+ 18 - 0
src/main/java/com/api/entity/AccountEntity.java

@@ -0,0 +1,18 @@
1
+package com.api.entity;
2
+
3
+import com.baomidou.mybatisplus.annotation.TableField;
4
+import com.baomidou.mybatisplus.annotation.TableId;
5
+import com.baomidou.mybatisplus.annotation.TableName;
6
+import lombok.Data;
7
+
8
+@Data
9
+@TableName("account")
10
+public class AccountEntity {
11
+    @TableId("id")
12
+    private Integer id;
13
+    // tableField 表示将数据库中的字段映射为实体中的属性
14
+    @TableField("user_name")
15
+    private String userName;
16
+    private Double balance;
17
+    private Integer depId;
18
+}

+ 7 - 0
src/main/java/com/api/service/AccountService.java

@@ -0,0 +1,7 @@
1
+package com.api.service;
2
+
3
+import com.api.entity.AccountEntity;
4
+import com.baomidou.mybatisplus.extension.service.IService;
5
+
6
+public interface AccountService extends IService<AccountEntity> {
7
+}

+ 4 - 0
src/main/java/com/api/service/TokenService.java

@@ -11,6 +11,8 @@ package com.api.service;
11 11
 import com.baomidou.mybatisplus.extension.service.IService;
12 12
 import com.api.entity.TokenEntity;
13 13
 
14
+import javax.servlet.http.HttpServletRequest;
15
+
14 16
 /**
15 17
  * 用户Token
16 18
  *
@@ -33,4 +35,6 @@ public interface TokenService extends IService<TokenEntity> {
33 35
 	 */
34 36
 	void expireToken(long userId);
35 37
 
38
+	void testCreateToken(HttpServletRequest httpServletRequest);
39
+
36 40
 }

+ 11 - 0
src/main/java/com/api/service/impl/AccountServiceImpl.java

@@ -0,0 +1,11 @@
1
+package com.api.service.impl;
2
+
3
+import com.api.dao.AccountMapper;
4
+import com.api.entity.AccountEntity;
5
+import com.api.service.AccountService;
6
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7
+import org.springframework.stereotype.Service;
8
+
9
+@Service
10
+public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountEntity> implements AccountService {
11
+}

+ 25 - 0
src/main/java/com/api/service/impl/TokenServiceImpl.java

@@ -13,8 +13,16 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
13 13
 import com.api.dao.TokenDao;
14 14
 import com.api.entity.TokenEntity;
15 15
 import com.api.service.TokenService;
16
+import com.doudian.open.core.DoudianOpSpi;
17
+import com.doudian.open.core.DoudianOpSpiBizHandler;
18
+import com.doudian.open.core.DoudianOpSpiContext;
19
+import com.doudian.open.core.GlobalConfig;
20
+import com.doudian.open.spi.demo_spi.DemoSpiRequest;
21
+import com.doudian.open.spi.demo_spi.data.DemoSpiData;
22
+import com.doudian.open.spi.demo_spi.param.DemoSpiParam;
16 23
 import org.springframework.stereotype.Service;
17 24
 
25
+import javax.servlet.http.HttpServletRequest;
18 26
 import java.util.Date;
19 27
 import java.util.UUID;
20 28
 
@@ -63,6 +71,23 @@ public class TokenServiceImpl extends ServiceImpl<TokenDao, TokenEntity> impleme
63 71
 		this.saveOrUpdate(tokenEntity);
64 72
 	}
65 73
 
74
+	@Override
75
+	public void testCreateToken(HttpServletRequest httpServletRequest) {
76
+		GlobalConfig.initAppKey("7090080248619877901");
77
+		GlobalConfig.initAppSecret("a4d9d3e6-aa69-4f0c-bffa-be4039e74262");
78
+		String s = DoudianOpSpi.config(DemoSpiRequest.class, this.bizHandler, httpServletRequest).responseJson();
79
+
80
+	}
81
+	private final DoudianOpSpiBizHandler bizHandler = new DoudianOpSpiBizHandler() {
82
+		public void handle(DoudianOpSpiContext context) {
83
+			DemoSpiParam param = (DemoSpiParam)context.getParam();
84
+			DemoSpiData data = (DemoSpiData)context.getData();
85
+			context.wrapSuccess();
86
+			context.wrapError(100002L, "系统错误");
87
+		}
88
+	};
89
+
90
+
66 91
 	private String generateToken(){
67 92
 		return UUID.randomUUID().toString().replace("-", "");
68 93
 	}

+ 2 - 2
src/main/resources/application-dev.yml

@@ -5,9 +5,9 @@ spring:
5 5
     type: com.alibaba.druid.pool.DruidDataSource
6 6
     druid:
7 7
       driver-class-name: com.mysql.cj.jdbc.Driver
8
-      url: jdbc:mysql://192.168.50.132:3306/sczn_eshop_test?zeroDateTimeBehavior=convertToNull&useUnicode=true&autoReconnect=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
8
+      url: jdbc:mysql://localhost:3306/test?zeroDateTimeBehavior=convertToNull&useUnicode=true&autoReconnect=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
9 9
       username: root
10
-      password: 123456
10
+      password:
11 11
       initial-size: 10
12 12
       max-active: 100
13 13
       min-idle: 10

+ 1 - 1
src/main/resources/application.yml

@@ -41,7 +41,7 @@ doudian:
41 41
 mybatis-plus:
42 42
   mapper-locations: classpath*:/mapper/**/*.xml
43 43
   #实体扫描,多个package用逗号或者分号分隔
44
-  typeAliasesPackage: com.api.*.entity
44
+  typeAliasesPackage: com.api.entity
45 45
   global-config:
46 46
     #数据库相关配置
47 47
     db-config:

+ 1 - 1
src/main/resources/logback-spring.xml

@@ -8,7 +8,7 @@
8 8
     <springProfile name="dev,test">
9 9
         <logger name="org.springframework.web" level="INFO"/>
10 10
         <logger name="org.springboot.sample" level="INFO" />
11
-        <logger name="io.renren" level="DEBUG" />
11
+        <logger name="com.api.dao" level="DEBUG" />
12 12
     </springProfile>
13 13
 
14 14
     <!-- 生产环境 -->

+ 8 - 0
src/main/resources/mapper/AccountMapper.xml

@@ -0,0 +1,8 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+
4
+<mapper namespace="com.api.dao.AccountMapper">
5
+    <select id="getPageVO" resultType="AccountEntity">
6
+        select id,user_name,balance,dep_id from account where dep_id = #{dep_id}
7
+    </select>
8
+</mapper>

+ 59 - 0
src/main/test/java/com/api/MybatisPlusTest.java

@@ -0,0 +1,59 @@
1
+package com.api;
2
+
3
+import com.api.dao.AccountMapper;
4
+import com.api.entity.AccountEntity;
5
+import com.api.service.AccountService;
6
+import com.api.service.UserService;
7
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
8
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
9
+import com.baomidou.mybatisplus.core.metadata.IPage;
10
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
11
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
12
+import org.junit.Test;
13
+import org.junit.runner.RunWith;
14
+import org.springframework.beans.factory.annotation.Autowired;
15
+import org.springframework.boot.test.context.SpringBootTest;
16
+import org.springframework.test.context.junit4.SpringRunner;
17
+
18
+import java.util.List;
19
+
20
+@RunWith(SpringRunner.class)
21
+@SpringBootTest
22
+public class MybatisPlusTest {
23
+    @Autowired
24
+    AccountMapper accountMapper;
25
+    @Autowired
26
+    AccountService accountService;
27
+    @Test
28
+    public void test1() {
29
+        QueryWrapper<AccountEntity> accountEntityQueryWrapper = new QueryWrapper<>();
30
+        accountEntityQueryWrapper.eq("id",16);
31
+        AccountEntity accountEntity = accountMapper.selectOne(accountEntityQueryWrapper);
32
+    }
33
+    @Test
34
+    public void test2() {
35
+//        StringUtils.isNotBlank()
36
+        // 使用lambdaWrapper
37
+        LambdaQueryWrapper<AccountEntity> accountEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
38
+        accountEntityLambdaQueryWrapper.eq(AccountEntity::getDepId,1);
39
+        List<AccountEntity> list = accountService.list(accountEntityLambdaQueryWrapper);
40
+    }
41
+    @Test
42
+    public void testPage() {
43
+        Page<AccountEntity> accountEntityPage = new Page<>();
44
+        accountEntityPage.setCurrent(2);
45
+        accountEntityPage.setSize(2);
46
+        LambdaQueryWrapper<AccountEntity> accountEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
47
+        accountEntityLambdaQueryWrapper.eq(AccountEntity::getDepId,1);
48
+        IPage<AccountEntity> page = accountService.page(accountEntityPage, accountEntityLambdaQueryWrapper);
49
+    }
50
+    @Test
51
+    public void testMapperPage() {
52
+        Page<AccountEntity> accountEntityPage = new Page<>();
53
+        accountEntityPage.setCurrent(2);
54
+        accountEntityPage.setSize(2);
55
+        accountEntityPage = accountMapper.getPageVO(accountEntityPage, 1);
56
+    }
57
+
58
+
59
+}