huwhois %!s(int64=4) %!d(string=hace) años
padre
commit
6454d6baa9
Se han modificado 22 ficheros con 647 adiciones y 205 borrados
  1. 30 0
      src/main/java/io/renren/common/utils/ConfigConstant.java
  2. 122 0
      src/main/java/io/renren/common/utils/HttpRequestUtil.java
  3. 67 0
      src/main/java/io/renren/common/utils/JsonUtils.java
  4. 30 81
      src/main/java/io/renren/modules/admin/controller/EmployeeController.java
  5. 4 6
      src/main/java/io/renren/modules/admin/controller/MemberController.java
  6. 9 5
      src/main/java/io/renren/modules/admin/dao/EmployeeDao.java
  7. 1 1
      src/main/java/io/renren/modules/admin/dao/MemberDao.java
  8. 20 2
      src/main/java/io/renren/modules/admin/entity/EmployeeEntity.java
  9. 2 2
      src/main/java/io/renren/modules/admin/entity/MemberEntity.java
  10. 19 15
      src/main/java/io/renren/modules/admin/service/EmployeeService.java
  11. 2 2
      src/main/java/io/renren/modules/admin/service/MemberService.java
  12. 69 11
      src/main/java/io/renren/modules/admin/service/impl/EmployeeServiceImpl.java
  13. 18 18
      src/main/java/io/renren/modules/admin/service/impl/MemberServiceImpl.java
  14. 32 21
      src/main/java/io/renren/modules/app/controller/AppRegisterController.java
  15. 40 0
      src/main/java/io/renren/modules/app/controller/SmsTestController.java
  16. 17 0
      src/main/java/io/renren/modules/app/dao/SmsCodeDao.java
  17. 41 0
      src/main/java/io/renren/modules/app/entity/SmsCodeEntity.java
  18. 13 0
      src/main/java/io/renren/modules/app/entity/SmsStatusEntity.java
  19. 5 23
      src/main/java/io/renren/modules/app/form/RegisterForm.java
  20. 38 0
      src/main/java/io/renren/modules/app/service/SmsCodeService.java
  21. 68 0
      src/main/java/io/renren/modules/app/service/impl/SmsCodeServiceImpl.java
  22. 0 18
      src/main/resources/mapper/admin/EmployeeDao.xml

+ 30 - 0
src/main/java/io/renren/common/utils/ConfigConstant.java

18
     * 云存储配置KEY
18
     * 云存储配置KEY
19
     */
19
     */
20
    public final static String CLOUD_STORAGE_CONFIG_KEY = "CLOUD_STORAGE_CONFIG_KEY";
20
    public final static String CLOUD_STORAGE_CONFIG_KEY = "CLOUD_STORAGE_CONFIG_KEY";
21
22
    /**
23
	 * 秒嘀短信平台url前半部分
24
	 */
25
	public static final String BASE_URL = "https://openapi.miaodiyun.com/distributor/sendSMS";
26
27
	/**
28
	 * 秒嘀短信平台开发者注册后系统自动生成的账号,可在官网登录后查看
29
	 */
30
	public static final String ACCOUNT_SID = "6f5c2612d691480a9bbbee0c64e10872";
31
32
	/**
33
	 * 秒嘀短信平台开发者注册后系统自动生成的TOKEN,可在官网登录后查看
34
	 */
35
	public static final String AUTH_TOKEN = "4fac48f2d37d4ba89cc037e7d012348e";
36
37
	
38
    /**
39
     * 秒嘀短信模板id
40
     */
41
    public static final String TEMPLATE_ID= "206770";
42
    /**
43
     * 短信过期时间(分钟)
44
     */
45
    public static final int EXPIRE_TIME = 5;
46
47
	/**
48
	 * http请求响应数据类型, JSON或XML
49
	 */
50
    public static final String RESP_DATA_TYPE = "JSON";
21
}
51
}

+ 122 - 0
src/main/java/io/renren/common/utils/HttpRequestUtil.java

1
package io.renren.common.utils;
2
3
import java.io.BufferedReader;
4
import java.io.IOException;
5
import java.io.InputStreamReader;
6
import java.io.OutputStreamWriter;
7
import java.net.URL;
8
import java.net.URLConnection;
9
10
import org.apache.commons.codec.digest.DigestUtils;
11
12
/**
13
 * http请求工具
14
 */
15
public class HttpRequestUtil {
16
    /**
17
     * 构造通用参数timestamp、sig和respDataType
18
     * 
19
     * @return
20
     */
21
    public static String createCommonParam(String sid,String token) {
22
        // 时间戳
23
        long timestamp = System.currentTimeMillis();
24
        // 签名
25
        String sig = DigestUtils.md5Hex(sid + token + timestamp);
26
27
        return "&timestamp=" + timestamp + "&sig=" + sig + "&respDataType=" + ConfigConstant.RESP_DATA_TYPE;
28
    }
29
30
    /**
31
     * post请求
32
     * 
33
     * @param url
34
     *            功能和操作
35
     * @param body
36
     *            要post的数据
37
     * @return
38
     * @throws IOException
39
     */
40
    public static String post(String url, String body) {
41
        System.out.println("body:" + System.lineSeparator() + body);
42
43
        String result = "";
44
        try {
45
            OutputStreamWriter out = null;
46
            BufferedReader in = null;
47
            URL realUrl = new URL(url);
48
            URLConnection conn = realUrl.openConnection();
49
50
            // 设置连接参数
51
            conn.setDoOutput(true);
52
            conn.setDoInput(true);
53
            conn.setConnectTimeout(5000);
54
            conn.setReadTimeout(20000);
55
            conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
56
            // 提交数据
57
            out = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
58
            out.write(body);
59
            out.flush();
60
61
            // 读取返回数据
62
            in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
63
            String line = "";
64
            boolean firstLine = true; // 读第一行不加换行符
65
            while ((line = in.readLine()) != null) {
66
                if (firstLine) {
67
                    firstLine = false;
68
                } else {
69
                    result += System.lineSeparator();
70
                }
71
                result += line;
72
            }
73
74
        } catch (Exception e) {
75
            e.printStackTrace();
76
        }
77
        return result;
78
    }
79
80
    /**
81
     * 回调测试工具方法
82
     * 
83
     * @param url
84
     * @return
85
     */
86
    public static String postHuiDiao(String url, String body) {
87
        String result = "";
88
        try {
89
            OutputStreamWriter out = null;
90
            BufferedReader in = null;
91
            URL realUrl = new URL(url);
92
            URLConnection conn = realUrl.openConnection();
93
94
            // 设置连接参数
95
            conn.setDoOutput(true);
96
            conn.setDoInput(true);
97
            conn.setConnectTimeout(5000);
98
            conn.setReadTimeout(20000);
99
100
            // 提交数据
101
            out = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
102
            out.write(body);
103
            out.flush();
104
105
            // 读取返回数据
106
            in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
107
            String line = "";
108
            boolean firstLine = true; // 读第一行不加换行符
109
            while ((line = in.readLine()) != null) {
110
                if (firstLine) {
111
                    firstLine = false;
112
                } else {
113
                    result += System.lineSeparator();
114
                }
115
                result += line;
116
            }
117
        } catch (Exception e) {
118
            e.printStackTrace();
119
        }
120
        return result;
121
    }
122
}

+ 67 - 0
src/main/java/io/renren/common/utils/JsonUtils.java

1
package io.renren.common.utils;
2
3
import java.io.IOException;
4
import org.springframework.util.StringUtils;
5
6
import com.fasterxml.jackson.core.JsonProcessingException;
7
import com.fasterxml.jackson.core.type.TypeReference;
8
import com.fasterxml.jackson.databind.ObjectMapper;
9
10
public class JsonUtils {
11
12
    private static ObjectMapper objectMapper = new ObjectMapper();
13
    
14
    //对象转字符串
15
    public static <T> String obj2String(final T obj) {
16
        if (obj == null) {
17
            return null;
18
        }
19
        try {
20
            return obj instanceof String ? (String) obj : objectMapper.writeValueAsString(obj);
21
        } catch (final Exception e) {
22
            e.printStackTrace();
23
            return null;
24
        }
25
    }
26
27
    // 字符串转对象
28
    @SuppressWarnings("unchecked")
29
    public static <T> T string2Obj(final String str, final Class<T> clazz) {
30
        if (StringUtils.isEmpty(str) || clazz == null) {
31
            return null;
32
        }
33
        try {
34
            return clazz.equals(String.class) ? (T) str : objectMapper.readValue(str, clazz);
35
        } catch (final IOException e) {
36
            e.printStackTrace();
37
            return null;
38
        }
39
    }
40
41
    public static String bean2Json(Object obj) {
42
        try {
43
            return objectMapper.writeValueAsString(obj);
44
        } catch (JsonProcessingException e) {
45
            e.printStackTrace();
46
            return null;
47
        }
48
    }
49
50
//    public static <T> T json2Bean(String jsonStr, Class<T> objClass) {
51
//        try {
52
//            return mapper.readValue(jsonStr, objClass);
53
//        } catch (IOException e) {
54
//            e.printStackTrace();
55
//            return null;
56
//        }
57
//    }
58
59
    public static <T> T json2Bean(String jsonStr, TypeReference<T> typeReference) {
60
        try {
61
            return objectMapper.readValue(jsonStr, typeReference);
62
        } catch (IOException e) {
63
            e.printStackTrace();
64
            return null;
65
        }
66
    }
67
}

+ 30 - 81
src/main/java/io/renren/modules/admin/controller/EmployeeController.java

1
package io.renren.modules.admin.controller;
1
package io.renren.modules.admin.controller;
2

2

3
import java.text.ParseException;
4
import java.text.SimpleDateFormat;
3
import java.util.Arrays;
5
import java.util.Date;
4
import java.util.Date;
6
import java.util.List;
5
import java.util.List;
7
import java.util.Map;
6
import java.util.Map;
8

7

8
import org.apache.commons.lang.RandomStringUtils;
9
import org.apache.shiro.authz.annotation.RequiresPermissions;
9
import org.apache.shiro.authz.annotation.RequiresPermissions;
10
import org.apache.shiro.crypto.hash.Sha256Hash;
10
import org.springframework.beans.factory.annotation.Autowired;
11
import org.springframework.beans.factory.annotation.Autowired;
11
import org.springframework.web.bind.annotation.GetMapping;
12
import org.springframework.web.bind.annotation.GetMapping;
12
import org.springframework.web.bind.annotation.PathVariable;
13
import org.springframework.web.bind.annotation.PathVariable;
19
import io.renren.common.annotation.SysLog;
20
import io.renren.common.annotation.SysLog;
20
import io.renren.common.utils.PageUtils;
21
import io.renren.common.utils.PageUtils;
21
import io.renren.common.utils.R;
22
import io.renren.common.utils.R;
23
import io.renren.common.validator.ValidatorUtils;
24
import io.renren.common.validator.group.AddGroup;
25
import io.renren.common.validator.group.UpdateGroup;
22
import io.renren.modules.admin.entity.EmployeeEntity;
26
import io.renren.modules.admin.entity.EmployeeEntity;
23
import io.renren.modules.admin.service.EmployeeService;
27
import io.renren.modules.admin.service.EmployeeService;
24

28

25

26

27
/**
29
/**
28
 * 
30
 * 
29
 *
31
 *
43
    @RequestMapping("/list")
45
    @RequestMapping("/list")
44
    @RequiresPermissions("admin:employee:list")
46
    @RequiresPermissions("admin:employee:list")
45
    public R list(@RequestParam Map<String, Object> params){
47
    public R list(@RequestParam Map<String, Object> params){
46
        PageUtils page = employeeService.queryPage(params);
48
        Long companyId = 1L;
49
        PageUtils page = employeeService.queryPage(params,  companyId);
47

50

48
        return R.ok().put("page", page);
51
        return R.ok().put("page", page);
49
    }
52
    }
90
    @RequiresPermissions("admin:employee:info")
93
    @RequiresPermissions("admin:employee:info")
91
    public R info(@PathVariable("id") Long id){
94
    public R info(@PathVariable("id") Long id){
92
		EmployeeEntity employee = employeeService.getById(id);
95
		EmployeeEntity employee = employeeService.getById(id);
93

96
        
94
        return R.ok().put("employee", employee);
97
        return R.ok().put("employee", employee);
95
    }
98
    }
96

99

100
    @RequestMapping("/save")
103
    @RequestMapping("/save")
101
    @RequiresPermissions("admin:employee:save")
104
    @RequiresPermissions("admin:employee:save")
102
    public R save(@RequestBody EmployeeEntity employee){
105
    public R save(@RequestBody EmployeeEntity employee){
103
//        Date date = new Date();
104
////        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
105
////        String format = dateFormat.format(date);
106
        //创建时间
107
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
108
        java.util.Date time = null;
109
        try {
110
            time= sdf.parse(sdf.format(new Date()));
111

112
        } catch (ParseException e) {
113
            e.printStackTrace();
114
        }
115
        employee.setCreateTime(time);
116
		employeeService.save(employee);
117

106
        ValidatorUtils.validateEntity(employee, AddGroup.class);
107
        employee.setCompanyId(1L);
108
        employeeService.saveEmployee(employee);
109
        
118
        return R.ok();
110
        return R.ok();
119
    }
111
    }
120

112

124
    @RequestMapping("/update")
116
    @RequestMapping("/update")
125
    @RequiresPermissions("admin:employee:update")
117
    @RequiresPermissions("admin:employee:update")
126
    public R update(@RequestBody EmployeeEntity employee){
118
    public R update(@RequestBody EmployeeEntity employee){
119
        ValidatorUtils.validateEntity(employee, UpdateGroup.class);
127

120

128

129
        //修改时间
130
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
131
        java.util.Date time = null;
132
        try {
133
            time= sdf.parse(sdf.format(new Date()));
134

135
        } catch (ParseException e) {
136
            e.printStackTrace();
137
        }
138
        employee.setModifyTime(time);
139
		employeeService.updateById(employee);
121
        employeeService.updateEmployee(employee);
122
        
140
        return R.ok();
123
        return R.ok();
141
    }
124
    }
142

125

146
    @RequestMapping("/delete")
129
    @RequestMapping("/delete")
147
    @RequiresPermissions("admin:employee:delete")
130
    @RequiresPermissions("admin:employee:delete")
148
    public R delete(@RequestBody Long[] ids){
131
    public R delete(@RequestBody Long[] ids){
149
		employeeService.delete(ids);
132
        employeeService.removeByIds(Arrays.asList(ids));
133
        
150
        return R.ok();
134
        return R.ok();
151
    }
135
    }
152

136

153
//    /**
154
//     * 删除
155
//     */
156
//    @RequestMapping("/delete/{id}")
157
//    @RequiresPermissions("admin:employee:delete")
158
//    public R delete(@PathVariable("id") Long id){
159
//		//employeeService.removeByIds(Arrays.asList(ids));
160
//        boolean flag = employeeService.delete(id);
161
//        if(flag){
162
//            R.ok("逻辑删除成功");
163
//
164
//
165
//        }
166
//
167
//        return R.ok();
168
//    }
169

170
//    /**
171
//     * 重置密码
172
//     */
173
//    @SysLog("修改密码")
174
//    @PostMapping("/password/{id}")
175
//    @RequiresPermissions("admin:employee:password")
176
//    public R password(@PathVariable("id") Long id){
177
//        boolean flag = employeeService.updatePasswordByid(id);
178
//
179
//        if(flag){
180
//            return  R.ok("重置密码成功");
181
//        }
182
//        return R.ok();
183
//
184
//    }
185

186
    /**
137
    /**
187
     * 重置密码
138
     * 重置密码
188
     */
139
     */
189
    @SysLog("修改密码")
190
    @PostMapping("/password")
191
    @RequiresPermissions("admin:employee:password")
192
    public R password(@RequestParam Map<String,Object> params){
193
        Long id = Long.valueOf(params.get("id").toString());
194
        boolean flag = employeeService.updatePasswordByid(id);
195

196
        if(flag){
197
            return  R.ok("重置密码成功");
198
        }
140
    @SysLog("重置密码")
141
    @PostMapping("/repassword/{id}")
142
    @RequiresPermissions("admin:employee:repassword")
143
    public R repassword(@PathVariable("id") Long id){
144
        EmployeeEntity employee = employeeService.getById(id);
145
        employee.setPassword("123456");
146
        employeeService.updateEmployee(employee);
147

199
        return R.ok();
148
        return R.ok();
200
    }
149
    }
201

150

202
    /**
151
    /**
203
     * 模糊查询name获取 employee(获得id在分配人员时使用)
152
     * 模糊查询name获取list
204
     */
153
     */
205
    @GetMapping("/listbyname")
154
    @GetMapping("/listbyname")
206
    @RequiresPermissions("admin:employee:list")
155
    @RequiresPermissions("admin:employee:list")
207
    public R listByName(@RequestParam Map<String,Object> params){
156
    public R listByName(@RequestParam Map<String,Object> params){
157
        Long companyId = 1L;
208
        String truename = (String) params.get("truename");
158
        String truename = (String) params.get("truename");
209
        List<Map<String, Object>> list = employeeService.selectNameList(truename);
159
        List<Map<String, Object>> list = employeeService.selectNameList(truename, companyId);
210
        return  R.ok().put("list", list);
160
        return  R.ok().put("list", list);
211
    }
161
    }
212

162

213
    /**
163
    /**
214
     * 模糊查询company_id获取 employee id,name(获得id在分配人员时使用)
164
     * 根据company_id获取 employee id,name(获得id在分配人员时使用)
215
     */
165
     */
216
    
217
    @GetMapping("/listbycid/{cid}")
166
    @GetMapping("/listbycid/{cid}")
218
    @RequiresPermissions("admin:employee:list")
167
    @RequiresPermissions("admin:employee:list")
219
    public R selectNameListByCompanyId(@PathVariable("cid") Long cid) {
168
    public R selectNameListByCompanyId(@PathVariable("cid") Long cid) {

+ 4 - 6
src/main/java/io/renren/modules/admin/controller/MemberController.java

25
import io.renren.modules.admin.entity.MemberEntity;
25
import io.renren.modules.admin.entity.MemberEntity;
26
import io.renren.modules.admin.service.MemberService;
26
import io.renren.modules.admin.service.MemberService;
27
import io.renren.modules.sys.controller.AbstractController;
27
import io.renren.modules.sys.controller.AbstractController;
28
import io.renren.modules.admin.service.AttendersService;
29
28
30
/**
29
/**
31
 * 会员表
30
 * 会员表
63
    public R info(@PathVariable("id") Long id){
62
    public R info(@PathVariable("id") Long id){
64
        MemberEntity member = memberService.getById(id);
63
        MemberEntity member = memberService.getById(id);
65
        member.setPassword("");
64
        member.setPassword("");
66
        List<Map<String, Object>> meetingList = memberService.getMeetingListById(id);
65
        List<Map<String, Object>> meetingList = memberService.getMeetingListByMemberId(id);
67
        
66
        
68
        return R.ok().put("member", member).put("meetingList", meetingList);
67
        return R.ok().put("member", member).put("meetingList", meetingList);
69
    }
68
    }
91
    @ApiOperation("修改")
90
    @ApiOperation("修改")
92
    public R update(@RequestBody MemberEntity member){
91
    public R update(@RequestBody MemberEntity member){
93
        ValidatorUtils.validateEntity(member, UpdateGroup.class);
92
        ValidatorUtils.validateEntity(member, UpdateGroup.class);
94
        member.setModifyTime(new Date());
93
95
        member.setModifyId(getUserId());
94
        member.setModifyId(getUserId());
96
		memberService.updateById(member);
95
		memberService.updateMember(member);
97
96
98
        return R.ok();
97
        return R.ok();
99
    }
98
    }
127
    public R repassword(@PathVariable("id") Long id){
126
    public R repassword(@PathVariable("id") Long id){
128
        MemberEntity member = memberService.getById(id);
127
        MemberEntity member = memberService.getById(id);
129
        member.setPassword("123456");
128
        member.setPassword("123456");
130
        member.setModifyTime(new Date());
131
        member.setModifyId(getUserId());
129
        member.setModifyId(getUserId());
132
		memberService.updateById(member);
130
		memberService.updateMember(member);
133
        return R.ok();
131
        return R.ok();
134
    }
132
    }
135
133

+ 9 - 5
src/main/java/io/renren/modules/admin/dao/EmployeeDao.java

17
 */
17
 */
18
@Mapper
18
@Mapper
19
public interface EmployeeDao extends BaseMapper<EmployeeEntity> {
19
public interface EmployeeDao extends BaseMapper<EmployeeEntity> {
20
    List<EmployeeEntity> findAllByisDel(int isDel);
20
    @Select("select e.id,e.truename,e.username,e.password,e.phone,e.email,e.create_time,e.modify_time,e.is_del,c.companyname,c.id as cid " +
21
            " from employee e left JOIN company c on e.company_id = c.id" +
22
            " where e.is_del = 0 AND (e.truename like '%${key}%' or e.username like '%${key2}%') limit #{startLimt},#{endLimt}")
23
    List<Map<String, Object>> getPageList(String key1, String key2, int startLimt, int endLimt);
21

24

22
    boolean updatePasswordByid(Long id);
25
    @Select("select count(*) from employee where is_del=0 and (truename like '%${key1}%' or username like '%${key2}%')")
26
    Integer getCounts(String key1,String key2);
23

27

24
//    boolean delete(Long id);
28
    List<EmployeeEntity> findAllByisDel(int isDel);
25

29

26
    //多表联查 + 分页
30
    //多表联查 + 分页
27
    @Select("select e.id,e.truename,e.username,e.password,e.phone,e.email,e.create_time,e.modify_time,e.is_del,c.companyname,c.id as cid " +
31
    @Select("select e.id,e.truename,e.username,e.password,e.phone,e.email,e.create_time,e.modify_time,e.is_del,c.companyname,c.id as cid " +
46
     * @param truename
50
     * @param truename
47
     * @return
51
     * @return
48
     */
52
     */
49
    @Select("select id,truename from employee where truename like '%${truename}%'")
50
    List<Map<String, Object>> selectNameList(String truename);
53
    @Select("select id,truename from employee where truename like '%${truename}%' and `company_id`=#{companyId};")
54
    List<Map<String, Object>> selectNameList(String truename, Long companyId);
51

55

52
    @Select("SELECT `id`,`truename` FROM `employee` WHERE `company_id`=#{companyId};")
56
    @Select("SELECT `id`,`truename` FROM `employee` WHERE `company_id`=#{companyId};")
53
    List<Map<String, Object>> selectNameListByCompanyId(Long companyId);
57
    List<Map<String, Object>> selectNameListByCompanyId(Long companyId);

+ 1 - 1
src/main/java/io/renren/modules/admin/dao/MemberDao.java

43
     * 根据会员id, 查询获取最近参加的会议
43
     * 根据会员id, 查询获取最近参加的会议
44
     */
44
     */
45
    @Select("SELECT a.id as aid,a.meeting_id,m.name_cn FROM attenders a JOIN meeting m ON a.meeting_id=m.id WHERE a.member_id=#{Id} ORDER BY a.id;")
45
    @Select("SELECT a.id as aid,a.meeting_id,m.name_cn FROM attenders a JOIN meeting m ON a.meeting_id=m.id WHERE a.member_id=#{Id} ORDER BY a.id;")
46
    List<Map<String, Object>> getMeetingListById(Long Id);
46
    List<Map<String, Object>> getMeetingListByMemberId(Long Id);
47
}
47
}

+ 20 - 2
src/main/java/io/renren/modules/admin/entity/EmployeeEntity.java

3
import com.baomidou.mybatisplus.annotation.TableId;
3
import com.baomidou.mybatisplus.annotation.TableId;
4
import com.baomidou.mybatisplus.annotation.TableLogic;
4
import com.baomidou.mybatisplus.annotation.TableLogic;
5
import com.baomidou.mybatisplus.annotation.TableName;
5
import com.baomidou.mybatisplus.annotation.TableName;
6
import com.fasterxml.jackson.annotation.JsonIgnore;
7

8
import io.renren.common.validator.group.AddGroup;
9
import io.renren.common.validator.group.UpdateGroup;
6

10

7
import java.io.Serializable;
11
import java.io.Serializable;
8
import java.util.Date;
12
import java.util.Date;
13
import javax.validation.constraints.Email;
14
import javax.validation.constraints.NotBlank;
15

9
import lombok.Data;
16
import lombok.Data;
10

17

11
/**
18
/**
28
	/**
35
	/**
29
	 * 账号
36
	 * 账号
30
	 */
37
	 */
38
	@NotBlank(message="用户名不能为空", groups = {AddGroup.class, UpdateGroup.class})
31
	private String username;
39
	private String username;
32
	/**
40
	/**
33
	 * 密码
41
	 * 密码
34
	 */
42
	 */
43
	@JsonIgnore
35
	private String password;
44
	private String password;
45
	/**
46
	 * 盐
47
	 */
48
	@JsonIgnore
49
	private String salt;
36
	/**
50
	/**
37
	 * 姓名
51
	 * 姓名
38
	 */
52
	 */
53
	@NotBlank(message="姓名不能为空", groups = {AddGroup.class, UpdateGroup.class})
39
	private String truename;
54
	private String truename;
40
	/**
55
	/**
41
	 * 单位id
56
	 * 单位id
48
	/**
63
	/**
49
	 * 部门id
64
	 * 部门id
50
	 */
65
	 */
51
	private Long departmentId;
66
	private String department;
52
	/**
67
	/**
53
	 * 职位id
68
	 * 职位id
54
	 */
69
	 */
55
	private Long positionId;
70
	private String position;
56
	/**
71
	/**
57
	 * 联系电话
72
	 * 联系电话
58
	 */
73
	 */
74
	@NotBlank(message="手机号不能为空", groups = {AddGroup.class, UpdateGroup.class})
59
	private String phone;
75
	private String phone;
60
	/**
76
	/**
61
	 * 邮箱
77
	 * 邮箱
62
	 */
78
	 */
79
	@Email(message="邮箱格式不正确", groups = {AddGroup.class, UpdateGroup.class})
63
	private String email;
80
	private String email;
64
	/**
81
	/**
65
	 * 创建时间
82
	 * 创建时间
72
	/**
89
	/**
73
	 * 是否被删除 状态  0:正常   1:删除
90
	 * 是否被删除 状态  0:正常   1:删除
74
	 */
91
	 */
92
	@JsonIgnore
75
	@TableLogic
93
	@TableLogic
76
	private Integer isDel;
94
	private Integer isDel;
77
}
95
}

+ 2 - 2
src/main/java/io/renren/modules/admin/entity/MemberEntity.java

37
	/**
37
	/**
38
	 * 密码
38
	 * 密码
39
	 */
39
	 */
40
	@NotBlank(message="密码不能为空", groups = AddGroup.class)
41
	// @JsonIgnore
40
	@JsonIgnore
42
	private String password;
41
	private String password;
43
	/**
42
	/**
44
	 * 盐
43
	 * 盐
111
	/**
110
	/**
112
	 * 是否被删除 状态  0:正常   1:删除
111
	 * 是否被删除 状态  0:正常   1:删除
113
	 */
112
	 */
113
	@JsonIgnore
114
	private Integer isDel;
114
	private Integer isDel;
115
}
115
}

+ 19 - 15
src/main/java/io/renren/modules/admin/service/EmployeeService.java

1
package io.renren.modules.admin.service;
1
package io.renren.modules.admin.service;
2

2

3
import com.baomidou.mybatisplus.core.conditions.Wrapper;
4
import com.baomidou.mybatisplus.core.metadata.IPage;
5
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
3
import java.util.List;
4
import java.util.Map;
5

6
import com.baomidou.mybatisplus.extension.service.IService;
6
import com.baomidou.mybatisplus.extension.service.IService;
7
import io.renren.common.utils.PageUtils;
7
import io.renren.common.utils.PageUtils;
8
import io.renren.modules.admin.entity.EmployeeEntity;
8
import io.renren.modules.admin.entity.EmployeeEntity;
9
import javafx.scene.control.Pagination;
10
import org.apache.ibatis.annotations.Param;
11

12
import java.util.List;
13
import java.util.Map;
14

9

15
/**
10
/**
16
 * 
11
 * 
23

18

24
    PageUtils queryPage(Map<String, Object> params);
19
    PageUtils queryPage(Map<String, Object> params);
25

20

21
    PageUtils queryPage(Map<String, Object> params, Long companyId);
22
    
23
    PageUtils myQueryPage(Map<String, Object> params);
24

26
    List<EmployeeEntity> findAllByisDel(int isDel);
25
    List<EmployeeEntity> findAllByisDel(int isDel);
27

26

28
    /**
27
    /**
33
     */
32
     */
34
    List<EmployeeEntity> findAllByTrueName(String truename);
33
    List<EmployeeEntity> findAllByTrueName(String truename);
35

34

36
    boolean updatePasswordByid(Long id);
37

38
    void delete(Long[] ids);
39

40
    // 多表联查 + 分页
35
    // 多表联查 + 分页
41
    PageUtils queryList(int page, int limit, String key);
36
    PageUtils queryList(int page, int limit, String key);
42

37

38
    
39

40
    
41
	void updateEmployee(EmployeeEntity employee);
42
    
43
	void saveEmployee(EmployeeEntity employee);
44
    
43
    /**
45
    /**
44
     * 根据真实姓名模糊查询id
46
     * 根据真实姓名模糊查询id
45
     * 
47
     * 
46
     * @param truename
48
     * @param truename
47
     * @return
49
     * @return
48
     */
50
     */
49
    List<Map<String, Object>> selectNameList(String truename);
51
    List<Map<String, Object>> selectNameList(String truename, Long companyId);
52
    /**
53
     * 获取工作人员联系方式
54
     */
55
    List<Map<String, Object>> getContact(String ids);
50

56

51
    /**
57
    /**
52
     * 根据单位获取员工列表
58
     * 根据单位获取员工列表
55
     * @return
61
     * @return
56
     */
62
     */
57
    Map<Long, String> selectNameListByCompanyId(Long companyId);
63
    Map<Long, String> selectNameListByCompanyId(Long companyId);
58

59
    List<Map<String, Object>> getContact(String ids);
60
}
64
}

+ 2 - 2
src/main/java/io/renren/modules/admin/service/MemberService.java

25
     * 根据会员id, 查询获取最近参加的会议
25
     * 根据会员id, 查询获取最近参加的会议
26
	 * @param id
26
	 * @param id
27
     */
27
     */
28
	List<Map<String, Object>> getMeetingListById(Long id);
28
	List<Map<String, Object>> getMeetingListByMemberId(Long id);
29
29
30
    /**
30
    /**
31
	 * 保存用户
31
	 * 保存用户
35
	/**
35
	/**
36
	 * 修改用户
36
	 * 修改用户
37
	 */
37
	 */
38
	void update(MemberEntity member);
38
	void updateMember(MemberEntity member);
39
39
40
	/**
40
	/**
41
	 * 更新审核状态
41
	 * 更新审核状态

+ 69 - 11
src/main/java/io/renren/modules/admin/service/impl/EmployeeServiceImpl.java

1
package io.renren.modules.admin.service.impl;
1
package io.renren.modules.admin.service.impl;
2

2

3
import org.apache.commons.lang.RandomStringUtils;
3
import org.apache.commons.lang.StringUtils;
4
import org.apache.commons.lang.StringUtils;
5
import org.apache.shiro.crypto.hash.Sha256Hash;
4
import org.springframework.stereotype.Service;
6
import org.springframework.stereotype.Service;
5

7

6
import java.util.Arrays;
8
import java.util.Arrays;
9
import java.util.Date;
7
import java.util.HashMap;
10
import java.util.HashMap;
8
import java.util.List;
11
import java.util.List;
9
import java.util.Map;
12
import java.util.Map;
23

26

24
    @Override
27
    @Override
25
    public PageUtils queryPage(Map<String, Object> params) {
28
    public PageUtils queryPage(Map<String, Object> params) {
29
        Long companyId = params.containsKey("companyId") ? Long.valueOf((String) params.get("companyId")) : 1L;
26
        String key = (String) params.get("key");
30
        String key = (String) params.get("key");
27
        IPage<EmployeeEntity> page = this.page(
31
        IPage<EmployeeEntity> page = this.page(
28
                new Query<EmployeeEntity>().getPage(params),
32
                new Query<EmployeeEntity>().getPage(params),
29
                new QueryWrapper<EmployeeEntity>()
33
                new QueryWrapper<EmployeeEntity>()
34
                .eq("company_id", companyId)
30
                .like(StringUtils.isNotBlank(key),"username",key)
35
                .like(StringUtils.isNotBlank(key),"username",key)
31
                        .or()
36
                        .or()
32
                .like(StringUtils.isNotBlank(key),"truename",key)
37
                .like(StringUtils.isNotBlank(key),"truename",key)
34

39

35
        return new PageUtils(page);
40
        return new PageUtils(page);
36
    }
41
    }
37

42
    
38
    @Override
43
    @Override
39
    public List<EmployeeEntity> findAllByisDel(int isDel) {
40
        return  baseMapper.findAllByisDel(isDel);
44
    public PageUtils queryPage(Map<String, Object> params, Long companyId) {
45
        String key = (String) params.get("key");
46
        IPage<EmployeeEntity> page = this.page(
47
                new Query<EmployeeEntity>().getPage(params),
48
                new QueryWrapper<EmployeeEntity>()
49
                .eq("company_id", companyId)
50
                .like(StringUtils.isNotBlank(key),"username",key)
51
                        .or()
52
                .like(StringUtils.isNotBlank(key),"truename",key)
53
        );
54

55
        return new PageUtils(page);
41
    }
56
    }
57
    
42

58

43
    @Override
59
    @Override
44
    public List<EmployeeEntity> findAllByTrueName(String truename) {
45
        return baseMapper.findAllByTrueName(truename);
60
    public PageUtils myQueryPage(Map<String, Object> params) {
61
        // Long company_id = params.containsKey("company_id") ? Long.valueOf((String) params.get("company_id")) : 1;
62
        String key = params.containsKey("page") ? (String) params.get("key") : "";
63
        int page = params.containsKey("page") ? Integer.valueOf(params.get("page").toString()): 1;
64
        int limit = params.containsKey("limit") ? Integer.valueOf(params.get("limit").toString()) : 10;
65

66
        if (page < 1) {
67
            page = 1;
68
        }
69
        int startLimt = (page-1) * limit;
70
        int endLimt = startLimt + limit;
71

72
        List<Map<String, Object>> employeeList=baseMapper.getPageList(key, key, startLimt, endLimt);
73
        int total = baseMapper.getCounts(key, key);
74

75
        return  new  PageUtils(employeeList, total, limit, page);
46
    }
76
    }
47

77

48
    @Override
78
    @Override
49
    public boolean updatePasswordByid(Long id) {
50
        return baseMapper.updatePasswordByid(id);
79
    public List<EmployeeEntity> findAllByisDel(int isDel) {
80
        return  baseMapper.findAllByisDel(isDel);
51
    }
81
    }
52

82

53
    @Override
83
    @Override
54
    public void delete(Long[]  ids) {
55
       baseMapper.deleteBatchIds(Arrays.asList(ids));
84
    public List<EmployeeEntity> findAllByTrueName(String truename) {
85
        return baseMapper.findAllByTrueName(truename);
56
    }
86
    }
57

87

58
    @Override
88
    @Override
68
    }
98
    }
69

99

70
    @Override
100
    @Override
71
    public List<Map<String, Object>> selectNameList(String truename) {
72
        return baseMapper.selectNameList(truename);
101
    public List<Map<String, Object>> selectNameList(String truename, Long companyId) {
102
        return baseMapper.selectNameList(truename, companyId);
73
    }
103
    }
74

104

75
    @Override
105
    @Override
89
    public List<Map<String, Object>> getContact(String ids) {
119
    public List<Map<String, Object>> getContact(String ids) {
90
        return baseMapper.getContact(ids);
120
        return baseMapper.getContact(ids);
91
    }
121
    }
122

123
    @Override
124
    public void saveEmployee(EmployeeEntity employee) {
125
        // if(StringUtils.isBlank(employee.getPassword())){
126
        //     employee.setPassword("123456");
127
        // }
128
        employee.setPassword("123456");
129
        employee.setCreateTime(new Date());
130
        String salt = RandomStringUtils.randomAlphanumeric(20);
131
        employee.setPassword(new Sha256Hash(employee.getPassword(), salt).toHex());
132
        employee.setSalt(salt);
133

134
        this.save(employee);
135
    }
136

137
    @Override
138
    public void updateEmployee(EmployeeEntity employee) {
139
        employee.setModifyTime(new Date());
140
        // if(StringUtils.isBlank(employee.getPassword())){
141
		// 	employee.setPassword(null);
142
		// }else{
143
        //     String salt = RandomStringUtils.randomAlphanumeric(20);
144
        //     employee.setPassword(new Sha256Hash(employee.getPassword(), salt).toHex());
145
        //     employee.setSalt(salt);
146
        // }
147
        employee.setPassword(null);
148
        this.updateById(employee);
149
    }
92
}
150
}

+ 18 - 18
src/main/java/io/renren/modules/admin/service/impl/MemberServiceImpl.java

13
import org.apache.commons.lang.RandomStringUtils;
13
import org.apache.commons.lang.RandomStringUtils;
14
import org.apache.commons.lang.StringUtils;
14
import org.apache.commons.lang.StringUtils;
15
import org.apache.shiro.crypto.hash.Sha256Hash;
15
import org.apache.shiro.crypto.hash.Sha256Hash;
16
import org.springframework.beans.factory.annotation.Autowired;
17
import org.springframework.stereotype.Service;
16
import org.springframework.stereotype.Service;
18
import org.springframework.transaction.annotation.Transactional;
17
import org.springframework.transaction.annotation.Transactional;
19
18
22
import io.renren.modules.admin.dao.MemberDao;
21
import io.renren.modules.admin.dao.MemberDao;
23
import io.renren.modules.admin.entity.MemberEntity;
22
import io.renren.modules.admin.entity.MemberEntity;
24
import io.renren.modules.admin.service.MemberService;
23
import io.renren.modules.admin.service.MemberService;
25
import io.renren.modules.admin.service.AttendersService;
26
24
27
@Service("memberService")
25
@Service("memberService")
28
public class MemberServiceImpl extends ServiceImpl<MemberDao, MemberEntity> implements MemberService {
26
public class MemberServiceImpl extends ServiceImpl<MemberDao, MemberEntity> implements MemberService {
29
27
30
    @Autowired
31
    private AttendersService attendersService;
32
33
    @Override
28
    @Override
34
    public PageUtils queryPage(Map<String, Object> params) {
29
    public PageUtils queryPage(Map<String, Object> params) {
35
        String key = (String)params.get("key");
30
        String key = (String)params.get("key");
57
            mMap.put("email", member.getEmail());
52
            mMap.put("email", member.getEmail());
58
            mMap.put("createTime", member.getCreateTime());
53
            mMap.put("createTime", member.getCreateTime());
59
            mMap.put("isCheck", member.getIsCheck());
54
            mMap.put("isCheck", member.getIsCheck());
60
            List<Map<String, Object>> meetingList = attendersService.getMeetingListByMemberId(memberId);
55
            List<Map<String, Object>> meetingList = this.getMeetingListByMemberId(memberId);
61
            int meetingCounts = meetingList.size();
56
            int meetingCounts = meetingList.size();
62
            if (meetingCounts > 0) {
57
            if (meetingCounts > 0) {
63
                Map<String, Object> meetingInfo = meetingList.get(meetingCounts - 1);
58
                Map<String, Object> meetingInfo = meetingList.get(meetingCounts - 1);
68
            mMap.put("meetingCounts", meetingCounts);
63
            mMap.put("meetingCounts", meetingCounts);
69
            list.add(mMap);
64
            list.add(mMap);
70
        }
65
        }
71
72
        return new PageUtils(list, (int)page.getTotal(), (int)page.getSize(), (int)page.getCurrent());
66
        return new PageUtils(list, (int)page.getTotal(), (int)page.getSize(), (int)page.getCurrent());
73
    }
67
    }
74
68
75
    @Override
69
    @Override
76
	@Transactional
70
	@Transactional
77
    public void saveMember(MemberEntity member){
71
    public void saveMember(MemberEntity member){
72
         // if(StringUtils.isBlank(member.getPassword())){
73
        //     member.setPassword("123456");
74
        // }
78
        member.setCreateTime(new Date());
75
        member.setCreateTime(new Date());
76
        member.setPassword("123456");
79
        //sha256加密
77
        //sha256加密
80
		String salt = RandomStringUtils.randomAlphanumeric(20);
78
		String salt = RandomStringUtils.randomAlphanumeric(20);
81
		member.setPassword(new Sha256Hash(member.getPassword(), salt).toHex());
79
		member.setPassword(new Sha256Hash(member.getPassword(), salt).toHex());
82
		member.setSalt(salt);
80
        member.setSalt(salt);
83
		this.save(member); 
81
		this.save(member); 
84
    }
82
    }
85
83
86
    @Override
84
    @Override
87
	@Transactional
85
	@Transactional
88
    public void update(MemberEntity member) {
86
    public void updateMember(MemberEntity member) {
87
        member.setModifyTime(new Date());
88
        // if(StringUtils.isBlank(member.getPassword())){
89
		// 	member.setPassword(null);
90
		// }else{
91
        //     String salt = RandomStringUtils.randomAlphanumeric(20);
92
        //     member.setPassword(new Sha256Hash(member.getPassword(), salt).toHex());
93
        //     member.setSalt(salt);
94
        // }
95
        member.setPassword(null);
89
        
96
        
90
        member.setUsername(null);
91
        if(StringUtils.isBlank(member.getPassword())){
92
			member.setPassword(null);
93
		}else{
94
			member.setPassword(new Sha256Hash(member.getPassword(), member.getSalt()).toHex());
95
		}
96
97
        this.updateById(member);
97
        this.updateById(member);
98
    }
98
    }
99
99
129
    }
129
    }
130
130
131
    @Override
131
    @Override
132
    public List<Map<String, Object>> getMeetingListById(Long id) {
133
        return baseMapper.getMeetingListById(id);
132
    public List<Map<String, Object>> getMeetingListByMemberId(Long id) {
133
        return baseMapper.getMeetingListByMemberId(id);
134
    }
134
    }
135
}
135
}

+ 32 - 21
src/main/java/io/renren/modules/app/controller/AppRegisterController.java

10
10
11
import io.renren.common.utils.R;
11
import io.renren.common.utils.R;
12
import io.renren.common.validator.ValidatorUtils;
12
import io.renren.common.validator.ValidatorUtils;
13
import io.renren.common.validator.group.AddGroup;
14
import io.renren.modules.app.entity.UserEntity;
13
import io.renren.modules.app.entity.UserEntity;
15
import io.renren.modules.app.form.RegisterForm;
14
import io.renren.modules.app.form.RegisterForm;
15
import io.renren.modules.app.service.SmsCodeService;
16
import io.renren.modules.app.service.UserService;
16
import io.renren.modules.app.service.UserService;
17
import io.renren.common.utils.JsonUtils;
18
import io.renren.modules.app.entity.SmsStatusEntity;
17
import io.swagger.annotations.Api;
19
import io.swagger.annotations.Api;
18
import io.swagger.annotations.ApiOperation;
20
import io.swagger.annotations.ApiOperation;
19
import org.apache.commons.codec.digest.DigestUtils;
20
import org.springframework.beans.factory.annotation.Autowired;
21
import org.springframework.beans.factory.annotation.Autowired;
21
import org.springframework.web.bind.annotation.PostMapping;
22
import org.springframework.web.bind.annotation.PostMapping;
22
import org.springframework.web.bind.annotation.RequestBody;
23
import org.springframework.web.bind.annotation.RequestBody;
23
import org.springframework.web.bind.annotation.RequestMapping;
24
import org.springframework.web.bind.annotation.RequestMapping;
24
import org.springframework.web.bind.annotation.RestController;
25
import org.springframework.web.bind.annotation.RestController;
25
26
26
import java.util.Date;
27
27
28
/**
28
/**
29
 * 注册
29
 * 注册
37
    @Autowired
37
    @Autowired
38
    private UserService userService;
38
    private UserService userService;
39
39
40
    // @PostMapping("register")
41
    // @ApiOperation("注册")
42
    // public R register(@RequestBody RegisterForm form){
43
    //     //表单校验
44
        //  ValidatorUtils.validateEntity(form);
45
46
        //  UserEntity user = new UserEntity();
47
        //  user.setMobile(form.getMobile());
48
        //  user.setUsername(form.getMobile());
49
        //  user.setPassword(DigestUtils.sha256Hex(form.getPassword()));
50
        //  user.setCreateTime(new Date());
51
        //  userService.save(user);
40
    @Autowired
41
    private SmsCodeService smsCodeService;
52
42
53
    //     return R.ok();
54
    // }
43
    /**
44
     * 短信验证码
45
     */
46
    @PostMapping("/mobilecode")
47
    public R mobileCode(String uuid, String phone) {
48
        // 获取短信验证码
49
        String code = smsCodeService.getCode(uuid, phone);
50
        try {
51
            String result = smsCodeService.sendCode(code, phone);
52
            return R.ok().put("result", result);
53
        } catch (Exception e) {
54
            e.printStackTrace();
55
            return R.error();
56
        }
57
    }
55
58
56
    @PostMapping("register")
59
    @PostMapping("register")
57
    @ApiOperation("注册")
60
    @ApiOperation("注册")
58
    public R register(@RequestBody UserEntity user){
59
        user.setUsername(user.getPhone());
61
    public R register(@RequestBody RegisterForm form){
62
        boolean captcha = smsCodeService.validate(form.getUuid(), form.getCode());
63
		if(!captcha){
64
			return R.error("验证码不正确");
65
        }
66
        
60
        //表单校验
67
        //表单校验
61
        ValidatorUtils.validateEntity(user, AddGroup.class);
68
         ValidatorUtils.validateEntity(form);
62
69
63
        userService.saveUser(user);
70
         UserEntity user = new UserEntity();
71
         user.setPhone(form.getPhone());
72
         user.setUsername(form.getPhone());
73
         user.setPassword(form.getPassword());
74
         userService.saveUser(user);
64
75
65
        return R.ok();
76
        return R.ok();
66
    }
77
    }

+ 40 - 0
src/main/java/io/renren/modules/app/controller/SmsTestController.java

1
package io.renren.modules.app.controller;
2
3
import io.renren.common.utils.HttpRequestUtil;
4
import io.renren.modules.app.service.SmsCodeService;
5
import io.renren.common.utils.ConfigConstant;
6
7
import java.net.URLEncoder;
8
import java.util.UUID;
9
10
import org.springframework.beans.factory.annotation.Autowired;
11
import org.springframework.web.bind.annotation.PostMapping;
12
import org.springframework.web.bind.annotation.RequestMapping;
13
import org.springframework.web.bind.annotation.RestController;
14
15
@RestController
16
@RequestMapping("app/smscode")
17
public class SmsTestController {
18
	@Autowired
19
    private SmsCodeService smsCodeService;
20
    
21
    /**
22
	 * 短信发送(验证码通知,会员营销)
23
	 * 接口文档地址:http://www.miaodiyun.com/doc/https_sms.html
24
	 */
25
	@PostMapping("/test")
26
	public String execute() throws Exception{
27
		String uuid = UUID.randomUUID().toString();
28
		String phone = "17611467373";
29
		String code = smsCodeService.getCode(uuid, phone);
30
		StringBuilder sb = new StringBuilder();
31
		sb.append("accountSid").append("=").append(ConfigConstant.ACCOUNT_SID);
32
		sb.append("&to").append("=").append(phone);
33
		sb.append("&param").append("=").append(URLEncoder.encode(code + "," + ConfigConstant.EXPIRE_TIME,"UTF-8"));
34
		sb.append("&templateid").append("=").append("206770");
35
		String body = sb.toString() + HttpRequestUtil.createCommonParam(ConfigConstant.ACCOUNT_SID, ConfigConstant.AUTH_TOKEN);
36
		String result = HttpRequestUtil.post(ConfigConstant.BASE_URL, body);
37
		System.out.println(result);
38
		return result;
39
	}
40
}

+ 17 - 0
src/main/java/io/renren/modules/app/dao/SmsCodeDao.java

1
package io.renren.modules.app.dao;
2
3
import io.renren.modules.app.entity.SmsCodeEntity;
4
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5
import org.apache.ibatis.annotations.Mapper;
6
7
/**
8
 * 短信平台验证码
9
 * 
10
 * @author chenshun
11
 * @email sunlightcs@gmail.com
12
 * @date 2020-05-20 09:54:35
13
 */
14
@Mapper
15
public interface SmsCodeDao extends BaseMapper<SmsCodeEntity> {
16
	
17
}

+ 41 - 0
src/main/java/io/renren/modules/app/entity/SmsCodeEntity.java

1
package io.renren.modules.app.entity;
2
3
import com.baomidou.mybatisplus.annotation.IdType;
4
import com.baomidou.mybatisplus.annotation.TableId;
5
import com.baomidou.mybatisplus.annotation.TableName;
6
7
import java.io.Serializable;
8
import java.util.Date;
9
import lombok.Data;
10
11
/**
12
 * 短信平台验证码
13
 * 
14
 * @author chenshun
15
 * @email sunlightcs@gmail.com
16
 * @date 2020-05-20 09:54:35
17
 */
18
@Data
19
@TableName("sms_code")
20
public class SmsCodeEntity implements Serializable {
21
	private static final long serialVersionUID = 1L;
22
23
	/**
24
	 * 
25
	 */
26
	@TableId(type = IdType.INPUT)
27
	private String uuid;
28
	/**
29
	 * 
30
	 */
31
	private String phone;
32
	/**
33
	 * 
34
	 */
35
	private String code;
36
	/**
37
	 * 过期时间
38
	 */
39
	private Date expireTime;
40
41
}

+ 13 - 0
src/main/java/io/renren/modules/app/entity/SmsStatusEntity.java

1
package io.renren.modules.app.entity;
2
import lombok.Data;
3
4
/**
5
 * 短信发送返回值实体类
6
 */
7
@Data
8
public class SmsStatusEntity {
9
    private String respCode;
10
    private String respDesc;
11
    private String smsId;
12
    private String[] failList;
13
}

+ 5 - 23
src/main/java/io/renren/modules/app/form/RegisterForm.java

13
import lombok.Data;
13
import lombok.Data;
14
14
15
import javax.validation.constraints.NotBlank;
15
import javax.validation.constraints.NotBlank;
16
import javax.validation.constraints.Email;
17
16
18
/**
17
/**
19
 * 注册表单
18
 * 注册表单
26
    @ApiModelProperty(value = "手机号")
25
    @ApiModelProperty(value = "手机号")
27
    @NotBlank(message="手机号不能为空")
26
    @NotBlank(message="手机号不能为空")
28
    private String phone;
27
    private String phone;
29
30
    @ApiModelProperty(value = "密码")
28
    @ApiModelProperty(value = "密码")
31
    @NotBlank(message="密码不能为空")
29
    @NotBlank(message="密码不能为空")
32
    private String password;
30
    private String password;
33
    @ApiModelProperty(value = "姓名")
34
    @NotBlank(message="姓名不能为空")
35
    private String truename;
36
    @ApiModelProperty(value = "性别")
37
	private Integer sex;
38
    @ApiModelProperty(value = "头像")
39
	private String titlePic;
40
41
    @ApiModelProperty(value = "所属机构")
42
	private String organization;
43
44
    @ApiModelProperty(value = "职位")
45
	private String position;
46
47
    @ApiModelProperty(value = "职称")
48
	private String jobTitle;
49
50
    @ApiModelProperty(value = "邮箱")
51
	@Email(message="邮箱格式不正确")
52
	private String email;
53
31
    @ApiModelProperty(value = "短信验证码")
32
    @NotBlank(message="短信验证码不能为空")
33
    private String code;
34
    @ApiModelProperty(value = "uuid")
35
    private String uuid;
54
}
36
}

+ 38 - 0
src/main/java/io/renren/modules/app/service/SmsCodeService.java

1
package io.renren.modules.app.service;
2
3
import com.baomidou.mybatisplus.extension.service.IService;
4
import io.renren.common.utils.PageUtils;
5
import io.renren.modules.app.entity.SmsCodeEntity;
6
7
import java.util.Map;
8
9
/**
10
 * 短信验证码
11
 *
12
 * @author chenshun
13
 * @email sunlightcs@gmail.com
14
 * @date 2020-05-20 09:54:35
15
 */
16
public interface SmsCodeService extends IService<SmsCodeEntity> {
17
    /**
18
     * 获取短信验证码
19
     */
20
    String getCode(String uuid, String phone);
21
22
    /**
23
     * 验证码效验
24
     * @param uuid  uuid
25
     * @param code  验证码
26
     * @return  true:成功  false:失败
27
     */
28
    boolean validate(String uuid, String code);
29
30
    /**
31
     *  发送短信验证码
32
     * @param code
33
     * @param phone
34
     * @return
35
     * @throws Exception
36
     */
37
	String sendCode(String code, String phone) throws Exception;
38
}

+ 68 - 0
src/main/java/io/renren/modules/app/service/impl/SmsCodeServiceImpl.java

1
package io.renren.modules.app.service.impl;
2
3
import org.springframework.stereotype.Service;
4
5
import java.io.UnsupportedEncodingException;
6
import java.net.URLEncoder;
7
import java.util.Date;
8
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
9
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
10
import io.renren.common.exception.RRException;
11
import org.apache.commons.lang.StringUtils;
12
13
import io.renren.common.utils.ConfigConstant;
14
import io.renren.common.utils.DateUtils;
15
import io.renren.common.utils.HttpRequestUtil;
16
import io.renren.modules.app.dao.SmsCodeDao;
17
import io.renren.modules.app.entity.SmsCodeEntity;
18
import io.renren.modules.app.service.SmsCodeService;
19
20
@Service("smsCodeService")
21
public class SmsCodeServiceImpl extends ServiceImpl<SmsCodeDao, SmsCodeEntity> implements SmsCodeService {
22
23
    @Override
24
    public String getCode(String uuid, String phone){
25
        if (StringUtils.isBlank(uuid)) {
26
            throw new RRException("uuid不能为空");
27
        }
28
        // 生成数字验证码
29
        String code = String.valueOf((int) ((Math.random() * 9 + 1) * 100000));
30
        SmsCodeEntity smsCodeEntity = new SmsCodeEntity();
31
        smsCodeEntity.setUuid(uuid);
32
        smsCodeEntity.setPhone(phone);
33
        smsCodeEntity.setCode(code);
34
        smsCodeEntity.setExpireTime(DateUtils.addDateMinutes(new Date(), ConfigConstant.EXPIRE_TIME));
35
36
        this.save(smsCodeEntity);
37
        return code;
38
    }
39
40
    @Override
41
    public boolean validate(String uuid, String code) {
42
        SmsCodeEntity smsCodeEntity = this.getOne(new QueryWrapper<SmsCodeEntity>().eq("uuid", uuid));
43
        if(smsCodeEntity == null){
44
            return false;
45
        }
46
47
        //删除验证码
48
        this.removeById(uuid);
49
50
        if(smsCodeEntity.getCode().equalsIgnoreCase(code) && smsCodeEntity.getExpireTime().getTime() >= System.currentTimeMillis()){
51
            return true;
52
        }
53
        return false;
54
    }
55
56
    @Override
57
    public String sendCode(String code, String phone) throws Exception {
58
        StringBuilder sb = new StringBuilder();
59
		sb.append("accountSid").append("=").append(ConfigConstant.ACCOUNT_SID);
60
		sb.append("&to").append("=").append(phone);
61
        sb.append("&param").append("=").append(URLEncoder.encode(code + "," + ConfigConstant.EXPIRE_TIME, "UTF-8"));
62
		sb.append("&templateid").append("=").append(ConfigConstant.TEMPLATE_ID);
63
		String body = sb.toString() + HttpRequestUtil.createCommonParam(ConfigConstant.ACCOUNT_SID, ConfigConstant.AUTH_TOKEN);
64
		String result = HttpRequestUtil.post(ConfigConstant.BASE_URL, body);
65
		System.out.println(result);
66
        return result;
67
    }
68
}

+ 0 - 18
src/main/resources/mapper/admin/EmployeeDao.xml

23
    <select id="findAllByisDel" resultType="io.renren.modules.admin.entity.EmployeeEntity">
23
    <select id="findAllByisDel" resultType="io.renren.modules.admin.entity.EmployeeEntity">
24
        select * from employee where  is_del = #{isDel}
24
        select * from employee where  is_del = #{isDel}
25
    </select>
25
    </select>
26

27
    <update id="updatePasswordByid" parameterType="map">
28
        update employee set password = "123456" where id = #{id}
29
    </update>
30

31
    <!--<update id="delete" parameterType="map">-->
32
        <!--update employee set is_del= 1  where id = #{id}-->
33
    <!--</update>-->
34
    <!--<select id="queryListBykey" resultType="io.renren.modules.generator.entity.EmployeeEntity">-->
35
      <!--select e.id,e.truename,e.username,e.password,e.phone,e.email,e.create_time,e.modify_time,e.is_del,c.companyname from employee e left JOIN company c on e.company_id = c.id-->
36
        <!--where e.is_del = 0 AND (e.truename like '%${key}%' or e.username like '%${key2}%') limit #{page},#{limit}-->
37

38
    <!--</select>-->
39

40
    <!--<select id="queryTotalCount" resultType="io.renren.modules.generator.entity.EmployeeEntity">-->
41
        <!--select count(*) from employee where is_del=0 and (truename like '%${key}%' or username like '%${key2}%')-->
42

43
    <!--</select>-->
44
</mapper>
26
</mapper>