Commit c22685a4 by guojuxing

新建商户和超级管理员

parent 299e3bc7
package com.gic.auth.constant;
/**
* @author guojx
* @date 2019/7/17 10:55 AM
*/
public class UserConstants {
/**
* 密码自动生成类型
*/
public static final int CREATE_AUTO = 1;
/**
* 自定义生成密码类型
*/
public static final int CREATE_MYSELF = 2;
}
......@@ -15,31 +15,45 @@ public class UserDTO implements Serializable{
public interface SaveUserValid {
}
public interface EditUserValid {
}
/**
* 用户id
*/
@NotNull(message = "用户ID不能为空", groups = {EditUserValid.class})
private Integer userId;
/**
* 用户名
*/
@NotBlank(message = "用户名不能为空", groups = {SaveUserValid.class})
@NotBlank(message = "用户名不能为空", groups = {SaveUserValid.class, EditUserValid.class})
private String userName;
/**
* 手机号码
*/
@NotBlank(message = "手机号不能为空", groups = {SaveUserValid.class})
@NotBlank(message = "手机号不能为空", groups = {SaveUserValid.class, EditUserValid.class})
private String phoneNumber;
/**
* 密码
*/
@NotBlank(message = "密码不能为空", groups = {SaveUserValid.class})
private String password;
/**
* 1:自动生成 2:自定义密码
*/
private Integer passwordType;
/**
* 确认密码
*/
private String confirmPassword;
/**
* 是否是超级管理员
*/
@NotNull(message = "用户类型不能为空", groups = {SaveUserValid.class})
......@@ -63,13 +77,13 @@ public class UserDTO implements Serializable{
/**
*
*/
@NotNull(message = "企业ID不能为空", groups = {SaveUserValid.class})
@NotNull(message = "企业ID不能为空", groups = {EditUserValid.class})
private Integer enterpriseId;
/**
* 国际区号,如中国 86
*/
@NotBlank(message = "手机国际区号不能为空", groups = {SaveUserValid.class})
@NotBlank(message = "手机国际区号不能为空", groups = {SaveUserValid.class, EditUserValid.class})
private String phoneAreaCode;
public Integer getUserId() {
......@@ -151,4 +165,20 @@ public class UserDTO implements Serializable{
public void setPhoneAreaCode(String phoneAreaCode) {
this.phoneAreaCode = phoneAreaCode;
}
public Integer getPasswordType() {
return passwordType;
}
public void setPasswordType(Integer passwordType) {
this.passwordType = passwordType;
}
public String getConfirmPassword() {
return confirmPassword;
}
public void setConfirmPassword(String confirmPassword) {
this.confirmPassword = confirmPassword;
}
}
......@@ -15,4 +15,13 @@ public interface UserApiService {
* @return
*/
ServiceResponse<Integer> saveUser(UserDTO userDTO);
/**
* 编辑
* @param userDTO
* @return
*/
ServiceResponse editUser(UserDTO userDTO);
ServiceResponse<UserDTO> getUserById(Integer userId);
}
package com.gic.auth.utils;
import java.util.Random;
/**
* @author guojx
* @date 2019/7/17 9:25 AM
*/
public class CreatePasswordAutoUtil {
/**
* 随机生成字母、数字参合的密码
* @param length 生成多少位数的密码
* @return
*/
public static String getStringRandom(int length) {
String val = "";
Random random = new Random();
//length为几位密码
for (int i = 0; i < length; i++) {
String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";
//输出字母还是数字
if ("char".equalsIgnoreCase(charOrNum)) {
//输出是大写字母还是小写字母
int temp = random.nextInt(2) % 2 == 0 ? 65 : 97;
val += (char) (random.nextInt(26) + temp);
} else if ("num".equalsIgnoreCase(charOrNum)) {
val += String.valueOf(random.nextInt(10));
}
}
return val;
}
}
package com.gic.enterprise.dao.mapper;
import com.gic.enterprise.entity.TabUser;
import org.apache.ibatis.annotations.Param;
public interface TabUserMapper {
/**
......@@ -50,4 +51,12 @@ public interface TabUserMapper {
* @return 更新条目数
*/
int updateByPrimaryKey(TabUser record);
/**
* 手机号码查询个数
* @param phone
* @param userId
* @return
*/
int countByPhone(@Param("phone") String phone, @Param("userId") Integer userId);
}
\ No newline at end of file
package com.gic.enterprise.service;
import com.gic.auth.dto.UserDTO;
import com.gic.enterprise.entity.TabUser;
/**
* @author guojx
......@@ -14,4 +15,21 @@ public interface UserService {
* @return
*/
int saveUser(UserDTO userDTO);
void editUser(UserDTO userDTO);
/**
* 根据主键获取数据
* @param userId
* @return
*/
TabUser getUserById(Integer userId);
/**
* 手机号码是否重复
* @param userId
* @param phone
* @return
*/
boolean isPhoneRepeat(Integer userId, String phone);
}
......@@ -22,4 +22,24 @@ public class UserServiceImpl implements UserService{
tabUserMapper.insert(tabUser);
return tabUser.getUserId();
}
@Override
public void editUser(UserDTO userDTO) {
TabUser tabUser = EntityUtil.changeEntityNew(TabUser.class, userDTO);
tabUserMapper.updateByPrimaryKeySelective(tabUser);
}
@Override
public TabUser getUserById(Integer userId) {
return tabUserMapper.selectByPrimaryKey(userId);
}
@Override
public boolean isPhoneRepeat(Integer userId, String phone) {
int count = tabUserMapper.countByPhone(phone, userId);
if (count > 0) {
return true;
}
return false;
}
}
......@@ -3,6 +3,9 @@ package com.gic.enterprise.service.outer;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.auth.dto.UserDTO;
import com.gic.auth.service.UserApiService;
import com.gic.commons.util.EntityUtil;
import com.gic.enterprise.entity.TabUser;
import com.gic.enterprise.error.ErrorCode;
import com.gic.enterprise.service.UserService;
import com.gic.store.utils.valid.ValidUtil;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -25,9 +28,41 @@ public class UserApiServiceImpl implements UserApiService{
if (!paramResult.isSuccess()) {
return paramResult;
}
if (userService.isPhoneRepeat(null, userDTO.getPhoneNumber())) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "手机号码不能重复");
}
userDTO.setCreateTime(new Date());
userDTO.setUpdateTime(new Date());
userDTO.setStatus(1);
return ServiceResponse.success(userService.saveUser(userDTO));
}
@Override
public ServiceResponse editUser(UserDTO userDTO) {
//valid param
ServiceResponse paramResult = ValidUtil.allCheckValidate(userDTO, UserDTO.EditUserValid.class);
if (!paramResult.isSuccess()) {
return paramResult;
}
TabUser tabUser = userService.getUserById(userDTO.getUserId());
if (tabUser == null) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "用户ID输入有误");
}
if (userService.isPhoneRepeat(userDTO.getUserId(), userDTO.getPhoneNumber())) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "手机号码不能重复");
}
userDTO.setUpdateTime(new Date());
userService.editUser(userDTO);
return ServiceResponse.success();
}
@Override
public ServiceResponse<UserDTO> getUserById(Integer userId) {
TabUser tabUser = userService.getUserById(userId);
if (tabUser == null) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "用户ID输入有误");
}
return ServiceResponse.success(EntityUtil.changeEntityNew(UserDTO.class, tabUser));
}
}
......@@ -15,30 +15,7 @@
<dubbo:protocol name="dubbo" port="20320"/>
<!--门店域-->
<dubbo:service interface="com.gic.store.service.StoreRegionApiService" ref="storeRegionApiService" timeout="60000" />
<!--门店品牌-->
<dubbo:service interface="com.gic.store.service.StoreBrandApiService" ref="storeBrandApiService" timeout="60000" />
<dubbo:service interface="com.gic.store.service.StoreDictApiService" ref="storeDictApiService" timeout="6000" />
<dubbo:service interface="com.gic.auth.service.UserApiService" ref="userApiService" timeout="60000" />
<dubbo:reference interface="com.gic.bizdict.api.service.BizdictService" id="bizdictService " timeout="6000" retries="0"/>
<!--分组-->
<dubbo:service interface="com.gic.store.service.StoreGroupApiService" ref="storeGroupApiService" timeout="60000" />
<!--自定义域字段-->
<dubbo:service interface="com.gic.store.service.StoreFieldApiService" ref="storeFieldApiService" timeout="60000" />
<dubbo:service interface="com.gic.store.service.StoreFieldSelectApiService" ref="storeFieldSelectApiService" timeout="60000" />
<!--门店-->
<dubbo:service interface="com.gic.store.service.StoreApiService" ref="storeApiService" timeout="60000" />
<dubbo:service interface="com.gic.store.service.ProvincesApiService" ref="provincesApiService" timeout="60000" />
<!--分组策略-->
<dubbo:service interface="com.gic.store.service.StoreStrategyApiService" ref="storeStrategyApiService" timeout="60000"/>
<!--门店导入-->
<dubbo:service interface="com.gic.store.service.StoreImportApiService" ref="storeImportApiService" timeout="60000" />
<dubbo:service interface="com.gic.store.service.StoreTaskApiService" ref="storeTaskApiService" timeout="60000" />
<dubbo:service interface="com.gic.store.service.StoreStatusSettingApiService" ref="storeStatusSettingApiService" timeout="60000" />
<dubbo:reference interface="com.gic.log.api.service.LogApiService" id="logApiService" timeout="60000" />
</beans>
......@@ -150,4 +150,13 @@
phone_area_code = #{phoneAreaCode,jdbcType=VARCHAR}
where user_id = #{userId,jdbcType=INTEGER}
</update>
<select id="countByPhone" resultType="int">
select count(1) from tab_user
where status = 1
<if test="userId != null">
user_id <![CDATA[ <> ]]> #{userId}
</if>
and phone_number = #{phone}
</select>
</mapper>
\ No newline at end of file
package com.gic.auth.web.exception;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.enterprise.error.ErrorCode;
import com.gic.store.constant.StoreGroupErrorEnum;
import com.gic.store.exception.StoreException;
import com.gic.store.exception.StoreGroupException;
import com.gic.store.utils.ErrorCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.BindException;
......@@ -34,7 +34,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class)
public RestResponse controllerException(HttpServletResponse response, Exception ex) {
logger.error("err", ex);
RestResponse failureResponse = getRestResponse(ErrorCode.ERR_3.getCode(), ErrorCode.ERR_3.getMsg());
RestResponse failureResponse = getRestResponse(ErrorCode.SYSTEM_ERROR.getCode(), ErrorCode.SYSTEM_ERROR.getMsg());
StringBuilder sb = new StringBuilder();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (PrintWriter printWriter = new PrintWriter(baos)) {
......@@ -76,7 +76,7 @@ public class GlobalExceptionHandler {
Set<ConstraintViolation<?>> constraintViolations = e.getConstraintViolations();
String paramName = constraintViolations.iterator().next().getPropertyPath().toString();
String paramError = constraintViolations.iterator().next().getMessage();
return getRestResponse(com.gic.enterprise.error.ErrorCode.ERR_5.getCode(), getFailFastMsg(paramName, paramError));
return getRestResponse(ErrorCode.PARAMETER_ERROR.getCode(), getFailFastMsg(paramName, paramError));
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment