|
|
@@ -6,13 +6,11 @@ import cc.iotkit.common.constant.UserConstants;
|
|
|
import cc.iotkit.common.enums.ErrCode;
|
|
|
import cc.iotkit.common.exception.BizException;
|
|
|
import cc.iotkit.common.satoken.utils.LoginHelper;
|
|
|
+import cc.iotkit.common.utils.JsonUtils;
|
|
|
import cc.iotkit.common.utils.MapstructUtils;
|
|
|
import cc.iotkit.common.utils.StreamUtils;
|
|
|
import cc.iotkit.data.system.*;
|
|
|
-import cc.iotkit.model.system.SysRole;
|
|
|
-import cc.iotkit.model.system.SysUser;
|
|
|
-import cc.iotkit.model.system.SysUserPost;
|
|
|
-import cc.iotkit.model.system.SysUserRole;
|
|
|
+import cc.iotkit.model.system.*;
|
|
|
import cc.iotkit.system.dto.bo.SysUserBo;
|
|
|
import cc.iotkit.system.dto.vo.SysUserVo;
|
|
|
import cc.iotkit.system.service.ISysUserService;
|
|
|
@@ -20,12 +18,20 @@ import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.http.*;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import java.util.Collection;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* 用户 业务层处理
|
|
|
@@ -34,6 +40,7 @@ import java.util.List;
|
|
|
*/
|
|
|
@RequiredArgsConstructor
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class SysUserServiceImpl implements ISysUserService {
|
|
|
|
|
|
@Autowired
|
|
|
@@ -54,6 +61,13 @@ public class SysUserServiceImpl implements ISysUserService {
|
|
|
@Autowired
|
|
|
private ISysUserPostData sysUserPostData;
|
|
|
|
|
|
+// @Autowired
|
|
|
+// private RestTemplate restTemplate;
|
|
|
+
|
|
|
+
|
|
|
+ @Value("${health.platform.url:http://web.poteviohealth.com/boss/admin/api/addIotUser.jhtml}")
|
|
|
+ private String healthPlatFormUrl;
|
|
|
+
|
|
|
|
|
|
public String selectUserNameById(Long userId) {
|
|
|
return null;
|
|
|
@@ -141,6 +155,7 @@ public class SysUserServiceImpl implements ISysUserService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional
|
|
|
public int insertUser(SysUserBo user) {
|
|
|
// 新增用户信息
|
|
|
SysUser newUser = sysUserData.save(user.to(SysUser.class));
|
|
|
@@ -149,9 +164,99 @@ public class SysUserServiceImpl implements ISysUserService {
|
|
|
insertUserPost(user, false);
|
|
|
// 新增用户与角色管理
|
|
|
insertUserRole(user, false);
|
|
|
+ // 同步健康数据
|
|
|
+ try {
|
|
|
+ syncHealthPlatform(user);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.toString());
|
|
|
+ throw new BizException("创建用户失败!");
|
|
|
+ }
|
|
|
return newUser != null ? 1 : 0;
|
|
|
}
|
|
|
|
|
|
+ private void syncHealthPlatform(SysUserBo user) throws Exception {
|
|
|
+ SysDept userDept = sysDeptData.findById(user.getDeptId());
|
|
|
+ SysDept parentDept = null;
|
|
|
+
|
|
|
+ if (Objects.nonNull(userDept)) {
|
|
|
+
|
|
|
+ String[] ancestors = userDept.getAncestors().split(",");
|
|
|
+ if (ancestors.length == 1) {
|
|
|
+ //总公司人员
|
|
|
+ syncUserdata(null, null, user.getUserName());
|
|
|
+ } else if (ancestors.length == 2) {
|
|
|
+ //分公司
|
|
|
+ syncUserdata(userDept.getDeptName(), null, user.getUserName());
|
|
|
+ } else if (ancestors.length == 3) {
|
|
|
+ //机构
|
|
|
+ parentDept = sysDeptData.findById(userDept.getParentId());
|
|
|
+ if (Objects.isNull(parentDept)) {
|
|
|
+ throw new BizException("机构信息有误!");
|
|
|
+ }
|
|
|
+ syncUserdata(parentDept.getDeptName(), userDept.getDeptName(), user.getUserName());
|
|
|
+ } else {
|
|
|
+ //其他
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ throw new BizException("用户信息有误!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void syncUserdata(String companyName, String deptName, String userName) throws Exception {
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ //头部类型
|
|
|
+ headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
|
|
+ MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
|
|
|
+ //接口参数
|
|
|
+ map.add("companyName",companyName);
|
|
|
+ map.add("password",deptName);
|
|
|
+ map.add("user",userName);
|
|
|
+ //构造实体对象
|
|
|
+ HttpEntity<MultiValueMap<String, Object>> param = new HttpEntity<>(map, headers);
|
|
|
+ ResponseEntity exchange = restTemplate.postForEntity(healthPlatFormUrl, param, Map.class);
|
|
|
+ if (exchange.getStatusCode() == HttpStatus.OK) {
|
|
|
+ Map resultRemote = (Map)exchange.getBody();
|
|
|
+ if((boolean) resultRemote.get("success")){
|
|
|
+ log.info("健康平台同步用户信息成功, 编码:"+ resultRemote.get("data"));
|
|
|
+ }else{
|
|
|
+ log.error("健康平台同步用户信息失败,用户名:"+map.get("user")+" 原因:"+resultRemote.get("data"));
|
|
|
+ throw new BizException("健康平台同步用户信息失败");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new BizException("健康平台同步用户信息失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ //头部类型
|
|
|
+ headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
|
|
+ MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
|
|
|
+ //接口参数
|
|
|
+ map.add("companyName","中康养科技公司");
|
|
|
+ map.add("password",null);
|
|
|
+ map.add("user","test03");
|
|
|
+ //构造实体对象
|
|
|
+ HttpEntity<MultiValueMap<String, Object>> param = new HttpEntity<>(map, headers);
|
|
|
+ ResponseEntity exchange = restTemplate.postForEntity("http://web.poteviohealth.com/boss/admin/api/addIotUser.jhtml", param, Map.class);
|
|
|
+ if (exchange.getStatusCode() == HttpStatus.OK) {
|
|
|
+ Map resultRemote = (Map)exchange.getBody();
|
|
|
+ if((boolean) resultRemote.get("success")){
|
|
|
+ log.info("健康平台同步用户信息成功, 编码:"+ resultRemote.get("data"));
|
|
|
+ }else{
|
|
|
+ log.error("健康平台同步用户信息失败,用户名:"+map.get("user")+" 原因:"+resultRemote.get("data"));
|
|
|
+ throw new BizException("健康平台同步用户信息失败");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new BizException("健康平台同步用户信息失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 新增用户角色信息
|
|
|
*
|