package com.xzx.gc.user.service;
|
|
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.lang.Snowflake;
|
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.RandomUtil;
|
import cn.hutool.core.util.StrUtil;
|
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageInfo;
|
import com.xzx.gc.common.Result;
|
import com.xzx.gc.common.constant.CommonEnum;
|
import com.xzx.gc.common.constant.Constants;
|
import com.xzx.gc.common.constant.OrderEnum;
|
import com.xzx.gc.common.constant.UserEnum;
|
import com.xzx.gc.common.dto.CommonDto;
|
import com.xzx.gc.common.exception.PlatformException;
|
import com.xzx.gc.common.exception.RestException;
|
import com.xzx.gc.common.utils.*;
|
import com.xzx.gc.common.utils.gdmap.GdTraceUtil;
|
import com.xzx.gc.entity.*;
|
import com.xzx.gc.model.admin.PunchChannelModel;
|
import com.xzx.gc.model.admin.UserEditroleModel;
|
import com.xzx.gc.model.admin.UserModel;
|
import com.xzx.gc.user.dto.RoleDto;
|
import com.xzx.gc.user.mapper.AccountMapper;
|
import com.xzx.gc.user.mapper.OtherUserMapper;
|
import com.xzx.gc.user.mapper.UserMapper;
|
import com.xzx.gc.user.mapper.UserRoleMapper;
|
import com.xzx.gc.util.PageQuery;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import tk.mybatis.mapper.entity.Example;
|
|
import javax.servlet.http.HttpServletRequest;
|
import java.io.UnsupportedEncodingException;
|
import java.math.BigDecimal;
|
import java.util.*;
|
|
@Service
|
@Transactional
|
@Slf4j
|
public class UserRoleService {
|
|
|
@Autowired
|
private PartnerGaodeService partnerGaodeService;
|
|
@Autowired
|
private UserRoleMapper userRoleMapper;
|
|
@Autowired
|
private PartnerAccountService partnerAccountService;
|
|
@Autowired
|
private PartnerAccountLogService partnerAccountLogService;
|
|
@Autowired
|
private OtherUserService otherUserService;
|
|
|
@Autowired
|
private OtherUserMapper otherUserMapper;
|
|
@Autowired
|
private TokenUtil tokenUtil;
|
|
@Autowired
|
private AccountMapper accountMapper;
|
|
|
@Autowired
|
private AccountService accountService;
|
|
@Autowired
|
private PartnerTraceService partnerTraceService;
|
|
|
@Autowired
|
private ConfigService configService;
|
|
|
@Autowired
|
private OrderService orderService;
|
|
@Autowired
|
private IdUtils idUtils;
|
|
@Autowired
|
private BusinessUtil businessUtil;
|
|
|
@Autowired
|
private AddressLevelService addressLevelService;
|
|
@Autowired
|
private RedisUtil redisUtil;
|
|
@Autowired
|
private PartnerFenceService partnerFenceService;
|
|
@Autowired
|
private CityPartnerService cityPartnerService;
|
|
@Autowired
|
private UserMapper userMapper;
|
|
public List<UserRole> findByRoleCode(String code){
|
|
Example example=new Example(UserRole.class);
|
|
Example.Criteria criteria = example.createCriteria();
|
|
if(StrUtil.isNotBlank(code)){
|
criteria.andEqualTo("roleCode",code);
|
}
|
|
criteria.andEqualTo("delFlag",Constants.DEL_NOT_FLAG);
|
List<UserRole> userRoles = userRoleMapper.selectByExample(example);
|
return userRoles;
|
}
|
|
public List<UserRole> findByRoleCodes(String codes){
|
|
Example example=new Example(UserRole.class);
|
|
Example.Criteria criteria = example.createCriteria();
|
|
criteria.andIn("roleCode",Arrays.asList(codes.split(",")));
|
|
criteria.andEqualTo("delFlag",Constants.DEL_NOT_FLAG);
|
List<UserRole> userRoles = userRoleMapper.selectByExample(example);
|
return userRoles;
|
}
|
|
|
public Result edit(RoleDto roleDto){
|
|
|
if((roleDto.getOldUserType().equals(CommonEnum.运营员.getValue())||roleDto.getUserType().equals(CommonEnum.运营员.getValue()))&&!roleDto.getUserType().equals(roleDto.getOldUserType())) {
|
return Result.error(-1,"运营员不能更改");
|
}
|
|
|
//编辑 除了运营员都需要判断金额>0 以及可使用额度==固定额度
|
if(roleDto.getOldUserType().equals(CommonEnum.回收员.getValue())){
|
List<OrderInfo> list1 = orderService.findByManageReceiver(roleDto.getUserId());
|
if(CollUtil.isNotEmpty(list1)){
|
return Result.error(-1,"当前回收员存在未完成的订单");
|
}
|
}
|
|
if(!roleDto.getOldUserType().equals(CommonEnum.运营员.getValue())&&!roleDto.getUserType().equals(roleDto.getOldUserType())) {
|
AccountInfo byUserId = accountService.findByUserId(roleDto.getUserId());
|
String money = byUserId.getMoney();
|
BigDecimal fixedLimit = Convert.toBigDecimal(byUserId.getFixedLimit(),Constants.MONEY_INIT);
|
BigDecimal overdraftLimit =Convert.toBigDecimal(byUserId.getOverdraftLimit(),Constants.MONEY_INIT);
|
if (StrUtil.isNotBlank(money) && Convert.toBigDecimal(money, Constants.MONEY_INIT).compareTo(BigDecimal.ZERO) != 0) {
|
return Result.error(-1, "当前用户还存在未提现的金额:" + money + "元");
|
}
|
|
if(CommonEnum.回收员.getValue().equals(roleDto.getOldUserType())) {
|
if (overdraftLimit.compareTo(fixedLimit) != 0) {
|
return Result.error(-1, "当前用户可使用额度与固定额度不一致");
|
}
|
}
|
}
|
|
|
//更换了身份
|
if(!roleDto.getUserType().equals(roleDto.getOldUserType())){
|
//删除当前用户
|
OtherUserInfo otherUserInfo=new OtherUserInfo();
|
otherUserInfo.setUserId(roleDto.getUserId());
|
otherUserInfo.setDelFlag(Constants.DEL_FLAG);
|
otherUserMapper.updateByPrimaryKeySelective(otherUserInfo);
|
|
//如果是打包员或者入库员 其账户下的可用额度将分别退还到打包站的账户和合伙人的账户
|
OtherUserInfo byId = otherUserService.findById(roleDto.getUserId());
|
String partnerId = byId.getPartnerId();
|
AccountInfo byUserId = accountService.findByUserId(byId.getUserId());
|
if(byUserId!=null){
|
String overdraftLimit = byUserId.getOverdraftLimit();
|
partnerAccountService.updateAddMoneyByPartnerId(partnerId,Convert.toBigDecimal(overdraftLimit));
|
|
PartnerAccountLog partnerAccountLog=new PartnerAccountLog();
|
partnerAccountLog.setPartnerId(partnerId);
|
partnerAccountLog.setFlowNo(roleDto.getUserId());
|
partnerAccountLog.setType(OrderEnum.人员变动.getValue());
|
partnerAccountLog.setMoney(overdraftLimit);
|
partnerAccountLogService.add(partnerAccountLog);
|
}
|
|
|
|
//删除账户
|
accountService.deleteByUserId(roleDto.getUserId());
|
|
|
//先删除再添加
|
//删除终端
|
if (CommonEnum.回收员.getValue().equals(roleDto.getOldUserType())) {
|
partnerTraceService.deleteTerimainal(partnerId,OrderEnum.回收员订单轨迹.getValue(),byId.getTerminalId());
|
partnerTraceService.deleteTerimainal(partnerId,OrderEnum.回收员全天轨迹.getValue(),byId.getTerminalDayId());
|
} else if (CommonEnum.推广员.getValue().equals(roleDto.getOldUserType())) {
|
partnerTraceService.deleteTerimainal(partnerId,OrderEnum.推广员全天轨迹.getValue(),byId.getTerminalId());
|
}
|
//添加
|
add(roleDto,partnerId);
|
tokenUtil.delete(roleDto.getUserId());
|
}else {
|
OtherUserInfo otherUserInfo=new OtherUserInfo();
|
BeanUtil.copyProperties(roleDto,otherUserInfo);
|
if(StrUtil.isNotBlank(roleDto.getTownId())) {
|
otherUserInfo.setTownId(roleDto.getTownId());
|
}
|
//赋值省市区
|
changeArea(roleDto, otherUserInfo);
|
otherUserService.update(otherUserInfo);
|
}
|
|
return Result.success("");
|
}
|
|
/**
|
* 新增角色
|
* @param roleDto
|
* @return
|
*/
|
public Result<String> add (RoleDto roleDto,String partnerId){
|
if(roleDto.getUserType().equals(CommonEnum.运营员.getValue())){
|
return Result.error(-1, "运营员不能新增");
|
}
|
|
OtherUserInfo otherUserInfo=new OtherUserInfo();
|
BeanUtil.copyProperties(roleDto,otherUserInfo);
|
otherUserInfo.setPartnerId(partnerId);
|
String user = idUtils.generate("USER", 5);
|
|
if(StrUtil.isBlank(roleDto.getUserId())) {
|
roleDto.setUserId(user);
|
}
|
|
otherUserInfo.setUserId(user);
|
otherUserInfo.setRegistTime(DateUtil.now());
|
|
UserRole byCode = findByCode(roleDto.getUserType());
|
if(byCode!=null){
|
otherUserInfo.setRoleIds(Convert.toStr(byCode.getId()));
|
}
|
|
if(StrUtil.isNotBlank(roleDto.getPassword())){
|
otherUserInfo.setSalt(Constants.PWD_DECRET);
|
}
|
|
if(StrUtil.isBlank(otherUserInfo.getAvatar())){
|
otherUserInfo.setAvatar(Constants.DEFAULT_AVATAR);
|
}
|
|
//赋值省市区
|
changeArea(roleDto,otherUserInfo);
|
|
String terimalId=null;
|
String terimalDayId=null;
|
//创建终端
|
if (CommonEnum.回收员.getValue().equals(roleDto.getUserType())) {
|
terimalId=partnerTraceService.createTerimainal(partnerId,OrderEnum.回收员订单轨迹.getValue(),user);
|
terimalDayId=partnerTraceService.createTerimainal(partnerId,OrderEnum.回收员全天轨迹.getValue(),user);
|
} else if (CommonEnum.推广员.getValue().equals(roleDto.getUserType())) {
|
terimalId=partnerTraceService.createTerimainal(partnerId,OrderEnum.推广员全天轨迹.getValue(),user);
|
}
|
otherUserInfo.setTerminalId(terimalId);
|
otherUserInfo.setTerminalDayId(terimalDayId);
|
otherUserMapper.insertSelective(otherUserInfo);
|
|
|
//增加一个默认账户
|
AccountInfo accountInfo =new AccountInfo();
|
accountInfo.setAccountId(idUtils.generate("ZH",4));
|
accountInfo.setAccountName(roleDto.getMobilePhone());
|
accountInfo.setUserId(user);
|
accountInfo.setFreezeMoney("0");
|
accountInfo.setWithdrawMoney("0");
|
accountInfo.setMoney("0");
|
|
ConfigInfo configInfo=null;
|
if(roleDto.getUserType().equals(CommonEnum.回收员.getValue())){
|
configInfo = configService.findByCode("OVERDRAW_PRICE");
|
}else if(roleDto.getUserType().equals(CommonEnum.入库员.getValue())){
|
configInfo = configService.findByCode("WAREHOUSING_PRICE");
|
}else{
|
configInfo=new ConfigInfo();
|
configInfo.setConfigValue(Constants.MONEY_INIT.toString());
|
}
|
accountInfo.setOverdraftLimit(configInfo.getConfigValue());
|
accountInfo.setFixedLimit(configInfo.getConfigValue());
|
accountInfo.setDelFlag(0);
|
accountInfo.setErrorTimes(0);
|
accountInfo.setIsProhibit("0");
|
accountInfo.setCreateTime(DateUtil.now());
|
accountInfo.setUpdateTime(DateUtil.now());
|
accountInfo.setCollectScore("0");
|
accountMapper.insertSelective(accountInfo);
|
|
return Result.success(partnerId);
|
}
|
|
|
private void changeArea(RoleDto roleDto,OtherUserInfo otherUserInfo){
|
String areaId = roleDto.getAreaId();
|
String areaName = roleDto.getAreaName();
|
int level = roleDto.getLevel();
|
if(level==2){
|
otherUserInfo.setCityId(Integer.parseInt(areaId));
|
otherUserInfo.setCity(areaName);
|
}else if(level==3){
|
otherUserInfo.setTownshipId(Integer.parseInt(areaId));
|
otherUserInfo.setTownship(areaName);
|
AddressLevelInfo addressLevelInfo=new AddressLevelInfo();
|
addressLevelInfo.setLevel3Id(areaId);
|
List<AddressLevelInfo> byAny = addressLevelService.findByAny(addressLevelInfo);
|
otherUserInfo.setProvinceId(Convert.toInt(byAny.get(0).getLevel1Id()));
|
otherUserInfo.setProvince(byAny.get(0).getLevel1Name());
|
otherUserInfo.setCityId(Convert.toInt(byAny.get(0).getLevel2Id()));
|
otherUserInfo.setCity(byAny.get(0).getLevel2Name());
|
}
|
}
|
|
|
|
|
|
/**
|
* 根据code查询
|
* @param code
|
* @return
|
*/
|
public UserRole findByCode (String code){
|
UserRole userRole=new UserRole();
|
userRole.setRoleCode(code);
|
userRole.setDelFlag(Constants.DEL_NOT_FLAG+"");
|
UserRole userRole1 = userRoleMapper.selectOne(userRole);
|
return userRole1;
|
}
|
|
|
public PageInfo<UserRole> queryByCondition(PageQuery query){
|
PageHelper.startPage(Convert.toInt(query.getPageNumber()),Convert.toInt(query.getPageSize()));
|
List<UserRole> ret = userRoleMapper.queryByCondition(query);
|
PageInfo<UserRole> pageInfo=new PageInfo<>(ret);
|
return pageInfo;
|
}
|
|
|
public void batchDelXzxUserRoleInfo(List<Long> ids){
|
try {
|
userRoleMapper.batchDelXzxUserRoleInfoByIds(ids);
|
} catch (Exception e) {
|
throw new PlatformException("批量删除XzxUserRoleInfo失败", e);
|
}
|
}
|
|
public String queryPunchChannel(){
|
return userRoleMapper.queryPunchChannel();
|
}
|
|
public void updatePunchChannel(PunchChannelModel model){
|
model.setConfigTypeCode("CODE_SCAN_RK");
|
userRoleMapper.updatePunchChannel(model);
|
}
|
|
public UserRole queryMaxAppRole(){
|
return userRoleMapper.queryMaxAppRole();
|
}
|
|
public void save(UserRole xzxUserRoleInfo) {
|
userRoleMapper.insertSelective(xzxUserRoleInfo);
|
}
|
|
public UserRole queryById(Long id) {
|
return userRoleMapper.selectByPrimaryKey(id);
|
}
|
|
public boolean update(UserRole roleInfo) {
|
return userRoleMapper.updateByPrimaryKeySelective(roleInfo)>0?true:false;
|
}
|
|
/**
|
* 根据手机号码查询用户
|
* @param model
|
* @return
|
*/
|
public Map<String, Object> queryEditroleApi(UserEditroleModel model){
|
List<String> partnerIds = new ArrayList<>();
|
if(null!=model.getPartnerId()&&!"".equals(model.getPartnerId())){
|
partnerIds.add(model.getPartnerId());
|
}else{
|
partnerIds = cityPartnerService.queryPartnerByCurrent();
|
}
|
model.setPartnerIds(partnerIds);
|
PageHelper.startPage(model.getPage(),model.getLimit());
|
List<UserEditroleModel> list = userRoleMapper.queryEditroleApi(model);
|
PageInfo<UserEditroleModel> pageInfo = new PageInfo<>(list);
|
for (UserEditroleModel userModel:list) {
|
if(userModel.getUserTypeValue().equals(CommonEnum.打包站运营员.getValue())){
|
userModel.setUserType("打包员");
|
}
|
if(!StringUtils.isEmpty(userModel.getNickName())){
|
userModel.setNickName(com.xzx.gc.common.utils.StringUtils.decode(userModel.getNickName()));
|
}
|
|
if(StrUtil.isNotBlank(userModel.getTownshipId())){
|
AddressLevelInfo addressLevelInfo=new AddressLevelInfo();
|
addressLevelInfo.setLevel3Id(userModel.getTownshipId());
|
List<AddressLevelInfo> byAny = addressLevelService.findByAny(addressLevelInfo);
|
if(CollUtil.isNotEmpty(byAny)){
|
userModel.setProvinceName(byAny.get(0).getLevel1Name());
|
userModel.setCityName(byAny.get(0).getLevel2Name());
|
userModel.setTownshipName(byAny.get(0).getLevel3Name());
|
}
|
}
|
}
|
Map<String, Object> m = new HashMap<>();
|
m.put("data", list);
|
m.put("count", pageInfo.getTotal());
|
m.put("code", 0);
|
return m;
|
}
|
|
/**
|
* 添加角色
|
* @param userEditroleModel
|
* @return
|
*/
|
public int addEditroleApi(UserEditroleModel userEditroleModel){
|
// 判断此用户类型是否已经删除过,如果已经删除了需要重新恢复
|
String type =userEditroleModel.getUserTypeValue();
|
String phone = userEditroleModel.getMobilePhone();
|
|
//修改才会传值
|
String userId1 = userEditroleModel.getUserId();
|
|
List<OtherUserInfo> byMobile = otherUserService.findByMobileForBidden(phone);
|
if(CollUtil.isNotEmpty(byMobile)){
|
if(StrUtil.isNotBlank(userId1)){
|
//修改
|
long count = byMobile.stream().filter(x -> !x.getUserId().equals(userId1)).count();
|
if(count>0){
|
throw new RestException("该手机号已存在别的身份");
|
}
|
}else {
|
//添加
|
throw new RestException("该手机号已存在别的身份");
|
}
|
}
|
|
String roleId = userEditroleModel.getRoleId();
|
String password = userEditroleModel.getPassword();
|
String name = userEditroleModel.getName();
|
String area = userEditroleModel.getArea();
|
String cityId=null;
|
String proviceId=null;
|
String townshipId=null;
|
String city=null;
|
String province=null;
|
String township=null;
|
String storageId = userEditroleModel.getStorageId();
|
|
if(StrUtil.isNotBlank(userEditroleModel.getTownshipId())){
|
AddressLevelInfo addressLevelInfo=new AddressLevelInfo();
|
addressLevelInfo.setLevel3Id(userEditroleModel.getTownshipId());
|
List<AddressLevelInfo> byAny = addressLevelService.findByAny(addressLevelInfo);
|
proviceId=byAny.get(0).getLevel1Id();
|
province=byAny.get(0).getLevel1Name();
|
cityId=byAny.get(0).getLevel2Id();
|
city=byAny.get(0).getLevel2Name();
|
townshipId=byAny.get(0).getLevel3Id();
|
township=byAny.get(0).getLevel3Name();
|
}
|
String partnerId="";
|
if(null!=area&&!"".equals(area)){
|
String[] areaList= area.split(",");
|
PartnerFence byFenceId = partnerFenceService.findByFenceId(areaList[0]);
|
partnerId= byFenceId.getPartnerId();
|
}
|
if(null!=userEditroleModel.getPartnerId()&&!"".equals(userEditroleModel.getPartnerId())){
|
partnerId = userEditroleModel.getPartnerId();
|
}else{
|
List<String> partnerIds = cityPartnerService.queryPartnerByCurrent();
|
if(null!=partnerIds&&partnerIds.size()>0){
|
userEditroleModel.setPartnerId(partnerIds.get(0));
|
partnerId = partnerIds.get(0);
|
}
|
}
|
if(null!=roleId&&!"".equals(roleId)){
|
type = findById(Convert.toLong(roleId)).getRoleCode();
|
}
|
|
|
if(null==area&&"".equals(area)){
|
return 0;
|
}
|
|
UserModel userModels = otherUserMapper.queryUserByUsertype1(phone, type, "1",null,null);
|
Snowflake snowflake = IdUtil.getSnowflake(1, 3);
|
String id="USER"+snowflake.nextIdStr();
|
userEditroleModel.setUserId(id);
|
boolean bool = true;
|
if(userModels == null){
|
// 添加角色需要添加到2个表,一个是用户表,一个是账号表
|
// 一个账号不能有相同的角色
|
UserModel oldModel = otherUserMapper.queryUserByUsertype1(phone, type, "0",null,null);
|
if(oldModel!=null){
|
if(type.equals("2")){
|
boolean flag = checkOtherUserByType("4",phone);
|
if(!flag){
|
return -1;
|
}
|
}else if(type.equals("4")){
|
boolean flag = checkOtherUserByType("2",phone);
|
if(!flag){
|
return -1;
|
}else{
|
flag = checkOtherUserByType("6",phone);
|
if(!flag){
|
return -2;
|
}
|
}
|
}else if(type.equals("6")){
|
boolean flag = checkOtherUserByType("4",phone);
|
if(!flag){
|
return -2;
|
}
|
}
|
String salt=null;
|
String pass=null;
|
if(null!=password&&!"".equals(password)){
|
salt = RandomUtil.randomString(16);
|
pass = SecurityUtil.encrypt(salt,password);
|
}else{
|
}
|
if(type.equals("4")){
|
otherUserMapper.updateDelflag(phone, type,roleId,name, pass,salt,area,partnerId,cityId,storageId,proviceId,townshipId,province,city,township);
|
|
}else{
|
otherUserMapper.updateDelflag(phone, type,roleId,name, pass,salt,area,partnerId,cityId,null,proviceId,townshipId,province,city,township);
|
|
}
|
CityPartner partner = cityPartnerService.findById(Convert.toInt(partnerId));
|
|
if(oldModel.getUserType().equals("2")){
|
if(type.equals("6")){
|
String sid = partnerTraceService.findByPartnerId(partnerId,Convert.toShort(OrderEnum.回收员订单轨迹.getValue())).getPartnerServiceId();
|
GdTraceUtil.deleteTerminal(partner.getPartnerKey(),sid,oldModel.getTerminalId());
|
sid = partnerTraceService.findByPartnerId(partnerId,Convert.toShort(OrderEnum.推广员全天轨迹.getValue())).getPartnerServiceId();
|
Result<String> terminal = GdTraceUtil.createTerminal(partner.getPartnerKey().split(",")[0], sid, id);
|
if(terminal.getCode()==0){
|
OtherUserInfo otherUserInfo=new OtherUserInfo();
|
otherUserInfo.setUserId(id);
|
otherUserInfo.setTerminalId(terminal.getData());
|
otherUserInfo.setBirthday("");
|
otherUserService.update(otherUserInfo);
|
}
|
}
|
}else if(oldModel.getUserType().equals("6")){
|
if(type.equals("2")){
|
String sid = partnerTraceService.findByPartnerId(partnerId,Convert.toShort(OrderEnum.推广员全天轨迹.getValue())).getPartnerServiceId();
|
GdTraceUtil.deleteTerminal(partner.getPartnerKey(),sid,oldModel.getTerminalId());
|
sid = partnerTraceService.findByPartnerId(partnerId,Convert.toShort(OrderEnum.回收员订单轨迹.getValue())).getPartnerServiceId();
|
Result<String> terminal = GdTraceUtil.createTerminal(partner.getPartnerKey().split(",")[0], sid, id);
|
String terimalId=null;
|
String terimalDayId=null;
|
if(terminal.getCode()==0){
|
terimalId=terminal.getData();
|
}
|
sid = partnerTraceService.findByPartnerId(partnerId,Convert.toShort(OrderEnum.回收员全天轨迹.getValue())).getPartnerServiceId();
|
terminal = GdTraceUtil.createTerminal(partner.getPartnerKey().split(",")[0], sid, id);
|
if(terminal.getCode()==0){
|
terimalDayId=terminal.getData();
|
}
|
OtherUserInfo otherUserInfo=new OtherUserInfo();
|
otherUserInfo.setUserId(id);
|
otherUserInfo.setTerminalDayId(terimalDayId);
|
otherUserInfo.setTerminalId(terimalId);
|
otherUserInfo.setBirthday("");
|
otherUserService.update(otherUserInfo);
|
|
}
|
}
|
|
// 删除redis 缓存
|
// redis为map, key为user id, 先根据手机号码查询所有id, 进行遍历删除
|
UserModel userModel = userMapper.queryUserByUsertype(phone, "1", "0",null,null);
|
// redisService.removeToken(userModel.getUserId());
|
if(null!=userModel){
|
redisUtil.remove("xzx:user:token:"+userModel.getUserId());
|
redisUtil.remove("xzx:user:token:"+id);
|
List<Map<String, Object>> userIds = otherUserMapper.queryCuserByPhoneRedisDelList(phone);
|
for (Map<String,Object> map:userIds) {
|
String userId = map.get("userId").toString();
|
redisUtil.remove("xzx:user:token:"+userId);
|
}
|
redisUtil.remove(phone);
|
}
|
|
return 1;
|
}else{
|
if(type.equals("7")){
|
return -2;
|
}
|
|
|
//新增用户 回收员不能与入库员共存
|
|
if(type.equals("2")){
|
boolean flag = checkOtherUserByType("4",phone);
|
if(!flag){
|
return -1;
|
}
|
}else if(type.equals("4")){
|
boolean flag = checkOtherUserByType("2",phone);
|
if(!flag){
|
return -1;
|
}
|
}
|
}
|
// 插入用户表
|
String salt = RandomUtil.randomString(16);
|
String pass="";
|
if(null!=password&&!"".equals(password)){
|
pass = SecurityUtil.encrypt(salt,password);
|
}else{
|
pass = SecurityUtil.encrypt(salt,"123456");
|
}
|
if(type.equals("4")){
|
otherUserMapper.addCuserRole(id, phone, pass,type, area,partnerId,name,salt, roleId,cityId,storageId,proviceId,townshipId,province,city,township);
|
}else{
|
if(userEditroleModel.getUserType().equals("9")){
|
otherUserMapper.addCuserRole(id, phone, pass,type, area,"-1",name,salt, roleId,cityId,null,proviceId,townshipId,province,city,township);
|
|
}else{
|
otherUserMapper.addCuserRole(id, phone, pass,type, area,partnerId,name,salt, roleId,cityId,null,proviceId,townshipId,province,city,township);
|
|
}
|
|
}
|
|
//创建终端
|
CityPartner partner = cityPartnerService.findById(Convert.toInt(partnerId));
|
|
//创建终端
|
if (CommonEnum.回收员.getValue().equals(type)) {
|
String sid = partnerTraceService.findByPartnerId(partnerId,Convert.toShort(OrderEnum.回收员订单轨迹.getValue())).getPartnerServiceId();
|
Result<String> terminal = GdTraceUtil.createTerminal(partner.getPartnerKey().split(",")[0], sid, id);
|
String terimalId=null;
|
String terimalDayId=null;
|
if(terminal.getCode()==0){
|
terimalId=terminal.getData();
|
}
|
sid = partnerTraceService.findByPartnerId(partnerId,Convert.toShort(OrderEnum.回收员全天轨迹.getValue())).getPartnerServiceId();
|
terminal = GdTraceUtil.createTerminal(partner.getPartnerKey().split(",")[0], sid, id);
|
if(terminal.getCode()==0){
|
terimalDayId=terminal.getData();
|
}
|
OtherUserInfo otherUserInfo=new OtherUserInfo();
|
otherUserInfo.setUserId(id);
|
otherUserInfo.setTerminalDayId(terimalDayId);
|
otherUserInfo.setTerminalId(terimalId);
|
otherUserInfo.setBirthday("");
|
otherUserService.update(otherUserInfo);
|
|
} else if (CommonEnum.推广员.getValue().equals(type)) {
|
String sid =partnerTraceService.findByPartnerId(partnerId,Convert.toShort(OrderEnum.推广员全天轨迹.getValue())).getPartnerServiceId();
|
Result<String> terminal = GdTraceUtil.createTerminal(partner.getPartnerKey().split(",")[0], sid, id);
|
if(terminal.getCode()==0){
|
OtherUserInfo otherUserInfo=new OtherUserInfo();
|
otherUserInfo.setUserId(id);
|
otherUserInfo.setTerminalId(terminal.getData());
|
otherUserInfo.setBirthday("");
|
otherUserService.update(otherUserInfo);
|
}
|
}
|
|
|
}else{
|
if(type.equals("7")){
|
return -2;
|
}
|
if(otherUserMapper.queryUserByUsertype1(phone, type, "1", null,null)!=null){
|
//如果有账号就修改,没有就新增
|
bool = false;
|
}
|
if(type.equals("2")){
|
boolean flag = checkOtherUserByType("4",phone);
|
if(!flag){
|
return -1;
|
}
|
}else if(type.equals("4")){
|
boolean flag = checkOtherUserByType("2",phone);
|
if(!flag){
|
return -1;
|
}
|
}
|
String salt =null;
|
String pass=null;
|
if(type.equals("4")){
|
otherUserMapper.updateDelflag(phone, type,roleId,name, pass,salt,area,partnerId,cityId,storageId,proviceId,townshipId,province,city,township);
|
|
}else{
|
if(userEditroleModel.getUserType().equals("9")){
|
otherUserMapper.updateDelflag(phone, type,roleId,name,pass,salt,area,"-1",cityId,null,proviceId,townshipId,province,city,township);
|
|
}else{
|
otherUserMapper.updateDelflag(phone, type,roleId,name, pass,salt,area,partnerId,cityId,null,proviceId,townshipId,province,city,township);
|
|
}
|
|
}
|
}
|
UserModel u = otherUserMapper.queryUserByUsertype1(phone, type, "0",null,null);
|
|
// 添加账号表
|
id="ZH"+snowflake.nextIdStr();
|
String value;
|
if(type.equals("4")){
|
value = configService.findByCode("WAREHOUSING_PRICE").getConfigValue();
|
}else{
|
value = configService.findByCode("OVERDRAW_PRICE").getConfigValue();
|
}
|
|
if(!bool){
|
accountMapper.updateCuserAccount(phone,u.getUserId());
|
}else{
|
accountMapper.addCuserAccountRole(id, phone, u.getUserId(),value);
|
}
|
List<Map<String, Object>> userIds = otherUserMapper.queryCuserByPhoneRedisDelList(phone);
|
for (Map<String,Object> map:userIds) {
|
String userId = map.get("userId").toString();
|
redisUtil.remove("xzx:user:token:"+userId);
|
}
|
redisUtil.remove(phone);
|
return 1;
|
}
|
|
public UserRole findById(Long id){
|
return userRoleMapper.selectByPrimaryKey(id);
|
}
|
|
private boolean checkOtherUserByType(String userType,String mobilePhone){
|
List<UserModel> list = otherUserMapper.checkOtherUserByType(userType,mobilePhone);
|
if(null!=list&&list.size()>0){
|
return false;
|
}else{
|
return true;
|
}
|
}
|
}
|