|
|
@@ -3,12 +3,19 @@ package com.izouma.wenlvju.service;
|
|
|
import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import com.izouma.wenlvju.config.Constants;
|
|
|
+import com.izouma.wenlvju.domain.ArtType;
|
|
|
+import com.izouma.wenlvju.domain.Organization;
|
|
|
import com.izouma.wenlvju.domain.User;
|
|
|
+import com.izouma.wenlvju.dto.ExpertDTO;
|
|
|
+import com.izouma.wenlvju.dto.OrganizationRegDTO;
|
|
|
import com.izouma.wenlvju.dto.PageQuery;
|
|
|
import com.izouma.wenlvju.dto.UserRegister;
|
|
|
import com.izouma.wenlvju.enums.AuthorityName;
|
|
|
import com.izouma.wenlvju.exception.BusinessException;
|
|
|
+import com.izouma.wenlvju.repo.ArtTypeRepo;
|
|
|
+import com.izouma.wenlvju.repo.OrganizationRepo;
|
|
|
import com.izouma.wenlvju.repo.UserRepo;
|
|
|
import com.izouma.wenlvju.security.Authority;
|
|
|
import com.izouma.wenlvju.security.JwtTokenUtil;
|
|
|
@@ -34,18 +41,21 @@ import javax.persistence.criteria.Predicate;
|
|
|
import javax.persistence.criteria.SetJoin;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
@AllArgsConstructor
|
|
|
public class UserService {
|
|
|
- private UserRepo userRepo;
|
|
|
- private WxMaService wxMaService;
|
|
|
- private WxMpService wxMpService;
|
|
|
- private SmsService smsService;
|
|
|
- private StorageService storageService;
|
|
|
- private JwtTokenUtil jwtTokenUtil;
|
|
|
- private CaptchaService captchaService;
|
|
|
+ private final UserRepo userRepo;
|
|
|
+ private final WxMaService wxMaService;
|
|
|
+ private final WxMpService wxMpService;
|
|
|
+ private final SmsService smsService;
|
|
|
+ private final StorageService storageService;
|
|
|
+ private final JwtTokenUtil jwtTokenUtil;
|
|
|
+ private final CaptchaService captchaService;
|
|
|
+ private final ArtTypeRepo artTypeRepo;
|
|
|
+ private final OrganizationRepo organizationRepo;
|
|
|
|
|
|
public Page<User> all(PageQuery pageQuery) {
|
|
|
return userRepo.findAll(JpaUtils.toSpecification(pageQuery, User.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
@@ -186,15 +196,39 @@ public class UserService {
|
|
|
return setPassword(userId, password);
|
|
|
}
|
|
|
|
|
|
- public Page<User> all1(PageQuery pageQuery) {
|
|
|
+ public Page<ExpertDTO> all1(PageQuery pageQuery) {
|
|
|
+ Map<Long, String> artMap = artTypeRepo.findAll()
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(ArtType::getId, ArtType::getName));
|
|
|
return userRepo.findAll(((root, criteriaQuery, criteriaBuilder) -> {
|
|
|
- List<Predicate> and = JpaUtils.toPredicates(pageQuery,User.class,root,criteriaQuery,criteriaBuilder);
|
|
|
+ List<Predicate> and = JpaUtils.toPredicates(pageQuery, User.class, root, criteriaQuery, criteriaBuilder);
|
|
|
// 只有专家权限
|
|
|
SetJoin<User, Authority> join = root.join(root.getModel()
|
|
|
.getSet("authorities", Authority.class), JoinType.LEFT);
|
|
|
and.add(join.in(Authority.get(AuthorityName.ROLE_EXPERT)));
|
|
|
return criteriaBuilder.and(and.toArray(new Predicate[0]));
|
|
|
+ }), JpaUtils.toPageRequest(pageQuery)).map(user -> new ExpertDTO(user, artMap.get(user.getArtTypeId())));
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ 注册承办单位
|
|
|
+ */
|
|
|
+ public User regOrganization(OrganizationRegDTO dto) {
|
|
|
+ User user = new User();
|
|
|
+ BeanUtil.copyProperties(dto, user);
|
|
|
+ if (StringUtils.isNotBlank(dto.getPassword())) {
|
|
|
+ user.setPassword(new BCryptPasswordEncoder().encode(dto.getPassword()));
|
|
|
+ }
|
|
|
+ user.setAuthorities(Collections.singleton(Authority.get(AuthorityName.ROLE_ORGANIZER)));
|
|
|
+ User save = userRepo.save(user);
|
|
|
+
|
|
|
+ organizationRepo.save(
|
|
|
+ Organization.builder()
|
|
|
+ .businessLicense(dto.getBusinessLicense())
|
|
|
+ .userId(save.getId())
|
|
|
+ .name(dto.getOrganizationName())
|
|
|
+ .build());
|
|
|
|
|
|
- }), JpaUtils.toPageRequest(pageQuery));
|
|
|
+ return user;
|
|
|
}
|
|
|
}
|