|
|
@@ -0,0 +1,188 @@
|
|
|
+package cn.tr.module.phototherapy.app.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import cn.tr.module.phototherapy.app.dto.AppDoctorUserAddDTO;
|
|
|
+import cn.tr.module.phototherapy.app.dto.AppDoctorUserDTO;
|
|
|
+import cn.tr.module.phototherapy.app.dto.AppDoctorUserQueryDTO;
|
|
|
+import cn.tr.module.phototherapy.app.mapper.AppDoctorUserMapper;
|
|
|
+import cn.tr.module.phototherapy.app.po.AppDoctorUserPO;
|
|
|
+import cn.tr.module.phototherapy.app.repository.AppDoctorUserRepository;
|
|
|
+import cn.tr.module.phototherapy.app.service.IAppDoctorUserService;
|
|
|
+import cn.tr.module.phototherapy.common.po.BusClinicPO;
|
|
|
+import cn.tr.module.phototherapy.common.repository.BusClinicRepository;
|
|
|
+import cn.tr.module.sys.exception.CustomException;
|
|
|
+import cn.tr.module.sys.oauth2.utils.SecurityUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.checkerframework.checker.units.qual.A;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.util.*;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import cn.tr.core.exception.ServiceException;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import cn.tr.core.exception.TRExcCode;
|
|
|
+
|
|
|
+/**
|
|
|
+ * app医生UserService接口实现类
|
|
|
+ *
|
|
|
+ * @author
|
|
|
+ * @date 2026-01-26
|
|
|
+ **/
|
|
|
+@Service
|
|
|
+public class AppDoctorUserServiceImpl extends ServiceImpl<AppDoctorUserRepository, AppDoctorUserPO> implements IAppDoctorUserService {
|
|
|
+ @Resource
|
|
|
+ private AppDoctorUserRepository baseRepository;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据条件查询app医生用户
|
|
|
+ * @param query 查询参数
|
|
|
+ * @author
|
|
|
+ * @date 2026-01-26
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<AppDoctorUserDTO> selectAppDoctorUserList(AppDoctorUserQueryDTO query){
|
|
|
+ return AppDoctorUserMapper.INSTANCE.convertDtoList(
|
|
|
+ baseRepository.selectList(new LambdaQueryWrapper<AppDoctorUserPO>()
|
|
|
+ .like(Objects.nonNull(query.getUsername()),AppDoctorUserPO::getUsername, query.getUsername())
|
|
|
+ .like(Objects.nonNull(query.getSex()),AppDoctorUserPO::getSex, query.getSex())
|
|
|
+ .like(Objects.nonNull(query.getRealName()),AppDoctorUserPO::getRealName, query.getRealName())
|
|
|
+ .eq(Objects.nonNull(query.getStatus()),AppDoctorUserPO::getStatus, query.getStatus())
|
|
|
+ .eq(Objects.nonNull(query.getTenantId()),AppDoctorUserPO::getTenantId, query.getTenantId())
|
|
|
+ .like(Objects.nonNull(query.getDoctorPhone()),AppDoctorUserPO::getDoctorPhone, query.getDoctorPhone())
|
|
|
+ )
|
|
|
+ );
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据id查询app医生用户
|
|
|
+ * @param id 主键id
|
|
|
+ * @author
|
|
|
+ * @date 2026-01-26
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public AppDoctorUserDTO selectAppDoctorUserById(String id){
|
|
|
+ return AppDoctorUserMapper.INSTANCE.convertDto(baseRepository.selectById(id));
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑app医生用户
|
|
|
+ * @param source 编辑实体类
|
|
|
+ * @author
|
|
|
+ * @date 2026-01-26
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public boolean updateAppDoctorUserById(AppDoctorUserPO source){
|
|
|
+ if(StrUtil.isNullOrUndefined(source.getId())){
|
|
|
+ throw new CustomException("用户id不能为空");
|
|
|
+ }
|
|
|
+ if(StrUtil.isNotBlank(source.getRealName())&&StrUtil.length(source.getRealName())>32){
|
|
|
+ throw new CustomException("医生名称不得超过32个字节");
|
|
|
+ }
|
|
|
+ return this.updateById(source);
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增app医生用户
|
|
|
+ * @param source 新增实体类
|
|
|
+ * @author
|
|
|
+ * @date 2026-01-26
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean insertAppDoctorUser(List<AppDoctorUserPO> source){
|
|
|
+// return baseRepository.insert(AppDoctorUserMapper.INSTANCE.convertPO(source))!=0;
|
|
|
+ if (CollectionUtil.isEmpty(source)){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (source.size() > 100){
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"一次最多只能新增100条数据");
|
|
|
+ }
|
|
|
+ for (AppDoctorUserPO appDoctorUserAddPO : source) {
|
|
|
+ if (StrUtil.isEmpty(appDoctorUserAddPO.getRealName())){
|
|
|
+ throw new CustomException(String.format("用户名:{%s},姓名不能为空",appDoctorUserAddPO.getUsername()));
|
|
|
+ }
|
|
|
+ appDoctorUserAddPO.setIsEdit(0);
|
|
|
+ }
|
|
|
+ List<String> userNames = source.stream()
|
|
|
+ .peek(appDoctorUserAddPO ->{
|
|
|
+ if (StrUtil.isEmpty(appDoctorUserAddPO.getPassword())){
|
|
|
+ appDoctorUserAddPO.setPassword("123456");
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .peek(appDoctorUserAddPO -> {
|
|
|
+ appDoctorUserAddPO.setPassword(SecurityUtil.encryptPassword(appDoctorUserAddPO.getPassword()));
|
|
|
+ })
|
|
|
+ .map(AppDoctorUserPO::getPassword).toList();
|
|
|
+
|
|
|
+ Set<String> userNameDistinct = new HashSet<>(userNames);
|
|
|
+ if(CollectionUtil.size(userNames)!=CollectionUtil.size(userNameDistinct)){
|
|
|
+ throw new CustomException("请检查新增的医生账户中是否存在重复用户名");
|
|
|
+ }
|
|
|
+ // 检查数据库中是否已存在相同用户名
|
|
|
+ List<AppDoctorUserPO> existUsers = baseRepository.selectList(
|
|
|
+ new QueryWrapper<AppDoctorUserPO>()
|
|
|
+ .lambda()
|
|
|
+ .select(AppDoctorUserPO::getUsername)
|
|
|
+ .in(AppDoctorUserPO::getUsername, userNameDistinct)
|
|
|
+ );
|
|
|
+ if (CollectionUtil.isNotEmpty(existUsers)) {
|
|
|
+ Set<String> existUsername = existUsers.stream()
|
|
|
+ .map(AppDoctorUserPO::getUsername)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ Collection<String> intersection = CollectionUtil.intersection(existUsername, userNameDistinct);
|
|
|
+ throw new CustomException(String.format("用户名%s已存在,不可重复添加", JSONUtil.toJsonStr(intersection)));
|
|
|
+ }
|
|
|
+ String sqlStatement = super.getSqlStatement(SqlMethod.INSERT_ONE);
|
|
|
+
|
|
|
+ return executeBatch(source, DEFAULT_BATCH_SIZE, (sqlSession, entity) -> sqlSession.insert(sqlStatement, entity));
|
|
|
+
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除app医生用户详情
|
|
|
+ * @param ids 删除主键集合
|
|
|
+ * @author
|
|
|
+ * @date 2026-01-26
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean removeAppDoctorUserByIds(Collection<String> ids){
|
|
|
+ if(CollectionUtil.isEmpty(ids)){
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"请选择要删除的数据");
|
|
|
+ }
|
|
|
+ boolean result = this.removeBatchByIds(ids);
|
|
|
+ if (!result){
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"删除失败");
|
|
|
+ }
|
|
|
+ SecurityUtil.getStpLogic().logout(ids);
|
|
|
+ return true;
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 重置密码
|
|
|
+ * @param id
|
|
|
+ * @param password
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public boolean resetPassword(String id, String password) {
|
|
|
+ if(StrUtil.isNullOrUndefined(id)){
|
|
|
+ throw new CustomException("用户id不能为空");
|
|
|
+ }
|
|
|
+ AppDoctorUserPO source = new AppDoctorUserPO();
|
|
|
+ source.setId(id);
|
|
|
+ // 密码加密
|
|
|
+ source.setPassword(SecurityUtil.encryptPassword(password));
|
|
|
+ return this.updateById(source);
|
|
|
+ }
|
|
|
+}
|