Commit fdaa5f8f by guojuxing

报名修改

parent a8435ca6
......@@ -35,6 +35,11 @@
<artifactId>gic-enterprise-base-api</artifactId>
<version>${gic-enterprise-base-api}</version>
</dependency>
<dependency>
<groupId>com.gic</groupId>
<artifactId>gic-platform-auth-api</artifactId>
<version>${gic-enterprise-base-api}</version>
</dependency>
<!--参数验证-->
<dependency>
<groupId>org.hibernate</groupId>
......
package com.gic.store.exception;
package com.gic.enterprise.exception;
/**
* @author guojx
* @date 2019/6/26 2:03 PM
*/
public class StoreException extends RuntimeException{
public class EnterpriseException extends RuntimeException{
private String errorCode;
public StoreException(String errorCode, String message) {
public EnterpriseException(String errorCode, String message) {
super(message);
this.errorCode = errorCode;
}
......
package com.gic.enterprise.service;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.auth.dto.UserDTO;
import com.gic.enterprise.dto.EnterpriseDTO;
/**
......@@ -16,6 +17,14 @@ public interface EnterpriseApiService {
*/
ServiceResponse<Integer> saveEnterprise(EnterpriseDTO enterpriseDTO);
/**
* 新建商户
* @param enterpriseDTO
* @param userDTO
* @return 主键ID
*/
ServiceResponse<Integer> saveEnterprise(EnterpriseDTO enterpriseDTO, UserDTO userDTO);
/**
* 编辑保存
......
......@@ -7,6 +7,7 @@ import com.gic.enterprise.entity.TabEnterprise;
import com.gic.enterprise.service.EnterpriseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* @author guojx
......@@ -18,6 +19,7 @@ public class EnterpriseServiceImpl implements EnterpriseService{
private TabEnterpriseMapper tabEnterpriseMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public int saveEnterprise(EnterpriseDTO enterpriseDTO) {
TabEnterprise tabEnterprise = EntityUtil.changeEntityNew(TabEnterprise.class, enterpriseDTO);
tabEnterpriseMapper.insert(tabEnterprise);
......
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.constant.EnterpriseStatusTypeEnum;
import com.gic.enterprise.dto.EnterpriseDTO;
import com.gic.enterprise.entity.TabEnterprise;
import com.gic.enterprise.error.ErrorCode;
import com.gic.enterprise.exception.EnterpriseException;
import com.gic.enterprise.service.EnterpriseApiService;
import com.gic.enterprise.service.EnterpriseService;
import com.gic.store.utils.valid.ValidUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
......@@ -22,6 +26,8 @@ import java.util.Date;
public class EnterpriseApiServiceImpl implements EnterpriseApiService {
@Autowired
private EnterpriseService enterpriseService;
@Autowired
private UserApiService userApiService;
@Override
public ServiceResponse<Integer> saveEnterprise(EnterpriseDTO enterpriseDTO) {
......@@ -31,7 +37,7 @@ public class EnterpriseApiServiceImpl implements EnterpriseApiService {
return paramResult;
}
if (enterpriseService.isRepeatEnterpriseName(enterpriseDTO.getEnterpriseName(), null)) {
ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "商户名称不能重复");
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "商户名称不能重复");
}
enterpriseDTO.setCreateTime(new Date());
......@@ -45,6 +51,35 @@ public class EnterpriseApiServiceImpl implements EnterpriseApiService {
}
@Override
@Transactional(rollbackFor = Exception.class)
public ServiceResponse<Integer> saveEnterprise(EnterpriseDTO enterpriseDTO, UserDTO userDTO) {
//valid param
ServiceResponse paramResult = ValidUtil.allCheckValidate(enterpriseDTO, EnterpriseDTO.SaveEnterpriseValid.class);
if (!paramResult.isSuccess()) {
return paramResult;
}
if (enterpriseService.isRepeatEnterpriseName(enterpriseDTO.getEnterpriseName(), null)) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "商户名称不能重复");
}
enterpriseDTO.setCreateTime(new Date());
enterpriseDTO.setUpdateTime(new Date());
enterpriseDTO.setIsInitComplete(0);
enterpriseDTO.setStatus(EnterpriseStatusTypeEnum.EFFECTIVE.getCode());
int enterpriseId = enterpriseService.saveEnterprise(enterpriseDTO);
userDTO.setEnterpriseId(enterpriseId);
//超级管理员
userDTO.setSuperAdmin(1);
ServiceResponse userResult = userApiService.saveUser(userDTO);
if (userResult.isSuccess()) {
return ServiceResponse.success();
} else {
throw new EnterpriseException(userResult.getCode(), userResult.getMessage());
}
}
@Override
public ServiceResponse<Integer> editEnterprise(EnterpriseDTO enterpriseDTO) {
//valid param
ServiceResponse paramResult = ValidUtil.allCheckValidate(enterpriseDTO,
......@@ -54,10 +89,10 @@ public class EnterpriseApiServiceImpl implements EnterpriseApiService {
}
TabEnterprise tabEnterprise = enterpriseService.getEnterpriseById(enterpriseDTO.getEnterpriseId());
if (tabEnterprise == null) {
ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "企业ID错误,查询不到数据");
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "企业ID错误,查询不到数据");
}
if (enterpriseService.isRepeatEnterpriseName(enterpriseDTO.getEnterpriseName(), enterpriseDTO.getEnterpriseId())) {
ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "商户名称不能重复");
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "商户名称不能重复");
}
enterpriseDTO.setUpdateTime(new Date());
......@@ -69,7 +104,7 @@ public class EnterpriseApiServiceImpl implements EnterpriseApiService {
public ServiceResponse<EnterpriseDTO> getEnterpriseById(Integer enterpriseId) {
TabEnterprise tabEnterprise = enterpriseService.getEnterpriseById(enterpriseId);
if (tabEnterprise == null) {
ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "商户ID输入有误");
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "商户ID输入有误");
}
return ServiceResponse.success(EntityUtil.changeEntityNew(EnterpriseDTO.class, tabEnterprise));
}
......@@ -78,7 +113,7 @@ public class EnterpriseApiServiceImpl implements EnterpriseApiService {
public ServiceResponse disableEnterprise(Integer enterpriseId) {
TabEnterprise tabEnterprise = enterpriseService.getEnterpriseById(enterpriseId);
if (tabEnterprise == null) {
ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "商户ID输入有误");
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "商户ID输入有误");
}
enterpriseService.changeEnterpriseStatus(enterpriseId, EnterpriseStatusTypeEnum.DISABLE.getCode());
return ServiceResponse.success();
......@@ -88,7 +123,7 @@ public class EnterpriseApiServiceImpl implements EnterpriseApiService {
public ServiceResponse enableEnterprise(Integer enterpriseId) {
TabEnterprise tabEnterprise = enterpriseService.getEnterpriseById(enterpriseId);
if (tabEnterprise == null) {
ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "商户ID输入有误");
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "商户ID输入有误");
}
enterpriseService.changeEnterpriseStatus(enterpriseId, EnterpriseStatusTypeEnum.EFFECTIVE.getCode());
return ServiceResponse.success();
......
package com.gic.enterprise.utils;
import com.gic.log.api.dto.SystemSetLogDTO;
import com.gic.log.api.service.LogApiService;
import com.gic.store.utils.PropertyNameMap;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.beans.PropertyDescriptor;
import java.util.Date;
/**
* @author zhiwj
* @date 2019/7/10
*/
@Component
public class LogUtils {
private static LogApiService logApiService;
public static <T> void saveAddLog(T obj) {
saveLog(obj, 1);
}
public static <T> void saveUpdateLog(T obj) {
saveLog(obj, 2);
}
@Autowired
public void setLogApiService(LogApiService logApiService) {
LogUtils.logApiService = logApiService;
}
public static <T> void saveLog(T obj, Integer type) {
// 日志
SystemSetLogDTO systemSetLogDTO = new SystemSetLogDTO();
// systemSetLogDTO.setEnterpriesId(storeBrandDTO.getEnterpriseId() + "");
systemSetLogDTO.setLogTime(new Date());
// systemSetLogDTO.setInterfaceName("com.gic.store.service.StoreBrandApiService.saveOrUpdateStoreBrand");
StringBuilder content = new StringBuilder();
getContent(obj, type, content);
systemSetLogDTO.setContent(content.toString());
// System.out.println(systemSetLogDTO.getContent());
logApiService.saveSystemSetLog(systemSetLogDTO);
}
private static <T> void getContent(T obj, Integer type, StringBuilder content) {
final BeanWrapper dtoBean = new BeanWrapperImpl(obj);
PropertyDescriptor[] pds = dtoBean.getPropertyDescriptors();
for (PropertyDescriptor pd : pds) {
String name = PropertyNameMap.get(pd.getName());
if (StringUtils.isNotBlank(name)) {
Object value = dtoBean.getPropertyValue(pd.getName());
if (value != null) {
if (value instanceof Iterable) {
for (Object o : (Iterable) value) {
getContent(o, type, content);
}
} else {
if (type == 1) {
content.append(name).append(" 新增 ").append(value).append("<br/>");
} else if (type == 2) {
content.append(name).append(" 修改为 ").append(value).append("<br/>");
}
}
}
}
}
}
}
package com.gic.store.utils;
import java.util.HashMap;
import java.util.Map;
/**
* @author zhiwj
* @date 2019/7/11
*/
public class PropertyNameMap {
/**
* 暂时放这里测试下, 以后移到enterprise_base_api里去
*/
private static final Map<String, String> map = new HashMap<>();
static {
map.put("regionName", "门店域名称");
map.put("regionCode", "门店域code");
map.put("storeBrandCode", "品牌code");
map.put("storeBrandName", "品牌名称");
map.put("storeBrandCategory", "经营类目");
map.put("storeSupport", "门店适用");
map.put("goodsSupport", "商品适用");
map.put("storeName", "门店名称");
map.put("conactsPhone", "门店电话");
map.put("address", "门店详细地址");
map.put("brandIds", "关联门店品牌id,多个用逗号分隔");
map.put("longitude", "经度");
map.put("latitude", "纬度");
// map.put("status", "门店启用状态");
map.put("erpStatus", "erp门店状态");
map.put("storeType", "门店类型");
map.put("weekday", "营业时间");
map.put("businessTimeList", "营业时间");
}
private PropertyNameMap() {
}
public static String get(String name) {
return map.get(name);
}
}
package com.gic.enterprise.utils.log;
import com.gic.enterprise.utils.LogUtils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
/**
* @author guojx
* @date 2019/7/12 10:26 AM
*/
@Aspect
public class LogAspect {
private static final Logger logger = LoggerFactory.getLogger(LogAspect.class);
@Pointcut("execution(* com.gic.enterprise.service.outer.*.save*(..))")
public void saveCell() {
}
@Pointcut("execution(public * com.gic.enterprise.service.outer.*.edit*(..))")
public void updateCell() {
}
@Pointcut("execution(* com.gic.enterprise.service.outer.*.delete*(..))")
public void deleteCell() {
}
@AfterReturning(value = "saveCell()", argNames = "joinPoint,object", returning = "object")
public void saveLog(JoinPoint joinPoint, Object object) {
if (joinPoint.getArgs() == null) {
return;
}
String methodName = joinPoint.getSignature().getName();
String operContent = "";
logger.info("aspectLog:{}", joinPoint.getArgs());
LogUtils.saveAddLog(arrToList(joinPoint.getArgs()));
}
@AfterReturning(value = "updateCell()", argNames = "joinPoint,object", returning = "object")
public void updateLog(JoinPoint joinPoint, Object object) {
if (joinPoint.getArgs() == null) {
return;
}
String methodName = joinPoint.getSignature().getName();
String operContent = "";
logger.info("aspectLog:{}", joinPoint.getArgs());
LogUtils.saveUpdateLog(arrToList(joinPoint.getArgs()));
}
private List<Object> arrToList(Object[] args) {
List<Object> resultList = new ArrayList<>(args.length);
for (Object obj : args) {
resultList.add(obj);
}
return resultList;
}
}
......@@ -20,4 +20,6 @@
<dubbo:reference interface="com.gic.log.api.service.LogApiService" id="logApiService" timeout="60000" />
<!--用户-->
<dubbo:reference interface="com.gic.auth.service.UserApiService" id="userApiService" timeout="60000" />
</beans>
......@@ -18,10 +18,6 @@
<context:annotation-config/>
<!-- 启动对@AspectJ注解的支持 -->
<aop:aspectj-autoproxy />
<!--<apollo:config namespaces="COMMON.sharding,COMMON.4.0-jdbc"/>-->
<!--<bean id="dataSource" class="com.gic.sharding.sdk.ShardingDatasource" init-method="init">-->
......
......@@ -25,7 +25,7 @@ import org.springframework.context.annotation.ImportResource;
@ImportResource(value = {
"classpath*:applicationContext-init.xml",
"classpath*:dubbo-setting.xml",
"classpath*:dubbo-gic-platform-enterprise-web.xml",
"classpath*:dubbo-gic-platform-operation-web.xml",
"classpath*:spring-interceptor.xml",
"classpath*:redis-init.xml"
})
......
......@@ -3,7 +3,6 @@ package com.gic.operation.web.controller;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.auth.constant.UserConstants;
import com.gic.auth.dto.UserDTO;
import com.gic.auth.exception.StoreException;
import com.gic.auth.service.UserApiService;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.enterprise.dto.EnterpriseDTO;
......@@ -15,7 +14,6 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -34,39 +32,26 @@ public class EnterpriseController {
private UserApiService userApiService;
@RequestMapping("/save-enterprise")
@Transactional(rollbackFor = Exception.class)
public RestResponse saveEnterprise(@Validated({EnterpriseDTO.SaveEnterpriseValid.class}) EnterpriseDTO enterpriseDTO,
@Validated({UserDTO.UserQoValid.class}) UserDTO userDTO) {
ServiceResponse<Integer> enterpriseResult = enterpriseApiService.saveEnterprise(enterpriseDTO);
if (enterpriseResult.isSuccess()) {
int enterpriseId = enterpriseResult.getResult();
userDTO.setEnterpriseId(enterpriseId);
int passwordType = userDTO.getPasswordType();
String password;
//加密
if (UserConstants.CREATE_AUTO == passwordType) {
//自动随机生成
password = UserPasswordUtil.createPasswordAuto();
} else {
if (StringUtils.isNotBlank(userDTO.getPassword()) && userDTO.getPassword().equals(userDTO.getConfirmPassword())) {
//如果一致
password = userDTO.getPassword();
} else {
return RestResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "密码不一致");
}
}
userDTO.setPassword(UserPasswordUtil.getEncryptPassword(password));
//超级管理员
userDTO.setSuperAdmin(1);
//新增
ServiceResponse userResult = userApiService.saveUser(userDTO);
if (userResult.isSuccess()) {
//todo 发送短信(如果是自动生成密码)
return RestResponse.success();
int passwordType = userDTO.getPasswordType();
String password;
//加密
if (UserConstants.CREATE_AUTO == passwordType) {
//自动随机生成
password = UserPasswordUtil.createPasswordAuto();
} else {
if (StringUtils.isNotBlank(userDTO.getPassword()) && userDTO.getPassword().equals(userDTO.getConfirmPassword())) {
//如果一致
password = userDTO.getPassword();
} else {
//回滚
throw new StoreException(userResult.getCode(), userResult.getMessage());
return RestResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "密码不一致");
}
}
userDTO.setPassword(UserPasswordUtil.getEncryptPassword(password));
ServiceResponse<Integer> enterpriseResult = enterpriseApiService.saveEnterprise(enterpriseDTO, userDTO);
if (enterpriseResult.isSuccess()) {
return RestResponse.success();
} else {
return EnterpriseRestResponse.failure(enterpriseResult);
}
......@@ -75,7 +60,7 @@ public class EnterpriseController {
@RequestMapping("/edit-enterprise")
public RestResponse editEnterprise(@Validated({EnterpriseDTO.EditEnterpriseValid.class, EnterpriseDTO.SaveEnterpriseValid.class})
EnterpriseDTO enterpriseDTO) {
ServiceResponse enterpriseResult = enterpriseApiService.saveEnterprise(enterpriseDTO);
ServiceResponse enterpriseResult = enterpriseApiService.editEnterprise(enterpriseDTO);
if (enterpriseResult.isSuccess()) {
return RestResponse.success();
} else {
......
......@@ -2,8 +2,8 @@ package com.gic.operation.web.exception;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.enterprise.error.ErrorCode;
import com.gic.enterprise.exception.EnterpriseException;
import com.gic.store.constant.StoreGroupErrorEnum;
import com.gic.store.exception.StoreException;
import com.gic.store.exception.StoreGroupException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -90,8 +90,8 @@ public class GlobalExceptionHandler {
return getRestResponse(e.getErrorCode(), e.getMessage());
}
@ResponseBody
@ExceptionHandler(StoreException.class)
public RestResponse customException(StoreException e) {
@ExceptionHandler(EnterpriseException.class)
public RestResponse customException(EnterpriseException e) {
return getRestResponse(e.getErrorCode(), e.getMessage());
}
......
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