|
@@ -1,12 +1,19 @@
|
|
|
package com.dgtly.system.service.impl;
|
|
package com.dgtly.system.service.impl;
|
|
|
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.dgtly.common.utils.ShiroSaltUtil;
|
|
|
|
|
+import com.dgtly.common.utils.http.HttpUtils;
|
|
|
|
|
+import com.dgtly.common.utils.security.EncryptPassWordClass;
|
|
|
import com.dgtly.system.domain.*;
|
|
import com.dgtly.system.domain.*;
|
|
|
import com.dgtly.system.mapper.*;
|
|
import com.dgtly.system.mapper.*;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import com.dgtly.common.annotation.DataScope;
|
|
import com.dgtly.common.annotation.DataScope;
|
|
@@ -50,6 +57,20 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private SysUserExtMapper userExtMapper;
|
|
private SysUserExtMapper userExtMapper;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private SysUserMapper sysUserMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private SysUserExtMapper sysUserExtMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private SysUserShopExtMapper userShopExtMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private SysUserServiceImpl sysUserService;
|
|
|
|
|
+
|
|
|
|
|
+ @Value(value = "${spring.esb.esbShopStoneLikePaintUser}")
|
|
|
|
|
+ private String esbShopStoneLikePaintUserUrl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -314,18 +335,18 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
public void insertShopUserRole(SysUser user)
|
|
public void insertShopUserRole(SysUser user)
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
- // 新增用户与角色管理
|
|
|
|
|
- List<SysUserRole> list = new ArrayList<SysUserRole>();
|
|
|
|
|
- SysUserRole ur = new SysUserRole();
|
|
|
|
|
- ur.setUserId(user.getUserId());
|
|
|
|
|
- ur.setRoleId(user.getRoleId());
|
|
|
|
|
- if(user.getShopType() != null){
|
|
|
|
|
- ur.setShopType(user.getShopType());
|
|
|
|
|
- }
|
|
|
|
|
- list.add(ur);
|
|
|
|
|
- if (list.size() > 0) {
|
|
|
|
|
- userRoleMapper.batchUserRole(list);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 新增用户与角色管理
|
|
|
|
|
+ List<SysUserRole> list = new ArrayList<SysUserRole>();
|
|
|
|
|
+ SysUserRole ur = new SysUserRole();
|
|
|
|
|
+ ur.setUserId(user.getUserId());
|
|
|
|
|
+ ur.setRoleId(user.getRoleId());
|
|
|
|
|
+ if(user.getShopType() != null){
|
|
|
|
|
+ ur.setShopType(user.getShopType());
|
|
|
|
|
+ }
|
|
|
|
|
+ list.add(ur);
|
|
|
|
|
+ if (list.size() > 0) {
|
|
|
|
|
+ userRoleMapper.batchUserRole(list);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -447,7 +468,7 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
// List<SysRole> roles = user.getRoles();
|
|
// List<SysRole> roles = user.getRoles();
|
|
|
// for(SysRole role:roles){
|
|
// for(SysRole role:roles){
|
|
|
// if(role.getRoleKey().equals("admin")){
|
|
// if(role.getRoleKey().equals("admin")){
|
|
|
- throw new BusinessException("不允许操作超级管理员用户");
|
|
|
|
|
|
|
+ throw new BusinessException("不允许操作超级管理员用户");
|
|
|
// }
|
|
// }
|
|
|
// }
|
|
// }
|
|
|
|
|
|
|
@@ -697,4 +718,213 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
return userMapper.deleteUserByLoginName(loginName);
|
|
return userMapper.deleteUserByLoginName(loginName);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Boolean buildStoneLikePaintByQwData(JSONObject json) {
|
|
|
|
|
+ Long roleId = roleMapper.selectRoleIdByRoleKey("shopStoneLikePaint");
|
|
|
|
|
+ //0TUC仿石漆服务商人员
|
|
|
|
|
+ Boolean i = buildShopUser(json,"0",roleId);
|
|
|
|
|
+
|
|
|
|
|
+ return i;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public Boolean buildShopUser(JSONObject jsonObject, String usertype, Long roleId){
|
|
|
|
|
+ JSONObject jo =jsonObject;
|
|
|
|
|
+ Set<String> loginNameSet = sysUserService.selectAllUserLoginName();
|
|
|
|
|
+ loginNameSet = loginNameSet.stream().map(String::toUpperCase).collect(Collectors.toSet());
|
|
|
|
|
+ try {
|
|
|
|
|
+ String userName = jo.getString("staff_name");
|
|
|
|
|
+ String userPhone = jo.getString("staff_mobile");
|
|
|
|
|
+ //是否同步企业微信
|
|
|
|
|
+ Boolean isSync = jo.getBoolean("is_synced_to_wecom");
|
|
|
|
|
+ //是否有效用户
|
|
|
|
|
+ Boolean isActive = jo.getBoolean("is_active");
|
|
|
|
|
+ String subOfficeCode = jo.getString("office_code");
|
|
|
|
|
+ String subOfficeName = jo.getString("office_name");
|
|
|
|
|
+ String shopCode = jo.getString("organization_code");
|
|
|
|
|
+ String shopName = jo.getString("organization_name");
|
|
|
|
|
+ String dataUpdateTime = jo.getString("update_datetime");
|
|
|
|
|
+ String dataUserId = jo.getString("id");
|
|
|
|
|
+ String customerCode = jo.getString("distributor_code");
|
|
|
|
|
+ String customerName = jo.getString("distributor_name");
|
|
|
|
|
+ /*人员信息是否有效,true有效,false无效。是否同步到企微 */
|
|
|
|
|
+ String loginName ="";
|
|
|
|
|
+ if(isActive && isSync){
|
|
|
|
|
+ loginName = jo.getString("wecom_userid");
|
|
|
|
|
+ }else{
|
|
|
|
|
+ //先判断该用户是否存在在处理离职和去掉角色,否则直接跳出循环不处理
|
|
|
|
|
+ //离职掉该门店和用户关联关系
|
|
|
|
|
+ if(!isActive){
|
|
|
|
|
+ //用户无效后接口获取不到企微id,需从关联表查询
|
|
|
|
|
+ loginName = userShopExtMapper.selectLoginNameByUserId(dataUserId,shopCode,usertype);
|
|
|
|
|
+ if(loginName !=null && !loginName.isEmpty()){
|
|
|
|
|
+ //查询用户信息
|
|
|
|
|
+ SysUser user = sysUserMapper.selectUserByLoginName(loginName);
|
|
|
|
|
+ userShopExtMapper.deleteUserShopExt(user.getUserId().toString(),loginName,shopCode,usertype);
|
|
|
|
|
+ //去掉该用户和角色的关联关系
|
|
|
|
|
+ userRoleMapper.deleteUserRoleByUserIdAndExt(user.getUserId(),roleId,usertype);
|
|
|
|
|
+ //离职处理以及用户主信息是否有门店账号处理需要添加
|
|
|
|
|
+ //查询门店用户表是否存在用户和其他门店的关联关系,如果存在就不离职,不存在查询是否有经销商的关联关系,如果存在就不离职,不存在就离职
|
|
|
|
|
+ SysUserShopExt shop = new SysUserShopExt();
|
|
|
|
|
+ shop.setUserId(user.getUserId().toString());
|
|
|
|
|
+ shop.setDelFlag("0");
|
|
|
|
|
+ List<SysUserShopExt> shopExtList = userShopExtMapper.selectSysUserShopExtList(shop);
|
|
|
|
|
+ if(shopExtList == null || shopExtList.size() == 0){
|
|
|
|
|
+ //在查用户经销商扩展信息
|
|
|
|
|
+ SysUserExt userCustomerExt = sysUserExtMapper.selectSysUserExtById(user.getUserId());
|
|
|
|
|
+ user.setIsShopAccount("0");
|
|
|
|
|
+ if(userCustomerExt == null){
|
|
|
|
|
+ //离职处理2
|
|
|
|
|
+ user.setQuit("2");
|
|
|
|
|
+ }
|
|
|
|
|
+ //修改用户信息
|
|
|
|
|
+ sysUserMapper.updateUser(user);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ //先建店
|
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
|
+ Map<String,String> urlMap = new HashMap<>();
|
|
|
|
|
+ urlMap.put("userid","ERP");
|
|
|
|
|
+ if (subOfficeName != null && subOfficeName.startsWith("BMD")){
|
|
|
|
|
+ //bmd token死值
|
|
|
|
|
+ String bmdToken="575A4BE6-FCD8-485D-98E0-E51592058AB7";
|
|
|
|
|
+ urlMap.put("token",bmdToken);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ //非bmd token 死值
|
|
|
|
|
+ String dorderToken="80027CC7791640CDBAE4D8F0E587985F";
|
|
|
|
|
+ urlMap.put("token",dorderToken);
|
|
|
|
|
+ }
|
|
|
|
|
+ urlMap.put("if","IF_NP_SHOP");
|
|
|
|
|
+ urlMap.put("callmethod","ADD_FSQ");
|
|
|
|
|
+ params.put("url", urlMap);
|
|
|
|
|
+ Map<String,Object> bodyMap = new HashMap<>();
|
|
|
|
|
+ bodyMap.put("MainCustomerCode",customerCode);
|
|
|
|
|
+ bodyMap.put("MainCustomerName",customerName);
|
|
|
|
|
+ bodyMap.put("OfficeCode",subOfficeCode);
|
|
|
|
|
+ bodyMap.put("OfficeName",subOfficeName);
|
|
|
|
|
+ bodyMap.put("ShopCode_Pre",shopCode);
|
|
|
|
|
+ bodyMap.put("ShopCode",shopCode);
|
|
|
|
|
+ bodyMap.put("ShopLinkman",userName);
|
|
|
|
|
+ bodyMap.put("ShopName",shopName);
|
|
|
|
|
+ bodyMap.put("ShopPhone",userPhone);
|
|
|
|
|
+ bodyMap.put("ShopTypeName","FSQ");
|
|
|
|
|
+ params.put("body", bodyMap);
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, String> headers = new HashMap<String, String>(2);
|
|
|
|
|
+ String uuidStr = UUID.randomUUID().toString();
|
|
|
|
|
+ headers.put("Content-Type","application/json");
|
|
|
|
|
+ headers.put("requestId",uuidStr);
|
|
|
|
|
+ headers.put("trackId",uuidStr);
|
|
|
|
|
+ headers.put("sourceSystem","SSB");
|
|
|
|
|
+ try{
|
|
|
|
|
+ if (subOfficeName != null && subOfficeName.startsWith("BMD")) {
|
|
|
|
|
+ // subOfficeName 以 "BMD" 开头的处理逻辑
|
|
|
|
|
+ //bmd
|
|
|
|
|
+ headers.put("serviceName","S_XXX_BMDOMS_BMDNewStore_S");
|
|
|
|
|
+ HttpUtils.sendJsonPostWithHeaders(esbShopStoneLikePaintUserUrl,headers,params);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ //非bmd
|
|
|
|
|
+ headers.put("serviceName","S_XXX_BMDOMS_DORDERNewStore_S");
|
|
|
|
|
+ HttpUtils.sendJsonPostWithHeaders(esbShopStoneLikePaintUserUrl,headers,params);
|
|
|
|
|
+ }
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ log.error("服务商调用建店异常"+jsonObject,e);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if (!loginNameSet.contains(loginName.toUpperCase().trim())) {
|
|
|
|
|
+
|
|
|
|
|
+ /** =============用户基本信息构建 start===============*/
|
|
|
|
|
+ SysUser user = new SysUser();
|
|
|
|
|
+ user.setLoginName(loginName);
|
|
|
|
|
+ log.info("门店新用户"+loginName +"门店类型身份"+usertype);
|
|
|
|
|
+ user.setUserName(userName);
|
|
|
|
|
+ user.setPhonenumber(userPhone);
|
|
|
|
|
+ user.setPassword(loginName);
|
|
|
|
|
+ user.setSalt(ShiroSaltUtil.randomSalt());
|
|
|
|
|
+ user.setPassword(EncryptPassWordClass.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt()));
|
|
|
|
|
+ user.setIsShopAccount("1");
|
|
|
|
|
+ user.setRoleId(roleId);
|
|
|
|
|
+ /** =============用户基本信息构建 end===============*/
|
|
|
|
|
+ insertUserAndExt(user);
|
|
|
|
|
+ //查询用户信息
|
|
|
|
|
+ SysUser userVoExt = sysUserMapper.selectUserByLoginName(loginName);
|
|
|
|
|
+ // 新增用户与角色管理
|
|
|
|
|
+ user.setUserId(userVoExt.getUserId());
|
|
|
|
|
+ user.setShopType(usertype);
|
|
|
|
|
+ sysUserService.insertShopUserRole(user);
|
|
|
|
|
+ /**======== 构建门店用户扩展信息表 start===============*/
|
|
|
|
|
+ SysUserShopExt shopExt = new SysUserShopExt();
|
|
|
|
|
+ shopExt.setLoginName(loginName);
|
|
|
|
|
+ shopExt.setShopCode(shopCode);
|
|
|
|
|
+ shopExt.setShopName(shopName);
|
|
|
|
|
+ shopExt.setSubofficeCode(subOfficeCode);
|
|
|
|
|
+ shopExt.setSubofficeName(subOfficeName);
|
|
|
|
|
+ shopExt.setIsShopType(usertype);
|
|
|
|
|
+ shopExt.setUserUpdateTime(dataUpdateTime);
|
|
|
|
|
+ shopExt.setDelFlag("0");
|
|
|
|
|
+ shopExt.setConstraintUserId(dataUserId);
|
|
|
|
|
+ //用户id
|
|
|
|
|
+ shopExt.setUserId(userVoExt.getUserId().toString());
|
|
|
|
|
+ userShopExtMapper.insertSysUserShopExt(shopExt);
|
|
|
|
|
+ loginNameSet.add(loginName);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ /*已经存在的,需增加用户标识,然后增加门店用户扩展信息*/
|
|
|
|
|
+ SysUser user = sysUserMapper.selectUserByLoginName(loginName);
|
|
|
|
|
+ user.setPhonenumber(userPhone);
|
|
|
|
|
+ //允许同步自动用户
|
|
|
|
|
+ if (("0").equals(user.getIsSync())) {
|
|
|
|
|
+ //查询该用户是否存在该接口返回中
|
|
|
|
|
+ user.setPhonenumber(userPhone);
|
|
|
|
|
+ user.setUserName(userName);
|
|
|
|
|
+ user.setIsShopAccount("1");
|
|
|
|
|
+ sysUserService.updateUserInfo(user);
|
|
|
|
|
+
|
|
|
|
|
+ /**======== 构建门店用户扩展信息表 start===============*/
|
|
|
|
|
+ //先删除用户门店扩展表,再插入
|
|
|
|
|
+ userShopExtMapper.deletePhysicsUserShopExt(user.getUserId().toString(),loginName,shopCode,usertype);
|
|
|
|
|
+ SysUserShopExt shopExt = new SysUserShopExt();
|
|
|
|
|
+ shopExt.setLoginName(loginName);
|
|
|
|
|
+ shopExt.setShopCode(shopCode);
|
|
|
|
|
+ shopExt.setShopName(shopName);
|
|
|
|
|
+ shopExt.setSubofficeCode(subOfficeCode);
|
|
|
|
|
+ shopExt.setSubofficeName(subOfficeName);
|
|
|
|
|
+ shopExt.setIsShopType(usertype);
|
|
|
|
|
+ shopExt.setUserUpdateTime(dataUpdateTime);
|
|
|
|
|
+ shopExt.setDelFlag("0");
|
|
|
|
|
+ shopExt.setConstraintUserId(dataUserId);
|
|
|
|
|
+ //用户id
|
|
|
|
|
+ shopExt.setUserId(user.getUserId().toString());
|
|
|
|
|
+ userShopExtMapper.insertSysUserShopExt(shopExt);
|
|
|
|
|
+ //去掉该用户和角色的关联关系
|
|
|
|
|
+ userRoleMapper.deleteUserRoleByUserIdAndExt(user.getUserId(),roleId,usertype);
|
|
|
|
|
+ user.setRoleId(roleId);
|
|
|
|
|
+ user.setUserId(user.getUserId());
|
|
|
|
|
+ user.setShopType(usertype);
|
|
|
|
|
+ sysUserService.insertShopUserRole(user);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ log.error("门店用户数据分析异常"+e.getMessage());
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public Integer insertUserAndExt(SysUser user) {
|
|
|
|
|
+ // 新增用户信息
|
|
|
|
|
+ int rows = sysUserMapper.insertUser(user);
|
|
|
|
|
+
|
|
|
|
|
+ return rows;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|