MaTechnicianController.java 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  1. package com.ylx.web.controller.massage;
  2. import java.util.*;
  3. import java.util.concurrent.TimeUnit;
  4. import java.util.regex.Pattern;
  5. import javax.servlet.http.HttpServletRequest;
  6. import javax.servlet.http.HttpServletResponse;
  7. import cn.hutool.json.JSONObject;
  8. import com.alibaba.fastjson.JSON;
  9. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  10. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  11. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  12. import com.ylx.common.annotation.Log;
  13. import com.ylx.common.constant.CacheConstants;
  14. import com.ylx.common.constant.Constants;
  15. import com.ylx.common.core.controller.BaseController;
  16. import com.ylx.common.core.domain.AjaxResult;
  17. import com.ylx.common.core.domain.R;
  18. import com.ylx.common.core.domain.model.LoginUser;
  19. import com.ylx.common.core.domain.model.WxLoginUser;
  20. import com.ylx.common.core.domain.model.aliyun.SMSVerificationCode;
  21. import com.ylx.common.core.domain.model.aliyun.SendSmsComponents;
  22. import com.ylx.common.core.domain.model.aliyun.SendSmsEnum;
  23. import com.ylx.common.core.page.TableDataInfo;
  24. import com.ylx.common.core.redis.RedisCache;
  25. import com.ylx.common.enums.BusinessType;
  26. import com.ylx.common.exception.user.CaptchaException;
  27. import com.ylx.common.exception.user.CaptchaExpireException;
  28. import com.ylx.common.utils.MessageUtils;
  29. import com.ylx.common.utils.SecurityUtils;
  30. import com.ylx.common.utils.StringUtils;
  31. import com.ylx.common.utils.poi.ExcelUtil;
  32. import com.ylx.framework.manager.AsyncManager;
  33. import com.ylx.framework.manager.factory.AsyncFactory;
  34. import com.ylx.framework.web.service.WxTokenService;
  35. import com.ylx.massage.domain.MaProject;
  36. import com.ylx.massage.domain.MaTechnician;
  37. import com.ylx.massage.domain.dto.*;
  38. import com.ylx.massage.domain.vo.*;
  39. import com.ylx.massage.service.IMaProjectService;
  40. import com.ylx.massage.service.IMaTechnicianService;
  41. import com.ylx.project.domain.Project;
  42. import com.ylx.servicecategory.domain.ServiceCategory;
  43. import com.ylx.servicecategory.service.ServiceCategoryService;
  44. import com.ylx.system.service.ISysConfigService;
  45. import io.swagger.annotations.Api;
  46. import io.swagger.annotations.ApiOperation;
  47. import lombok.extern.slf4j.Slf4j;
  48. import org.springframework.beans.BeanUtils;
  49. import org.springframework.beans.factory.annotation.Autowired;
  50. import org.springframework.data.redis.core.StringRedisTemplate;
  51. import org.springframework.security.access.prepost.PreAuthorize;
  52. import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
  53. import org.springframework.transaction.annotation.Transactional;
  54. import org.springframework.util.ObjectUtils;
  55. import org.springframework.web.bind.annotation.*;
  56. import com.ylx.common.annotation.Log;
  57. import com.ylx.common.core.controller.BaseController;
  58. import com.ylx.common.core.domain.AjaxResult;
  59. import com.ylx.common.enums.BusinessType;
  60. import com.ylx.massage.domain.MaTechnician;
  61. import com.ylx.massage.service.IMaTechnicianService;
  62. import com.ylx.common.utils.poi.ExcelUtil;
  63. import com.ylx.common.core.page.TableDataInfo;
  64. import org.springframework.web.multipart.MultipartFile;
  65. import javax.servlet.http.HttpServletRequest;
  66. import javax.servlet.http.HttpServletResponse;
  67. import javax.validation.Valid;
  68. import java.util.List;
  69. import java.util.Objects;
  70. import java.util.Random;
  71. import java.util.concurrent.TimeUnit;
  72. import java.util.regex.Pattern;
  73. import static jdk.nashorn.internal.runtime.regexp.joni.Config.log;
  74. /**
  75. * 技师Controller
  76. *
  77. * @author ylx
  78. * @date 2024-03-22
  79. */
  80. @Api("技师管理")
  81. @Slf4j
  82. @RestController
  83. @RequestMapping("/technician/technician")
  84. public class MaTechnicianController extends BaseController {
  85. @Autowired
  86. private IMaTechnicianService maTechnicianService;
  87. @Autowired
  88. private StringRedisTemplate redisTemplate;
  89. @Autowired
  90. private SendSmsComponents sendSms;
  91. @Autowired
  92. private ServiceCategoryService serviceCategoryService;
  93. @Autowired
  94. private IMaProjectService maProjectService;
  95. @Autowired
  96. private ISysConfigService configService;
  97. @Autowired
  98. private RedisCache redisCache;
  99. @Autowired
  100. private WxTokenService wxTokenService;
  101. public static final String PHONE_THREEUSERPARTCLIENT_CODE_KEY = "sys:clientLogin:phone:";
  102. @GetMapping("/sendMsg")
  103. @ApiOperation(value = "短信发送", notes = "短信发送")
  104. public Result sendMsg(@RequestParam String phone, HttpServletRequest request) {
  105. if (org.apache.commons.lang3.StringUtils.isEmpty(phone)) {
  106. return Result.error("手机号不能为空");
  107. }
  108. Random rand = new Random();
  109. // randNumber 将被赋值为一个 MIN 和 MAX 范围内的随机数
  110. int randNumber = rand.nextInt(9999 - 1000 + 1) + 1000;
  111. // 保存验证码到redis
  112. redisTemplate.opsForValue()
  113. .set("userH5:order:phone:" + phone, String.valueOf(randNumber), 5L
  114. , TimeUnit.MINUTES);
  115. try {
  116. SMSVerificationCode smsVerificationCode = new SMSVerificationCode(String.valueOf(randNumber));
  117. String jsonString = JSON.toJSONString(smsVerificationCode);
  118. sendSms.sendSms(phone, SendSmsEnum.SMS_220650024, jsonString);
  119. return Result.ok("发送成功");
  120. } catch (Exception e) {
  121. e.printStackTrace();
  122. }
  123. return Result.ok("发送成功");
  124. }
  125. /**
  126. * 商户登录接口
  127. *
  128. * @param thirdPartyLoginsVo
  129. * @return Result<WxLoginUser>
  130. */
  131. @ApiOperation(value = "商户登录", notes = "商户登录")
  132. @PostMapping(value = "/clientLogin")
  133. @Transactional
  134. public Result<WxLoginUser> login(@RequestBody ThirdPartyLoginsVo thirdPartyLoginsVo) throws Exception {
  135. // 获取登录用户信息
  136. Result<WxLoginUser> result = new Result<>();
  137. // 校验手机号是否为空
  138. if (StringUtils.isEmpty(thirdPartyLoginsVo.getPhone())) {
  139. return result.error500("请输入手机号");
  140. }
  141. // 校验用户是否存在且有效
  142. LambdaQueryWrapper<MaTechnician> queryWrapper = new LambdaQueryWrapper<>();
  143. queryWrapper.eq(MaTechnician::getTePhone, thirdPartyLoginsVo.getPhone());
  144. MaTechnician maTechnician = maTechnicianService.getOne(queryWrapper);
  145. // 校验用户是否有效
  146. if (ObjectUtils.isEmpty(maTechnician)) {
  147. return result.error500("商户不存在,请先注册");
  148. }
  149. if (thirdPartyLoginsVo.getCodeSwitch()) {
  150. // 短信验证
  151. String msg = redisTemplate.opsForValue().get(PHONE_THREEUSERPARTCLIENT_CODE_KEY + thirdPartyLoginsVo.getPhone());
  152. if (StringUtils.isEmpty(msg)) {
  153. return Result.error("验证码已失效");
  154. }
  155. if (!thirdPartyLoginsVo.getPhoneMsg().equals(msg)) {
  156. return Result.error("短信验证码不正确");
  157. }
  158. } else {
  159. // 初始化加密工具
  160. BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
  161. // 验证:比对是否匹配
  162. boolean isOk = encoder.matches(thirdPartyLoginsVo.getPassWord(), maTechnician.getTePassword());
  163. /*if (!isOk) {
  164. return Result.error("密码错误");
  165. }*/
  166. }
  167. WxLoginUser wxUser = new WxLoginUser();
  168. BeanUtils.copyProperties(maTechnician, wxUser);
  169. // 生成并返回令牌
  170. String token = wxTokenService.createToken(wxUser);
  171. log.info("token的值:{}", token);
  172. if (token == null || token.isEmpty()) {
  173. return Result.error("生成令牌失败");
  174. }
  175. //给我把token的值保存到redis中
  176. redisTemplate.opsForValue().set(wxUser.getCOpenid(), token, 180, TimeUnit.MINUTES);
  177. wxUser.setToken(token);
  178. // 返回用户信息
  179. // 记录登录信息
  180. AsyncManager.me().execute(AsyncFactory.recordLogininfor(wxUser.getCOpenid(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
  181. result.setResult(wxUser);
  182. // 登录成功删除验证码
  183. redisTemplate.delete(PHONE_THREEUSERPARTCLIENT_CODE_KEY + thirdPartyLoginsVo.getPhone());
  184. result.success("登录成功");
  185. return result;
  186. }
  187. /**
  188. * 商户忘记密码接口
  189. */
  190. @PostMapping("/resetPassword")
  191. @ApiOperation("商户忘记密码接口")
  192. public Result<?> resetPassword(@RequestBody ThirdPartyLoginsVo thirdPartyLoginsVo) {
  193. // 核心正则表达式:
  194. // ^ 表示开头,$ 表示结尾
  195. // [a-zA-Z0-9] 表示只能是字母或数字
  196. // {8,20} 表示长度必须在8到20之间
  197. String regex = "^[a-zA-Z0-9]{8,20}$";
  198. boolean isMatch = Pattern.matches(regex, thirdPartyLoginsVo.getPassWord().trim());
  199. if (!isMatch) {
  200. // 根据需求返回指定的异常提示
  201. return Result.error("请输入8-20位数字/字母组合");
  202. }
  203. // 短信验证
  204. String msg = redisTemplate.opsForValue().get(PHONE_THREEUSERPARTCLIENT_CODE_KEY + thirdPartyLoginsVo.getPhone());
  205. if (StringUtils.isEmpty(msg)) {
  206. return Result.error("验证码已失效");
  207. }
  208. if (msg != null && msg.startsWith("\"") && msg.endsWith("\"")) {
  209. msg = msg.substring(1, msg.length() - 1);
  210. }
  211. if (!thirdPartyLoginsVo.getPhoneMsg().equals(msg)) {
  212. return Result.error("短信验证码不正确");
  213. }
  214. // 重置密码逻辑
  215. LambdaUpdateWrapper<MaTechnician> updateWrapper = new LambdaUpdateWrapper<>();
  216. updateWrapper.eq(MaTechnician::getTePhone, thirdPartyLoginsVo.getPhone());
  217. updateWrapper.set(MaTechnician::getTePassword, thirdPartyLoginsVo.getPassWord());
  218. maTechnicianService.update(updateWrapper);
  219. redisTemplate.delete(PHONE_THREEUSERPARTCLIENT_CODE_KEY + thirdPartyLoginsVo.getPhone());
  220. return Result.ok("重置密码成功");
  221. }
  222. /**
  223. * 校验图形验证码接口
  224. */
  225. @PostMapping("/getValidateCaptcha")
  226. @ApiOperation("校验图形验证码接口")
  227. public Result<?> getValidateCaptcha(@RequestBody ValidateCaptchaDto req) {
  228. validateCaptcha(req.getPhone(), req.getCode(), req.getUuid());
  229. return Result.ok("校验成功");
  230. }
  231. /**
  232. * 商户入驻申请接口
  233. *
  234. * @param req
  235. * @return Result<?>
  236. */
  237. @PostMapping("/apply")
  238. @ApiOperation("商户入驻申请接口")
  239. public Result<?> apply(@RequestBody MaTechnicianAppAddVo req) {
  240. try {
  241. // 1. 基础参数校验
  242. if (StringUtils.isAnyBlank(req.getTeName(), req.getTePhone(), req.getAvatar())) {
  243. return Result.error("必填项不能为空");
  244. }
  245. //校验性别不能为空
  246. if (Objects.isNull(req.getTeSex())) {
  247. return Result.error("性别不能为空");
  248. }
  249. // 短信验证
  250. String msg = redisTemplate.opsForValue().get(PHONE_THREEUSERPARTCLIENT_CODE_KEY + req.getTePhone());
  251. log.info("短信验证码的值:{}", msg);
  252. /*if (StringUtils.isEmpty(msg)) {
  253. return Result.error("验证码已失效");
  254. }
  255. if (msg != null && msg.startsWith("\"") && msg.endsWith("\"")) {
  256. msg = msg.substring(1, msg.length() - 1);
  257. }
  258. if (!req.getPhoneMsg().equals(msg)) {
  259. return Result.error("短信验证码不正确");
  260. }*/
  261. if (StringUtils.isNotEmpty(req.getPhoneImgMsg())) {
  262. validateCaptcha(req.getTeName(), req.getPhoneImgMsg(), req.getUuid());
  263. }
  264. // 2. 调用业务层处理入驻申请
  265. maTechnicianService.apply(req);
  266. return Result.ok("提交成功,进入审核流程");
  267. } catch (Exception e) {
  268. e.printStackTrace();
  269. throw new RuntimeException(e);
  270. }
  271. }
  272. /**
  273. * 校验验证码
  274. *
  275. * @param username 用户名
  276. * @param code 验证码
  277. * @param uuid 唯一标识
  278. * @return 结果
  279. */
  280. public void validateCaptcha(String username, String code, String uuid) {
  281. boolean captchaEnabled = configService.selectCaptchaEnabled();
  282. if (captchaEnabled) {
  283. String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + StringUtils.nvl(uuid, "");
  284. String captcha = redisCache.getCacheObject(verifyKey);
  285. redisCache.deleteObject(verifyKey);
  286. if (captcha == null) {
  287. AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire")));
  288. throw new CaptchaExpireException();
  289. }
  290. if (!code.equalsIgnoreCase(captcha)) {
  291. AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error")));
  292. throw new CaptchaException();
  293. }
  294. }
  295. }
  296. /**
  297. * 申请技师文件
  298. *
  299. * @param req
  300. * @return Result<?>
  301. */
  302. @PostMapping("/applyFile")
  303. @ApiOperation("申请技师文件")
  304. public Result applyFile(@RequestBody MerchantApplyFileRequestDto req) {
  305. try {
  306. maTechnicianService.applyFile(req);
  307. return Result.ok("上传成功");
  308. } catch (Exception e) {
  309. e.printStackTrace();
  310. throw new RuntimeException(e);
  311. }
  312. }
  313. /**
  314. * 获取待接单列表:前端传技师实时经纬度筛选订单
  315. */
  316. @PostMapping("/wait/list")
  317. @ApiOperation("获取待接单列表")
  318. public Result<List<WaitOrderDTO>> getWaitOrder(@RequestBody WaitOrderQueryDTO query) {
  319. List<WaitOrderDTO> list = maTechnicianService.listWaitOrder(query);
  320. return Result.ok(list);
  321. }
  322. /**
  323. * 滑动接单逻辑不变,
  324. * 仅列表查询逻辑修正
  325. */
  326. @PostMapping("/accept")
  327. @ApiOperation("滑动接单")
  328. public Result<String> acceptOrder(@RequestBody AcceptOrderReqDTO req) {
  329. String tip = maTechnicianService.acceptOrder(req);
  330. return Result.ok(tip);
  331. }
  332. /**
  333. * 技师接单确认逻辑不变,
  334. * 仅列表查询逻辑修正
  335. */
  336. @GetMapping("/rest/confirm")
  337. @ApiOperation("确认接单")
  338. public Result<String> confirmRestAccept(@RequestParam Long techId, @RequestParam Long orderId) {
  339. String tip = maTechnicianService.confirmRestAccept(techId, orderId);
  340. return Result.ok(tip);
  341. }
  342. /**
  343. * 技师拒绝接单逻辑不变,
  344. * 仅列表查询逻辑修正
  345. */
  346. @PostMapping("/refuse")
  347. @ApiOperation("拒绝接单")
  348. public Result<Void> refuseOrder(@RequestBody RefuseOrderReqDTO req) {
  349. maTechnicianService.refuseOrder(req);
  350. return Result.ok("拒绝成功");
  351. }
  352. /**
  353. * 技师状态切换
  354. *
  355. * @param userId 商户ID
  356. * @param forceConfirm 是否强制切换
  357. * @return Result<?>
  358. */
  359. @GetMapping("/switchToOffline")
  360. @ApiOperation("技师状态切换")
  361. public Result switchToOffline(@RequestParam Long userId, @RequestParam Boolean forceConfirm) {
  362. try {
  363. return maTechnicianService.switchToOffline(userId, forceConfirm);
  364. } catch (Exception e) {
  365. e.printStackTrace();
  366. throw new RuntimeException(e);
  367. }
  368. }
  369. /**
  370. * 查询商户信息
  371. *
  372. * @param openid 微信openid
  373. * @return Result<?>
  374. */
  375. @GetMapping("/getTechnician")
  376. @ApiOperation("查询商户信息")
  377. public Result<?> getTechnician(@RequestParam String openid) {
  378. try {
  379. MerchantAuditFile technicianInfo = maTechnicianService.getTechnicianInfo(openid);
  380. return Result.ok(technicianInfo.getMerchant());
  381. } catch (Exception e) {
  382. log.error("查询商户信息失败", e);
  383. return Result.error(e.getMessage());
  384. }
  385. }
  386. /**
  387. * 查询商户信息和入驻资料
  388. *
  389. * @param openid 微信openid
  390. * @return Result<?>
  391. */
  392. @GetMapping("/getTechnicianInfo")
  393. @ApiOperation("查询商户信息和入驻资料")
  394. public Result<?> getTechnicianInfo(@RequestParam("openid") String openid) {
  395. try {
  396. return Result.ok(maTechnicianService.getTechnicianInfo(openid));
  397. } catch (Exception e) {
  398. log.error("查询商户信息和入驻资料失败", e);
  399. return Result.error(e.getMessage());
  400. }
  401. }
  402. /**
  403. * 修改商户信息
  404. *
  405. * @param req
  406. * @return Result<?>
  407. */
  408. @PostMapping("/updateTechnician")
  409. @ApiOperation("修改商户信息接口")
  410. public Result<?> updateTechnician(@RequestBody MerchantApplyFileRequestDto req) {
  411. try {
  412. maTechnicianService.updateTechnician(req);
  413. return Result.ok("修改成功");
  414. } catch (Exception e) {
  415. log.error("修改商户信息失败", e);
  416. return Result.error(e.getMessage());
  417. }
  418. }
  419. /**
  420. * 查询技师列表
  421. */
  422. @PreAuthorize("@ss.hasPermi('technician:technician:list')")
  423. @GetMapping("/list")
  424. public TableDataInfo list(MaTechnician maTechnician) {
  425. startPage();
  426. List<MaTechnician> list = maTechnicianService.selectMaTechnicianList(maTechnician);
  427. return getDataTable(list);
  428. }
  429. /**
  430. * 导出技师列表
  431. */
  432. @PreAuthorize("@ss.hasPermi('technician:technician:export')")
  433. @Log(title = "技师", businessType = BusinessType.EXPORT)
  434. @PostMapping("/export")
  435. public void export(HttpServletResponse response, MaTechnician maTechnician) {
  436. List<MaTechnician> list = maTechnicianService.selectMaTechnicianList(maTechnician);
  437. ExcelUtil<MaTechnician> util = new ExcelUtil<MaTechnician>(MaTechnician.class);
  438. util.exportExcel(response, list, "技师数据");
  439. }
  440. /**
  441. * 获取技师详细信息
  442. */
  443. @PreAuthorize("@ss.hasPermi('technician:technician:query')")
  444. @GetMapping(value = "/{id}")
  445. public AjaxResult getInfo(@PathVariable("id") Long id) {
  446. return success(maTechnicianService.selectMaTechnicianById(id));
  447. }
  448. /**
  449. * 新增技师
  450. */
  451. @ApiOperation("技师入驻")
  452. @PreAuthorize("@ss.hasPermi('technician:technician:add')")
  453. @Log(title = "技师", businessType = BusinessType.INSERT)
  454. @PostMapping
  455. public AjaxResult add(@RequestBody MaTechnicianAppAddVo maTechnicianAppAddVo) {
  456. return toAjax(maTechnicianService.insertMaTechnician(maTechnicianAppAddVo));
  457. }
  458. /**
  459. * 后台新增商户
  460. *
  461. * @param dto 商户新增DTO
  462. * @return AjaxResult 结果
  463. */
  464. @ApiOperation("后台新增商户")
  465. @PreAuthorize("@ss.hasPermi('technician:technician:add')")
  466. @Log(title = "商户", businessType = BusinessType.INSERT)
  467. @PostMapping("/merchant")
  468. public AjaxResult addMerchant(@RequestBody MaTechnicianMerchantAddDTO dto) {
  469. try {
  470. LoginUser loginUser = getLoginUser();
  471. return toAjax(maTechnicianService.insertMerchant(dto, loginUser));
  472. } catch (Exception e) {
  473. e.printStackTrace();
  474. throw new RuntimeException(e);
  475. }
  476. }
  477. /**
  478. * 后台编辑商户
  479. *
  480. * @param id 商户ID
  481. * @param dto 商户编辑DTO
  482. * @return AjaxResult 结果
  483. */
  484. @ApiOperation("后台编辑商户")
  485. @PreAuthorize("@ss.hasPermi('technician:technician:edit')")
  486. @Log(title = "商户", businessType = BusinessType.UPDATE)
  487. @PutMapping("/merchant/{id}")
  488. public AjaxResult editMerchant(@PathVariable("id") Integer id, @RequestBody MaTechnicianMerchantAddDTO dto) {
  489. try {
  490. LoginUser loginUser = getLoginUser();
  491. return toAjax(maTechnicianService.updateMerchant(id, dto, loginUser));
  492. } catch (Exception e) {
  493. e.printStackTrace();
  494. throw new RuntimeException(e);
  495. }
  496. }
  497. /**
  498. * 后台上传商户合同文件
  499. *
  500. * @param id 商户ID
  501. * @param map 合同文件
  502. * @return R 上传结果
  503. */
  504. @ApiOperation("后台上传商户合同文件")
  505. @PreAuthorize("@ss.hasPermi('technician:technician:edit')")
  506. @Log(title = "商户合同", businessType = BusinessType.UPDATE)
  507. @PostMapping("/merchant/{id}/contract")
  508. public R uploadMerchantContract(@PathVariable("id") Integer id, @RequestBody Map<String, Object> map) {
  509. try {
  510. LoginUser loginUser = getLoginUser();
  511. return R.ok(maTechnicianService.uploadMerchantContract(id, map, loginUser));
  512. } catch (Exception e) {
  513. e.printStackTrace();
  514. throw new RuntimeException(e);
  515. }
  516. }
  517. /**
  518. * 查询商户入驻审核列表
  519. *
  520. * @param page 分页参数
  521. * @param dto 查询条件
  522. * @return Page 商户入驻审核分页列表
  523. */
  524. @ApiOperation("后台查询商户入驻审核列表")
  525. @PreAuthorize("@ss.hasPermi('technician:technician:list')")
  526. @GetMapping("/merchant/audit/list")
  527. public R<Page<MaTechnicianAuditListVO>> merchantAuditList
  528. (Page<MaTechnicianAuditListVO> page, MaTechnicianAuditQueryDTO dto) {
  529. try {
  530. return R.ok(maTechnicianService.selectMerchantAuditList(page, dto));
  531. } catch (Exception e) {
  532. e.printStackTrace();
  533. throw new RuntimeException(e);
  534. }
  535. }
  536. /**
  537. * 商户入驻审核
  538. *
  539. * @param id 商户ID
  540. * @param dto 审核提交参数
  541. * @return AjaxResult 结果
  542. */
  543. @ApiOperation("商户入驻审核")
  544. @PreAuthorize("@ss.hasPermi('technician:technician:edit')")
  545. @Log(title = "商户入驻审核", businessType = BusinessType.UPDATE)
  546. @PutMapping("/merchant/audit/{id}/submit")
  547. public AjaxResult submitMerchantAudit(@PathVariable("id") Integer id, @RequestBody MaTechnicianAuditSubmitDTO
  548. dto) {
  549. try {
  550. LoginUser loginUser = getLoginUser();
  551. return toAjax(maTechnicianService.submitMerchantAudit(id, dto, loginUser));
  552. } catch (Exception e) {
  553. e.printStackTrace();
  554. throw new RuntimeException(e);
  555. }
  556. }
  557. /**
  558. * 待审核页面审核通过商户
  559. *
  560. * @param id 商户ID
  561. * @param dto 待审核通过参数
  562. * @return AjaxResult 结果
  563. */
  564. @ApiOperation("待审核页面审核通过商户")
  565. @PreAuthorize("@ss.hasPermi('technician:technician:edit')")
  566. @Log(title = "商户待审核通过", businessType = BusinessType.UPDATE)
  567. @PutMapping("/merchant/audit/{id}/approve")
  568. public AjaxResult approvePendingMerchantAudit(@PathVariable("id") Integer id,
  569. @RequestBody MaTechnicianPendingAuditSubmitDTO
  570. dto) {
  571. try {
  572. LoginUser loginUser = getLoginUser();
  573. return toAjax(maTechnicianService.approvePendingMerchantAudit(id, dto, loginUser));
  574. } catch (Exception e) {
  575. e.printStackTrace();
  576. throw new RuntimeException(e);
  577. }
  578. }
  579. /**
  580. * 查询商户列表
  581. *
  582. * @param page 分页参数
  583. * @param dto 商户查询DTO
  584. * @return Page 商户分页列表
  585. */
  586. @ApiOperation("后台查询商户列表")
  587. @PreAuthorize("@ss.hasPermi('technician:technician:list')")
  588. @GetMapping("/merchant/list")
  589. public R<Page<MaTechnicianMerchantListVO>> merchantList
  590. (Page<MaTechnicianMerchantListVO> page, MaTechnicianMerchantQueryDTO dto) {
  591. try {
  592. return R.ok(maTechnicianService.selectMerchantList(page, dto));
  593. } catch (Exception e) {
  594. e.printStackTrace();
  595. throw new RuntimeException(e);
  596. }
  597. }
  598. /**
  599. * 查询商户详情
  600. *
  601. * @param id 商户ID
  602. * @return R<MaTechnicianMerchantDetailVO> 商户详情
  603. */
  604. @ApiOperation("后台查询商户详情")
  605. @PreAuthorize("@ss.hasPermi('technician:technician:query')")
  606. @GetMapping("/merchant/detail/{id}")
  607. public R<MaTechnicianMerchantDetailVO> merchantDetail(@PathVariable("id") Long id) {
  608. try {
  609. return R.ok(maTechnicianService.selectMerchantDetail(id));
  610. } catch (Exception e) {
  611. e.printStackTrace();
  612. throw new RuntimeException(e);
  613. }
  614. }
  615. /**
  616. * 查看商户证照
  617. *
  618. * @param id 商户ID
  619. * @return R<MaTechnicianCertificateVO> 商户证照
  620. */
  621. @ApiOperation("后台查看商户证照")
  622. @PreAuthorize("@ss.hasPermi('technician:technician:query')")
  623. @GetMapping("/merchant/{id}/certificate")
  624. public R<MaTechnicianCertificateVO> merchantCertificate(@PathVariable("id") Integer id) {
  625. try {
  626. return R.ok(maTechnicianService.selectMerchantCertificate(id));
  627. } catch (Exception e) {
  628. e.printStackTrace();
  629. throw new RuntimeException(e);
  630. }
  631. }
  632. /**
  633. * 修改技师
  634. */
  635. @PreAuthorize("@ss.hasPermi('technician:technician:edit')")
  636. @Log(title = "技师", businessType = BusinessType.UPDATE)
  637. @PutMapping
  638. public AjaxResult edit(@RequestBody MaTechnicianAppAddVo maTechnicianAppAddVo) {
  639. return toAjax(maTechnicianService.updateMaTechnician(maTechnicianAppAddVo));
  640. }
  641. /**
  642. * 删除技师
  643. */
  644. @PreAuthorize("@ss.hasPermi('technician:technician:remove')")
  645. @Log(title = "技师", businessType = BusinessType.DELETE)
  646. @DeleteMapping("/{ids}")
  647. public AjaxResult remove(@PathVariable Long[] ids) {
  648. return toAjax(maTechnicianService.deleteMaTechnicianByIds(ids));
  649. }
  650. /**
  651. * 1. 获取服务类目列表
  652. */
  653. @GetMapping("/getServiceCategoryList")
  654. @ApiOperation("获取服务类目列表")
  655. public AjaxResult getServiceCategoryList() {
  656. List<ServiceCategory> list = serviceCategoryService.listH5ServiceCategory();
  657. return AjaxResult.success(list);
  658. }
  659. /**
  660. * 1. 获取技能列表
  661. *
  662. */
  663. @PostMapping("/getSkillList")
  664. @ApiOperation("获取技能列表")
  665. public Result<List<MaProject>> getSkillList(@RequestBody MaProjectGetVo req) {
  666. List<MaProject> list = maTechnicianService.selectMaTechnicianListBy(req.getUserId(), req.getAuditStatus());
  667. return Result.ok(list);
  668. }
  669. /**
  670. * 查询未开通的服务项目列表
  671. *
  672. * @param req
  673. * @return
  674. */
  675. @PostMapping("/getNotApplyList")
  676. @ApiOperation("查询未开通的服务项目列表")
  677. public Result<?> getNotApplyList(@RequestBody MaProjectGetVo req) {
  678. return Result.ok(maTechnicianService.getNotApplyList(req.getUserId(), req.getTypeId()));
  679. }
  680. /**
  681. * 申请开通新服务
  682. */
  683. @PostMapping("/applyForService")
  684. @ApiOperation("申请开通新服务")
  685. public AjaxResult applyForService(@RequestBody MaProjectSaveDto dto) {
  686. return toAjax(maTechnicianService.applyForService(dto));
  687. }
  688. /**
  689. * 重新申请开通新服务
  690. *
  691. * @param req
  692. * @return
  693. */
  694. @PostMapping("/updateApply")
  695. @ApiOperation("重新申请开通新服务")
  696. public Result<?> updateApply(@RequestBody MaProjectUpdateDto req) {
  697. if (StringUtils.isNotEmpty(req.getProjectId()) && StringUtils.isNotEmpty(req.getApplyReason())) {
  698. LambdaUpdateWrapper<MaProject> updateWrapper = new LambdaUpdateWrapper<>();
  699. updateWrapper.eq(MaProject::getId, req.getProjectId());
  700. updateWrapper.set(MaProject::getApplyReason, req.getApplyReason());
  701. updateWrapper.set(MaProject::getAuditStatus, 0);
  702. maProjectService.update(updateWrapper);
  703. }
  704. return Result.ok("重新申请成功,提交到审核阶段");
  705. }
  706. /**
  707. * 申请下架,删除服务项目,编辑售价价格
  708. *
  709. * @param req
  710. * @return
  711. */
  712. @PostMapping("/updateMaProject")
  713. @ApiOperation("申请下架,删除服务项目,编辑售价价格")
  714. public Result<?> updateMaProject(@RequestBody MaProjectUpdateDto req) {
  715. String message = "";
  716. if (StringUtils.isNotEmpty(req.getProjectId())) {
  717. if (req.getIsDelete()) {
  718. LambdaUpdateWrapper<MaProject> updateWrapper = new LambdaUpdateWrapper<>();
  719. updateWrapper.eq(MaProject::getProjectId, req.getProjectId());
  720. updateWrapper.set(MaProject::getIsDelete, 1);
  721. maProjectService.update(updateWrapper);
  722. message = "删除成功";
  723. }
  724. if (req.getIsPass()) {
  725. LambdaUpdateWrapper<MaProject> updateWrapper = new LambdaUpdateWrapper<>();
  726. updateWrapper.eq(MaProject::getId, req.getProjectId());
  727. updateWrapper.set(MaProject::getProjectIsEnable, 1);
  728. maProjectService.update(updateWrapper);
  729. message = "申请下架成功";
  730. }
  731. if (req.getProjectCurrentPrice() != null) {
  732. LambdaUpdateWrapper<MaProject> updateWrapper = new LambdaUpdateWrapper<>();
  733. updateWrapper.eq(MaProject::getId, req.getProjectId());
  734. updateWrapper.set(MaProject::getProjectCurrentPrice, req.getProjectCurrentPrice());
  735. maProjectService.update(updateWrapper);
  736. message = "修改价格完成";
  737. }
  738. }
  739. return Result.ok(message);
  740. }
  741. /**
  742. * 商户入驻信息
  743. *
  744. * @param userId
  745. * @return Result<?>
  746. */
  747. @GetMapping("/getTechnicianList")
  748. @ApiOperation("商户入驻信息")
  749. public Result<?> getTechnicianList(@RequestParam(value = "userId") Integer userId) {
  750. return Result.ok(maTechnicianService.getTechnicianList(userId));
  751. }
  752. /**
  753. * 查询商户合同记录信息
  754. *
  755. * @param userId
  756. * @return
  757. */
  758. @GetMapping("/getContractRecords")
  759. @ApiOperation("查询商户合同记录信息")
  760. public Result<?> getContractRecords(@RequestParam(value = "userId") Long userId) {
  761. return Result.ok(maTechnicianService.getContractRecords(userId));
  762. }
  763. }