shikeyin
2024-01-11 65da8373531677b1c37a98f53eaa30c892f35e5a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package com.iplatform.api;
 
import com.iplatform.base.PushController;
import com.iplatform.base.PushData;
import com.iplatform.base.service.UserServiceImpl;
import com.iplatform.model.po.S_user_core;
import com.walker.db.page.GenericPager;
import com.walker.infrastructure.utils.DateUtils;
import com.walker.infrastructure.utils.JsonUtils;
import com.walker.web.ResponseValue;
import com.walker.web.WebRuntimeException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.security.core.parameters.P;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
 
@RestController
@RequestMapping("/test/web")
public class TestWebController extends PushController {
 
//    private SchedulerServiceImpl schedulerService;
    private JdbcTemplate jdbcTemplate;
    private UserServiceImpl userService;
 
    @Autowired
    public TestWebController(JdbcTemplate jdbcTemplate, UserServiceImpl userService){
//        this.schedulerService = schedulerService;
        this.jdbcTemplate = jdbcTemplate;
        this.userService = userService;
    }
 
    @RequestMapping("/push_msg")
    public ResponseValue testPushMessage() throws Exception{
 
        PushData pushData = new PushData();
        pushData.setTitle("审批文件事项");
        pushData.setBusinessType("001");
        pushData.setBusinessId("123456789");
        pushData.setUserId("1");    // shikeying
 
        this.pushMessageNotification(pushData);
        logger.info("----------- 'msg' end -----------");
 
        TimeUnit.SECONDS.sleep(2);
 
        this.pushMailNotification("测试标题", "你好!这是一个邮件信息", "1");
        logger.info("----------- 'mail' end -----------");
        return ResponseValue.success();
    }
 
    @Transactional
    @RequestMapping("/rollback")
    public ResponseValue<String> testTransactionRollback(String error){
        // 更新记录: 1
        this.jdbcTemplate.execute("update s_scheduler set status=2 where id=1");
        if(error != null && error.equals("true")){
            throw new WebRuntimeException("业务异常,回滚", "data");
        }
        // 更新记录: 2
        this.jdbcTemplate.execute("update s_scheduler set status=2 where id=2");
        return ResponseValue.success();
    }
 
    @RequestMapping("/po")
    public ResponseValue testPoJson() throws Exception{
        S_user_core user_core = new S_user_core();
        user_core.setId(123L);
        user_core.setUser_name("时克英");
        user_core.setUpdate_time(20230324103901L);
        String json = JsonUtils.objectToJsonString(user_core);
//        JsonUtils
        return ResponseValue.success(json);
    }
 
    @RequestMapping("/jdbc")
    public ResponseValue testJdbc(){
 
        // 批量添加
//        List<S_user_core> user_coreList = new ArrayList<>(8);
//        user_coreList.add(this.createOneUser(100));
//        user_coreList.add(this.createOneUser(101));
//        user_coreList.add(this.createOneUser(102));
//        int success = this.userService.insertBatch(user_coreList);
//        System.out.println("--------> 批量写入新用户: " + success);
//
//        List<S_user_core> editList = new ArrayList<>(4);
//        S_user_core edit100 = new S_user_core();
//        edit100.setId(100L);
//        edit100.setNick_name("修改名字100");
//        S_user_core edit101 = new S_user_core();
//        edit101.setId(101L);
//        edit101.setNick_name("修改名字101");
//        editList.add(edit100);
//        editList.add(edit101);
//        success = this.userService.updateBatch(editList);
//        System.out.println("--------> 批量更新用户(相同属性): " + success);
 
        S_user_core selectPo = new S_user_core();
        selectPo.setStatus(0);
        selectPo.setDept_id(1670057808440L);
//        selectPo.setUser_name("login_%");
        selectPo.setUser_name("13838277463");
        List<S_user_core> list = this.userService.select(selectPo);
        if(list != null){
            for(S_user_core user : list){
                System.out.println(user);
            }
        }
        System.out.println("--------> 搜索用户集合: ");
 
        S_user_core userPo = new S_user_core();
        userPo.setUser_type(2);
//        userPo.setDept_id(1670057686025L);
        GenericPager<S_user_core> pager = this.userService.selectSplit(userPo, 2, 6);
        for(S_user_core s : pager.getDatas()){
            System.out.println("------- 用户:" + s.getNick_name());
        }
        return ResponseValue.success();
    }
 
    private S_user_core createOneUser(long id){
        S_user_core user = new S_user_core();
        user.setId(id);
        user.setCreate_by("insertBatch");
        user.setCreate_time(DateUtils.getDateTimeNumber());
        user.setUser_name("login_" + id);
        user.setNick_name("姓名_" + id);
        user.setUser_type(2);
        user.setOrg_id(1670031584892L);
        user.setDept_id(1670057808440L);
        user.setPassword("$2a$10$9lSwwUFMULR6/KhPsUbTj.0PTZfTnq0fB3OtS6PWoKAibpa8hL1cy");
        return user;
    }
}