|
@@ -1,7 +1,12 @@
|
|
|
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.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;
|
|
@@ -50,7 +55,17 @@ 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;
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -697,4 +712,159 @@ 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");
|
|
|
|
|
+ /*人员信息是否有效,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;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ 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;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|