jinshihui 2 týždňov pred
rodič
commit
48fab5e8f7

+ 25 - 25
nightFragrance-admin/src/main/java/com/ylx/web/controller/massage/MaTechnicianController.java

@@ -387,41 +387,41 @@ public class MaTechnicianController extends BaseController {
     }
 
     /**
-     * 查询商户信息接口
+     * 查询商户信息
+     *
+     * @param openid 微信openid
+     * @return Result<?>
      */
     @GetMapping("/getTechnician")
-    @ApiOperation("查询商户信息接口")
+    @ApiOperation("查询商户信息")
     public Result<?> getTechnician(@RequestParam String openid) {
-        LambdaQueryWrapper<MaTechnician> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.eq(MaTechnician::getCOpenid, openid);
-        MaTechnician maTechnician = maTechnicianService.getBaseMapper().selectOne(queryWrapper);
-        return Result.ok(maTechnician);
+        try {
+            LambdaQueryWrapper<MaTechnician> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.eq(MaTechnician::getCOpenid, openid);
+            MaTechnician maTechnician = maTechnicianService.getOne(queryWrapper);
+            return Result.ok(maTechnician);
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new RuntimeException(e);
+        }
     }
 
     /**
-     * 修改商户信息接口
+     * 修改商户信息
+     *
+     * @param req
+     * @return Result<?>
      */
     @PostMapping("/updateTechnician")
     @ApiOperation("修改商户信息接口")
-    public Result<?> updateTechnician(@RequestBody MaTechnicianAppAddVo req) {
-        if (req.getAuditStatus() == 0 || req.getAuditStatus() == 3) {
-            //修改基本信息
-            updateMaTechnician(req);
+    public Result<?> updateTechnician(@RequestBody MerchantApplyFileRequestDto req) {
+        try {
+            maTechnicianService.updateTechnician(req);
+            return Result.ok("修改成功");
+        } catch (Exception e) {
+            log.error("修改商户信息失败", e);
+            return Result.error(e.getMessage());
         }
-        return Result.ok("修改成功");
-    }
-
-
-    private void updateMaTechnician(MaTechnicianAppAddVo req) {
-        LambdaUpdateWrapper<MaTechnician> updateWrapper = new LambdaUpdateWrapper<>();
-        updateWrapper.eq(MaTechnician::getId, req.getId());
-        updateWrapper.set(MaTechnician::getTePhone, req.getTePhone());
-        updateWrapper.set(MaTechnician::getTeName, req.getTeName());
-        updateWrapper.set(MaTechnician::getOpenService, req.getServiceTag());
-        updateWrapper.set(MaTechnician::getTeAge, req.getTeAge());
-        updateWrapper.set(MaTechnician::getAvatar, req.getAvatar());
-        updateWrapper.set(MaTechnician::getTeBrief, req.getTeBrief());
-        maTechnicianService.update(updateWrapper);
     }
 
     /**

+ 6 - 3
nightFragrance-massage/src/main/java/com/ylx/massage/domain/MerchantApplyFile.java

@@ -30,11 +30,13 @@ public class MerchantApplyFile implements Serializable {
     //商户ID
     @TableField("merchant_id")
     private Integer merchantId;
-    //文件类型//文件类型1-形象照,2-生活照,3-身份证正面
-    //    // 4-身份证反面 5-手持身份证 6-健康证,
-    //    // 7-从业资格证,8-无犯罪证明,9-承诺书,10-承诺录音,11-承诺录像,12-其他 默认为:'',
+
+    /**
+     * 文件类型(1:形象照 2:生活照 3:宣传视频 4-身份证正面 5-身份证反面 6-手持身份证 7-健康证 8-从业资格证,9-无犯罪证明,10-承诺书,11-承诺录音,12-承诺录像,13-其他 )
+     */
     @TableField("file_type")
     private String fileType;
+
     //原始文件名
     @TableField("file_name")
     private String fileName;
@@ -71,6 +73,7 @@ public class MerchantApplyFile implements Serializable {
     //修改人
     @TableField("update_by")
     private String updateBy;
+
     //是否删除(0否1是)
     @TableField("is_delete")
     private Integer isDelete;

+ 1 - 1
nightFragrance-massage/src/main/java/com/ylx/massage/domain/vo/MaTechnicianAppAddVo.java

@@ -208,7 +208,7 @@ public class MaTechnicianAppAddVo {
 //    @ApiModelProperty("承诺录像")
 //    private String commitmentVideo;
     /**
-     * 审核状态:0-待审核,1-待审核,2-审核通过,3-审核驳回
+     * 审核状态:0-待入驻,1-待审核,2-审核通过,3-审核驳回
      */
     @Excel(name = "审核状态:0-待入驻,1-待审核,2-审核通过,3-审核驳回")
     @ApiModelProperty("审核状态:0-待入驻,1-待审核,2-审核通过,3-审核驳回")

+ 8 - 0
nightFragrance-massage/src/main/java/com/ylx/massage/service/IMaTechnicianService.java

@@ -198,6 +198,14 @@ public interface IMaTechnicianService extends IService<MaTechnician> {
      */
     void applyFile(MerchantApplyFileRequestDto req);
 
+    /**
+     * 修改商户资料。
+     * 基础信息仅允许修改昵称和简介,入驻资料文件按文件类型新增或更新。
+     *
+     * @param req 修改参数
+     */
+    void updateTechnician(MerchantApplyFileRequestDto req);
+
     /**
      * 技师状态切换
      *

+ 120 - 9
nightFragrance-massage/src/main/java/com/ylx/massage/service/impl/MaTechnicianServiceImpl.java

@@ -204,6 +204,7 @@ public class MaTechnicianServiceImpl extends ServiceImpl<MaTechnicianMapper, MaT
     @Override
     public void applyFile(MerchantApplyFileRequestDto req) {
         if (req == null || req.getReq().isEmpty()) {
+            throw new RuntimeException("请上传申请入驻文件");
         }
         for (MerchantApplyFileDto re : req.getReq()) {
             LambdaQueryWrapper<MerchantApplyFile> queryWrapper = new LambdaQueryWrapper<>();
@@ -215,14 +216,12 @@ public class MaTechnicianServiceImpl extends ServiceImpl<MaTechnicianMapper, MaT
                 merchantApplyFileMapper.deleteById(merchantApplyFile);
             } else {
                 //插入文件信息
-                MerchantApplyFile maTechnician = new MerchantApplyFile();
-                BeanUtils.copyProperties(re, maTechnician);
-                maTechnician.setCreateBy(re.getMerchantId().toString());
-                maTechnician.setUpdateBy(re.getMerchantId().toString());
-                merchantApplyFileMapper.insert(maTechnician);
+                MerchantApplyFile merchantApplyFile1 = new MerchantApplyFile();
+                BeanUtils.copyProperties(re, merchantApplyFile1);
+                merchantApplyFile1.setCreateBy(re.getMerchantId().toString());
+                merchantApplyFile1.setUpdateBy(re.getMerchantId().toString());
+                merchantApplyFileMapper.insert(merchantApplyFile1);
             }
-
-
         }
         LambdaUpdateWrapper<MaTechnician> updateWrapper = new LambdaUpdateWrapper<>();
         updateWrapper.eq(MaTechnician::getId, req.getTechnician().getId());
@@ -231,6 +230,118 @@ public class MaTechnicianServiceImpl extends ServiceImpl<MaTechnicianMapper, MaT
         maTechnicianService.update(updateWrapper);
     }
 
+    /**
+     * 修改商户资料。
+     * <p>
+     * 基础信息只允许修改昵称和简介;入驻资料文件按商户ID和文件类型进行新增或更新。
+     * </p>
+     *
+     * @param req 修改参数
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void updateTechnician(MerchantApplyFileRequestDto req) {
+        if (req == null) {
+            throw new ServiceException("修改参数不能为空");
+        }
+        MaTechnician technician = req.getTechnician();
+        Integer merchantId = resolveMerchantId(technician, req.getReq());
+        updateTechnicianBaseInfo(technician);
+        upsertApplyFiles(merchantId, req.getReq());
+    }
+
+    /**
+     * 修改商户基础信息,仅允许修改昵称和简介。
+     *
+     * @param technician 商户基础信息
+     */
+    private void updateTechnicianBaseInfo(MaTechnician technician) {
+        if (technician == null) {
+            return;
+        }
+        Integer merchantId = technician.getId();
+        if (merchantId == null) {
+            throw new ServiceException("商户ID不能为空");
+        }
+        if (technician.getTeNickName() == null && technician.getTeBrief() == null) {
+            return;
+        }
+        LambdaUpdateWrapper<MaTechnician> updateWrapper = new LambdaUpdateWrapper<>();
+        updateWrapper.eq(MaTechnician::getId, merchantId);
+        if (technician.getTeNickName() != null) {
+            updateWrapper.set(MaTechnician::getTeNickName, technician.getTeNickName());
+        }
+        if (technician.getTeBrief() != null) {
+            updateWrapper.set(MaTechnician::getTeBrief, technician.getTeBrief());
+        }
+        int rows = maTechnicianMapper.update(null, updateWrapper);
+        if (rows <= 0) {
+            throw new ServiceException("修改商户基础信息失败");
+        }
+    }
+
+    /**
+     * 新增或更新商户入驻资料文件。
+     *
+     * @param merchantId 商户ID
+     * @param files      入驻资料文件
+     */
+    private void upsertApplyFiles(Integer merchantId, List<MerchantApplyFileDto> files) {
+        if (CollectionUtils.isEmpty(files)) {
+            return;
+        }
+        for (MerchantApplyFileDto file : files) {
+            checkApplyFileParam(merchantId, file);
+            LambdaQueryWrapper<MerchantApplyFile> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.eq(MerchantApplyFile::getMerchantId, merchantId)
+                    .eq(MerchantApplyFile::getFileType, file.getFileType())
+                    .last("LIMIT 1");
+            MerchantApplyFile existsFile = merchantApplyFileMapper.selectOne(queryWrapper);
+            MerchantApplyFile applyFile = new MerchantApplyFile();
+            BeanUtils.copyProperties(file, applyFile);
+            applyFile.setMerchantId(merchantId);
+            applyFile.setUpdateBy(merchantId.toString());
+            applyFile.setIsDelete(NOT_DELETED);
+            if (existsFile == null) {
+                applyFile.setCreateBy(merchantId.toString());
+                merchantApplyFileMapper.insert(applyFile);
+            } else {
+                applyFile.setId(existsFile.getId());
+                merchantApplyFileMapper.updateById(applyFile);
+            }
+        }
+    }
+
+    private Integer resolveMerchantId(MaTechnician technician, List<MerchantApplyFileDto> files) {
+        if (technician != null && technician.getId() != null) {
+            return technician.getId();
+        }
+        if (!CollectionUtils.isEmpty(files)) {
+            return files.stream()
+                    .filter(Objects::nonNull)
+                    .map(MerchantApplyFileDto::getMerchantId)
+                    .filter(Objects::nonNull)
+                    .findFirst()
+                    .orElseThrow(() -> new ServiceException("商户ID不能为空"));
+        }
+        throw new ServiceException("商户ID不能为空");
+    }
+
+    private void checkApplyFileParam(Integer merchantId, MerchantApplyFileDto file) {
+        if (file == null) {
+            throw new ServiceException("入驻资料文件不能为空");
+        }
+        if (StringUtils.isBlank(file.getFileType())) {
+            throw new ServiceException("文件类型不能为空");
+        }
+        if (StringUtils.isBlank(file.getFileUrl())) {
+            throw new ServiceException("文件访问地址不能为空");
+        }
+        if (file.getMerchantId() != null && !merchantId.equals(file.getMerchantId())) {
+            throw new ServiceException("文件商户ID与当前商户不一致");
+        }
+    }
+
     /**
      * 商户入住前置条件校验
      *
@@ -1031,8 +1142,8 @@ public class MaTechnicianServiceImpl extends ServiceImpl<MaTechnicianMapper, MaT
 
         // 3. 计算当前用户距离商户距离
         String distanceStr = DistanceUtil.formatDistanceInKilometers(
-                dto.getLatitude(),dto.getLongitude(),
-                address.getLatitude(),address.getLongitude()
+                dto.getLatitude(), dto.getLongitude(),
+                address.getLatitude(), address.getLongitude()
         );
         detail.setDistance(distanceStr);
 

+ 135 - 0
nightFragrance-massage/src/test/java/com/ylx/massage/service/impl/MaTechnicianServiceImplTest.java

@@ -0,0 +1,135 @@
+package com.ylx.massage.service.impl;
+
+import com.baomidou.mybatisplus.core.MybatisConfiguration;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
+import com.ylx.massage.domain.MaTechnician;
+import com.ylx.massage.domain.MerchantApplyFile;
+import com.ylx.massage.domain.dto.MerchantApplyFileDto;
+import com.ylx.massage.domain.dto.MerchantApplyFileRequestDto;
+import com.ylx.massage.mapper.MaTechnicianMapper;
+import com.ylx.massage.mapper.MerchantApplyFileMapper;
+import org.apache.ibatis.builder.MapperBuilderAssistant;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import java.util.Arrays;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.isNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class MaTechnicianServiceImplTest {
+
+    @BeforeAll
+    public static void initMybatisPlusTableInfo() {
+        MybatisConfiguration configuration = new MybatisConfiguration();
+        TableInfoHelper.initTableInfo(new MapperBuilderAssistant(configuration, ""), MaTechnician.class);
+        TableInfoHelper.initTableInfo(new MapperBuilderAssistant(configuration, ""), MerchantApplyFile.class);
+    }
+
+    @Test
+    public void updateTechnicianOnlyUpdatesNicknameAndBriefForBaseInfo() {
+        MaTechnicianMapper maTechnicianMapper = mock(MaTechnicianMapper.class);
+        MerchantApplyFileMapper merchantApplyFileMapper = mock(MerchantApplyFileMapper.class);
+        when(maTechnicianMapper.update(isNull(), any(LambdaUpdateWrapper.class))).thenReturn(1);
+        MaTechnicianServiceImpl service = buildService(maTechnicianMapper, merchantApplyFileMapper);
+
+        MerchantApplyFileRequestDto request = new MerchantApplyFileRequestDto();
+        MaTechnician technician = new MaTechnician();
+        technician.setId(7);
+        technician.setTeName("不能修改的姓名");
+        technician.setTePhone("18800000000");
+        technician.setAvatar("不能修改的形象照");
+        technician.setTeNickName("新昵称");
+        technician.setTeBrief("新简介");
+        request.setTechnician(technician);
+
+        service.updateTechnician(request);
+
+        ArgumentCaptor<LambdaUpdateWrapper<MaTechnician>> wrapperCaptor = ArgumentCaptor.forClass(LambdaUpdateWrapper.class);
+        verify(maTechnicianMapper).update(isNull(), wrapperCaptor.capture());
+        String sqlSet = String.join(",", wrapperCaptor.getValue().getSqlSet());
+        assertTrue(sqlSet.contains("te_nick_name"));
+        assertTrue(sqlSet.contains("te_brief"));
+        assertFalse(sqlSet.contains("te_name"));
+        assertFalse(sqlSet.contains("te_phone"));
+        assertFalse(sqlSet.contains("avatar"));
+        assertFalse(sqlSet.contains("te_avatar"));
+    }
+
+    @Test
+    public void updateTechnicianUpsertsApplyFilesByMerchantAndFileType() {
+        MaTechnicianMapper maTechnicianMapper = mock(MaTechnicianMapper.class);
+        MerchantApplyFileMapper merchantApplyFileMapper = mock(MerchantApplyFileMapper.class);
+        when(maTechnicianMapper.update(isNull(), any(LambdaUpdateWrapper.class))).thenReturn(1);
+        MerchantApplyFile existsFile = new MerchantApplyFile();
+        existsFile.setId(3L);
+        existsFile.setMerchantId(7);
+        existsFile.setFileType("1");
+        when(merchantApplyFileMapper.selectOne(any(LambdaQueryWrapper.class))).thenReturn(existsFile, null);
+        MaTechnicianServiceImpl service = buildService(maTechnicianMapper, merchantApplyFileMapper);
+
+        MerchantApplyFileRequestDto request = new MerchantApplyFileRequestDto();
+        MaTechnician technician = new MaTechnician();
+        technician.setId(7);
+        technician.setTeNickName("新昵称");
+        technician.setTeBrief("新简介");
+        request.setTechnician(technician);
+
+        MerchantApplyFileDto updateFile = buildFile(7, "1", "new-image.jpg", "https://file/new-image.jpg");
+        MerchantApplyFileDto insertFile = buildFile(7, "2", "life.jpg", "https://file/life.jpg");
+        request.setReq(Arrays.asList(updateFile, insertFile));
+
+        service.updateTechnician(request);
+
+        ArgumentCaptor<MerchantApplyFile> updateCaptor = ArgumentCaptor.forClass(MerchantApplyFile.class);
+        verify(merchantApplyFileMapper).updateById(updateCaptor.capture());
+        MerchantApplyFile updatedFile = updateCaptor.getValue();
+        assertEquals(3L, updatedFile.getId());
+        assertEquals(7, updatedFile.getMerchantId());
+        assertEquals("1", updatedFile.getFileType());
+        assertEquals("new-image.jpg", updatedFile.getFileName());
+        assertEquals("https://file/new-image.jpg", updatedFile.getFileUrl());
+        assertEquals("7", updatedFile.getUpdateBy());
+        assertEquals(0, updatedFile.getIsDelete());
+
+        ArgumentCaptor<MerchantApplyFile> insertCaptor = ArgumentCaptor.forClass(MerchantApplyFile.class);
+        verify(merchantApplyFileMapper).insert(insertCaptor.capture());
+        MerchantApplyFile insertedFile = insertCaptor.getValue();
+        assertEquals(7, insertedFile.getMerchantId());
+        assertEquals("2", insertedFile.getFileType());
+        assertEquals("life.jpg", insertedFile.getFileName());
+        assertEquals("https://file/life.jpg", insertedFile.getFileUrl());
+        assertEquals("7", insertedFile.getCreateBy());
+        assertEquals("7", insertedFile.getUpdateBy());
+        assertEquals(0, insertedFile.getIsDelete());
+    }
+
+    private MaTechnicianServiceImpl buildService(MaTechnicianMapper maTechnicianMapper,
+                                                 MerchantApplyFileMapper merchantApplyFileMapper) {
+        MaTechnicianServiceImpl service = new MaTechnicianServiceImpl();
+        ReflectionTestUtils.setField(service, "maTechnicianMapper", maTechnicianMapper);
+        ReflectionTestUtils.setField(service, "merchantApplyFileMapper", merchantApplyFileMapper);
+        return service;
+    }
+
+    private MerchantApplyFileDto buildFile(Integer merchantId, String fileType, String fileName, String fileUrl) {
+        MerchantApplyFileDto file = new MerchantApplyFileDto();
+        file.setMerchantId(merchantId);
+        file.setFileType(fileType);
+        file.setFileName(fileName);
+        file.setFileUrl(fileUrl);
+        file.setFileSize(1024L);
+        file.setContentType("image/jpeg");
+        return file;
+    }
+}