|
|
@@ -0,0 +1,143 @@
|
|
|
+package com.etotem.cfc.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.etotem.cfc.common.Result;
|
|
|
+import com.etotem.cfc.dto.ServiceRoleApplyDTO;
|
|
|
+import com.etotem.cfc.entity.*;
|
|
|
+import com.etotem.cfc.mapper.*;
|
|
|
+import com.etotem.cfc.service.ServiceRoleApplicationService;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class ServiceRoleApplicationServiceImpl
|
|
|
+ extends ServiceImpl<ServiceRoleApplicationMapper, ServiceRoleApplication>
|
|
|
+ implements ServiceRoleApplicationService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private UserMapper userMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private GuideMapper guideMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ButlerProfileMapper butlerProfileMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result submit(Long userId, ServiceRoleApplyDTO dto) {
|
|
|
+ ServiceRoleApplication existing = this.getOne(
|
|
|
+ new LambdaQueryWrapper<ServiceRoleApplication>()
|
|
|
+ .eq(ServiceRoleApplication::getUserId, userId)
|
|
|
+ .eq(ServiceRoleApplication::getStatus, 0));
|
|
|
+ if (existing != null) {
|
|
|
+ return Result.error("您已提交过申请,请等待审核");
|
|
|
+ }
|
|
|
+
|
|
|
+ ServiceRoleApplication app = new ServiceRoleApplication();
|
|
|
+ app.setUserId(userId);
|
|
|
+ app.setRoles(JSON.toJSONString(dto.getRoles()));
|
|
|
+ app.setIdCard(dto.getIdCard());
|
|
|
+ app.setIdCardImages(dto.getIdCardImages() != null ? JSON.toJSONString(dto.getIdCardImages()) : null);
|
|
|
+ app.setCertificateImages(dto.getCertificateImages() != null ? JSON.toJSONString(dto.getCertificateImages()) : null);
|
|
|
+ app.setProvince(dto.getProvince());
|
|
|
+ app.setCity(dto.getCity());
|
|
|
+ app.setDistrict(dto.getDistrict());
|
|
|
+ app.setStreet(dto.getStreet());
|
|
|
+ app.setAddressDetail(dto.getAddressDetail());
|
|
|
+ app.setStatus(0);
|
|
|
+ this.save(app);
|
|
|
+ return Result.success("申请提交成功,请等待审核");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result getMyApplication(Long userId) {
|
|
|
+ ServiceRoleApplication app = this.getOne(
|
|
|
+ new LambdaQueryWrapper<ServiceRoleApplication>()
|
|
|
+ .eq(ServiceRoleApplication::getUserId, userId)
|
|
|
+ .orderByDesc(ServiceRoleApplication::getCreatedAt)
|
|
|
+ .last("LIMIT 1"));
|
|
|
+ return Result.success(app);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Result approve(Long id, Long reviewerId) {
|
|
|
+ ServiceRoleApplication app = this.getById(id);
|
|
|
+ if (app == null) {
|
|
|
+ return Result.error("申请记录不存在");
|
|
|
+ }
|
|
|
+ if (app.getStatus() != 0) {
|
|
|
+ return Result.error("该申请已处理");
|
|
|
+ }
|
|
|
+
|
|
|
+ app.setStatus(1);
|
|
|
+ app.setReviewedBy(reviewerId);
|
|
|
+ app.setReviewedAt(LocalDateTime.now());
|
|
|
+ this.updateById(app);
|
|
|
+
|
|
|
+ List<String> roles = JSON.parseArray(app.getRoles(), String.class);
|
|
|
+ User user = userMapper.selectById(app.getUserId());
|
|
|
+
|
|
|
+ for (String role : roles) {
|
|
|
+ switch (role) {
|
|
|
+ case "planner":
|
|
|
+ Guide guide = new Guide();
|
|
|
+ guide.setUserId(app.getUserId());
|
|
|
+ guide.setStatus("active");
|
|
|
+ guide.setProvince(app.getProvince());
|
|
|
+ guide.setCity(app.getCity());
|
|
|
+ guide.setDistrict(app.getDistrict());
|
|
|
+ guide.setStreet(app.getStreet());
|
|
|
+ guideMapper.insert(guide);
|
|
|
+ break;
|
|
|
+ case "nutritionist":
|
|
|
+ user.setNutritionistStatus("approved");
|
|
|
+ break;
|
|
|
+ case "butler":
|
|
|
+ user.setButlerStatus("approved");
|
|
|
+ ButlerProfile bp = new ButlerProfile();
|
|
|
+ bp.setUserId(app.getUserId());
|
|
|
+ bp.setStatus("active");
|
|
|
+ butlerProfileMapper.insert(bp);
|
|
|
+ break;
|
|
|
+ case "vendor":
|
|
|
+ user.setVendorStatus("approved");
|
|
|
+ break;
|
|
|
+ case "article_admin":
|
|
|
+ user.setArticleAdminStatus("approved");
|
|
|
+ break;
|
|
|
+ case "activity_provider":
|
|
|
+ user.setActivityProviderStatus("approved");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ userMapper.updateById(user);
|
|
|
+
|
|
|
+ return Result.success("审核通过");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Result reject(Long id, String reason, Long reviewerId) {
|
|
|
+ ServiceRoleApplication app = this.getById(id);
|
|
|
+ if (app == null) {
|
|
|
+ return Result.error("申请记录不存在");
|
|
|
+ }
|
|
|
+ if (app.getStatus() != 0) {
|
|
|
+ return Result.error("该申请已处理");
|
|
|
+ }
|
|
|
+
|
|
|
+ app.setStatus(2);
|
|
|
+ app.setRejectReason(reason);
|
|
|
+ app.setReviewedBy(reviewerId);
|
|
|
+ app.setReviewedAt(LocalDateTime.now());
|
|
|
+ this.updateById(app);
|
|
|
+ return Result.success("已驳回");
|
|
|
+ }
|
|
|
+}
|