Commit 89c3cc92 by 林永健

feat(strategy): 新增策略中心门店员工管理功能

1 parent e8274c93
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
<dependency> <dependency>
<groupId>cn.com.glsx.merchants</groupId> <groupId>cn.com.glsx.merchants</groupId>
<artifactId>platform-merchants-api</artifactId> <artifactId>platform-merchants-api</artifactId>
<version>5.5.1-SNAPSHOT</version> <version>5.6.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>cn.com.glsx.dj</groupId> <groupId>cn.com.glsx.dj</groupId>
......
package cn.com.glsx.dj.strategy.config.dubbo;
import cn.com.glsx.merchants.remote.MerchantRoleRemote;
import cn.com.glsx.merchants.remote.MerchantStaffRemote;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MerchantDubboConfig extends DubboConfig {
@Bean
public MerchantStaffRemote merchantStaffRemote() {
return factory.builder(MerchantStaffRemote.class).version("2.0.0").check(check)/*.url("dubbo://localhost:20885")*/.timeout(timeout).build();
}
@Bean
public MerchantRoleRemote merchantRoleRemote() {
return factory.builder(MerchantRoleRemote.class).version("2.0.0").check(check)/*.url("dubbo://localhost:20885")*/.timeout(timeout).build();
}
}
package cn.com.glsx.dj.strategy.controller;
import cn.com.glsx.dj.strategy.request.StrategyStaffRequest;
import cn.com.glsx.dj.strategy.uitl.CommonUtil;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.framework.core.util.RpcAssert;
import cn.com.glsx.framework.rop.response.RopResponse;
import cn.com.glsx.merchants.model.request.MerchantRoleRequest;
import cn.com.glsx.merchants.model.request.MerchantStaffRequest;
import cn.com.glsx.merchants.model.request.StaffBatchRequest;
import cn.com.glsx.merchants.model.request.wechatbinding.MerchantStaffListRequest;
import cn.com.glsx.merchants.model.response.MerchantRoleResponse;
import cn.com.glsx.merchants.model.response.MerchantStaffResponse;
import cn.com.glsx.merchants.remote.MerchantRoleRemote;
import cn.com.glsx.merchants.remote.MerchantStaffRemote;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.google.common.collect.Lists;
import com.rop.annotation.NeedInSessionType;
import com.rop.annotation.ServiceMethod;
import com.rop.annotation.ServiceMethodBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@Api("策略中心-员工操作")
@RequiredArgsConstructor
@ServiceMethodBean(version = "1.0.0", needInSession = NeedInSessionType.YES)
public class MerchantStaffController {
@Autowired
private MerchantStaffRemote merchantStaffRemote;
@Autowired
private MerchantRoleRemote merchantRoleRemote;
@ApiOperation("添加员工")
@ServiceMethod(method = "dj.api.strategy.merchant.staff.add")
public RopResponse<Boolean> addMerchantStaff(StrategyStaffRequest request) {
try {
checkStaffExist(request);
RpcResponse<Boolean> res = merchantStaffRemote.saveStaffRemote(buildMerchantStaffRequest(request));
return RopResponse.success(res.getResult());
} catch (RpcServiceException e) {
log.info("addMerchantStaff occur error!", e);
return RopResponse.error(e);
} catch (Exception e) {
log.info("addMerchantStaff occur error!", e);
return RopResponse.result(DefaultErrorEnum.SERVICE_ERROR);
}
}
/**
* 检查手机号和门店是否存在
*/
private void checkStaffExist(StrategyStaffRequest request) {
RpcAssert.assertNotNull(request.getMerchantId(), DefaultErrorEnum.SERVER_ERROR, "门店号不能为空");
RpcAssert.assertNotNull(request.getStaffPhone(), DefaultErrorEnum.SERVER_ERROR, "手机号不能为空");
MerchantStaffListRequest staffQuery = new MerchantStaffListRequest();
staffQuery.setMerchantIds(Lists.newArrayList(request.getMerchantId()));
staffQuery.setStaffPhone(request.getStaffPhone());
log.info("查询员工列表参数:{}", staffQuery);
RpcResponse<List<MerchantStaffResponse>> staffListRes = merchantStaffRemote.selectStaffListByMerchantIdsAndPhone(staffQuery);
if (staffListRes.isFailed()) {
log.error("查询员工列表失败,response:{}", staffListRes);
throw new RpcServiceException(DefaultErrorEnum.SERVICE_ERROR, staffListRes.getMessage());
}
if (CollectionUtils.isNotEmpty(staffListRes.getResult())) {
log.info("员工已存在, staffIds:{}", staffListRes.getResult().stream().map(MerchantStaffResponse::getUuid).collect(Collectors.toList()));
throw new RpcServiceException(DefaultErrorEnum.SERVICE_ERROR, "已存在员工账号");
}
}
/**
* 构建创建员工的传参
*/
private MerchantStaffRequest buildMerchantStaffRequest(StrategyStaffRequest request) {
MerchantStaffRequest staffRequest = new MerchantStaffRequest();
staffRequest.setMerchantId(request.getMerchantId());
staffRequest.setStaffName(request.getStaffName());
staffRequest.setStaffPhone(request.getStaffPhone());
staffRequest.setPassword("Gl123456");
staffRequest.setVisibleInferiorMer(request.getMerchantId().toString());
staffRequest.setCreatedAccount(CommonUtil.getPhone());
staffRequest.setCreatedName(CommonUtil.getUserName());
staffRequest.setStaffLabel(request.getStaffLabel());
staffRequest.setStaffBusinessType(0);
// 查找该门店的角色id
MerchantRoleRequest roleQuery = new MerchantRoleRequest();
roleQuery.setMerchantNo(request.getMerchantId());
roleQuery.setRoleName("驻店人员");
log.info("查询角色列表参数:{}", roleQuery);
RpcResponse<List<MerchantRoleResponse>> roleListRes = merchantRoleRemote.getRoleListRemote(roleQuery);
if (!roleListRes.hasResult() || CollectionUtils.isEmpty(roleListRes.getResult())) {
log.error("查询角色列表失败,response:{}", roleListRes);
throw new RpcServiceException(DefaultErrorEnum.SERVICE_ERROR, "门店驻店人员角色不存在");
}
Integer roleId = roleListRes.getResult().get(0).getId();
staffRequest.setRoleIds(Lists.newArrayList(roleId));
return staffRequest;
}
@ApiOperation("禁用员工")
@ServiceMethod(method = "dj.api.strategy.merchant.staff.disable")
public RopResponse<Boolean> disableMerchantStaff(StrategyStaffRequest request) {
try {
StaffBatchRequest staffBatchRequest = new StaffBatchRequest();
staffBatchRequest.setStaffUuid(request.getStaffUuid());
staffBatchRequest.setStatus(2);
log.info("禁用员工:{}", staffBatchRequest);
RpcResponse<Boolean> res = merchantStaffRemote.updateStaffStatusByPhone(staffBatchRequest);
return RopResponse.success(res.getResult());
} catch (RpcServiceException e) {
log.info("disableMerchantStaff occur error!", e);
return RopResponse.error(e);
} catch (Exception e) {
log.info("disableMerchantStaff occur error!", e);
return RopResponse.result(DefaultErrorEnum.SERVICE_ERROR);
}
}
}
package cn.com.glsx.dj.strategy.request;
import com.rop.AbstractRopRequest;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "门店员工")
public class StrategyStaffRequest extends AbstractRopRequest implements Serializable {
private static final long serialVersionUID = -1L;
@ApiModelProperty(notes = "门店号")
private Integer merchantId;
@ApiModelProperty(notes = "员工编号")
private String staffUuid;
@ApiModelProperty(notes = "员工手机号")
private String staffPhone;
@ApiModelProperty(notes = "员工姓名")
private String staffName;
@ApiModelProperty(notes = "员工标签:0: 会员权益 1:精品升级 2:膨胀金活动 3:售后众筹 4:次新车转化 7: 二手车")
private String staffLabel;
}
...@@ -252,6 +252,22 @@ public class CommonUtil { ...@@ -252,6 +252,22 @@ public class CommonUtil {
return user.getLoginAccout(); return user.getLoginAccout();
} }
public static String getUuid() {
LoginUserDTO user = getLoginUser();
if (user == null) {
return null;
}
return user.getUuid();
}
public static String getPhone() {
LoginUserDTO user = getLoginUser();
if (user == null) {
return null;
}
return user.getPhone();
}
/** /**
* @return * @return
* @Description:获取用户名,如为商户则返回商户名称,员工则返回员工姓名 * @Description:获取用户名,如为商户则返回商户名称,员工则返回员工姓名
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!