@@ -38,6 +38,11 @@ public class CommonConfig { | |||
*/ | |||
public static String pilotURL; | |||
/** | |||
* oidc地址 | |||
*/ | |||
public static String oidcUrl; | |||
/** | |||
* 图片域名赋值 | |||
* | |||
@@ -97,4 +102,13 @@ public class CommonConfig { | |||
pilotURL = url; | |||
} | |||
/** | |||
* OICD平台 | |||
* @param url 不同环境对应不同的url | |||
*/ | |||
@Value("${tuoheng.oidc-url}") | |||
public void setOidcUrlL(String url) { | |||
oidcUrl = url; | |||
} | |||
} |
@@ -2,25 +2,29 @@ package com.tuoheng.admin.constant; | |||
/** | |||
* oidc认证平台常量url | |||
* | |||
* @Author xiaoying | |||
* @Date 2022/10/18 10:52 | |||
*/ | |||
public class OidcUrlConstant { | |||
public interface OidcUrlConstant { | |||
/** | |||
* 判断username是否已存在 | |||
*/ | |||
public static String USER_JUDGE = "/oidc/admin/user/judge/create/{username}"; | |||
String USER_JUDGE = "/oidc/admin/user/judge/create/{username}"; | |||
/** | |||
* 判断username是否已存在 | |||
*/ | |||
public static String USER_CREATE = "/oidc/admin/user/create"; | |||
String USER_CREATE = "/oidc/admin/user/create"; | |||
/** | |||
* 判断username是否已存在 | |||
*/ | |||
public static String USER_UPDATEPASS = "/oidc/admin/user/updatePass"; | |||
String USER_UPDATEPASS = "/oidc/admin/user/updatePass"; | |||
/** | |||
* 修改用户角色 | |||
*/ | |||
public static String USER_UPDATEROLE = "/oidc/admin/user/updateRole"; | |||
String USER_UPDATEROLE = "/oidc/admin/user/updateRole"; | |||
} |
@@ -1,12 +1,14 @@ | |||
package com.tuoheng.admin.controller; | |||
import com.tuoheng.admin.query.InspectionFileQuery; | |||
import com.tuoheng.admin.request.inspection.EditInspectionRequest; | |||
import com.tuoheng.admin.request.inspectionfile.QueryInspectionFileDistributionListRequest; | |||
import com.tuoheng.admin.request.inspectionfile.QueryInspectionFilePageListByInspectionIdRequest; | |||
import com.tuoheng.admin.request.inspectionfile.QueryInspectionFilePageListRequest; | |||
import com.tuoheng.admin.request.inspectionfile.QueryInspectionFileWorkOrderPageListRequest; | |||
import com.tuoheng.admin.service.IInspectionFileService; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
@@ -16,6 +18,7 @@ import java.util.List; | |||
* @Author ChengWang | |||
* @Date 2022/11/29 | |||
*/ | |||
@Slf4j | |||
@RestController | |||
@RequestMapping("/inspectionFile") | |||
public class InspectionFileController { | |||
@@ -63,7 +66,7 @@ public class InspectionFileController { | |||
} | |||
/** | |||
* 任务问题忽略 | |||
* 任务问题确认 | |||
* | |||
* @return | |||
*/ | |||
@@ -113,4 +116,13 @@ public class InspectionFileController { | |||
public JsonResult getListByWorkOrderId(QueryInspectionFileWorkOrderPageListRequest request){ | |||
return iInspectionFileService.getPageListByWorkOrderId(request); | |||
} | |||
/** | |||
* 修改巡检任务问题类型 | |||
*/ | |||
@PutMapping("/edit/question/{id}/{questionName}") | |||
public JsonResult editQuestionTyppe(@PathVariable("id") String id, @PathVariable("questionName") Integer questionName) { | |||
log.info("进入修改问题类型接口, id={}, questionName={}", id, questionName); | |||
return iInspectionFileService.editQuestionTyppe(id, questionName); | |||
} | |||
} |
@@ -220,4 +220,13 @@ public class User implements Serializable { | |||
@TableField(exist = false) | |||
private String[] city; | |||
/** | |||
* 角色id | |||
*/ | |||
private Integer roleId; | |||
/** | |||
* 标识id 小程序,pc | |||
*/ | |||
private String clientId; | |||
} |
@@ -0,0 +1,44 @@ | |||
package com.tuoheng.admin.enums; | |||
import lombok.Getter; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
/** | |||
* client 枚举类 | |||
* | |||
* @Author xiaoying | |||
* @Date 2022/11/25 16:51 | |||
*/ | |||
public enum ClientEnum { | |||
ADMIN(1, "tuoheng-freeway-admin"), | |||
API(0, "tuoheng-freeway-mp"); | |||
ClientEnum(int code, String description) { | |||
this.code = code; | |||
this.description = description; | |||
} | |||
@Getter | |||
private int code; | |||
@Getter | |||
private String description; | |||
private static Map<Integer, ClientEnum> data = new HashMap<>(); | |||
static { | |||
for (ClientEnum type : ClientEnum.values()) { | |||
data.put(type.code, type); | |||
} | |||
} | |||
public static ClientEnum parse(int code) { | |||
if (data.containsKey(code)) { | |||
return data.get(code); | |||
} | |||
return null; | |||
} | |||
} |
@@ -0,0 +1,51 @@ | |||
package com.tuoheng.admin.enums.code.inspectionfile; | |||
/** | |||
* 修改巡检任务问题类型返回码 | |||
* 模块代码:24(问题管理) | |||
* 接口代码:08 (修改巡检任务问题类型) | |||
* | |||
* @author wanjing | |||
* @team tuoheng | |||
* @date 2022-12-16 | |||
*/ | |||
public enum EditInspectionFileQuestionTypeCodeEnum { | |||
EDIT_IS_FAILED(1240800, "修改数据失败"), | |||
ID_IS_NULL(1240801, "任务问题id为空"), | |||
QUESTION_NAME_IS_NULL(1240802, "问题类型id为空"), | |||
INSPECTION_FILE_IS_NOT_EXIST(1240803, "任务问题不存在"), | |||
QUESTION_TYPE_IS_NOT_EXIST(1240804, "问题类型不存在"); | |||
/** | |||
* 错误码 | |||
*/ | |||
private int code; | |||
/** | |||
* 错误信息 | |||
*/ | |||
private String msg; | |||
EditInspectionFileQuestionTypeCodeEnum(int code, String msg){ | |||
this.code = code; | |||
this.msg = msg; | |||
} | |||
public int getCode() { | |||
return code; | |||
} | |||
public void setCode(int code) { | |||
this.code = code; | |||
} | |||
public String getMsg() { | |||
return msg; | |||
} | |||
public void setMsg(String msg) { | |||
this.msg = msg; | |||
} | |||
} |
@@ -1,16 +0,0 @@ | |||
package com.tuoheng.admin.request; | |||
import com.tuoheng.admin.dto.ClientRoleDto; | |||
import lombok.Data; | |||
import java.util.List; | |||
@Data | |||
public class OidcCreateUserRequest { | |||
private String username; | |||
private String password; | |||
private List<ClientRoleDto> clientRoleDtoList; | |||
} |
@@ -0,0 +1,31 @@ | |||
package com.tuoheng.admin.request.oidc; | |||
import com.tuoheng.admin.dto.ClientRoleDto; | |||
import lombok.Data; | |||
import java.util.List; | |||
/** | |||
* @Author xiaoying | |||
* @Date 2022/11/30 13:23 | |||
*/ | |||
@Data | |||
public class OidcCreateUserRequest { | |||
private String username; | |||
private String password; | |||
private List<ClientRoleDto> clientRoleDtoList; | |||
/** | |||
* 如果不是租户,传值:用户所属租户名称 | |||
*/ | |||
private String tenantName; | |||
/** | |||
* 是否为租户标识 | |||
* 0:不是;1:是 | |||
*/ | |||
private Integer tenantFlag; | |||
} |
@@ -0,0 +1,16 @@ | |||
package com.tuoheng.admin.request.oidc; | |||
import lombok.Data; | |||
/** | |||
* @Author ChengWang | |||
* @Date 2022/10/31 | |||
*/ | |||
@Data | |||
public class OidcUpdateUserPasswordRequest { | |||
private String username; | |||
private String password; | |||
} |
@@ -1,4 +1,4 @@ | |||
package com.tuoheng.admin.request; | |||
package com.tuoheng.admin.request.oidc; | |||
import com.tuoheng.admin.dto.ClientRoleDto; | |||
import lombok.Data; | |||
@@ -15,6 +15,7 @@ public class OidcUpdateUserRequest { | |||
* 用户名 | |||
*/ | |||
private String username; | |||
/** | |||
* 客户端以及对应的权限 | |||
*/ |
@@ -3,6 +3,7 @@ package com.tuoheng.admin.service; | |||
import com.tuoheng.admin.query.InspectionFileQuery; | |||
import com.tuoheng.admin.request.inspectionfile.*; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import org.springframework.web.bind.annotation.PathVariable; | |||
import java.util.List; | |||
@@ -86,4 +87,15 @@ public interface IInspectionFileService { | |||
* @return | |||
*/ | |||
JsonResult processing(InspectionFileProcessingRresultRequest request); | |||
/** | |||
* | |||
* 修改巡检任务问题类型 | |||
* | |||
* @param id | |||
* @param questionName | |||
* | |||
* @return | |||
*/ | |||
JsonResult editQuestionTyppe(String id, Integer questionName); | |||
} |
@@ -23,6 +23,7 @@ import com.tuoheng.admin.service.inspectionfile.query.QueryInspectionFileDistrib | |||
import com.tuoheng.admin.service.inspectionfile.query.QueryInspectionFilePageListByInspectionIdService; | |||
import com.tuoheng.admin.service.inspectionfile.query.QueryInspectionFilePageListByWorkOrderIdService; | |||
import com.tuoheng.admin.service.inspectionfile.query.QueryInspectionFilePageListService; | |||
import com.tuoheng.admin.service.inspectionfile.update.UpdateInspectionFileQuestionTypeService; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.admin.vo.InspectionFileVo; | |||
import com.tuoheng.admin.vo.ListByDeptUserTypeVo; | |||
@@ -90,6 +91,9 @@ public class InspectionFileServiceImpl implements IInspectionFileService { | |||
@Autowired | |||
private InspectionFileProcessingService inspectionFileProcessingService; | |||
@Autowired | |||
private UpdateInspectionFileQuestionTypeService updateInspectionFileQuestionTypeService; | |||
/** | |||
* 问题类型和任务名称 | |||
* | |||
@@ -419,4 +423,18 @@ public class InspectionFileServiceImpl implements IInspectionFileService { | |||
public JsonResult processing(InspectionFileProcessingRresultRequest request) { | |||
return inspectionFileProcessingService.processing(request); | |||
} | |||
/** | |||
* | |||
* 修改巡检任务问题类型 | |||
* | |||
* @param id | |||
* @param questionName | |||
* | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult editQuestionTyppe(String id, Integer questionName) { | |||
return updateInspectionFileQuestionTypeService.update(id, questionName); | |||
} | |||
} |
@@ -0,0 +1,95 @@ | |||
package com.tuoheng.admin.service.inspectionfile.update; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
import com.tuoheng.admin.entity.InspectionFile; | |||
import com.tuoheng.admin.entity.QuestionType; | |||
import com.tuoheng.admin.enums.code.inspectionfile.EditInspectionFileQuestionTypeCodeEnum; | |||
import com.tuoheng.admin.mapper.InspectionFileMapper; | |||
import com.tuoheng.admin.mapper.QuestionTypeMapper; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.common.core.utils.DateUtils; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
/** | |||
* 修改任务问题类型业务层处理 | |||
* | |||
* @author wanjing | |||
* @team tuoheng | |||
* @date 2022-12-16 | |||
*/ | |||
@Slf4j | |||
@Service | |||
public class UpdateInspectionFileQuestionTypeService { | |||
@Autowired | |||
private InspectionFileMapper inspectionFileMapper; | |||
@Autowired | |||
private QuestionTypeMapper questionTypeMapper; | |||
/** | |||
* 修改任务问题类型 | |||
* | |||
* @return | |||
*/ | |||
public JsonResult update(String id, Integer questionName) { | |||
log.info("进入修改任务问题类型业务接口"); | |||
String userId = CurrentUserUtil.getUserId(); | |||
JsonResult result = this.check(id, questionName); | |||
if (0 != result.getCode()) { | |||
log.info("修改任务问题类型业务接口:校验失败:{}", result.getMsg()); | |||
return result; | |||
} | |||
QuestionType questionType = (QuestionType) result.getData(); | |||
InspectionFile inspectionFile = new InspectionFile(); | |||
inspectionFile.setId(id); | |||
inspectionFile.setQuestionId(questionType.getId()); | |||
inspectionFile.setUpdateUser(userId); | |||
inspectionFile.setUpdateTime(DateUtils.now()); | |||
Integer rowId = inspectionFileMapper.updateById(inspectionFile); | |||
if (rowId <= 0) { | |||
log.info("修改任务问题类型业务接口:修改任务失败:{}", result.getMsg()); | |||
return JsonResult.error(EditInspectionFileQuestionTypeCodeEnum.EDIT_IS_FAILED.getCode(), EditInspectionFileQuestionTypeCodeEnum.EDIT_IS_FAILED.getMsg()); | |||
} | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 检查参数 | |||
* | |||
* @param id | |||
* @param questionName | |||
* @return | |||
*/ | |||
private JsonResult check(String id, Integer questionName) { | |||
if (StringUtils.isEmpty(id)) { | |||
return JsonResult.error(EditInspectionFileQuestionTypeCodeEnum.ID_IS_NULL.getCode(), EditInspectionFileQuestionTypeCodeEnum.ID_IS_NULL.getMsg()); | |||
} | |||
if (ObjectUtil.isNull(questionName)) { | |||
return JsonResult.error(EditInspectionFileQuestionTypeCodeEnum.QUESTION_NAME_IS_NULL.getCode(), EditInspectionFileQuestionTypeCodeEnum.QUESTION_NAME_IS_NULL.getMsg()); | |||
} | |||
InspectionFile inspectionFile = inspectionFileMapper.selectOne(Wrappers.<InspectionFile>lambdaQuery() | |||
.eq(InspectionFile::getId, id) | |||
.eq(InspectionFile::getMark, 1)); | |||
if (ObjectUtil.isNull(inspectionFile)) { | |||
return JsonResult.error(EditInspectionFileQuestionTypeCodeEnum.INSPECTION_FILE_IS_NOT_EXIST.getCode(), EditInspectionFileQuestionTypeCodeEnum.INSPECTION_FILE_IS_NOT_EXIST.getMsg()); | |||
} | |||
QuestionType questionType = questionTypeMapper.selectOne(Wrappers.<QuestionType>lambdaQuery() | |||
.eq(QuestionType::getName, questionName) | |||
.eq(QuestionType::getMark, 1)); | |||
if (ObjectUtil.isNull(questionType)) { | |||
return JsonResult.error(EditInspectionFileQuestionTypeCodeEnum.QUESTION_TYPE_IS_NOT_EXIST.getCode(), EditInspectionFileQuestionTypeCodeEnum.QUESTION_TYPE_IS_NOT_EXIST.getMsg()); | |||
} | |||
return JsonResult.success(questionType); | |||
} | |||
} |
@@ -0,0 +1,93 @@ | |||
package com.tuoheng.admin.service.third.oidc; | |||
import com.tuoheng.admin.constant.OidcUrlConstant; | |||
import com.tuoheng.admin.dto.ClientRoleDto; | |||
import com.tuoheng.admin.entity.Tenant; | |||
import com.tuoheng.admin.entity.User; | |||
import com.tuoheng.admin.enums.ClientEnum; | |||
import com.tuoheng.admin.request.oidc.OidcCreateUserRequest; | |||
import com.tuoheng.common.core.config.common.CommonConfig; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.SecurityUserUtils; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.beans.factory.annotation.Qualifier; | |||
import org.springframework.http.HttpEntity; | |||
import org.springframework.http.HttpHeaders; | |||
import org.springframework.http.HttpMethod; | |||
import org.springframework.http.ResponseEntity; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.web.client.RestTemplate; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
@Slf4j | |||
@Service | |||
public class AddOidcUserService { | |||
@Autowired | |||
@Qualifier("restTemplate") | |||
private RestTemplate restTemplate; | |||
public JsonResult addUser(User user, Tenant tenant) { | |||
OidcCreateUserRequest request = extracted(user, tenant); | |||
//设置请求头 | |||
HttpHeaders resultRequestHeader = new HttpHeaders(); | |||
resultRequestHeader.add("Authorization", "Bearer " + SecurityUserUtils.token()); | |||
HttpEntity httpEntity = new HttpEntity(request, resultRequestHeader); | |||
String url = CommonConfig.oidcUrl + OidcUrlConstant.USER_CREATE; | |||
ResponseEntity<JsonResult> response; | |||
try { | |||
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class); | |||
} catch (Exception e) { | |||
log.info("oidc新增用户失败"); | |||
return JsonResult.error("oidc新增用户失败"); | |||
} | |||
if (null == response || !response.hasBody()) { | |||
log.error("oidc新增用户响应失败"); | |||
return JsonResult.error("oidc新增用户响应失败"); | |||
} | |||
if (response.getBody().getCode() != JsonResult.SUCCESS) { | |||
log.error("oidc新增用户响应失败" + response.getBody()); | |||
return JsonResult.error(response.getBody().getMsg()); | |||
} | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 封装请求->oidc认证信息 | |||
* | |||
* @param user | |||
* @return | |||
*/ | |||
private OidcCreateUserRequest extracted(User user, Tenant tenant) { | |||
OidcCreateUserRequest oidcCreateUserRequest = new OidcCreateUserRequest(); | |||
oidcCreateUserRequest.setUsername(user.getUsername()); | |||
if (StringUtils.isNotEmpty(user.getPassword())) { | |||
oidcCreateUserRequest.setPassword(user.getPassword()); | |||
} else { | |||
oidcCreateUserRequest.setPassword("123456"); | |||
} | |||
// 普通用户新增 | |||
oidcCreateUserRequest.setTenantFlag(0); | |||
oidcCreateUserRequest.setTenantName(tenant.getUsername()); | |||
List<ClientRoleDto> clientRoleDtoList = new ArrayList<>(); | |||
ClientRoleDto clientRoleDto; | |||
String[] clientIdArr = user.getClientId().split(","); | |||
for (String clientIdStr : clientIdArr) { | |||
int clientId = Integer.valueOf(clientIdStr); | |||
ClientEnum clientEnum = ClientEnum.parse(clientId); | |||
if (null != clientEnum) { | |||
clientRoleDto = new ClientRoleDto(); | |||
clientRoleDto.setClientId(clientEnum.getDescription()); | |||
clientRoleDto.setRoleId(user.getRoleId()); | |||
clientRoleDtoList.add(clientRoleDto); | |||
} | |||
} | |||
oidcCreateUserRequest.setClientRoleDtoList(clientRoleDtoList); | |||
return oidcCreateUserRequest; | |||
} | |||
} |
@@ -0,0 +1,11 @@ | |||
package com.tuoheng.admin.service.third.oidc; | |||
import com.tuoheng.admin.entity.Tenant; | |||
import com.tuoheng.admin.entity.User; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
public interface OidcService { | |||
JsonResult addUser(User user, Tenant tenant); | |||
} |
@@ -0,0 +1,21 @@ | |||
package com.tuoheng.admin.service.third.oidc; | |||
import com.tuoheng.admin.entity.Tenant; | |||
import com.tuoheng.admin.entity.User; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
@Slf4j | |||
@Service | |||
public class OidcServiceImpl implements OidcService { | |||
@Autowired | |||
private AddOidcUserService addOidcUserService; | |||
public JsonResult addUser(User user, Tenant tenant) { | |||
return addOidcUserService.addUser(user, tenant); | |||
} | |||
} |
@@ -19,7 +19,7 @@ import org.springframework.web.client.RestTemplate; | |||
@Slf4j | |||
@Service | |||
public class AddPilotTskService { | |||
public class AddPilotTaskService { | |||
@Autowired | |||
private TenantMapper tenantMapper; |
@@ -10,10 +10,10 @@ import org.springframework.stereotype.Service; | |||
public class PilotServiceImpl implements PilotService { | |||
@Autowired | |||
private AddPilotTskService addPilotTskService; | |||
private AddPilotTaskService addPilotTaskService; | |||
@Override | |||
public JsonResult addTask(User user, Inspection inspection) { | |||
return addPilotTskService.addTask(user, inspection); | |||
return addPilotTaskService.addTask(user, inspection); | |||
} | |||
} |
@@ -0,0 +1,189 @@ | |||
package com.tuoheng.admin.service.user.add; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||
import com.tuoheng.admin.entity.Role; | |||
import com.tuoheng.admin.entity.Tenant; | |||
import com.tuoheng.admin.entity.User; | |||
import com.tuoheng.admin.enums.code.dept.AddDeptCodeEnum; | |||
import com.tuoheng.admin.mapper.TenantMapper; | |||
import com.tuoheng.admin.mapper.UserMapper; | |||
import com.tuoheng.admin.request.dept.AddDeptRequest; | |||
import com.tuoheng.admin.service.third.oidc.OidcService; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.common.core.config.common.CommonConfig; | |||
import com.tuoheng.common.core.utils.CommonUtils; | |||
import com.tuoheng.common.core.utils.DateUtils; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.http.*; | |||
import org.springframework.stereotype.Service; | |||
import java.util.List; | |||
/** | |||
* 添加用户业务层处理 | |||
* | |||
* @author wanjing | |||
* @team tuoheng | |||
* @date 2022-12-16 | |||
*/ | |||
@Slf4j | |||
@Service | |||
public class AddUserService { | |||
@Autowired | |||
private UserMapper userMapper; | |||
@Autowired | |||
private TenantMapper tenantMapper; | |||
@Autowired | |||
private OidcService oidcService; | |||
/** | |||
* 添加用户数据 | |||
* | |||
* @return | |||
*/ | |||
public JsonResult add(User user) { | |||
log.info("进入添加用户业务接口"); | |||
String tenantId = CurrentUserUtil.getTenantId(); | |||
JsonResult result = this.check(tenantId, user); | |||
if (0 != result.getCode()) { | |||
log.info("添加用户业务接口:校验失败:{}", result.getMsg()); | |||
return result; | |||
} | |||
Tenant tenant = tenantMapper.selectById(tenantId); | |||
// 添加oidc | |||
oidcService.addUser(user, tenant); | |||
this.buildUser(user, tenantId); | |||
// result = this.saveOrUpdate(user); | |||
// if (!result) { | |||
// return JsonResult.error(); | |||
// } | |||
// // 删除已存在的用户角色关系数据 | |||
// userRoleService.deleteUserRole(user.getId()); | |||
// | |||
// // 插入用户角色关系数据 | |||
// //userRoleService.insertUserRole(entity.getId(), entity.getRoleIds()); | |||
// UserRole userRole = new UserRole(); | |||
// //租户id | |||
// userRole.setTenantId(user.getTenantId()); | |||
// userRole.setUserId(user.getId()); | |||
// userRole.setRoleId(user.getRoleId()); | |||
// userRoleService.save(userRole); | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 检查参数 | |||
* @param tenantId | |||
* @param user | |||
* @return | |||
*/ | |||
private JsonResult check(String tenantId, User user) { | |||
if (StringUtils.isNotEmpty(user.getMobile())) { | |||
//校验手机号 | |||
boolean flag = CommonUtils.isMobile(user.getMobile()); | |||
if (!flag) { | |||
return JsonResult.error("该用户手机号格式有误"); | |||
} | |||
} | |||
Integer count = userMapper.selectCount(new LambdaQueryWrapper<User>() | |||
.eq(User::getTenantId, tenantId) | |||
.eq(User::getUsername, user.getUsername()) | |||
.eq(User::getMark, 1)); | |||
if (count > 0) { | |||
return JsonResult.error("系统中已经存在相同的账号信息"); | |||
} | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* | |||
* 构建实体字段数据 | |||
* | |||
* @param user | |||
* @param tenantId | |||
*/ | |||
private void buildUser(User user, String tenantId) { | |||
// 设置密码 | |||
if (StringUtils.isNotEmpty(user.getPassword())) { | |||
user.setPassword(CommonUtils.password(user.getPassword())); | |||
} else { | |||
//默认为123456密码 | |||
user.setPassword(CommonUtils.password("123456")); | |||
} | |||
if (StringUtils.isNotNull(user.getAvatar()) && user.getAvatar().contains(CommonConfig.imageURL)) { | |||
user.setAvatar(user.getAvatar().replaceAll(CommonConfig.imageURL, "")); | |||
} else { | |||
//添加默认头像 | |||
user.setAvatar("imagedir/n1o1j9ndau_1670488066287.png"); | |||
} | |||
//id | |||
user.setCreateUser(CurrentUserUtil.getUserId()); | |||
user.setTenantId(tenantId); | |||
user.setCityName(this.selectCityName(user)); | |||
user.setCreateUser(CurrentUserUtil.getUserId()); | |||
user.setCreateTime(DateUtils.now()); | |||
} | |||
/** | |||
* 用于新增修改终端用户 回显所管辖区域名称 | |||
* | |||
* @param user | |||
* @return | |||
*/ | |||
private String selectCityName(User user) { | |||
//根据用户查询出对应的角色 | |||
// QueryWrapper<City> queryWrapper = new QueryWrapper<>(); | |||
// | |||
// Role role = roleMapper.selectById(user.getRoleId()); | |||
// String userCityCode = ""; | |||
// if (!StringUtils.isEmpty(user.getStreetCode()) && ("006".equals(role.getCode()) || role.getCode().equals("007"))) { | |||
// String citys = ""; | |||
// String[] s = user.getStreetCode().split(","); | |||
// for (String scode : s) { | |||
// queryWrapper = new QueryWrapper<>(); | |||
// queryWrapper.eq("citycode", scode); | |||
// queryWrapper.eq("mark", 1); | |||
// List<City> listStreet = cityMapper.selectList(queryWrapper); | |||
// if (listStreet.size() > 0) { | |||
// for (City cityone : listStreet) { | |||
// citys += cityone.getName() + ","; | |||
// } | |||
// } | |||
// } | |||
// return citys.substring(0, citys.length() - 1); | |||
// } else if (!StringUtils.isEmpty(user.getDistrictCode()) && (role.getCode().equals("004") || role.getCode().equals("007"))) { | |||
// userCityCode = user.getDistrictCode(); | |||
// } else if (!StringUtils.isEmpty(user.getCityCode()) && (role.getCode().equals("003") || role.getCode().equals("007"))) { | |||
// userCityCode = user.getCityCode(); | |||
// } else if (!StringUtils.isEmpty(user.getProvinceCode())) { | |||
// userCityCode = user.getProvinceCode(); | |||
// } | |||
// queryWrapper.eq("citycode", userCityCode); | |||
// List<City> list = cityMapper.selectList(queryWrapper); | |||
// if (list.size() > 0) { | |||
// return list.get(0).getName(); | |||
// } else { | |||
// return null; | |||
// } | |||
return ""; | |||
} | |||
} |
@@ -0,0 +1,114 @@ | |||
package com.tuoheng.admin.service.user.update; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.tuoheng.admin.entity.User; | |||
import com.tuoheng.admin.mapper.UserMapper; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.common.core.config.common.CommonConfig; | |||
import com.tuoheng.common.core.utils.CommonUtils; | |||
import com.tuoheng.common.core.utils.DateUtils; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
/** | |||
* 修改用户业务层处理 | |||
* | |||
* @author wanjing | |||
* @team tuoheng | |||
* @date 2022-12-16 | |||
*/ | |||
@Slf4j | |||
@Service | |||
public class UpdateUserService { | |||
@Autowired | |||
private UserMapper userMapper; | |||
/** | |||
* 修改用户数据 | |||
* | |||
* @return | |||
*/ | |||
public JsonResult update(User user) { | |||
log.info("进入修改用户业务接口"); | |||
String tenantId = CurrentUserUtil.getTenantId(); | |||
JsonResult result = this.check(tenantId, user); | |||
if (0 != result.getCode()) { | |||
log.info("添加修改用户业务接口:校验失败:{}", result.getMsg()); | |||
return result; | |||
} | |||
// 添加oidc | |||
//id | |||
user.setCreateUser(CurrentUserUtil.getUserId()); | |||
// 设置密码 | |||
if (StringUtils.isNotEmpty(user.getPassword())) { | |||
user.setPassword(CommonUtils.password(user.getPassword())); | |||
} else { | |||
//默认为123456密码 | |||
user.setPassword(CommonUtils.password("123456")); | |||
} | |||
if (StringUtils.isNotNull(user.getAvatar()) && user.getAvatar().contains(CommonConfig.imageURL)) { | |||
user.setAvatar(user.getAvatar().replaceAll(CommonConfig.imageURL, "")); | |||
} else { | |||
//添加默认头像 | |||
user.setAvatar("imagedir/n1o1j9ndau_1670488066287.png"); | |||
} | |||
if (StringUtils.isNotEmpty(user.getMobile())) { | |||
//校验手机号 | |||
boolean flag = CommonUtils.isMobile(user.getMobile()); | |||
if (!flag) { | |||
return JsonResult.error("该用户手机号格式有误"); | |||
} | |||
} | |||
// user.setTenantId(CurrentUserUtil.getTenantId()); | |||
// user.setCityName(selectCityName(user)); | |||
// user.setCreateUser(CurrentUserUtil.getUserId()); | |||
// user.setCreateTime(DateUtils.now()); | |||
// | |||
// result = this.saveOrUpdate(user); | |||
// if (!result) { | |||
// return JsonResult.error(); | |||
// } | |||
// // 删除已存在的用户角色关系数据 | |||
// userRoleService.deleteUserRole(user.getId()); | |||
// | |||
// // 插入用户角色关系数据 | |||
// //userRoleService.insertUserRole(entity.getId(), entity.getRoleIds()); | |||
// UserRole userRole = new UserRole(); | |||
// //租户id | |||
// userRole.setTenantId(user.getTenantId()); | |||
// userRole.setUserId(user.getId()); | |||
// userRole.setRoleId(user.getRoleId()); | |||
// userRoleService.save(userRole); | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 检查参数 | |||
* @param tenantId | |||
* @param user | |||
* @return | |||
*/ | |||
private JsonResult check(String tenantId, User user) { | |||
Integer count = userMapper.selectCount(new LambdaQueryWrapper<User>() | |||
.eq(User::getTenantId, tenantId) | |||
.eq(User::getUsername, user.getUsername()) | |||
.eq(User::getMark, 1)); | |||
if (count > 0) { | |||
return JsonResult.error("系统中已经存在相同的账号信息"); | |||
} | |||
return JsonResult.success(); | |||
} | |||
} |
@@ -40,10 +40,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
<result property="updateUser" column="update_user" /> | |||
<result property="updateTime" column="update_time" /> | |||
<result property="mark" column="mark" /> | |||
<result property="roleId" column="role_id" /> | |||
<result property="clientId" column="client_id" /> | |||
</resultMap> | |||
<sql id="selectThUserVo"> | |||
id, tenant_id, code, realname, nickname, gender, avatar, mobile, email, birthday, dept_id, province_code, city_code, district_code, street_code, address, city_name, username, password, type, driver_type, driver_code, salt, intro, status, note, sort, login_num, login_ip, login_time, create_user, create_time, update_user, update_time, mark | |||
id, tenant_id, code, realname, nickname, gender, avatar, mobile, email, birthday, dept_id, province_code, city_code, district_code, street_code, address, city_name, username, password, type, driver_type, driver_code, salt, intro, status, note, sort, login_num, login_ip, login_time, create_user, create_time, update_user, update_time, role_id, client_id, mark | |||
</sql> | |||