MaTechnicianServiceImpl.java 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539
  1. package com.ylx.massage.service.impl;
  2. import java.math.BigDecimal;
  3. import java.text.SimpleDateFormat;
  4. import java.time.Duration;
  5. import java.time.LocalDate;
  6. import java.time.LocalDateTime;
  7. import java.time.ZoneId;
  8. import java.time.format.DateTimeFormatter;
  9. import java.util.*;
  10. import java.util.function.Function;
  11. import java.util.stream.Collectors;
  12. import cn.hutool.core.collection.CollUtil;
  13. import cn.hutool.core.util.ObjectUtil;
  14. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  15. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  16. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  17. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  18. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  19. import com.ylx.attendanceconfig.domain.AttendanceRule;
  20. import com.ylx.attendanceconfig.mapper.AttendanceRuleMapper;
  21. import com.ylx.common.core.domain.AjaxResult;
  22. import com.ylx.common.core.domain.model.LoginUser;
  23. import com.ylx.common.exception.ServiceException;
  24. import com.ylx.common.utils.DateUtils;
  25. import com.ylx.common.utils.DistanceUtil;
  26. import com.ylx.common.utils.StringUtils;
  27. import com.ylx.fareSetting.service.IMaProjectFareSettingService;
  28. import com.ylx.massage.controller.CityOperationApplicationController;
  29. import com.ylx.massage.domain.*;
  30. import com.ylx.massage.domain.dto.*;
  31. import com.ylx.massage.domain.vo.*;
  32. import com.ylx.massage.enums.*;
  33. import com.ylx.massage.mapper.*;
  34. import com.ylx.massage.domain.ContractRecord;
  35. import com.ylx.massage.domain.MaProject;
  36. import com.ylx.massage.domain.MaTeProject;
  37. import com.ylx.massage.domain.dto.MaProjectSaveDto;
  38. import com.ylx.massage.domain.dto.MaTechnicianAuditQueryDTO;
  39. import com.ylx.massage.domain.dto.MaTechnicianAuditSubmitDTO;
  40. import com.ylx.massage.domain.dto.MaTechnicianMerchantAddDTO;
  41. import com.ylx.massage.domain.dto.MaTechnicianMerchantQueryDTO;
  42. import com.ylx.massage.domain.dto.MassageMerchantRecommendDto;
  43. import com.ylx.massage.domain.vo.MaTechnicianAppAddVo;
  44. import com.ylx.massage.domain.vo.MaTechnicianAuditListVO;
  45. import com.ylx.massage.domain.vo.MaTechnicianCertificateVO;
  46. import com.ylx.massage.domain.vo.MaTechnicianMerchantDetailVO;
  47. import com.ylx.massage.domain.vo.MaTechnicianMerchantListVO;
  48. import com.ylx.massage.domain.vo.MerchantVo;
  49. import com.ylx.massage.mapper.ContractRecordMapper;
  50. import com.ylx.massage.mapper.MaProjectMapper;
  51. import com.ylx.massage.mapper.MaTeProjectMapper;
  52. import com.ylx.massage.service.TAddressService;
  53. import com.ylx.massage.service.TbFileService;
  54. import com.ylx.merchant.domain.dto.MerchantDetailDTO;
  55. import com.ylx.merchant.domain.dto.MerchantListDTO;
  56. import com.ylx.merchant.domain.dto.MerchantProjectDTO;
  57. import com.ylx.merchant.domain.vo.MerchantDetailVO;
  58. import com.ylx.merchant.domain.vo.MerchantListVO;
  59. import com.ylx.order.domain.TOrder;
  60. import com.ylx.order.mapper.TOrderMapper;
  61. import com.ylx.project.domain.Project;
  62. import com.ylx.project.domain.bookMerchant.vo.ProjectInfoVO;
  63. import com.ylx.project.mapper.ProjectMapper;
  64. import lombok.Data;
  65. import org.springframework.beans.BeanUtils;
  66. import org.springframework.beans.factory.annotation.Autowired;
  67. import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
  68. import org.springframework.stereotype.Service;
  69. import com.ylx.massage.service.IMaTechnicianService;
  70. import org.springframework.transaction.annotation.Transactional;
  71. import org.springframework.util.CollectionUtils;
  72. import org.springframework.web.multipart.MultipartFile;
  73. import javax.annotation.Resource;
  74. import static com.ylx.massage.enums.FileTypeEnum.*;
  75. /**
  76. * 技师Service业务层处理
  77. *
  78. * @author ylx
  79. * @date 2024-03-22
  80. */
  81. @Service
  82. public class MaTechnicianServiceImpl extends ServiceImpl<MaTechnicianMapper, MaTechnician> implements IMaTechnicianService {
  83. private static final int SERVICE_STATE_AVAILABLE = 1;
  84. private static final int POST_STATE_OFFLINE = 0;
  85. private static final int ENABLED = 1;
  86. private static final int DEFAULT_AGE = 18;
  87. private static final int AUDIT_APPROVED = 2;
  88. private static final int AUDIT_WAIT_ENTER = 0;
  89. private static final int AUDIT_WAIT_REVIEW = 1;
  90. private static final int AUDIT_REJECTED = 3;
  91. private static final int AUDIT_REMARK_MAX_LENGTH = 500;
  92. private static final int NS_STATUS_NOT_ON_DUTY = -1;
  93. private static final int DEFAULT_STAT_VALUE = 0;
  94. private static final Integer NOT_DELETED = 0;
  95. private static final String MERCHANT_STATUS_NORMAL = "0";
  96. private static final String PASSWORD = "123456";
  97. @Resource
  98. private MaTechnicianMapper maTechnicianMapper;
  99. @Resource
  100. private MaTeProjectMapper maTeProjectMapper;
  101. @Resource
  102. private MaProjectMapper maProjectMapper;
  103. @Autowired
  104. private ProjectMapper projectMapper;
  105. @Autowired
  106. private TbFileService fileService;
  107. @Resource
  108. private TFareFreeRuleMapper tFareFreeRuleMapper;
  109. @Resource
  110. private ContractRecordMapper contractRecordMapper;
  111. @Resource
  112. private MerchantDailyAttendanceMapper merchantDailyAttendanceMapper;
  113. @Resource
  114. private AttendanceRuleMapper attendanceRuleMapper;
  115. @Resource
  116. private TAddressMapper addressMapper;
  117. @Resource
  118. private MerchantApplyFileMapper merchantApplyFileMapper;
  119. @Resource
  120. private TOrderMapper orderMapper;
  121. @Autowired
  122. private IMaTechnicianService maTechnicianService;
  123. @Resource
  124. private CityOperationApplicationMapper cityOperationApplicationMapper;
  125. @Resource
  126. private IMaProjectFareSettingService maProjectFareSettingService;
  127. @Resource
  128. private TAddressService addressService;
  129. /**
  130. * 商户入驻申请注册
  131. *
  132. * @param req 申请参数
  133. */
  134. @Override
  135. @Transactional(rollbackFor = Exception.class)
  136. public void apply(MaTechnicianAppAddVo req) {
  137. String phone = req.getTePhone();
  138. //商户入住前置条件校验
  139. getMaTechnician(req, phone);
  140. MaTechnician maTechnician = new MaTechnician();
  141. BeanUtils.copyProperties(req, maTechnician);
  142. LambdaQueryWrapper<MaTechnician> queryWrapper = new LambdaQueryWrapper<>();
  143. queryWrapper.eq(MaTechnician::getCOpenid, req.getCOpenid());
  144. MaTechnician maTechnician1 = maTechnicianMapper.selectOne(queryWrapper);
  145. if (maTechnician1 == null) {
  146. throw new RuntimeException("商户不存在");
  147. }
  148. //添加城市管理地址
  149. insertCity(req, maTechnician1, maTechnician);
  150. }
  151. /**
  152. * 添加城市管理地址
  153. *
  154. * @param req
  155. * @param maTechnician1
  156. * @param maTechnician
  157. */
  158. private void insertCity(MaTechnicianAppAddVo req, MaTechnician maTechnician1, MaTechnician maTechnician) {
  159. // 初始化加密工具
  160. BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
  161. //技师类型默认为真实商户
  162. maTechnician.setTechType(0);
  163. maTechnician.setCreateBy("admin");
  164. maTechnician.setAuditStatus(AUDIT_WAIT_ENTER);
  165. maTechnician.setTePassword(encoder.encode(PASSWORD));
  166. LambdaUpdateWrapper<MaTechnician> updateWrapper = new LambdaUpdateWrapper<>();
  167. updateWrapper.eq(MaTechnician::getId, maTechnician1.getId());
  168. maTechnicianMapper.update(maTechnician, updateWrapper);
  169. CityOperationApplication cityOperationApplication = new CityOperationApplication();
  170. cityOperationApplication.setMerchantId(maTechnician1.getId());
  171. cityOperationApplication.setOperationCenterId(req.getOperationCenterId());
  172. cityOperationApplication.setProvinceCode(req.getProvinceCode());
  173. cityOperationApplication.setProvinceName(req.getProvinceName());
  174. cityOperationApplication.setCityCode(req.getCityCode());
  175. cityOperationApplication.setCityName(req.getCityName());
  176. cityOperationApplication.setDistrictCode(req.getDistrictCode());
  177. cityOperationApplication.setDistrictName(req.getDistrictName());
  178. cityOperationApplication.setOperationCenterName(req.getOperationCenterName());
  179. cityOperationApplication.setCreateBy(maTechnician1.getId().toString());
  180. cityOperationApplication.setUpdateBy(maTechnician1.getId().toString());
  181. cityOperationApplicationMapper.insert(cityOperationApplication);
  182. }
  183. /**
  184. * 商户入驻申请文件上传
  185. *
  186. * @param req
  187. */
  188. @Override
  189. public void applyFile(MerchantApplyFileRequestDto req) {
  190. if (req == null || req.getReq().isEmpty()) {
  191. }
  192. for (MerchantApplyFileDto re : req.getReq()) {
  193. LambdaQueryWrapper<MerchantApplyFile> queryWrapper = new LambdaQueryWrapper<>();
  194. queryWrapper.eq(MerchantApplyFile::getMerchantId, re.getMerchantId());
  195. queryWrapper.eq(MerchantApplyFile::getFileType, re.getFileType());
  196. MerchantApplyFile merchantApplyFile = merchantApplyFileMapper.selectOne(queryWrapper);
  197. if (merchantApplyFile != null) {
  198. // 删除原有文件
  199. merchantApplyFileMapper.deleteById(merchantApplyFile);
  200. } else {
  201. //插入文件信息
  202. MerchantApplyFile maTechnician = new MerchantApplyFile();
  203. BeanUtils.copyProperties(re, maTechnician);
  204. maTechnician.setCreateBy(re.getMerchantId().toString());
  205. maTechnician.setUpdateBy(re.getMerchantId().toString());
  206. merchantApplyFileMapper.insert(maTechnician);
  207. }
  208. }
  209. LambdaUpdateWrapper<MaTechnician> updateWrapper = new LambdaUpdateWrapper<>();
  210. updateWrapper.eq(MaTechnician::getId, req.getTechnician().getId());
  211. updateWrapper.set(MaTechnician::getTeNickName, req.getTechnician().getTeNickName());
  212. updateWrapper.set(MaTechnician::getTeBrief, req.getTechnician().getTeBrief());
  213. maTechnicianService.update(updateWrapper);
  214. }
  215. /**
  216. * 商户入住前置条件校验
  217. *
  218. * @param req
  219. * @param phone
  220. */
  221. private void getMaTechnician(MaTechnicianAppAddVo req, String phone) {
  222. // 1. 判断当前用户是否已入驻
  223. MaTechnician userProfile = getMaTechnician(req);
  224. if (userProfile != null) {
  225. throw new RuntimeException("当前用户已入驻,请勿重复提交");
  226. }
  227. // 2. 判断手机号是否已存在
  228. LambdaQueryWrapper<MaTechnician> queryPhoneWrapper = new LambdaQueryWrapper<>();
  229. queryPhoneWrapper.eq(MaTechnician::getTePhone, phone);
  230. queryPhoneWrapper.eq(MaTechnician::getIsDelete, 0);
  231. MaTechnician maTechnicianPhone = maTechnicianMapper.selectOne(queryPhoneWrapper);
  232. if (maTechnicianPhone != null) {
  233. throw new RuntimeException("手机号已存在,请更换手机号");
  234. }
  235. //3、判断手机号是否已绑定其他用户
  236. LambdaQueryWrapper<MaTechnician> queryTePhoneWrapper = new LambdaQueryWrapper<>();
  237. queryTePhoneWrapper.eq(MaTechnician::getTePhone, phone);
  238. queryTePhoneWrapper.eq(MaTechnician::getIsDelete, 0);
  239. queryTePhoneWrapper.eq(MaTechnician::getAuditStatus, 2);
  240. MaTechnician maTechnicianTePhone = maTechnicianMapper.selectOne(queryTePhoneWrapper);
  241. if (maTechnicianTePhone != null) {
  242. throw new RuntimeException("手机号已被其他用户绑定,请更换手机号");
  243. }
  244. }
  245. /**
  246. * 判断当前用户是否已入驻
  247. *
  248. * @return
  249. */
  250. private MaTechnician getMaTechnician(MaTechnicianAppAddVo req) {
  251. LambdaQueryWrapper<MaTechnician> queryWrapper = new LambdaQueryWrapper<>();
  252. queryWrapper.eq(MaTechnician::getTePhone, req.getTePhone());
  253. queryWrapper.eq(MaTechnician::getIsDelete, 0);
  254. queryWrapper.eq(MaTechnician::getAuditStatus, 2);
  255. //queryWrapper.eq(MaTechnician::getOpenService, req.getOpenService());
  256. queryWrapper.eq(MaTechnician::getServiceTag, req.getServiceTag());
  257. MaTechnician userProfile = maTechnicianMapper.selectOne(queryWrapper);
  258. return userProfile;
  259. }
  260. /**
  261. * 查询商户服务项目列表
  262. *
  263. * @param userId 商户id
  264. * @param auditStatus 审核状态
  265. * @return 技师列表
  266. */
  267. @Override
  268. public List<MaProject> selectMaTechnicianListBy(String userId, String auditStatus) {
  269. LambdaQueryWrapper<MaProject> queryWrapper = new LambdaQueryWrapper<>();
  270. queryWrapper.eq(MaProject::getMerchantId, userId);
  271. queryWrapper.eq(MaProject::getAuditStatus, auditStatus);
  272. return maProjectMapper.selectList(queryWrapper);
  273. }
  274. /**
  275. * 查询服务分类项目列表
  276. *
  277. * @param typeId 技师类型
  278. * @return 技师列表
  279. */
  280. @Override
  281. public List<Project> selectTechnicianListBy(String typeId) {
  282. LambdaQueryWrapper<Project> queryWrapper = new LambdaQueryWrapper<>();
  283. queryWrapper.eq(Project::getType, typeId);
  284. return projectMapper.selectList(queryWrapper);
  285. }
  286. /**
  287. * 查询技师
  288. *
  289. * @param id 技师主键
  290. * @return 技师
  291. */
  292. @Override
  293. public MaTechnician selectMaTechnicianById(Long id) {
  294. return maTechnicianMapper.selectMaTechnicianById(id);
  295. }
  296. /**
  297. * 查询技师列表
  298. *
  299. * @param maTechnician 技师
  300. * @return 技师
  301. */
  302. @Override
  303. public List<MaTechnician> selectMaTechnicianList(MaTechnician maTechnician) {
  304. return maTechnicianMapper.selectMaTechnicianList(maTechnician);
  305. }
  306. /**
  307. * 新增技师
  308. *
  309. * @param maTechnicianAppAddVo 技师
  310. * @return 结果
  311. */
  312. @Override
  313. @Transactional(rollbackFor = Exception.class)
  314. public int insertMaTechnician(MaTechnicianAppAddVo maTechnicianAppAddVo) {
  315. MaTechnician maTechnician = new MaTechnician();
  316. BeanUtils.copyProperties(maTechnicianAppAddVo, maTechnician);
  317. int rows = maTechnicianMapper.insertMaTechnician(maTechnician);
  318. if (maTechnicianAppAddVo.getProjectIds() != null && !maTechnicianAppAddVo.getProjectIds().isEmpty()) {
  319. insertProjectRelations(maTechnician.getId(), new LinkedHashSet<>(maTechnicianAppAddVo.getProjectIds()));
  320. }
  321. return rows;
  322. }
  323. /**
  324. * 后台新增商户
  325. *
  326. * @param dto 新增商户参数
  327. * @param loginUser 当前登录用户
  328. * @return 结果
  329. */
  330. @Override
  331. @Transactional(rollbackFor = Exception.class)
  332. public int insertMerchant(MaTechnicianMerchantAddDTO dto, LoginUser loginUser) {
  333. MerchantProjectSelection selection = checkMerchantAddParam(dto);
  334. String userName = loginUser.getUser().getUserName();
  335. MaTechnician maTechnician = new MaTechnician();
  336. maTechnician.setTeName(dto.getTeName().trim());
  337. maTechnician.setTeNickName(dto.getTeNickName().trim());
  338. maTechnician.setTeSex(dto.getTeSex());
  339. maTechnician.setTePhone(dto.getTePhone().trim());
  340. maTechnician.setOpenService(joinIds(selection.getCategoryIds()));
  341. maTechnician.setTeProject(joinProjectTitles(selection.getProjectIds(), selection.getProjectMap()));
  342. maTechnician.setTechType(dto.getTechType());
  343. maTechnician.setIsRecommend(normalizeSwitchValue(dto.getIsRecommend(), "是否推荐"));
  344. maTechnician.setServiceState(SERVICE_STATE_AVAILABLE);
  345. maTechnician.setPostState(POST_STATE_OFFLINE);
  346. maTechnician.setTeIsEnable(ENABLED);
  347. //上岗状态:默认-1 未上岗
  348. maTechnician.setNStatus2(NS_STATUS_NOT_ON_DUTY);
  349. maTechnician.setMerchantStatus(MERCHANT_STATUS_NORMAL);
  350. //审核状态
  351. maTechnician.setAuditStatus(AUDIT_APPROVED);
  352. maTechnician.setTeAddress("");
  353. maTechnician.setNStar(DEFAULT_STAT_VALUE);
  354. maTechnician.setNNum(DEFAULT_STAT_VALUE);
  355. maTechnician.setCreateBy(userName);
  356. maTechnician.setUpdateBy(userName);
  357. maTechnician.setCreateTime(DateUtils.getNowDate());
  358. maTechnician.setUpdateTime(DateUtils.getNowDate());
  359. int rows = maTechnicianMapper.insert(maTechnician);
  360. if (rows <= 0) {
  361. throw new ServiceException("新增商户失败");
  362. }
  363. insertProjectRelations(maTechnician.getId(), selection.getProjectIds());
  364. return rows;
  365. }
  366. /**
  367. * 后台编辑商户
  368. *
  369. * @param id 商户ID
  370. * @param dto 编辑商户参数
  371. * @param loginUser 当前登录用户
  372. * @return 结果
  373. */
  374. @Override
  375. @Transactional(rollbackFor = Exception.class)
  376. public int updateMerchant(Integer id, MaTechnicianMerchantAddDTO dto, LoginUser loginUser) {
  377. if (id == null) {
  378. throw new ServiceException("商户ID不能为空");
  379. }
  380. MaTechnician existsMerchant = maTechnicianMapper.selectMerchantById(id.intValue());
  381. if (existsMerchant == null || !NOT_DELETED.equals(existsMerchant.getIsDelete())) {
  382. throw new ServiceException("商户不存在或已删除");
  383. }
  384. MerchantProjectSelection selection = checkMerchantAddParam(dto);
  385. String userName = loginUser.getUser().getUserName();
  386. MaTechnician maTechnician = new MaTechnician();
  387. maTechnician.setId(id);
  388. maTechnician.setTeName(dto.getTeName().trim());
  389. maTechnician.setTeNickName(dto.getTeNickName().trim());
  390. maTechnician.setTeSex(dto.getTeSex());
  391. maTechnician.setTePhone(dto.getTePhone().trim());
  392. maTechnician.setOpenService(joinIds(selection.getCategoryIds()));
  393. maTechnician.setTeProject(joinProjectTitles(selection.getProjectIds(), selection.getProjectMap()));
  394. maTechnician.setTechType(dto.getTechType());
  395. maTechnician.setIsRecommend(normalizeSwitchValue(dto.getIsRecommend(), "是否推荐"));
  396. maTechnician.setUpdateBy(userName);
  397. maTechnician.setUpdateTime(DateUtils.getNowDate());
  398. int rows = maTechnicianMapper.updateMerchantById(maTechnician);
  399. if (rows <= 0) {
  400. throw new ServiceException("编辑商户失败");
  401. }
  402. replaceProjectRelations(id, selection.getProjectIds());
  403. return rows;
  404. }
  405. /**
  406. * 后台上传商户合同文件
  407. *
  408. * @param id 商户ID
  409. * @param
  410. * @param loginUser 当前登录用户
  411. * @return 上传结果
  412. */
  413. @Override
  414. @Transactional(rollbackFor = Exception.class)
  415. public Integer uploadMerchantContract(Integer id, Map<String, Object> map, LoginUser loginUser) {
  416. if (id == null) {
  417. throw new ServiceException("商户ID不能为空");
  418. }
  419. MaTechnician existsMerchant = maTechnicianMapper.selectMerchantById(id);
  420. if (existsMerchant == null || !NOT_DELETED.equals(existsMerchant.getIsDelete())) {
  421. throw new ServiceException("商户不存在或已删除");
  422. }
  423. // 合同的名称
  424. String contractName = String.valueOf(map.get("contractName"));
  425. // 合同文件的URL
  426. String url = String.valueOf(map.get("url"));
  427. if (StringUtils.isBlank(url)) {
  428. throw new ServiceException("合同文件上传失败,未返回文件地址");
  429. }
  430. ContractRecord contractRecord = new ContractRecord();
  431. contractRecord.setMerchantId(id);
  432. contractRecord.setContractName(contractName);
  433. contractRecord.setFileUrl(url);
  434. contractRecord.setSignTime(DateUtils.getNowDate());
  435. contractRecord.setSignerName(existsMerchant.getTeName());
  436. contractRecord.setCreateTime(DateUtils.getNowDate());
  437. int rows = contractRecordMapper.insert(contractRecord);
  438. if (rows <= 0) {
  439. throw new ServiceException("保存合同记录失败");
  440. }
  441. return rows;
  442. }
  443. /**
  444. * 商户入驻审核。
  445. *
  446. * @param id 商户ID
  447. * @param dto 审核提交参数
  448. * @param loginUser 当前登录用户
  449. * @return 结果
  450. */
  451. @Override
  452. @Transactional(rollbackFor = Exception.class)
  453. public int submitMerchantAudit(Integer id, MaTechnicianAuditSubmitDTO dto, LoginUser loginUser) {
  454. if (id == null) {
  455. throw new ServiceException("商户ID不能为空");
  456. }
  457. if (dto == null) {
  458. throw new ServiceException("审核参数不能为空");
  459. }
  460. checkEnumValue(dto.getAuditStatus(), "审核意见", AUDIT_APPROVED, AUDIT_REJECTED);
  461. String auditRemark = dto.getAuditRemark() == null ? "" : dto.getAuditRemark().trim();
  462. if (dto.getAuditStatus() == AUDIT_REJECTED && StringUtils.isBlank(auditRemark)) {
  463. throw new ServiceException("审核驳回时审核备注不能为空");
  464. }
  465. if (auditRemark.length() > AUDIT_REMARK_MAX_LENGTH) {
  466. throw new ServiceException("审核备注长度不能超过" + AUDIT_REMARK_MAX_LENGTH + "个字符");
  467. }
  468. MaTechnician existsMerchant = maTechnicianMapper.selectMerchantById(id);
  469. if (existsMerchant == null || !NOT_DELETED.equals(existsMerchant.getIsDelete())) {
  470. throw new ServiceException("商户不存在或已删除");
  471. }
  472. Integer currentAuditStatus = existsMerchant.getAuditStatus();
  473. if (currentAuditStatus == null || (currentAuditStatus != AUDIT_WAIT_ENTER)) {
  474. throw new ServiceException("当前商户待入驻已审核,不用重复审核");
  475. }
  476. MaTechnician maTechnician = new MaTechnician();
  477. maTechnician.setId(id);
  478. // 修改为1:待审核
  479. maTechnician.setAuditStatus(1);
  480. maTechnician.setAuditRemark(auditRemark);
  481. maTechnician.setApproveTime(DateUtils.getNowDate());
  482. if (loginUser != null && loginUser.getUser() != null) {
  483. maTechnician.setUpdateBy(loginUser.getUser().getUserName());
  484. }
  485. maTechnician.setUpdateTime(DateUtils.getNowDate());
  486. int rows = maTechnicianMapper.submitMerchantAuditById(maTechnician);
  487. if (rows <= 0) {
  488. throw new ServiceException("提交商户审核失败");
  489. }
  490. return rows;
  491. }
  492. /**
  493. * 后台查询商户证照
  494. *
  495. * @param id 商户ID
  496. * @return 商户证照
  497. */
  498. @Override
  499. public MaTechnicianCertificateVO selectMerchantCertificate(Integer id) {
  500. if (id == null) {
  501. throw new ServiceException("商户ID不能为空");
  502. }
  503. LambdaQueryWrapper<MerchantApplyFile> queryWrapper = Wrappers.lambdaQuery();
  504. queryWrapper.eq(MerchantApplyFile::getMerchantId, id);
  505. List<MerchantApplyFile> merchantApplyFiles = merchantApplyFileMapper.selectList(queryWrapper);
  506. if (merchantApplyFiles == null) {
  507. throw new ServiceException("商户不存在或已删除");
  508. }
  509. MaTechnicianCertificateVO certificate = new MaTechnicianCertificateVO();
  510. certificate.setMerchantId(merchantApplyFiles.get(0).getMerchantId());
  511. merchantApplyFiles.forEach(merchant -> {
  512. certificate.setAvatar(typeFIleUrl(merchant, PORTRAIT.getCode()));
  513. certificate.setLifePhotos(typeFIleUrl(merchant, LIFE_PHOTO.getCode()));
  514. certificate.setIdCardFrout(typeFIleUrl(merchant, ID_CARD_FRONT.getCode()));
  515. certificate.setIdCardBack(typeFIleUrl(merchant, ID_CARD_BACK.getCode()));
  516. certificate.setIdCardHandheld(typeFIleUrl(merchant, ID_CARD_HANDHELD.getCode()));
  517. certificate.setHealthCertificate(typeFIleUrl(merchant, HEALTH_CERT.getCode()));
  518. certificate.setQualificationCertificate(typeFIleUrl(merchant, QUALIFICATION_CERT.getCode()));
  519. certificate.setNoCrimeRecord(typeFIleUrl(merchant, NO_CRIME_RECORD.getCode()));
  520. certificate.setCommitmentPdf(typeFIleUrl(merchant, COMMITMENT_LETTER.getCode()));
  521. certificate.setCommitmentVideo(typeFIleUrl(merchant, COMMITMENT_VIDEO.getCode()));
  522. certificate.setCommitmentAudio(typeFIleUrl(merchant, COMMITMENT_AUDIO.getCode()));
  523. });
  524. return certificate;
  525. }
  526. private String typeFIleUrl(MerchantApplyFile merchant, String type) {
  527. LambdaQueryWrapper<MerchantApplyFile> queryWrapper1 = Wrappers.lambdaQuery();
  528. queryWrapper1.eq(MerchantApplyFile::getMerchantId, merchant.getMerchantId());
  529. queryWrapper1.eq(MerchantApplyFile::getFileType, type);
  530. MerchantApplyFile merchantApplyFiles = merchantApplyFileMapper.selectOne(queryWrapper1);
  531. if (merchantApplyFiles == null) {
  532. return null;
  533. }
  534. return merchantApplyFiles.getFileUrl();
  535. }
  536. /**
  537. * 全量替换商户与服务项目关联关系。
  538. *
  539. * @param technicianId 商户ID
  540. * @param projectIds 服务项目ID集合
  541. */
  542. private void replaceProjectRelations(Integer technicianId, Set<Integer> projectIds) {
  543. if (technicianId == null) {
  544. throw new ServiceException("商户ID不能为空");
  545. }
  546. maTeProjectMapper.deleteByTechnicianId(technicianId);
  547. for (Integer projectId : projectIds) {
  548. MaTeProject relation = new MaTeProject();
  549. relation.setTeId(technicianId);
  550. relation.setProjectId(projectId);
  551. int rows = maTeProjectMapper.insert(relation);
  552. if (rows <= 0) {
  553. throw new ServiceException("编辑商户服务项目失败");
  554. }
  555. }
  556. }
  557. /**
  558. * 后台查询商户入驻审核列表
  559. *
  560. * @param page 分页参数
  561. * @param dto 查询条件
  562. * @return 商户入驻审核分页列表
  563. */
  564. @Override
  565. public Page<MaTechnicianAuditListVO> selectMerchantAuditList(Page<MaTechnicianAuditListVO> page, MaTechnicianAuditQueryDTO dto) {
  566. if (dto != null && dto.getAuditStatus() != null) {
  567. checkEnumValue(dto.getAuditStatus(), "审核状态", 0, 1, 2, 3);
  568. }
  569. Page<MaTechnicianAuditListVO> pageParam = page == null ? new Page<>(1, 10) : page;
  570. return maTechnicianMapper.selectMerchantAuditList(pageParam, dto);
  571. }
  572. /**
  573. * 后台查询商户列表
  574. *
  575. * @param page 分页参数
  576. * @param dto 查询条件
  577. * @return 商户分页列表
  578. */
  579. @Override
  580. public Page<MaTechnicianMerchantListVO> selectMerchantList(Page<MaTechnicianMerchantListVO> page,
  581. MaTechnicianMerchantQueryDTO dto) {
  582. Page<MaTechnicianMerchantListVO> pageParam = page == null ? new Page<>(1, 10) : page;
  583. return maTechnicianMapper.selectMerchantList(pageParam, dto);
  584. }
  585. /**
  586. * 后台查询商户详情
  587. *
  588. * @param id 商户ID
  589. * @return 商户详情
  590. */
  591. @Override
  592. public MaTechnicianMerchantDetailVO selectMerchantDetail(Long id) {
  593. if (id == null) {
  594. throw new ServiceException("商户ID不能为空");
  595. }
  596. MaTechnicianMerchantDetailVO detail = maTechnicianMapper.selectMerchantDetailById(id);
  597. if (detail == null) {
  598. throw new ServiceException("商户不存在或已删除");
  599. }
  600. return detail;
  601. }
  602. /**
  603. * 修改技师
  604. *
  605. * @param maTechnicianAppAddVo
  606. * @return 结果
  607. */
  608. @Override
  609. public int updateMaTechnician(MaTechnicianAppAddVo maTechnicianAppAddVo) {
  610. MaTechnician maTechnician = new MaTechnician();
  611. BeanUtils.copyProperties(maTechnicianAppAddVo, maTechnician);
  612. return maTechnicianMapper.updateMaTechnician(maTechnician);
  613. }
  614. /**
  615. * 批量删除技师
  616. *
  617. * @param ids 需要删除的技师主键
  618. * @return 结果
  619. */
  620. @Override
  621. public int deleteMaTechnicianByIds(Long[] ids) {
  622. return maTechnicianMapper.deleteMaTechnicianByIds(ids);
  623. }
  624. /**
  625. * 删除技师信息
  626. *
  627. * @param id 技师主键
  628. * @return 结果
  629. */
  630. @Override
  631. public int deleteMaTechnicianById(Long id) {
  632. return maTechnicianMapper.deleteMaTechnicianById(id);
  633. }
  634. /**
  635. * 首页选中的城市是否有开通服务
  636. *
  637. * @param areaCode
  638. * @return
  639. */
  640. @Override
  641. public Boolean isHasMerchantCity(String areaCode) {
  642. return maTechnicianMapper.isHasMerchantCity(areaCode);
  643. }
  644. /**
  645. * 首页按摩推荐
  646. *
  647. * @param dto
  648. * @return
  649. */
  650. @Override
  651. public List<MerchantVo> getMerchantRecommend(MassageMerchantRecommendDto dto) {
  652. return maTechnicianMapper.getMerchantRecommend(dto);
  653. }
  654. private MerchantProjectSelection checkMerchantAddParam(MaTechnicianMerchantAddDTO dto) {
  655. if (dto == null) {
  656. throw new ServiceException("商户参数不能为空");
  657. }
  658. checkRequiredText(dto.getTeName(), "姓名", 10);
  659. checkRequiredText(dto.getTeNickName(), "昵称", 10);
  660. checkRequiredText(dto.getTePhone(), "电话", 11);
  661. checkEnumValue(dto.getTeSex(), "性别", 0, 1);
  662. Set<Integer> categoryIds = checkOpenServiceIds(dto.getOpenService());
  663. checkEnumValue(dto.getTechType(), "商户类型", 0, 1);
  664. if (dto.getIsRecommend() != null) {
  665. checkEnumValue(dto.getIsRecommend(), "是否推荐", 0, 1);
  666. }
  667. return checkProjectIds(dto.getProjectIds(), categoryIds);
  668. }
  669. private void checkRequiredText(String value, String fieldName, int maxLength) {
  670. if (StringUtils.isBlank(value)) {
  671. throw new ServiceException(fieldName + "不能为空");
  672. }
  673. if (value.trim().length() > maxLength) {
  674. throw new ServiceException(fieldName + "长度不能超过" + maxLength + "个字符");
  675. }
  676. }
  677. private void checkEnumValue(Integer value, String fieldName, int... allowedValues) {
  678. if (value == null) {
  679. throw new ServiceException(fieldName + "不能为空");
  680. }
  681. for (int allowedValue : allowedValues) {
  682. if (value == allowedValue) {
  683. return;
  684. }
  685. }
  686. throw new ServiceException(fieldName + "值不正确");
  687. }
  688. private Integer normalizeSwitchValue(Integer value, String fieldName) {
  689. if (value == null) {
  690. return 0;
  691. }
  692. checkEnumValue(value, fieldName, 0, 1);
  693. return value;
  694. }
  695. /**
  696. * 校验服务项目ID集合
  697. *
  698. * @param projectIds 服务项目ID集合
  699. * @param categoryIds 服务类目ID集合
  700. * @return 有效服务项目ID集合
  701. */
  702. private MerchantProjectSelection checkProjectIds(List<Integer> projectIds, Set<Integer> categoryIds) {
  703. if (projectIds == null || projectIds.isEmpty()) {
  704. throw new ServiceException("服务项目不能为空");
  705. }
  706. Set<Integer> distinctProjectIds = new LinkedHashSet<>();
  707. for (Integer projectId : projectIds) {
  708. if (projectId == null) {
  709. throw new ServiceException("服务项目ID不能为空");
  710. }
  711. distinctProjectIds.add(projectId);
  712. }
  713. List<Project> projects = projectMapper.selectList(new LambdaQueryWrapper<Project>()
  714. .in(Project::getId, distinctProjectIds)
  715. .eq(Project::getIsDelete, 0));
  716. if (projects.size() != distinctProjectIds.size()) {
  717. throw new ServiceException("服务项目不存在或已删除");
  718. }
  719. Map<Integer, Project> projectMap = projects.stream()
  720. .collect(Collectors.toMap(project -> project.getId(), Function.identity(), (left, right) -> left));
  721. Set<Integer> projectCategoryIds = new LinkedHashSet<>();
  722. for (Integer projectId : distinctProjectIds) {
  723. Project project = projectMap.get(projectId);
  724. if (project == null || project.getCategoryId() == null) {
  725. throw new ServiceException("服务项目类目不能为空");
  726. }
  727. if (!categoryIds.contains(project.getCategoryId())) {
  728. throw new ServiceException("服务项目不属于所选服务类目");
  729. }
  730. projectCategoryIds.add(project.getCategoryId());
  731. }
  732. if (!projectCategoryIds.containsAll(categoryIds)) {
  733. throw new ServiceException("每个服务类目至少选择一个服务项目");
  734. }
  735. return new MerchantProjectSelection(categoryIds, distinctProjectIds, projectMap);
  736. }
  737. /**
  738. * 校验服务类目ID集合
  739. *
  740. * @param openService 服务类目ID集合
  741. * @return 去重后的服务类目ID集合
  742. */
  743. private Set<Integer> checkOpenServiceIds(List<Integer> openService) {
  744. if (openService == null || openService.isEmpty()) {
  745. throw new ServiceException("服务类目不能为空");
  746. }
  747. Set<Integer> categoryIds = new LinkedHashSet<>();
  748. for (Integer categoryId : openService) {
  749. if (categoryId == null) {
  750. throw new ServiceException("服务类目ID不能为空");
  751. }
  752. categoryIds.add(categoryId);
  753. }
  754. return categoryIds;
  755. }
  756. private String joinIds(Set<Integer> ids) {
  757. return ids.stream()
  758. .map(String::valueOf)
  759. .collect(Collectors.joining(","));
  760. }
  761. private String joinProjectTitles(Set<Integer> projectIds, Map<Integer, Project> projectMap) {
  762. return projectIds.stream()
  763. .map(projectMap::get)
  764. .map(Project::getTitle)
  765. .filter(StringUtils::isNotBlank)
  766. .collect(Collectors.joining(","));
  767. }
  768. /**
  769. * 新增商户与服务项目关联关系
  770. *
  771. * @param technicianId
  772. * @param projectIds
  773. */
  774. private void insertProjectRelations(Integer technicianId, Set<Integer> projectIds) {
  775. if (technicianId == null) {
  776. throw new ServiceException("商户ID不能为空");
  777. }
  778. List<MaTeProject> relations = new ArrayList<>();
  779. for (Integer projectId : projectIds) {
  780. MaTeProject relation = new MaTeProject();
  781. relation.setTeId(technicianId);
  782. relation.setProjectId(projectId);
  783. relations.add(relation);
  784. }
  785. int rows = maTeProjectMapper.insertBatch(relations);
  786. if (rows != relations.size()) {
  787. throw new ServiceException("新增商户服务项目失败");
  788. }
  789. }
  790. private static class MerchantProjectSelection {
  791. private final Set<Integer> categoryIds;
  792. private final Set<Integer> projectIds;
  793. private final Map<Integer, Project> projectMap;
  794. private MerchantProjectSelection(Set<Integer> categoryIds, Set<Integer> projectIds, Map<Integer, Project> projectMap) {
  795. this.categoryIds = categoryIds;
  796. this.projectIds = projectIds;
  797. this.projectMap = projectMap;
  798. }
  799. private Set<Integer> getCategoryIds() {
  800. return categoryIds;
  801. }
  802. private Set<Integer> getProjectIds() {
  803. return projectIds;
  804. }
  805. private Map<Integer, Project> getProjectMap() {
  806. return projectMap;
  807. }
  808. }
  809. /**
  810. * 获取未申请技能列表
  811. *
  812. * @param userId
  813. * @param typeId
  814. * @return
  815. */
  816. @Override
  817. public List<Project> getNotApplyList(String userId, String typeId) {
  818. LambdaQueryWrapper<MaProject> query = new LambdaQueryWrapper<>();
  819. query.eq(MaProject::getMerchantId, userId);
  820. query.eq(MaProject::getServiceTag, typeId);
  821. List<MaProject> maProjectList = maProjectMapper.selectList(query);
  822. // 获取已申请技能ID集合
  823. List<Long> projectIdList = maProjectList.stream().map(MaProject::getProjectId).collect(Collectors.toList());
  824. if (projectIdList.size() == 0) {
  825. LambdaQueryWrapper<Project> query1 = new LambdaQueryWrapper<>();
  826. query1.eq(Project::getType, typeId);
  827. return projectMapper.selectList(query1);
  828. }
  829. LambdaQueryWrapper<Project> query2 = new LambdaQueryWrapper<>();
  830. query2.eq(Project::getType, typeId);
  831. query2.notIn(Project::getId, projectIdList);
  832. return projectMapper.selectList(query2);
  833. }
  834. /**
  835. * 申请开通新服务
  836. *
  837. * @param dto
  838. * @return
  839. */
  840. @Transactional(rollbackFor = Exception.class)
  841. public int applyForService(MaProjectSaveDto dto) {
  842. if (Objects.isNull(dto)) {
  843. return 0;
  844. }
  845. if (dto.getProjectIdList().size() > 0) {
  846. // 插入商户技能
  847. extracted(dto);
  848. } else {
  849. return 0;
  850. }
  851. return 1;
  852. }
  853. /**
  854. * 商户入住信息
  855. *
  856. * @param userId
  857. * @return
  858. */
  859. @Override
  860. public MerchantAuditFile getTechnicianList(Long userId) {
  861. LambdaQueryWrapper<MaTechnician> query = new LambdaQueryWrapper<>();
  862. query.eq(MaTechnician::getId, userId);
  863. MaTechnician merchant = maTechnicianMapper.selectOne(query);
  864. LambdaQueryWrapper<MerchantApplyFile> query1 = new LambdaQueryWrapper<>();
  865. query1.eq(MerchantApplyFile::getMerchantId, userId);
  866. List<MerchantApplyFile> merchantApplyFile = merchantApplyFileMapper.selectList(query1);
  867. MerchantAuditFile merchantAuditFile = new MerchantAuditFile();
  868. merchantAuditFile.setMerchant(merchant);
  869. merchantAuditFile.setMerchantAuditFile(merchantApplyFile);
  870. return merchantAuditFile;
  871. }
  872. /**
  873. * 查询商户合同记录信息
  874. *
  875. * @param userId
  876. * @return
  877. */
  878. @Override
  879. public List<ContractRecord> getContractRecords(Long userId) {
  880. LambdaQueryWrapper<ContractRecord> query = new LambdaQueryWrapper<>();
  881. query.eq(ContractRecord::getMerchantId, userId);
  882. List<ContractRecord> contractRecordList = contractRecordMapper.selectList(query);
  883. if (contractRecordList.size() == 0) {
  884. return new ArrayList<>();
  885. } else {
  886. Set<String> seen = new HashSet<>();
  887. contractRecordList = contractRecordList.stream()
  888. .filter(record -> record.getContractName() != null && seen.add(record.getContractName()))
  889. .collect(Collectors.toList());
  890. }
  891. return contractRecordList;
  892. }
  893. @Override
  894. public Page<MerchantListVO> getMerchantPage(MerchantListDTO dto) {
  895. // 1. 执行分页查询 (不带免车费过滤)
  896. Page<MerchantListVO> page = new Page<>(dto.getCurrent(), dto.getSize());
  897. page = this.baseMapper.getMerchantPage(page, dto);
  898. List<MerchantListVO> records = page.getRecords();
  899. if (CollUtil.isEmpty(records)) {
  900. return page;
  901. }
  902. // 2. 如果用户勾选了“免车费”,则在内存中进行精准过滤
  903. if (Boolean.TRUE.equals(dto.getFreeCarFee())) {
  904. boolean isDay = this.maProjectFareSettingService.isDayTimePeriod(LocalDateTime.now());
  905. // 3. 过滤列表
  906. Iterator<MerchantListVO> iterator = records.iterator();
  907. while (iterator.hasNext()) {
  908. MerchantListVO vo = iterator.next();
  909. double currentDistance = vo.getDistance(); // 数据库算出的距离(km)
  910. // 获取该商户的有效免费里程
  911. BigDecimal freeKm = this.maProjectFareSettingService.getMerchantFreeKm(Long.parseLong(vo.getId()), vo.getProjectId(), isDay);
  912. // 核心判断:如果没配置(为0) 或者 距离超过了免费里程,则剔除
  913. if (freeKm == null || freeKm.doubleValue() <= 0 || currentDistance > freeKm.doubleValue()) {
  914. iterator.remove();
  915. }
  916. }
  917. }
  918. return page;
  919. }
  920. @Override
  921. public Page<ProjectInfoVO> getByMerchantProject(MerchantProjectDTO dto) {
  922. Page<ProjectInfoVO> page = new Page<>(dto.getCurrent(), dto.getSize());
  923. return this.baseMapper.getByMerchantProject(page, dto);
  924. }
  925. @Override
  926. public MerchantDetailVO getDetail(MerchantDetailDTO dto) {
  927. // 1. 获取商户信息
  928. MerchantDetailVO detail = this.baseMapper.getDetail(dto);
  929. if (ObjectUtil.isNull(detail)) {
  930. throw new ServiceException("商户不存在");
  931. }
  932. // 2. 获取商户的默认地址
  933. TAddress address = this.addressService.getOne(new LambdaQueryWrapper<TAddress>()
  934. .eq(TAddress::getMerchantId, dto.getMerchantId())
  935. .eq(TAddress::getIsDefault, 1)
  936. .eq(TAddress::getIsDelete, 0));
  937. if (ObjectUtil.isNull(address)) {
  938. throw new ServiceException("无法获取商户的默认地址");
  939. }
  940. // 3. 计算当前用户距离商户距离
  941. String distanceStr = DistanceUtil.formatDistanceInKilometers(
  942. dto.getLatitude(),dto.getLongitude(),
  943. address.getLatitude(),address.getLongitude()
  944. );
  945. detail.setDistance(distanceStr);
  946. return detail;
  947. }
  948. private void extracted(MaProjectSaveDto dto) {
  949. LambdaQueryWrapper<Project> query = new LambdaQueryWrapper<>();
  950. query.in(Project::getId, dto.getProjectIdList());
  951. List<Project> projectList = projectMapper.selectList(query);
  952. for (Project project : projectList) {
  953. MaProject maProject = new MaProject();
  954. maProject.setProjectId(project.getId().longValue());
  955. maProject.setProjectName(project.getTitle());
  956. maProject.setProjectDescribe(project.getDetail());
  957. maProject.setProjectDuration(project.getStandardDuration());
  958. maProject.setProjectOriginalPrice(project.getPrice());
  959. maProject.setProjectMaxPrice(project.getPriceMax());
  960. maProject.setProjectLowestPrice(project.getPriceMin());
  961. maProject.setCreateBy(dto.getUserId());
  962. maProject.setUpdateBy(dto.getUserId());
  963. maProject.setMerchantId(dto.getUserId());
  964. maProject.setApplyTime(DateUtils.getNowDate());
  965. maProject.setMerchantPhone(dto.getMerchantPhone());
  966. maProjectMapper.insert(maProject);
  967. }
  968. }
  969. /**
  970. * 状态切换
  971. *
  972. * @param userId
  973. * @param forceConfirm
  974. * @return
  975. */
  976. @Override
  977. public Result switchToOffline(Long userId, Boolean forceConfirm) {
  978. MaTechnician technician = getTechnician(userId);
  979. // 1. 基础权限校验 (对应流程图左下角)
  980. if (!hasActiveSkills(userId)) {
  981. throw new RuntimeException("请先申请开通技能");
  982. }
  983. if (!hasHomeAddress(userId)) {
  984. // 这里通常会触发前端弹窗要求添加地址,或者直接阻断
  985. throw new RuntimeException("请完善家庭地址");
  986. }
  987. if (ProjectCategoryEnum.MASSAGE.getCode().equals(technician.getServiceTag())) {
  988. // 2. 状态判断逻辑 (对应流程图中间的菱形判断)
  989. // 只有处于“在线接单”状态才需要检查疲劳度/时长限制
  990. if (TechnicianStatusEnum.ONLINE.getCode().equals(technician.getPostState())) {
  991. if (technician.getServiceState().equals(JsStatusEnum.JS_SERVICE.getCode())) {
  992. throw new ServiceException("您有服务中的订单,不能下岗");
  993. }
  994. // 获取今日的商户考勤记录
  995. MerchantDailyAttendance attendance = getTodayAttendance(userId);
  996. long minutesOnline = 0;
  997. if (attendance != null && attendance.getAttendanceStartTime() != null) {
  998. LocalDateTime localDateTime = attendance.getAttendanceStartTime().toInstant()
  999. .atZone(ZoneId.systemDefault())
  1000. .toLocalDateTime();
  1001. //计算截止现在的时长,单位为分钟
  1002. minutesOnline = Duration.between(localDateTime, LocalDateTime.now()).toMinutes();
  1003. // 计算今日的累加在线时长
  1004. minutesOnline = minutesOnline + getWorkDuration(userId);
  1005. }
  1006. AttendanceRule rule = getAttendanceRule();
  1007. if (rule != null) {
  1008. // 将小时转换为分钟进行比较
  1009. BigDecimal minutes = rule.getBasicWorkHours().multiply(new BigDecimal(60));
  1010. // 2. 精确转换成 long(无小数、无溢出才成功)
  1011. long requiredMinutes = minutes.longValueExact();
  1012. // 判断是否超过了平台规定的在线时间 (X小时)
  1013. if (minutesOnline < requiredMinutes) {
  1014. // 情况 A: 超时了,且用户还没有点击“确认下线”(forceConfirm=false)
  1015. if (!forceConfirm) {
  1016. // 返回特定错误码或数据结构,告诉前端弹出“我在想想/确认下线”的模态框
  1017. return Result.ok("平台对您的在线时间做了约定,每日在线需满足"
  1018. + (requiredMinutes / 60) + "小时,距离您下线时间还剩余" + ((requiredMinutes / 60) - minutesOnline) + "小时"
  1019. + "不满足在线时间将收到平台处罚,是否确认下线?");
  1020. }
  1021. // 情况 B: 超时了,但用户已经点击了“确认下线”,允许通过
  1022. }
  1023. }
  1024. }
  1025. // 3. 执行状态更新 (更新为休息中状态)
  1026. updateStatus(userId, TechnicianStatusEnum.RESTING);
  1027. if (!forceConfirm) {
  1028. // 格式化成 yyyy-MM-dd 纯日期字符串
  1029. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  1030. String today = sdf.format(new Date());
  1031. // 查询商户今日的最近考勤记录
  1032. LambdaQueryWrapper<MerchantDailyAttendance> query = new LambdaQueryWrapper<>();
  1033. query.eq(MerchantDailyAttendance::getMerchantId, userId)
  1034. .eq(MerchantDailyAttendance::getAttendanceDate, today)
  1035. .orderByDesc(MerchantDailyAttendance::getCreateTime);
  1036. MerchantDailyAttendance update = merchantDailyAttendanceMapper.selectOne(query);
  1037. if (update != null) {
  1038. LocalDateTime localDateTime = update.getAttendanceStartTime().toInstant()
  1039. .atZone(ZoneId.systemDefault())
  1040. .toLocalDateTime();
  1041. LambdaUpdateWrapper<MerchantDailyAttendance> updateWrapper = new LambdaUpdateWrapper<>();
  1042. updateWrapper.eq(MerchantDailyAttendance::getId, update.getId())
  1043. .set(MerchantDailyAttendance::getAttendanceEndTime, DateUtils.getNowDate())
  1044. .set(MerchantDailyAttendance::getTotalWorkMinutes, Duration.between(localDateTime, LocalDateTime.now()).toMinutes())
  1045. .set(MerchantDailyAttendance::getUpdateTime, DateUtils.getNowDate());
  1046. merchantDailyAttendanceMapper.update(update, updateWrapper);
  1047. }
  1048. }
  1049. } else {
  1050. //更新状态为在线接单
  1051. updateStatus(userId, TechnicianStatusEnum.ONLINE);
  1052. // 插入今日考勤记录
  1053. MerchantDailyAttendance merchantDailyAttendance = new MerchantDailyAttendance()
  1054. .setMerchantId(userId.intValue())
  1055. .setAttendanceDate(DateUtils.getNowDate())
  1056. .setMerchantName(technician.getTeName())
  1057. .setAttendanceStartTime(DateUtils.getNowDate())
  1058. .setCreateBy(technician.getTeName())
  1059. .setCreateTime(LocalDateTime.now());
  1060. merchantDailyAttendanceMapper.insert(merchantDailyAttendance);
  1061. }
  1062. return Result.ok("状态已切换成功");
  1063. }
  1064. /**
  1065. * 获取今天商户的考勤记录
  1066. *
  1067. * @param userId 技师ID
  1068. * @return 考勤记录
  1069. */
  1070. private MerchantDailyAttendance getTodayAttendance(Long userId) {
  1071. LambdaQueryWrapper<MerchantDailyAttendance> wrapper = new LambdaQueryWrapper<>();
  1072. wrapper.eq(MerchantDailyAttendance::getMerchantId, userId)
  1073. .eq(MerchantDailyAttendance::getAttendanceDate, DateUtils.getNowDate())
  1074. .orderByDesc(MerchantDailyAttendance::getCreateTime)
  1075. .last("LIMIT 1");
  1076. return merchantDailyAttendanceMapper.selectOne(wrapper);
  1077. }
  1078. /**
  1079. * 获取商户的累计工作时长
  1080. *
  1081. * @param userId 技师ID
  1082. * @return 工作时长(分钟)
  1083. */
  1084. private long getWorkDuration(Long userId) {
  1085. LambdaQueryWrapper<MerchantDailyAttendance> wrapper = new LambdaQueryWrapper<>();
  1086. wrapper.eq(MerchantDailyAttendance::getMerchantId, userId)
  1087. .eq(MerchantDailyAttendance::getAttendanceDate, DateUtils.getNowDate());
  1088. List<MerchantDailyAttendance> attendances = merchantDailyAttendanceMapper.selectList(wrapper);
  1089. if (attendances == null || attendances.isEmpty()) return 0;
  1090. // 计算指定日期的总分钟数
  1091. long totalMinutes = attendances.stream()
  1092. .filter(attendance -> DateUtils.getNowDate().toString().equals(attendance.getAttendanceDate().toString()))
  1093. .mapToLong(MerchantDailyAttendance::getTotalWorkMinutes)
  1094. .sum();
  1095. return totalMinutes;
  1096. }
  1097. /**
  1098. * 获取商户的考勤规则
  1099. *
  1100. * @return 考勤规则
  1101. */
  1102. private AttendanceRule getAttendanceRule() {
  1103. LambdaQueryWrapper<AttendanceRule> wrapper = new LambdaQueryWrapper<>();
  1104. wrapper.eq(AttendanceRule::getIsDelete, 0);
  1105. wrapper.eq(AttendanceRule::getWorkDurationRuleEnabled, 1);
  1106. wrapper.last("LIMIT 1");
  1107. return attendanceRuleMapper.selectOne(wrapper);
  1108. }
  1109. /**
  1110. * 判断用户是否有生效中的技能
  1111. *
  1112. * @param userId 技师ID
  1113. * @return true: 有可用技能, false: 无
  1114. */
  1115. public boolean hasActiveSkills(Long userId) {
  1116. if (userId == null) return false;
  1117. // 构建查询条件:用户ID匹配 AND 状态为已发布/生效中
  1118. LambdaQueryWrapper<MaProject> wrapper = new LambdaQueryWrapper<>();
  1119. wrapper.eq(MaProject::getMerchantId, userId)
  1120. .eq(MaProject::getAuditStatus, 1); // 假设 1 代表 "生效/已审核"
  1121. // 只要查到一条记录即返回 true
  1122. return maProjectMapper.selectCount(wrapper) > 0;
  1123. }
  1124. /**
  1125. * 判断用户是否有家庭地址(通常指设置为默认的地址)
  1126. *
  1127. * @param userId 技师ID
  1128. * @return true: 有地址, false: 无
  1129. */
  1130. public boolean hasHomeAddress(Long userId) {
  1131. if (userId == null) return false;
  1132. // 构建查询条件:用户ID匹配 AND 是默认地址(可选) AND 未删除
  1133. LambdaQueryWrapper<TAddress> wrapper = new LambdaQueryWrapper<>();
  1134. wrapper.eq(TAddress::getMerchantId, userId)
  1135. .eq(TAddress::getUserType, 2) // 商户类型
  1136. .eq(TAddress::getIsDelete, 0); // 逻辑未删除
  1137. // 统计数量是否大于0
  1138. long count = addressMapper.selectCount(wrapper);
  1139. return count > 0;
  1140. }
  1141. // 辅助方法:模拟获取用户
  1142. private MaTechnician getTechnician(Long userId) {
  1143. // ... DB查询逻辑
  1144. LambdaQueryWrapper<MaTechnician> query = new LambdaQueryWrapper<>();
  1145. query.eq(MaTechnician::getId, userId);
  1146. return maTechnicianMapper.selectOne(query);
  1147. }
  1148. // 辅助方法:更新状态
  1149. private void updateStatus(Long userId, TechnicianStatusEnum status) {
  1150. LambdaUpdateWrapper<MaTechnician> update = new LambdaUpdateWrapper<>();
  1151. update.eq(MaTechnician::getId, userId);
  1152. update.set(MaTechnician::getPostState, status.getCode());
  1153. // ... DB Update逻辑,同时记录上线/下线时间
  1154. maTechnicianMapper.update(null, update);
  1155. }
  1156. /**
  1157. * 后台待审核页面审核通过商户。
  1158. *
  1159. * @param id 商户ID
  1160. * @param dto 待审核通过参数
  1161. * @param loginUser 当前登录用户
  1162. * @return 结果
  1163. */
  1164. @Override
  1165. @Transactional(rollbackFor = Exception.class)
  1166. public int approvePendingMerchantAudit(Integer id, MaTechnicianPendingAuditSubmitDTO dto, LoginUser loginUser) {
  1167. if (id == null) {
  1168. throw new ServiceException("商户ID不能为空");
  1169. }
  1170. if (dto == null) {
  1171. throw new ServiceException("审核参数不能为空");
  1172. }
  1173. String idCardFront = checkRequiredFileUrl(dto.getIdCardFront(), "身份证正面加密图片");
  1174. String idCardBack = checkRequiredFileUrl(dto.getIdCardBack(), "身份证反面加密图片");
  1175. String healthCertificate = checkRequiredFileUrl(dto.getHealthCertificate(), "健康证加密图片");
  1176. String qualificationCertificate = checkRequiredFileUrl(dto.getQualificationCertificate(), "资格证加密图片");
  1177. checkRequiredExpirationDate(dto.getIdCardExpirationDate(), "身份证到期时间");
  1178. checkRequiredExpirationDate(dto.getHealthCertificateExpirationDate(), "健康证到期时间");
  1179. checkRequiredExpirationDate(dto.getQualificationCertificateExpirationDate(), "资格证到期时间");
  1180. String auditRemark = dto.getAuditRemark() == null ? "" : dto.getAuditRemark().trim();
  1181. if (auditRemark.length() > AUDIT_REMARK_MAX_LENGTH) {
  1182. throw new ServiceException("审核备注长度不能超过" + AUDIT_REMARK_MAX_LENGTH + "个字符");
  1183. }
  1184. MaTechnician existsMerchant = maTechnicianMapper.selectMerchantById(id);
  1185. if (existsMerchant == null || !NOT_DELETED.equals(existsMerchant.getIsDelete())) {
  1186. throw new ServiceException("商户不存在或已删除");
  1187. }
  1188. if (!Integer.valueOf(AUDIT_WAIT_REVIEW).equals(existsMerchant.getAuditStatus())) {
  1189. throw new ServiceException("当前商户不是待审核状态,不能审核通过");
  1190. }
  1191. MaTechnician maTechnician = new MaTechnician();
  1192. maTechnician.setId(id);
  1193. /*maTechnician.setIdCard(String.join(",", idCardFront, idCardBack));
  1194. maTechnician.setHealthCertificate(healthCertificate);
  1195. maTechnician.setQualificationCertificate(qualificationCertificate);*/
  1196. maTechnician.setIdCardExpirationDate(dto.getIdCardExpirationDate());
  1197. maTechnician.setHealthCertificateExpirationDate(dto.getHealthCertificateExpirationDate());
  1198. maTechnician.setQualificationCertificateExpirationDate(dto.getQualificationCertificateExpirationDate());
  1199. maTechnician.setAuditStatus(AUDIT_APPROVED);
  1200. maTechnician.setAuditRemark(auditRemark);
  1201. maTechnician.setApproveTime(DateUtils.getNowDate());
  1202. if (loginUser != null && loginUser.getUser() != null) {
  1203. maTechnician.setUpdateBy(loginUser.getUser().getUserName());
  1204. }
  1205. maTechnician.setUpdateTime(DateUtils.getNowDate());
  1206. int rows = maTechnicianMapper.approvePendingMerchantAuditById(maTechnician);
  1207. if (rows <= 0) {
  1208. throw new ServiceException("待审核商户审核通过失败");
  1209. }
  1210. return rows;
  1211. }
  1212. private String checkRequiredFileUrl(String value, String fieldName) {
  1213. if (StringUtils.isBlank(value)) {
  1214. throw new ServiceException(fieldName + "不能为空");
  1215. }
  1216. return value.trim();
  1217. }
  1218. private void checkRequiredExpirationDate(LocalDate value, String fieldName) {
  1219. if (value == null) {
  1220. throw new ServiceException(fieldName + "不能为空");
  1221. }
  1222. if (value.isBefore(LocalDate.now())) {
  1223. throw new ServiceException(fieldName + "不能早于当前日期");
  1224. }
  1225. }
  1226. /**
  1227. * 技师待处理订单列表
  1228. *
  1229. * @param query
  1230. * @return
  1231. */
  1232. @Override
  1233. public List<WaitOrderDTO> listWaitOrder(WaitOrderQueryDTO query) {
  1234. LambdaQueryWrapper<TOrder> queryWrapper = new LambdaQueryWrapper<>();
  1235. queryWrapper.eq(TOrder::getStatus, OrderStatusEnum.WAIT_JD.getCode());
  1236. // 1.查询所有待派未接单订单(status=待接单)
  1237. List<TOrder> allWaitOrder = orderMapper.selectList(queryWrapper);
  1238. if (CollectionUtils.isEmpty(allWaitOrder)) {
  1239. return Collections.emptyList();
  1240. }
  1241. BigDecimal techLat = query.getTechLat();
  1242. BigDecimal techLng = query.getTechLng();
  1243. // 2.逐个计算两点距离(Haversine公式)
  1244. List<WaitOrderDTO> dtoList = allWaitOrder.stream().map(order -> {
  1245. WaitOrderDTO dto = new WaitOrderDTO();
  1246. dto.setOrderId(order.getId());
  1247. dto.setProjectName(getShortProjectName(order.getProjectName()));
  1248. dto.setCustomerType("新客户");//无历史绑定默认新客,接单后再统计老客
  1249. dto.setOrderCreateTime(order.getCreateTime());
  1250. dto.setAppointTime(order.getAppointmentStartTime());
  1251. dto.setTargetAddress(order.getContactAddressInfo());
  1252. dto.setOrderLat(order.getUserLatitude());
  1253. dto.setOrderLng(order.getUserLongitude());
  1254. // 计算两点距离 单位:米
  1255. BigDecimal disMeter = calcDistance(techLat, techLng, order.getUserLatitude(), order.getUserLongitude());
  1256. dto.setDistanceMeter(disMeter);
  1257. dto.setDistanceDesc(formatDistance(disMeter));
  1258. return dto;
  1259. }).collect(Collectors.toList());
  1260. // 3.距离升序:近的排在最前面
  1261. return dtoList.stream()
  1262. .sorted(Comparator.comparing(WaitOrderDTO::getDistanceMeter))
  1263. .collect(Collectors.toList());
  1264. }
  1265. /**
  1266. * 接单
  1267. *
  1268. * @param req
  1269. * @return
  1270. */
  1271. @Override
  1272. public String acceptOrder(AcceptOrderReqDTO req) {
  1273. Long techId = req.getTechId();
  1274. Long orderId = req.getOrderId();
  1275. //【校验1:订单是否已被其他技师接单】
  1276. TOrder order = orderMapper.selectById(orderId);
  1277. if (OrderStatusEnum.RECEIVED_ORDER.getCode().equals(order.getStatus())) {
  1278. return OrderTipEnum.REPEAT_ORDER.getTip();
  1279. }
  1280. //【校验2:时间冲突校验(该技师已有已接单订单)】
  1281. boolean isTimeConflict = checkOrderTimeConflict(techId, order);
  1282. if (isTimeConflict) {
  1283. String tip = String.format(OrderTipEnum.TIME_CONFLICT.getTip(),
  1284. order.getStartTime().format(DateTimeFormatter.ofPattern("MM月dd日HH:mm")),
  1285. order.getCompletedTime().format(DateTimeFormatter.ofPattern("MM月dd日HH:mm")));
  1286. return tip;
  1287. }
  1288. //【校验3:技师休息状态】
  1289. MaTechnician tech = maTechnicianMapper.selectById(techId);
  1290. if (TechnicianStatusEnum.RESTING.getCode().equals(tech.getPostState())) {
  1291. return OrderTipEnum.REST_CONFIRM.getTip();
  1292. }
  1293. // 正常接单,绑定技师ID到订单
  1294. doAcceptOrder(techId, orderId);
  1295. return OrderTipEnum.ALREADY_ACCEPT.getTip();
  1296. }
  1297. /**
  1298. * 技师接单确认接单
  1299. *
  1300. * @param techId
  1301. * @param orderId
  1302. * @return
  1303. */
  1304. @Override
  1305. public String confirmRestAccept(Long techId, Long orderId) {
  1306. LambdaUpdateWrapper<MaTechnician> update = new LambdaUpdateWrapper<>();
  1307. update.eq(MaTechnician::getId, techId);
  1308. update.set(MaTechnician::getPostState, TechnicianStatusEnum.ONLINE.getCode());
  1309. maTechnicianMapper.update(null, update);
  1310. doAcceptOrder(techId, orderId);
  1311. return OrderTipEnum.ALREADY_ACCEPT.getTip();
  1312. }
  1313. /**
  1314. * 技师拒绝接单
  1315. *
  1316. * @param req
  1317. * @return
  1318. */
  1319. @Override
  1320. public void refuseOrder(RefuseOrderReqDTO req) {
  1321. LambdaUpdateWrapper<TOrder> update = new LambdaUpdateWrapper<>();
  1322. update.eq(TOrder::getId, req.getOrderId());
  1323. update.set(TOrder::getStatus, OrderStatusEnum.REFUSE.getCode());
  1324. update.set(TOrder::getRejectedReason, req.getRefuseReason());
  1325. orderMapper.update(null, update);
  1326. //拒单后订单重回待接单池,其他技师可刷到
  1327. LambdaUpdateWrapper<TOrder> update2 = new LambdaUpdateWrapper<>();
  1328. update2.eq(TOrder::getId, req.getOrderId());
  1329. update2.set(TOrder::getStatus, OrderStatusEnum.WAIT_JD.getCode());
  1330. update2.set(TOrder::getMerchantId, "");
  1331. update2.set(TOrder::getRejectedReason, "");
  1332. orderMapper.update(null, update2);
  1333. }
  1334. // =================工具方法=================
  1335. /**
  1336. * Haversine 计算经纬度距离 返回米
  1337. */
  1338. private BigDecimal calcDistance(BigDecimal lat1, BigDecimal lng1, BigDecimal lat2, BigDecimal lng2) {
  1339. // 球面距离计算公式,地球半径6371000米
  1340. // 可使用BigDecimal三角函数或数据库函数优化
  1341. double latRad1 = Math.toRadians(lat1.doubleValue());
  1342. double latRad2 = Math.toRadians(lat2.doubleValue());
  1343. double lngRad1 = Math.toRadians(lng1.doubleValue());
  1344. double lngRad2 = Math.toRadians(lng2.doubleValue());
  1345. double dLat = latRad2 - latRad1;
  1346. double dLng = lngRad2 - lngRad1;
  1347. double a = Math.pow(Math.sin(dLat / 2), 2)
  1348. + Math.cos(latRad1) * Math.cos(latRad2)
  1349. * Math.pow(Math.sin(dLng / 2), 2);
  1350. double dis = 2 * 6371000 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
  1351. return BigDecimal.valueOf(dis).setScale(2, BigDecimal.ROUND_HALF_UP);
  1352. }
  1353. private String getShortProjectName(String name) {
  1354. if (name != null && name.length() > 10) {
  1355. return name.substring(0, 8) + "...";
  1356. }
  1357. return name;
  1358. }
  1359. private String formatDistance(BigDecimal distanceMeter) {
  1360. BigDecimal km = distanceMeter.divide(new BigDecimal(1000), 2, BigDecimal.ROUND_HALF_UP);
  1361. if (km.compareTo(BigDecimal.ONE) > 0) {
  1362. return km + "km";
  1363. } else {
  1364. return distanceMeter.intValue() + "m";
  1365. }
  1366. }
  1367. /**
  1368. * 校验技师已有订单时间冲突(只查该技师已接单数据)
  1369. */
  1370. private boolean checkOrderTimeConflict(Long techId, TOrder newOrder) {
  1371. LambdaQueryWrapper<TOrder> query = new LambdaQueryWrapper<>();
  1372. query.eq(TOrder::getMerchantId, techId);
  1373. query.eq(TOrder::getStatus, OrderStatusEnum.RECEIVED_ORDER.getCode());
  1374. query.eq(TOrder::getStartTime, newOrder.getStartTime());
  1375. List<TOrder> acceptedOrders = orderMapper.selectList(query);
  1376. LocalDate newOrderDate = newOrder.getStartTime().toLocalDate();
  1377. LocalDateTime newStart = newOrder.getStartTime();
  1378. for (TOrder old : acceptedOrders) {
  1379. if (!newOrderDate.isEqual(old.getCompletedTime().toLocalDate())) {
  1380. continue;
  1381. }
  1382. LocalDateTime oldEnd = old.getCompletedTime();
  1383. if (newStart.isBefore(oldEnd) || newStart.isEqual(oldEnd)) {
  1384. return true;
  1385. }
  1386. }
  1387. return false;
  1388. }
  1389. /**
  1390. * 接单:给订单赋值技师ID
  1391. */
  1392. private void doAcceptOrder(Long techId, Long orderId) {
  1393. TOrder update = new TOrder();
  1394. update.setId(orderId);
  1395. update.setMerchantId(techId);
  1396. update.setStatus(OrderStatusEnum.RECEIVED_ORDER.getCode());
  1397. orderMapper.updateById(update);
  1398. }
  1399. }