123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- package com.ylx.web.controller.massage;
- import cn.binarywang.wx.miniapp.api.WxMaService;
- import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.ylx.common.annotation.Log;
- import com.ylx.common.core.controller.BaseController;
- import com.ylx.common.core.domain.R;
- import com.ylx.common.core.domain.model.WxLoginUser;
- import com.ylx.common.enums.BusinessType;
- import com.ylx.common.exception.ServiceException;
- import com.ylx.common.utils.ListUtils;
- import com.ylx.massage.domain.Location;
- import com.ylx.massage.domain.TJs;
- import com.ylx.massage.domain.vo.TJsVo;
- import com.ylx.massage.enums.JsStatusEnum;
- import com.ylx.massage.service.TJsService;
- import com.ylx.massage.service.TWxUserService;
- import com.ylx.massage.utils.LocationUtil;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import lombok.extern.slf4j.Slf4j;
- import me.chanjar.weixin.common.error.WxErrorException;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.web.bind.annotation.*;
- import javax.annotation.Resource;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- import java.util.stream.Collectors;
- /**
- * 技师Controller
- *
- * @author ylx
- * @date 2024-03-22
- */
- @RestController
- @RequestMapping("api/js/v1")
- @Api(tags = {"技师管理"})
- @Slf4j
- public class TJsController extends BaseController {
- @Resource
- private TJsService jsService;
- @Resource
- private LocationUtil locationUtil;
- @Resource
- private TWxUserService wxUserService;
- @Autowired
- private WxMaService wxMaService;
- @Value("${wx.template_id_1}")
- private String msgTemplateId1;
- /**
- * 添加技师申请
- *
- * @param js
- * @return
- */
- @Log(title = "技师管理", businessType = BusinessType.INSERT)
- @RequestMapping(value = "wx/add", method = RequestMethod.POST)
- @ApiOperation("添加技师申请")
- public R add(@RequestBody TJs js) {
- try {
- WxLoginUser wxLoginUser = getWxLoginUser();
- js.setcOpenId(wxLoginUser.getCOpenid());
- return R.ok(jsService.addJs(js));
- } catch (ServiceException s) {
- log.error(s.toString());
- return R.fail(s.getMessage());
- } catch (Exception e) {
- log.error(e.toString());
- return R.fail("系统异常");
- }
- }
- /**
- * 更新技师信息
- *
- * @param js
- * @return
- */
- @Log(title = "技师管理", businessType = BusinessType.UPDATE)
- @RequestMapping(value = "wx/update", method = RequestMethod.POST)
- @ApiOperation("更新技师信息")
- public R wxUpdate(@RequestBody TJs js) {
- try {
- return R.ok(jsService.wxUpdateJs(js));
- } catch (ServiceException s) {
- log.error(s.toString());
- return R.fail(s.getMessage());
- } catch (Exception e) {
- log.error(e.toString());
- return R.fail("系统异常");
- }
- }
- @Log(title = "实时更新技师位置", businessType = BusinessType.UPDATE)
- @RequestMapping(value = "wx/updateLocation", method = RequestMethod.POST)
- @ApiOperation("实时更新技师位置")
- public R updateLocation(@RequestBody TJs js) {
- try {
- return R.ok(jsService.updateLocation(js));
- } catch (ServiceException s) {
- log.error(s.toString());
- return R.fail(s.getMessage());
- } catch (Exception e) {
- log.error(e.toString());
- return R.fail("系统异常");
- }
- }
- /**
- * 微信查询
- *
- * @param
- * @return
- */
- @RequestMapping(value = "wx/select", method = RequestMethod.GET)
- @ApiOperation("微信查询")
- public R wxSelect(Page<TJs> page, TJsVo js) {
- try {
- if (js.getLatitude() != null && js.getLongitude() != null) {
- // 检查经纬度是否在合理范围内
- Location location = new Location();
- location.setLatitude(js.getLatitude().doubleValue());
- location.setLongitude(js.getLongitude().doubleValue());
- location.setLimit(100L); // 考虑将此值作为参数或配置项
- location.setRadius(1000.00);
- List<TJs> nearbyTechnicians = locationUtil.dis(location);
- if (nearbyTechnicians != null) {
- Map<String, BigDecimal> collect = nearbyTechnicians.stream().collect(Collectors.toMap(TJs::getcOpenId, TJs::getDistance));
- js.setIds(nearbyTechnicians.stream().map(TJs::getcOpenId).collect(Collectors.toList()));
- int size = (int) page.getSize();
- int pageNum = (int) page.getCurrent();
- page.setSize(nearbyTechnicians.size());
- page.setCurrent(1);
- Page<TJs> all = jsService.getAll(page, js);
- all.getRecords().forEach(item -> {
- item.setDistance(collect.get(item.getcOpenId()).setScale(2, RoundingMode.DOWN));
- });
- List<TJs> objects = (List<TJs>) ListUtils.subList(all.getRecords(), size, pageNum);
- page.setRecords(objects);
- page.setSize(size);
- return R.ok(page);
- }
- }
- return R.ok(jsService.getAll(page, js));
- } catch (Exception e) {
- // 异常处理
- e.printStackTrace();
- return R.fail("操作失败");
- }
- }
- /**
- * 分页查询数据
- */
- @RequestMapping(value = "/select", method = RequestMethod.GET)
- @ApiOperation("分页查询数据")
- public Page<TJs> selectSp(Page<TJs> page, TJs js) {
- LambdaQueryWrapper<TJs> mhCompanyLambdaQueryWrapper = new LambdaQueryWrapper<>();
- mhCompanyLambdaQueryWrapper.eq(null != js.getnTong(), TJs::getnTong, js.getnTong()).
- like(StringUtils.isNotBlank(js.getcName()), TJs::getcName, js.getcName()).
- like(StringUtils.isNotBlank(js.getcNickName()), TJs::getcNickName, js.getcNickName()).
- like(StringUtils.isNotBlank(js.getcPhone()), TJs::getcPhone, js.getcPhone()).
- eq(js.getnStatus() != null, TJs::getnStatus, js.getnStatus()).
- eq(js.getnSex() != null, TJs::getnSex, js.getnSex()).
- orderByDesc(TJs::getDtCreateTime);
- return jsService.page(page, mhCompanyLambdaQueryWrapper);
- }
- /**
- * 删除
- */
- @Log(title = "技师管理", businessType = BusinessType.DELETE)
- @RequestMapping(value = "/del", method = RequestMethod.POST)
- @ApiOperation("删除")
- public Boolean del(@RequestBody TJs js) {
- return jsService.removeById(js);
- }
- @ApiOperation("根据id查询技师")
- @RequestMapping(value = "/wx/getByid", method = RequestMethod.POST)
- public R getById(@RequestBody TJs js) {
- try {
- return R.ok(jsService.getByJsId(js.getId(), js.getcOpenId()));
- } catch (ServiceException s) {
- log.error(s.getMessage());
- return R.fail(s.getMessage());
- } catch (Exception e) {
- log.error(e.getMessage());
- return R.fail("系统异常");
- }
- }
- @ApiOperation("根据OpenId查询技师")
- @RequestMapping(value = "/wx/getByOpenId", method = RequestMethod.POST)
- public R getByOpenId(@RequestBody TJs js) {
- try {
- LambdaQueryWrapper<TJs> mhCompanyLambdaQueryWrapper = new LambdaQueryWrapper<>();
- mhCompanyLambdaQueryWrapper.eq(TJs::getcOpenId, js.getcOpenId());
- return R.ok(jsService.getOne(mhCompanyLambdaQueryWrapper));
- } catch (ServiceException s) {
- log.error(s.getMessage());
- return R.fail(s.getMessage());
- } catch (Exception e) {
- log.error(e.getMessage());
- return R.fail("系统异常");
- }
- }
- @ApiOperation("审核")
- @RequestMapping(value = "/auditing", method = RequestMethod.POST)
- public R auditing(@RequestBody TJs js) {
- try {
- return R.ok(jsService.auditing(js));
- } catch (ServiceException s) {
- log.error(s.getMessage());
- return R.fail(s.getMessage());
- } catch (Exception e) {
- log.error(e.getMessage());
- return R.fail("系统异常");
- }
- }
- @ApiOperation("退回")
- @RequestMapping(value = "/repulse", method = RequestMethod.POST)
- public R repulse(@RequestBody TJs js) {
- try {
- LambdaQueryWrapper<TJs> mhCompanyLambdaQueryWrapper = new LambdaQueryWrapper<>();
- mhCompanyLambdaQueryWrapper.eq(TJs::getId, js.getId()).eq(TJs::getnTong, JsStatusEnum.JS_NOT_PASS.getCode());
- js.setnTong(JsStatusEnum.JS_RETURN.getCode());
- return R.ok(jsService.update(js, mhCompanyLambdaQueryWrapper));
- } catch (ServiceException s) {
- log.error(s.getMessage());
- return R.fail(s.getMessage());
- } catch (Exception e) {
- log.error(e.getMessage());
- return R.fail("系统异常");
- }
- }
- @ApiOperation("通知")
- @RequestMapping(value = "/tongzhi", method = RequestMethod.GET)
- public boolean sendSubscribeMessage(String openId) {
- String page="pages/index/index"; // 应该是消息点击后跳转页面
- WxMaSubscribeMessage message = new WxMaSubscribeMessage();
- message.setTemplateId(msgTemplateId1);
- message.setToUser(openId);
- message.setPage(page);
- List<WxMaSubscribeMessage.MsgData> subscribeDataList = new ArrayList<>();
- WxMaSubscribeMessage.MsgData subscribeData = new WxMaSubscribeMessage.MsgData();
- subscribeData.setName("key1"); // 你在小程序自定义的key(比如“商家名称”)
- subscribeData.setValue("夜来香"); //key对应的内容
- WxMaSubscribeMessage.MsgData msgData = new WxMaSubscribeMessage.MsgData();
- msgData.setName("key2");
- msgData.setValue("");
- //添加你配置要且要展示的内容
- subscribeDataList.add(subscribeData);
- message.setData(subscribeDataList);
- try {
- wxMaService.getMsgService().sendSubscribeMsg(message);
- return true;
- } catch (WxErrorException e) {
- log.error("发送小程序订阅消息失败,errCode:{},errMsg:{}", e.getError().getErrorCode(), e.getError().getErrorMsg());
- }
- return false;
- }
- }
|