ADD:add register
Showing
17 changed files
with
329 additions
and
189 deletions
@@ -69,6 +69,12 @@ | @@ -69,6 +69,12 @@ | ||
69 | <artifactId>fastjson</artifactId> | 69 | <artifactId>fastjson</artifactId> |
70 | <version>1.2.9</version> | 70 | <version>1.2.9</version> |
71 | </dependency> | 71 | </dependency> |
72 | + | ||
73 | + <dependency> | ||
74 | + <groupId>joda-time</groupId> | ||
75 | + <artifactId>joda-time</artifactId> | ||
76 | + <version>2.4</version> | ||
77 | + </dependency> | ||
72 | </dependencies> | 78 | </dependencies> |
73 | 79 | ||
74 | <build> | 80 | <build> |
@@ -42,7 +42,8 @@ public class LogAspect { | @@ -42,7 +42,8 @@ public class LogAspect { | ||
42 | }else{ | 42 | }else{ |
43 | sb.append(","); | 43 | sb.append(","); |
44 | } | 44 | } |
45 | - sb.append(obj.toString()); | 45 | + if(obj!=null) |
46 | + sb.append(obj.toString()); | ||
46 | } | 47 | } |
47 | } | 48 | } |
48 | log.info(sb.toString()); | 49 | log.info(sb.toString()); |
@@ -41,7 +41,7 @@ public class CurrentAdminMethodArgumentResolver implements HandlerMethodArgument | @@ -41,7 +41,7 @@ public class CurrentAdminMethodArgumentResolver implements HandlerMethodArgument | ||
41 | public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { | 41 | public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { |
42 | //取出鉴权时存入的登录用户Id | 42 | //取出鉴权时存入的登录用户Id |
43 | String currentAdminId = ((String) webRequest.getAttribute(Constants.CURRENT_USER_ID, RequestAttributes.SCOPE_REQUEST)). | 43 | String currentAdminId = ((String) webRequest.getAttribute(Constants.CURRENT_USER_ID, RequestAttributes.SCOPE_REQUEST)). |
44 | - replace(UpSoftAccountController.UPSOFT_TOKEN_PREFIX, "").replace(AdminAccountController.USPIH_TOKEN_PREFIX, ""); | 44 | + replace(UpSoftAccountController.UPSOFT_TOKEN_PREFIX, "").replace(AdminAccountController.USPIH_TOKEN_PREFIX, "").replace(Constants.ADMIN_TOKEN_PREFIX,""); |
45 | if (currentAdminId != null) { | 45 | if (currentAdminId != null) { |
46 | //从数据库中查询并返回 | 46 | //从数据库中查询并返回 |
47 | XklAdminEntity admin = adminRepository.findByIdAndStatus(Long.parseLong(currentAdminId), Constants.STATUS_OK); | 47 | XklAdminEntity admin = adminRepository.findByIdAndStatus(Long.parseLong(currentAdminId), Constants.STATUS_OK); |
@@ -3,6 +3,7 @@ package com.xkl.config; | @@ -3,6 +3,7 @@ package com.xkl.config; | ||
3 | import com.xkl.domain.XklAmpReportCategoryEntity; | 3 | import com.xkl.domain.XklAmpReportCategoryEntity; |
4 | import com.xkl.domain.XklAmpReportMetaItemsEntity; | 4 | import com.xkl.domain.XklAmpReportMetaItemsEntity; |
5 | import com.xkl.domain.XklAmpReportMetaScoreStandardEntity; | 5 | import com.xkl.domain.XklAmpReportMetaScoreStandardEntity; |
6 | +import com.xkl.model.CityModel; | ||
6 | 7 | ||
7 | import java.util.HashMap; | 8 | import java.util.HashMap; |
8 | import java.util.Map; | 9 | import java.util.Map; |
@@ -42,6 +43,19 @@ public interface Constants { | @@ -42,6 +43,19 @@ public interface Constants { | ||
42 | * 分年龄段平均得分 | 43 | * 分年龄段平均得分 |
43 | */ | 44 | */ |
44 | Map<String,Double> aveScoreMap = new HashMap<>(); | 45 | Map<String,Double> aveScoreMap = new HashMap<>(); |
46 | + /** | ||
47 | + * 身份证前六位-省市区 | ||
48 | + */ | ||
49 | + Map<String,CityModel> cityMap = new HashMap<>(); | ||
50 | + int ID_TYPE_COUNTRY = 2; | ||
51 | + int ID_TYPE_PROVINCE = 3; | ||
52 | + int ID_TYPE_CITY = 4; | ||
53 | + int ID_TYPE_COUNTY = 5; | ||
54 | + | ||
55 | + /** | ||
56 | + * admin-token前缀 | ||
57 | + */ | ||
58 | + String ADMIN_TOKEN_PREFIX = "ADMINTOKENPREFIX"; | ||
45 | 59 | ||
46 | public static final int MALE = 0; | 60 | public static final int MALE = 0; |
47 | public static final int FEMALE = 1; | 61 | public static final int FEMALE = 1; |
1 | package com.xkl.config; | 1 | package com.xkl.config; |
2 | 2 | ||
3 | -import com.xkl.domain.XklAmpReportAverageScoreEntity; | ||
4 | -import com.xkl.domain.XklAmpReportCategoryEntity; | ||
5 | -import com.xkl.domain.XklAmpReportMetaItemsEntity; | ||
6 | -import com.xkl.domain.XklAmpReportMetaScoreStandardEntity; | ||
7 | -import com.xkl.repository.XklAmpReportAveScoreRespository; | ||
8 | -import com.xkl.repository.XklAmpReportCategoryRespository; | ||
9 | -import com.xkl.repository.XklAmpReportMetaItemsRespository; | ||
10 | -import com.xkl.repository.XklAmpReportMetaScoreStandardRespository; | 3 | +import com.xkl.domain.*; |
4 | +import com.xkl.model.CityModel; | ||
5 | +import com.xkl.repository.*; | ||
11 | import lombok.extern.apachecommons.CommonsLog; | 6 | import lombok.extern.apachecommons.CommonsLog; |
12 | import org.springframework.beans.factory.annotation.Autowired; | 7 | import org.springframework.beans.factory.annotation.Autowired; |
13 | import org.springframework.scheduling.annotation.Scheduled; | 8 | import org.springframework.scheduling.annotation.Scheduled; |
14 | import org.springframework.stereotype.Component; | 9 | import org.springframework.stereotype.Component; |
15 | 10 | ||
16 | -import java.util.Iterator; | 11 | +import java.util.*; |
17 | 12 | ||
18 | 13 | ||
19 | /** | 14 | /** |
@@ -31,6 +26,8 @@ public class ScheduledTask implements Constants{ | @@ -31,6 +26,8 @@ public class ScheduledTask implements Constants{ | ||
31 | private XklAmpReportCategoryRespository reportCategoryRespository; | 26 | private XklAmpReportCategoryRespository reportCategoryRespository; |
32 | @Autowired | 27 | @Autowired |
33 | private XklAmpReportAveScoreRespository reportAveScoreRespository; | 28 | private XklAmpReportAveScoreRespository reportAveScoreRespository; |
29 | + @Autowired | ||
30 | + private XklCityRespository xklCityRespository; | ||
34 | 31 | ||
35 | @Scheduled(initialDelay = 0,fixedRate = 24*60*60*1000) | 32 | @Scheduled(initialDelay = 0,fixedRate = 24*60*60*1000) |
36 | public void getTableMap(){ | 33 | public void getTableMap(){ |
@@ -72,4 +69,68 @@ public class ScheduledTask implements Constants{ | @@ -72,4 +69,68 @@ public class ScheduledTask implements Constants{ | ||
72 | aveScoreMap.put(ageAndType,reportCategory.getAverageScore()); | 69 | aveScoreMap.put(ageAndType,reportCategory.getAverageScore()); |
73 | } | 70 | } |
74 | } | 71 | } |
72 | + | ||
73 | + @Scheduled(initialDelay = 0,fixedRate = 24*60*60*1000) | ||
74 | + public void getCityMap(){ | ||
75 | + log.info("Load City Table"); | ||
76 | + Map<Long,XklCityEntity> idCityMap = new HashMap<>(); | ||
77 | + Iterator<XklCityEntity> iterator = xklCityRespository.findAll().iterator(); | ||
78 | + while(iterator.hasNext()){ | ||
79 | + XklCityEntity city = iterator.next(); | ||
80 | + idCityMap.put(city.getId(),city); | ||
81 | + } | ||
82 | + for (Map.Entry<Long, XklCityEntity> entry : idCityMap.entrySet()) { | ||
83 | + long id = entry.getKey(); | ||
84 | + XklCityEntity xklCity = entry.getValue(); | ||
85 | + long parentId = xklCity.getParentId(); | ||
86 | + List<Long> idList = new ArrayList<>(); | ||
87 | + idList.add(id); | ||
88 | + idList.add(parentId); | ||
89 | + getIdList(parentId,idCityMap,idList); | ||
90 | + CityModel cityModel = new CityModel(); | ||
91 | + if(idList.size()== Constants.ID_TYPE_COUNTRY){//国家级:中国000000 | ||
92 | + cityModel.setType(Constants.ID_TYPE_COUNTRY); | ||
93 | + cityModel.setCountry(idList.get(0)); | ||
94 | + }else if(idList.size() == Constants.ID_TYPE_PROVINCE){//省级:北京110000,河北130000 | ||
95 | + cityModel.setType(Constants.ID_TYPE_PROVINCE); | ||
96 | + cityModel.setCountry(idList.get(1)); | ||
97 | + cityModel.setProvince(idList.get(0)); | ||
98 | + }else if(idList.size() == Constants.ID_TYPE_CITY){//市级:东城区110101,石家庄市130100 | ||
99 | + cityModel.setType(Constants.ID_TYPE_CITY); | ||
100 | + cityModel.setCountry(idList.get(2)); | ||
101 | + cityModel.setProvince(idList.get(1)); | ||
102 | + cityModel.setCity(idList.get(0)); | ||
103 | + }else if(idList.size() == Constants.ID_TYPE_COUNTY){//区级:石家庄市长安区130102 | ||
104 | + cityModel.setType(Constants.ID_TYPE_COUNTY); | ||
105 | + cityModel.setCountry(idList.get(3)); | ||
106 | + cityModel.setProvince(idList.get(2)); | ||
107 | + cityModel.setCity(idList.get(1)); | ||
108 | + cityModel.setCounty(idList.get(0)); | ||
109 | + }else{ | ||
110 | + cityModel.setType(Constants.ID_TYPE_COUNTRY); | ||
111 | + cityModel.setCountry(idList.get(0)); | ||
112 | + } | ||
113 | + cityMap.put(xklCity.getIdCardCode(),cityModel); | ||
114 | + } | ||
115 | + log.info("load city table success"); | ||
116 | + } | ||
117 | + | ||
118 | + /** | ||
119 | + * 递归找parent,直到中国 | ||
120 | + * @param parentId | ||
121 | + * @param idCityMap | ||
122 | + * @param idList | ||
123 | + */ | ||
124 | + public void getIdList(long parentId,Map<Long,XklCityEntity> idCityMap,List<Long> idList){ | ||
125 | + if(parentId == 0) return; | ||
126 | + | ||
127 | + XklCityEntity city = idCityMap.get(parentId); | ||
128 | + if(city!=null){ | ||
129 | + long grandParentId = city.getParentId(); | ||
130 | + idList.add(grandParentId); | ||
131 | + getIdList(grandParentId,idCityMap,idList); | ||
132 | + }else{ | ||
133 | + return; | ||
134 | + } | ||
135 | + } | ||
75 | } | 136 | } |
@@ -3,14 +3,13 @@ package com.xkl.controller; | @@ -3,14 +3,13 @@ package com.xkl.controller; | ||
3 | import com.wordnik.swagger.annotations.ApiImplicitParam; | 3 | import com.wordnik.swagger.annotations.ApiImplicitParam; |
4 | import com.wordnik.swagger.annotations.ApiImplicitParams; | 4 | import com.wordnik.swagger.annotations.ApiImplicitParams; |
5 | import com.wordnik.swagger.annotations.ApiOperation; | 5 | import com.wordnik.swagger.annotations.ApiOperation; |
6 | -import com.xkl.authorization.annotation.Authorization; | ||
7 | -import com.xkl.authorization.annotation.CurrentUser; | ||
8 | -import com.xkl.authorization.annotation.LogAnnotation; | ||
9 | -import com.xkl.authorization.annotation.Sign; | 6 | +import com.xkl.authorization.annotation.*; |
10 | import com.xkl.authorization.manager.ITokenManager; | 7 | import com.xkl.authorization.manager.ITokenManager; |
11 | import com.xkl.authorization.model.TokenModel; | 8 | import com.xkl.authorization.model.TokenModel; |
9 | +import com.xkl.config.Constants; | ||
12 | import com.xkl.config.ResultStatus; | 10 | import com.xkl.config.ResultStatus; |
13 | import com.xkl.domain.User; | 11 | import com.xkl.domain.User; |
12 | +import com.xkl.domain.XklAdminEntity; | ||
14 | import com.xkl.model.ResultModel; | 13 | import com.xkl.model.ResultModel; |
15 | import com.xkl.security.AntiXSS; | 14 | import com.xkl.security.AntiXSS; |
16 | import com.xkl.service.ILoginService; | 15 | import com.xkl.service.ILoginService; |
@@ -76,4 +75,43 @@ public class TokenController { | @@ -76,4 +75,43 @@ public class TokenController { | ||
76 | return new ResponseEntity<>(ResultModel.ok(ResultStatus.USER_LOGOUT), HttpStatus.OK); | 75 | return new ResponseEntity<>(ResultModel.ok(ResultStatus.USER_LOGOUT), HttpStatus.OK); |
77 | } | 76 | } |
78 | 77 | ||
78 | + @LogAnnotation | ||
79 | + @AntiXSS | ||
80 | + @Sign | ||
81 | + @RequestMapping(value = "/admin", method = RequestMethod.POST) | ||
82 | + @ApiOperation(value = "管理员登录接口") | ||
83 | + public ResponseEntity<ResultModel> adminLogin(HttpServletRequest request, @RequestParam String username, @RequestParam String password, | ||
84 | + @RequestParam String sign, @RequestParam long t, @RequestParam int type) { | ||
85 | + if (!(boolean) request.getAttribute("signAspect")) | ||
86 | + return new ResponseEntity<>(ResultModel.error(ResultStatus.SIGN_ERROR), HttpStatus.OK); | ||
87 | + | ||
88 | + Assert.notNull(username, "username can not be empty"); | ||
89 | + Assert.notNull(password, "password can not be empty"); | ||
90 | + | ||
91 | + XklAdminEntity admin = loginService.checkAdmin(username, password); | ||
92 | + if (admin == null) {//用户,密码错误 | ||
93 | + return new ResponseEntity<>(ResultModel.error(ResultStatus.USERNAME_OR_PASSWORD_ERROR), HttpStatus.OK); | ||
94 | + } | ||
95 | + //生成一个token,保存用户登录状态 | ||
96 | + TokenModel model = tokenManager.createToken(Constants.ADMIN_TOKEN_PREFIX + String.valueOf(admin.getId())); | ||
97 | + return new ResponseEntity<>(ResultModel.ok(model), HttpStatus.OK); | ||
98 | + } | ||
99 | + | ||
100 | + @LogAnnotation | ||
101 | + @AntiXSS | ||
102 | + @Authorization | ||
103 | + @Sign | ||
104 | + @RequestMapping(value = "/admin",method = RequestMethod.DELETE) | ||
105 | + @ApiOperation(value = "Admin logout") | ||
106 | + @ApiImplicitParams({ | ||
107 | + @ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"), | ||
108 | + }) | ||
109 | + public ResponseEntity<ResultModel> logout(HttpServletRequest request, @CurrentAdmin XklAdminEntity admin, | ||
110 | + @RequestParam String sign, @RequestParam long t, @RequestParam int type) { | ||
111 | + if (!(boolean) request.getAttribute("signAspect")) | ||
112 | + return new ResponseEntity<>(ResultModel.error(ResultStatus.SIGN_ERROR), HttpStatus.OK); | ||
113 | + tokenManager.deleteToken(Constants.ADMIN_TOKEN_PREFIX + admin.getId()); | ||
114 | + return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK); | ||
115 | + } | ||
116 | + | ||
79 | } | 117 | } |
@@ -6,15 +6,19 @@ import com.xkl.config.Constants; | @@ -6,15 +6,19 @@ import com.xkl.config.Constants; | ||
6 | import com.xkl.config.ResultStatus; | 6 | import com.xkl.config.ResultStatus; |
7 | import com.xkl.domain.User; | 7 | import com.xkl.domain.User; |
8 | import com.xkl.domain.XklAdminEntity; | 8 | import com.xkl.domain.XklAdminEntity; |
9 | +import com.xkl.domain.XklCompanyEntity; | ||
9 | import com.xkl.domain.XklMemberEntity; | 10 | import com.xkl.domain.XklMemberEntity; |
11 | +import com.xkl.model.CityModel; | ||
10 | import com.xkl.model.ResultModel; | 12 | import com.xkl.model.ResultModel; |
11 | import com.xkl.repository.UserRepository; | 13 | import com.xkl.repository.UserRepository; |
14 | +import com.xkl.repository.XklCompanyRespository; | ||
12 | import com.xkl.repository.XklMemberRespository; | 15 | import com.xkl.repository.XklMemberRespository; |
13 | import com.xkl.security.AntiXSS; | 16 | import com.xkl.security.AntiXSS; |
14 | import com.wordnik.swagger.annotations.ApiImplicitParam; | 17 | import com.wordnik.swagger.annotations.ApiImplicitParam; |
15 | import com.wordnik.swagger.annotations.ApiImplicitParams; | 18 | import com.wordnik.swagger.annotations.ApiImplicitParams; |
16 | import com.wordnik.swagger.annotations.ApiOperation; | 19 | import com.wordnik.swagger.annotations.ApiOperation; |
17 | import com.xkl.security.SecurityTool; | 20 | import com.xkl.security.SecurityTool; |
21 | +import com.xkl.tools.UtilTools; | ||
18 | import org.springframework.beans.factory.annotation.Autowired; | 22 | import org.springframework.beans.factory.annotation.Autowired; |
19 | import org.springframework.http.HttpStatus; | 23 | import org.springframework.http.HttpStatus; |
20 | import org.springframework.http.ResponseEntity; | 24 | import org.springframework.http.ResponseEntity; |
@@ -25,7 +29,7 @@ import org.springframework.web.bind.annotation.RequestParam; | @@ -25,7 +29,7 @@ import org.springframework.web.bind.annotation.RequestParam; | ||
25 | import org.springframework.web.bind.annotation.RestController; | 29 | import org.springframework.web.bind.annotation.RestController; |
26 | 30 | ||
27 | import javax.servlet.http.HttpServletRequest; | 31 | import javax.servlet.http.HttpServletRequest; |
28 | -import javax.xml.transform.Result; | 32 | +import java.sql.Date; |
29 | 33 | ||
30 | /** | 34 | /** |
31 | * Created by win7 on 2016/10/19. | 35 | * Created by win7 on 2016/10/19. |
@@ -39,39 +43,77 @@ public class UserInfoController { | @@ -39,39 +43,77 @@ public class UserInfoController { | ||
39 | private ITokenManager tokenManager; | 43 | private ITokenManager tokenManager; |
40 | @Autowired | 44 | @Autowired |
41 | private XklMemberRespository xklMemberRespository; | 45 | private XklMemberRespository xklMemberRespository; |
46 | + @Autowired | ||
47 | + private XklCompanyRespository xklCompanyRespository; | ||
42 | 48 | ||
43 | @LogAnnotation | 49 | @LogAnnotation |
44 | @AntiXSS | 50 | @AntiXSS |
51 | + @Authorization | ||
45 | @Sign | 52 | @Sign |
46 | @RequestMapping(method = RequestMethod.POST) | 53 | @RequestMapping(method = RequestMethod.POST) |
47 | @ApiOperation(value = "用户注册接口") | 54 | @ApiOperation(value = "用户注册接口") |
48 | - public ResponseEntity<ResultModel> register(HttpServletRequest request,@RequestParam String username, @RequestParam String password, | ||
49 | - @RequestParam String sign,@RequestParam long t,@RequestParam int type) { | 55 | + public ResponseEntity<ResultModel> register(HttpServletRequest request, @CurrentAdmin XklAdminEntity admin, @RequestParam String username, @RequestParam String password, |
56 | + @RequestParam String name, @RequestParam String phone,@RequestParam boolean sex,@RequestParam String birthDate, | ||
57 | + @RequestParam(required=false) String idcard, | ||
58 | + @RequestParam String sign, @RequestParam long t, @RequestParam int type) { | ||
50 | if(!(boolean)request.getAttribute("signAspect")) | 59 | if(!(boolean)request.getAttribute("signAspect")) |
51 | return new ResponseEntity<>(ResultModel.error(ResultStatus.SIGN_ERROR), HttpStatus.OK); | 60 | return new ResponseEntity<>(ResultModel.error(ResultStatus.SIGN_ERROR), HttpStatus.OK); |
52 | 61 | ||
53 | Assert.notNull(username, "username can not be empty"); | 62 | Assert.notNull(username, "username can not be empty"); |
54 | Assert.notNull(password, "password can not be empty"); | 63 | Assert.notNull(password, "password can not be empty"); |
64 | + Assert.notNull(name, "name can not be empty"); | ||
65 | + Assert.notNull(sex, "sex can not be empty"); | ||
66 | + Assert.notNull(birthDate, "birthDate can not be empty"); | ||
67 | + Assert.notNull(phone, "phone can not be empty"); | ||
55 | 68 | ||
56 | User user = userRepository.findByLoginAccountAndStatus(username, Constants.STATUS_OK2); | 69 | User user = userRepository.findByLoginAccountAndStatus(username, Constants.STATUS_OK2); |
57 | if (user != null ) { //用户已注册 | 70 | if (user != null ) { //用户已注册 |
58 | return new ResponseEntity<>(ResultModel.error(ResultStatus.USER_IS_EXIT), HttpStatus.OK); | 71 | return new ResponseEntity<>(ResultModel.error(ResultStatus.USER_IS_EXIT), HttpStatus.OK); |
59 | }else{ | 72 | }else{ |
60 | - String salt= SecurityTool.genSalt(); | ||
61 | - String pass=SecurityTool.getPassword(username,password,salt); | ||
62 | - user = new User(); | ||
63 | /** | 73 | /** |
64 | - * TODO: | ||
65 | - * 1. sign检测注解@Sign先注释掉 ,便于测试 | ||
66 | - * 2. 暂时把所有注册的用户的member表member_id都设置为1 | 74 | + * member表 |
67 | */ | 75 | */ |
76 | + XklMemberEntity member = new XklMemberEntity(); | ||
77 | + member.setName(name); | ||
78 | + member.setSex(sex); | ||
79 | + member.setBirthDate(birthDate); | ||
80 | + member.setPhone(phone); | ||
81 | + member.setRegisterBy(admin.getId()); | ||
82 | + member.setCompanyId(admin.getCoid()); | ||
83 | + member.setRegisterTime(UtilTools.getNow()); | ||
84 | + member.setStatus(1); | ||
85 | + //member表自动判断归属地 | ||
86 | + if(idcard!=null&&idcard!=""){//身份证存在 | ||
87 | + member.setIdcard(idcard); | ||
88 | + CityModel cityModel = Constants.cityMap.get(idcard.substring(0,6)); | ||
89 | + if(cityModel!=null){ | ||
90 | + member.setCountry(cityModel.getCountry()); | ||
91 | + member.setProvince(cityModel.getProvince()); | ||
92 | + member.setCity(cityModel.getCity()); | ||
93 | + } | ||
94 | + }else{ | ||
95 | + long coid = admin.getCoid(); | ||
96 | + XklCompanyEntity xklCompanyEntity = xklCompanyRespository.findOne(coid); | ||
97 | + if(xklCompanyEntity!=null){ | ||
98 | + member.setCountry(xklCompanyEntity.getCountryId()); | ||
99 | + member.setProvince(xklCompanyEntity.getProvinceId()); | ||
100 | + member.setCity(xklCompanyEntity.getCityId()); | ||
101 | + } | ||
102 | + | ||
103 | + } | ||
104 | + XklMemberEntity memberEntity = xklMemberRespository.save(member); | ||
105 | + if(memberEntity!=null){ | ||
106 | + String salt= SecurityTool.genSalt(); | ||
107 | + String pass=SecurityTool.getPassword(username,password,salt); | ||
108 | + user = new User(); | ||
68 | 109 | ||
69 | - user.setMemberId(1); | ||
70 | - user.setLoginAccount(username); | ||
71 | - user.setLoginPwd(pass); | ||
72 | - user.setSalt(salt); | ||
73 | - user.setStatus(true); | ||
74 | - userRepository.save(user); | 110 | + user.setMemberId(memberEntity.getId()); |
111 | + user.setLoginAccount(username); | ||
112 | + user.setLoginPwd(pass); | ||
113 | + user.setSalt(salt); | ||
114 | + user.setStatus(true); | ||
115 | + userRepository.save(user); | ||
116 | + } | ||
75 | } | 117 | } |
76 | return new ResponseEntity<>(ResultModel.ok(ResultStatus.USER_REGISTER), HttpStatus.OK); | 118 | return new ResponseEntity<>(ResultModel.ok(ResultStatus.USER_REGISTER), HttpStatus.OK); |
77 | } | 119 | } |
@@ -32,54 +32,6 @@ public class User { | @@ -32,54 +32,6 @@ public class User { | ||
32 | private boolean status; | 32 | private boolean status; |
33 | 33 | ||
34 | @Column(name = "member_id") | 34 | @Column(name = "member_id") |
35 | + private long memberId; | ||
35 | 36 | ||
36 | - private int memberId; | ||
37 | - | ||
38 | - public String getLoginAccount() { | ||
39 | - return loginAccount; | ||
40 | - } | ||
41 | - | ||
42 | - public void setLoginAccount(String loginAccount) { | ||
43 | - this.loginAccount = loginAccount; | ||
44 | - } | ||
45 | - | ||
46 | - public String getLoginPwd() { | ||
47 | - return loginPwd; | ||
48 | - } | ||
49 | - | ||
50 | - public void setLoginPwd(String loginPwd) { | ||
51 | - this.loginPwd = loginPwd; | ||
52 | - } | ||
53 | - | ||
54 | - public long getId() { | ||
55 | - return id; | ||
56 | - } | ||
57 | - | ||
58 | - public void setId(long id) { | ||
59 | - this.id = id; | ||
60 | - } | ||
61 | - | ||
62 | - public String getSalt() { | ||
63 | - return salt; | ||
64 | - } | ||
65 | - | ||
66 | - public void setSalt(String salt) { | ||
67 | - this.salt = salt; | ||
68 | - } | ||
69 | - | ||
70 | - public boolean isStatus() { | ||
71 | - return status; | ||
72 | - } | ||
73 | - | ||
74 | - public void setStatus(boolean status) { | ||
75 | - this.status = status; | ||
76 | - } | ||
77 | - | ||
78 | - public int getMemberId() { | ||
79 | - return memberId; | ||
80 | - } | ||
81 | - | ||
82 | - public void setMemberId(int memberId) { | ||
83 | - this.memberId = memberId; | ||
84 | - } | ||
85 | } | 37 | } |
1 | +package com.xkl.domain; | ||
2 | + | ||
3 | +import lombok.Data; | ||
4 | + | ||
5 | +import javax.persistence.*; | ||
6 | + | ||
7 | +/** | ||
8 | + * Created by win7 on 2017/2/27. | ||
9 | + */ | ||
10 | +@Data | ||
11 | +@Entity | ||
12 | +@Table(name = "xkl_city") | ||
13 | +public class XklCityEntity { | ||
14 | + @Id | ||
15 | + @GeneratedValue | ||
16 | + @Column(name = "id") | ||
17 | + private long id; | ||
18 | + @Basic | ||
19 | + @Column(name = "city_name") | ||
20 | + private String cityName; | ||
21 | + @Basic | ||
22 | + @Column(name = "parent_id") | ||
23 | + private long parentId; | ||
24 | + @Basic | ||
25 | + @Column(name = "state") | ||
26 | + private Byte state; | ||
27 | + @Basic | ||
28 | + @Column(name = "remark") | ||
29 | + private String remark; | ||
30 | + @Basic | ||
31 | + @Column(name = "city_sort") | ||
32 | + private Byte citySort; | ||
33 | + @Basic | ||
34 | + @Column(name = "city_area") | ||
35 | + private String cityArea; | ||
36 | + @Basic | ||
37 | + @Column(name = "id_card_code") | ||
38 | + private String idCardCode; | ||
39 | + @Basic | ||
40 | + @Column(name = "first_pinyin") | ||
41 | + private String firstPinyin; | ||
42 | + @Basic | ||
43 | + @Column(name = "full_pinyin") | ||
44 | + private String fullPinyin; | ||
45 | + @Basic | ||
46 | + @Column(name = "simple_pinyin") | ||
47 | + private String simplePinyin; | ||
48 | +} |
1 | -package com.xkl.domain; | 1 | +import lombok.Data; |
2 | 2 | ||
3 | -import javax.persistence.Column; | ||
4 | -import javax.persistence.Entity; | ||
5 | -import javax.persistence.Id; | ||
6 | -import javax.persistence.Table; | 3 | +import javax.persistence.*; |
7 | 4 | ||
8 | /** | 5 | /** |
9 | - * 公司数据的domain类 | 6 | + * Created by win7 on 2017/2/27. |
10 | */ | 7 | */ |
8 | +@Data | ||
11 | @Entity | 9 | @Entity |
12 | @Table(name = "xkl_company") | 10 | @Table(name = "xkl_company") |
13 | public class XklCompanyEntity { | 11 | public class XklCompanyEntity { |
14 | - //公司id | ||
15 | @Id | 12 | @Id |
13 | + @GeneratedValue | ||
16 | @Column(name = "id") | 14 | @Column(name = "id") |
17 | private long id; | 15 | private long id; |
18 | - | 16 | + @Basic |
19 | @Column(name = "name") | 17 | @Column(name = "name") |
20 | private String name; | 18 | private String name; |
21 | - | 19 | + @Basic |
22 | @Column(name = "parent_id") | 20 | @Column(name = "parent_id") |
23 | private long parentId; | 21 | private long parentId; |
24 | - | 22 | + @Basic |
25 | @Column(name = "province_id") | 23 | @Column(name = "province_id") |
26 | private long provinceId; | 24 | private long provinceId; |
27 | - | 25 | + @Basic |
28 | @Column(name = "city_id") | 26 | @Column(name = "city_id") |
29 | private long cityId; | 27 | private long cityId; |
30 | - | 28 | + @Basic |
31 | @Column(name = "country_id") | 29 | @Column(name = "country_id") |
32 | private long countryId; | 30 | private long countryId; |
33 | - | 31 | + @Basic |
34 | @Column(name = "company_code") | 32 | @Column(name = "company_code") |
35 | private long companyCode; | 33 | private long companyCode; |
36 | - | 34 | + @Basic |
37 | @Column(name = "company_type") | 35 | @Column(name = "company_type") |
38 | private int companyType; | 36 | private int companyType; |
39 | - | 37 | + @Basic |
40 | @Column(name = "level") | 38 | @Column(name = "level") |
41 | private int level; | 39 | private int level; |
42 | - | 40 | + @Basic |
43 | @Column(name = "show_level") | 41 | @Column(name = "show_level") |
44 | private int showLevel; | 42 | private int showLevel; |
45 | - | 43 | + @Basic |
46 | @Column(name = "status") | 44 | @Column(name = "status") |
47 | private int status; | 45 | private int status; |
48 | - | ||
49 | - public long getId() { | ||
50 | - return id; | ||
51 | - } | ||
52 | - | ||
53 | - public void setId(long id) { | ||
54 | - this.id = id; | ||
55 | - } | ||
56 | - | ||
57 | - public String getName() { | ||
58 | - return name; | ||
59 | - } | ||
60 | - | ||
61 | - public void setName(String name) { | ||
62 | - this.name = name; | ||
63 | - } | ||
64 | - | ||
65 | - public long getParentId() { | ||
66 | - return parentId; | ||
67 | - } | ||
68 | - | ||
69 | - public void setParentId(long parentId) { | ||
70 | - this.parentId = parentId; | ||
71 | - } | ||
72 | - | ||
73 | - public long getProvinceId() { | ||
74 | - return provinceId; | ||
75 | - } | ||
76 | - | ||
77 | - public void setProvinceId(long provinceId) { | ||
78 | - this.provinceId = provinceId; | ||
79 | - } | ||
80 | - | ||
81 | - public long getCityId() { | ||
82 | - return cityId; | ||
83 | - } | ||
84 | - | ||
85 | - public void setCityId(long cityId) { | ||
86 | - this.cityId = cityId; | ||
87 | - } | ||
88 | - | ||
89 | - public long getCountryId() { | ||
90 | - return countryId; | ||
91 | - } | ||
92 | - | ||
93 | - public void setCountryId(long countryId) { | ||
94 | - this.countryId = countryId; | ||
95 | - } | ||
96 | - | ||
97 | - public long getCompanyCode() { | ||
98 | - return companyCode; | ||
99 | - } | ||
100 | - | ||
101 | - public void setCompanyCode(long companyCode) { | ||
102 | - this.companyCode = companyCode; | ||
103 | - } | ||
104 | - | ||
105 | - public int getCompanyType() { | ||
106 | - return companyType; | ||
107 | - } | ||
108 | - | ||
109 | - public void setCompanyType(int companyType) { | ||
110 | - this.companyType = companyType; | ||
111 | - } | ||
112 | - | ||
113 | - public int getLevel() { | ||
114 | - return level; | ||
115 | - } | ||
116 | - | ||
117 | - public void setLevel(int level) { | ||
118 | - this.level = level; | ||
119 | - } | ||
120 | - | ||
121 | - public int getShowLevel() { | ||
122 | - return showLevel; | ||
123 | - } | ||
124 | - | ||
125 | - public void setShowLevel(int showLevel) { | ||
126 | - this.showLevel = showLevel; | ||
127 | - } | ||
128 | - | ||
129 | - public int getStatus() { | ||
130 | - return status; | ||
131 | - } | ||
132 | - | ||
133 | - public void setStatus(int status) { | ||
134 | - this.status = status; | ||
135 | - } | ||
136 | } | 46 | } |
@@ -23,10 +23,10 @@ public class XklMemberEntity { | @@ -23,10 +23,10 @@ public class XklMemberEntity { | ||
23 | private String name; | 23 | private String name; |
24 | @Basic | 24 | @Basic |
25 | @Column(name = "sex") | 25 | @Column(name = "sex") |
26 | - private Byte sex; | 26 | + private boolean sex; |
27 | @Basic | 27 | @Basic |
28 | @Column(name = "birth_date") | 28 | @Column(name = "birth_date") |
29 | - private Date birthDate; | 29 | + private String birthDate; |
30 | @Basic | 30 | @Basic |
31 | @Column(name = "idcard") | 31 | @Column(name = "idcard") |
32 | private String idcard; | 32 | private String idcard; |
@@ -53,5 +53,5 @@ public class XklMemberEntity { | @@ -53,5 +53,5 @@ public class XklMemberEntity { | ||
53 | private long registerBy; | 53 | private long registerBy; |
54 | @Basic | 54 | @Basic |
55 | @Column(name = "status") | 55 | @Column(name = "status") |
56 | - private Byte status; | 56 | + private int status; |
57 | } | 57 | } |
src/main/java/com/xkl/model/CityModel.java
0 → 100644
1 | +package com.xkl.model; | ||
2 | + | ||
3 | +import lombok.AllArgsConstructor; | ||
4 | +import lombok.Data; | ||
5 | + | ||
6 | +/** | ||
7 | + * Created by win7 on 2017/2/27. | ||
8 | + */ | ||
9 | +@Data | ||
10 | +public class CityModel { | ||
11 | + long country = 0;//国家 | ||
12 | + long province = 0;//省(直辖市) | ||
13 | + long city = 0;//市(直辖市的区) | ||
14 | + long county = 0;//县 | ||
15 | + int type = 0; | ||
16 | +} |
1 | +package com.xkl.repository; | ||
2 | + | ||
3 | +import com.xkl.domain.XklCityEntity; | ||
4 | +import com.xkl.domain.XklInterKeyEntity; | ||
5 | +import org.springframework.data.repository.CrudRepository; | ||
6 | + | ||
7 | +/** | ||
8 | + * Created by win7 on 2016/11/20. | ||
9 | + */ | ||
10 | +public interface XklCityRespository extends CrudRepository<XklCityEntity, Long> { | ||
11 | + | ||
12 | +} |
1 | +package com.xkl.repository; | ||
2 | + | ||
3 | +import com.xkl.domain.XklCityEntity; | ||
4 | +import com.xkl.domain.XklCompanyEntity; | ||
5 | +import org.springframework.data.repository.CrudRepository; | ||
6 | + | ||
7 | +/** | ||
8 | + * Created by win7 on 2016/11/20. | ||
9 | + */ | ||
10 | +public interface XklCompanyRespository extends CrudRepository<XklCompanyEntity, Long> { | ||
11 | + | ||
12 | +} |
1 | package com.xkl.service; | 1 | package com.xkl.service; |
2 | 2 | ||
3 | import com.xkl.domain.User; | 3 | import com.xkl.domain.User; |
4 | +import com.xkl.domain.XklAdminEntity; | ||
4 | 5 | ||
5 | /** | 6 | /** |
6 | * Created by win7 on 2016/12/18. | 7 | * Created by win7 on 2016/12/18. |
@@ -8,5 +9,5 @@ import com.xkl.domain.User; | @@ -8,5 +9,5 @@ import com.xkl.domain.User; | ||
8 | public interface ILoginService { | 9 | public interface ILoginService { |
9 | public User check(String username, String password); | 10 | public User check(String username, String password); |
10 | public User check(String username); | 11 | public User check(String username); |
11 | - | 12 | + public XklAdminEntity checkAdmin(String username, String password); |
12 | } | 13 | } |
@@ -2,6 +2,8 @@ package com.xkl.service; | @@ -2,6 +2,8 @@ package com.xkl.service; | ||
2 | 2 | ||
3 | import com.xkl.config.Constants; | 3 | import com.xkl.config.Constants; |
4 | import com.xkl.domain.User; | 4 | import com.xkl.domain.User; |
5 | +import com.xkl.domain.XklAdminEntity; | ||
6 | +import com.xkl.repository.AdminRepository; | ||
5 | import com.xkl.repository.UserRepository; | 7 | import com.xkl.repository.UserRepository; |
6 | import com.xkl.security.SecurityTool; | 8 | import com.xkl.security.SecurityTool; |
7 | import org.springframework.beans.factory.annotation.Autowired; | 9 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -14,6 +16,8 @@ import org.springframework.stereotype.Service; | @@ -14,6 +16,8 @@ import org.springframework.stereotype.Service; | ||
14 | public class LoginServiceImpl implements ILoginService{ | 16 | public class LoginServiceImpl implements ILoginService{ |
15 | @Autowired | 17 | @Autowired |
16 | private UserRepository userRepository; | 18 | private UserRepository userRepository; |
19 | + @Autowired | ||
20 | + private AdminRepository adminRepository; | ||
17 | @Override | 21 | @Override |
18 | public User check(String username, String password) { | 22 | public User check(String username, String password) { |
19 | User user = userRepository.findByLoginAccountAndStatus(username, Constants.STATUS_OK2); | 23 | User user = userRepository.findByLoginAccountAndStatus(username, Constants.STATUS_OK2); |
@@ -35,4 +39,19 @@ public class LoginServiceImpl implements ILoginService{ | @@ -35,4 +39,19 @@ public class LoginServiceImpl implements ILoginService{ | ||
35 | User user = userRepository.findByLoginAccountAndStatus(username.trim(), Constants.STATUS_OK2); | 39 | User user = userRepository.findByLoginAccountAndStatus(username.trim(), Constants.STATUS_OK2); |
36 | return user; | 40 | return user; |
37 | } | 41 | } |
42 | + | ||
43 | + @Override | ||
44 | + public XklAdminEntity checkAdmin(String username, String password) { | ||
45 | + XklAdminEntity admin = adminRepository.findByAccountAndStatus(username, Constants.STATUS_OK); | ||
46 | + if(admin == null){ | ||
47 | + return null; | ||
48 | + }else{ | ||
49 | + String salt = admin.getSalt(); | ||
50 | + String pass_in_db = admin.getPwd(); | ||
51 | + String pass = SecurityTool.getPassword(username, password, salt); | ||
52 | + if (!pass.equals(pass_in_db))//密码错误 | ||
53 | + return null; | ||
54 | + } | ||
55 | + return admin; | ||
56 | + } | ||
38 | } | 57 | } |
@@ -79,6 +79,13 @@ public class UtilTools { | @@ -79,6 +79,13 @@ public class UtilTools { | ||
79 | return a; | 79 | return a; |
80 | } | 80 | } |
81 | 81 | ||
82 | + public static String getNow(){ | ||
83 | + Calendar c = Calendar.getInstance(); //获取东八区时间 | ||
84 | + SimpleDateFormat s=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | ||
85 | + String curDate = s.format(c.getTime()); | ||
86 | + return curDate; | ||
87 | + } | ||
88 | + | ||
82 | public static long _long(String value) { | 89 | public static long _long(String value) { |
83 | if (value == null || "null".equals(value)) { | 90 | if (value == null || "null".equals(value)) { |
84 | return 0; | 91 | return 0; |
@@ -129,7 +136,8 @@ public class UtilTools { | @@ -129,7 +136,8 @@ public class UtilTools { | ||
129 | } | 136 | } |
130 | 137 | ||
131 | public static void main(String[] args) { | 138 | public static void main(String[] args) { |
132 | - System.out.println(getLongTime("2016-10-11 22:22:22")); | 139 | + System.out.println(getLongTime("2016-10-11 22:22:22")); |
140 | + System.out.println(getNow()); | ||
133 | } | 141 | } |
134 | 142 | ||
135 | 143 |
-
Please register or login to post a comment