Ver código fonte

修改问题

jinshihui 6 dias atrás
pai
commit
8b03126d4f

+ 125 - 1
nightFragrance-massage/src/main/java/com/ylx/massage/service/impl/MaTechnicianServiceImpl.java

@@ -7,10 +7,12 @@ import java.util.stream.Collectors;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ylx.common.core.domain.AjaxResult;
 import com.ylx.common.core.domain.model.LoginUser;
 import com.ylx.common.exception.ServiceException;
 import com.ylx.common.utils.DateUtils;
 import com.ylx.common.utils.StringUtils;
+import com.ylx.massage.domain.ContractRecord;
 import com.ylx.massage.domain.MaProject;
 import com.ylx.massage.domain.MaTeProject;
 import com.ylx.massage.domain.dto.MaProjectSaveDto;
@@ -21,8 +23,10 @@ import com.ylx.massage.domain.vo.MaTechnicianAppAddVo;
 import com.ylx.massage.domain.vo.MaTechnicianMerchantDetailVO;
 import com.ylx.massage.domain.vo.MaTechnicianMerchantListVO;
 import com.ylx.massage.domain.vo.MerchantVo;
+import com.ylx.massage.mapper.ContractRecordMapper;
 import com.ylx.massage.mapper.MaProjectMapper;
 import com.ylx.massage.mapper.MaTeProjectMapper;
+import com.ylx.massage.service.TbFileService;
 import com.ylx.project.domain.Project;
 import com.ylx.project.mapper.ProjectMapper;
 import lombok.Data;
@@ -33,6 +37,7 @@ import com.ylx.massage.mapper.MaTechnicianMapper;
 import com.ylx.massage.domain.MaTechnician;
 import com.ylx.massage.service.IMaTechnicianService;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
 
 /**
  * 技师Service业务层处理
@@ -49,7 +54,7 @@ public class MaTechnicianServiceImpl extends ServiceImpl<MaTechnicianMapper, MaT
     private static final int AUDIT_APPROVED = 2;
     private static final int NS_STATUS_NOT_ON_DUTY = -1;
     private static final int DEFAULT_STAT_VALUE = 0;
-    private static final long NOT_DELETED = 0L;
+    private static final Integer NOT_DELETED = 0;
     private static final String MERCHANT_STATUS_NORMAL = "0";
 
     @Autowired
@@ -59,9 +64,16 @@ public class MaTechnicianServiceImpl extends ServiceImpl<MaTechnicianMapper, MaT
     private MaTeProjectMapper maTeProjectMapper;
 
     private MaProjectMapper maProjectMapper;
+
     @Autowired
     private ProjectMapper projectMapper;
 
+    @Autowired
+    private TbFileService fileService;
+
+    @Autowired
+    private ContractRecordMapper contractRecordMapper;
+
     /**
      * 商户入驻申请注册
      *
@@ -246,6 +258,118 @@ public class MaTechnicianServiceImpl extends ServiceImpl<MaTechnicianMapper, MaT
         return rows;
     }
 
+    /**
+     * 后台编辑商户
+     *
+     * @param id        商户ID
+     * @param dto       编辑商户参数
+     * @param loginUser 当前登录用户
+     * @return 结果
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public int updateMerchant(Long id, MaTechnicianMerchantAddDTO dto, LoginUser loginUser) {
+        if (id == null) {
+            throw new ServiceException("商户ID不能为空");
+        }
+        MaTechnician existsMerchant = maTechnicianMapper.selectMerchantById(id.intValue());
+        if (existsMerchant == null || !NOT_DELETED.equals(existsMerchant.getIsDelete())) {
+            throw new ServiceException("商户不存在或已删除");
+        }
+
+        MerchantProjectSelection selection = checkMerchantAddParam(dto);
+        String userName = loginUser.getUser().getUserName();
+
+        MaTechnician maTechnician = new MaTechnician();
+        maTechnician.setId(id);
+        maTechnician.setTeName(dto.getTeName().trim());
+        maTechnician.setTeNickName(dto.getTeNickName().trim());
+        maTechnician.setTeSex(dto.getTeSex());
+        maTechnician.setTePhone(dto.getTePhone().trim());
+        maTechnician.setOpenService(joinIds(selection.getCategoryIds()));
+        maTechnician.setTeProject(joinProjectTitles(selection.getProjectIds(), selection.getProjectMap()));
+        maTechnician.setTechType(dto.getTechType());
+        maTechnician.setIsRecommend(normalizeSwitchValue(dto.getIsRecommend(), "是否推荐"));
+        maTechnician.setUpdateBy(userName);
+        maTechnician.setUpdateTime(DateUtils.getNowDate());
+
+        int rows = maTechnicianMapper.updateMerchantById(maTechnician);
+        if (rows <= 0) {
+            throw new ServiceException("编辑商户失败");
+        }
+        replaceProjectRelations(id, selection.getProjectIds());
+        return rows;
+    }
+
+    /**
+     * 后台上传商户合同文件
+     *
+     * @param id        商户ID
+     * @param file      合同文件
+     * @param loginUser 当前登录用户
+     * @return 上传结果
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public AjaxResult uploadMerchantContract(Integer id, MultipartFile file, LoginUser loginUser) {
+        if (id == null) {
+            throw new ServiceException("商户ID不能为空");
+        }
+        if (file == null || file.isEmpty()) {
+            throw new ServiceException("合同文件不能为空");
+        }
+        MaTechnician existsMerchant = maTechnicianMapper.selectMerchantById(id);
+        if (existsMerchant == null || !NOT_DELETED.equals(existsMerchant.getIsDelete())) {
+            throw new ServiceException("商户不存在或已删除");
+        }
+
+        AjaxResult uploadResult = fileService.uploadFile(file);
+        if (uploadResult == null || uploadResult.isError()) {
+            String message = uploadResult == null ? "合同文件上传失败" : String.valueOf(uploadResult.get(AjaxResult.MSG_TAG));
+            throw new ServiceException(message);
+        }
+        Object url = uploadResult.get("url");
+        if (url == null || StringUtils.isBlank(String.valueOf(url))) {
+            throw new ServiceException("合同文件上传失败,未返回文件地址");
+        }
+
+        ContractRecord contractRecord = new ContractRecord();
+        contractRecord.setMerchantId(id);
+        contractRecord.setContractName(file.getOriginalFilename());
+        contractRecord.setFileUrl(String.valueOf(url));
+        contractRecord.setSignTime(DateUtils.getNowDate());
+        contractRecord.setSignerName(existsMerchant.getTeName());
+        contractRecord.setCreateTime(DateUtils.getNowDate());
+
+        int rows = contractRecordMapper.insert(contractRecord);
+        if (rows <= 0) {
+            throw new ServiceException("保存合同记录失败");
+        }
+        return uploadResult;
+    }
+
+    /**
+     * 全量替换商户与服务项目关联关系。
+     *
+     * @param technicianId 商户ID
+     * @param projectIds   服务项目ID集合
+     */
+    private void replaceProjectRelations(Long technicianId, Set<Long> projectIds) {
+        if (technicianId == null) {
+            throw new ServiceException("商户ID不能为空");
+        }
+        maTeProjectMapper.deleteByTechnicianId(technicianId);
+        for (Long projectId : projectIds) {
+            MaTeProject relation = new MaTeProject();
+            relation.setTeId(technicianId);
+            relation.setProjectId(projectId);
+            int rows = maTeProjectMapper.insert(relation);
+            if (rows <= 0) {
+                throw new ServiceException("编辑商户服务项目失败");
+            }
+        }
+    }
+
     /**
      * 后台查询商户列表
      *