package com.ruoyi.other.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.other.api.domain.Technician;
import com.ruoyi.other.api.domain.TechnicianScore;
import com.ruoyi.other.service.TechnicianScoreService;
import com.ruoyi.other.service.TechnicianService;
import com.ruoyi.other.vo.TechnicianDetailVO;
import com.ruoyi.other.vo.TechnicianVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
/**
*
* 前端控制器
*
*
* @author luodangjia
* @since 2024-11-20
*/
@RestController
@RequestMapping("/technician")
@Api("技师")
public class TechnicianController extends BaseController {
@Resource
private TechnicianService technicianService;
@Resource
private TechnicianScoreService technicianScoreService;
@Resource
private TokenService tokenService;
// @PostMapping("/shop/list")
// @ApiOperation(value = "获取门店的技师列表", tags = {"小程序-门店详情-技师预约"})
// public R> shoplist(@RequestParam Integer shopId,@RequestParam Integer pageNum,@RequestParam Integer pageSize){
// //查出技师列表
// Page page = technicianService.lambdaQuery().eq(Technician::getShopId, shopId).eq(Technician::getStatus, 2).page(Page.of(pageNum, pageSize));
// for (Technician technician : page.getRecords()) {
// //查出技师订单
// R> orderIdsByTechId = orderClient.getOrderIdsByTechId(technician.getId());
// if (orderIdsByTechId.getData().isEmpty()){
// technician.setGrade(new BigDecimal(0));
// technician.setServeCount(0);
// continue;
// }
// //查出技师评价
// List list = goodsEvaluateService.lambdaQuery().in(GoodsEvaluate::getOrderId, orderIdsByTechId.getData()).list();
//
// //算出平均分并保留一位小数
// BigDecimal avg = list.stream().map(GoodsEvaluate::getGrade).reduce(BigDecimal.ZERO, BigDecimal::add).divide(new BigDecimal(list.size()), 1, BigDecimal.ROUND_HALF_UP);
// technician.setGrade(avg);
// technician.setServeCount(orderIdsByTechId.getData().size());
//
// }
// return R.ok(page);
// }
// @PostMapping("/shop/detail")
// @ApiOperation(value = "获取门店的技师详情", tags = {"小程序-门店详情-技师预约"})
// public R shopdetail(@RequestParam Integer techId){
// //查出技师列表
// Technician technician = technicianService.getById(techId);
//
// //查出技师订单
// R> orderIdsByTechId = orderClient.getOrderIdsByTechId(technician.getId());
// if (orderIdsByTechId.getData().isEmpty()){
// technician.setGrade(new BigDecimal(0));
// technician.setServeCount(0);
// return R.ok(technician);
// }
// //查出技师评价
// List list = goodsEvaluateService.lambdaQuery().in(GoodsEvaluate::getOrderId, orderIdsByTechId.getData()).list();
//
// //算出平均分并保留一位小数
// BigDecimal avg = list.stream().map(GoodsEvaluate::getGrade).reduce(BigDecimal.ZERO, BigDecimal::add).divide(new BigDecimal(list.size()), 1, BigDecimal.ROUND_HALF_UP);
// technician.setGrade(avg);
// technician.setServeCount(orderIdsByTechId.getData().size());
// return R.ok(technician);
// }
// @PostMapping("/shop/tech")
// @ApiOperation(value = "预约操作", tags = {"小程序-门店详情-技师预约"})
// public R shoptech(@RequestBody TechnicianSubscribe subscribe){
// Long userId = tokenService.getLoginUserApplet().getUserid();
// subscribe.setAppUserId(userId);
// technicianSubscribeService.save(subscribe);
// return R.ok();
// }
/**
* 指定门店技师列表
*/
@GetMapping("/technicianListByShopId")
@ApiOperation(value = "技师列表", tags = {"技师列表-小程序"})
public R> technicianListByShopId(@ApiParam("门店id") @RequestParam Long shopId,@ApiParam("技师姓名") String name) {
startPage();
return R.ok(getDataTable(technicianService.getTechnicianListByShopId(shopId,name)));
}
@GetMapping("/manage/list")
@ApiOperation(value = "技师列表", tags = {"门店-技师列表"})
public R> managelist(@RequestParam Integer pageNum,@RequestParam Integer pageSize,@ApiParam("技师姓名") String name,@ApiParam("技师电话") String phone) {
Integer objectId = tokenService.getLoginUser().getSysUser().getObjectId();
Page page = technicianService.lambdaQuery().like(name != null, Technician::getName, name)
.like(phone != null, Technician::getPhone, phone)
.eq(Technician::getShopId, objectId)
.page(Page.of(pageNum, pageSize));
return R.ok(page);
}
@PostMapping("/manage/addorupdate")
@ApiOperation(value = "添加编辑", tags = {"门店-技师列表"})
public R> add(@RequestBody Technician technician) {
Integer objectId = tokenService.getLoginUser().getSysUser().getObjectId();
technician.setShopId(objectId);
technicianService.saveOrUpdate(technician);
return R.ok();
}
@GetMapping("/manage/delete")
@ApiOperation(value = "删除", tags = {"门店-技师列表"})
public R> delete(@RequestParam Integer id) {
technicianService.removeById(id);
return R.ok();
}
@GetMapping("/manage/changeStatus")
@ApiOperation(value = "上下架", tags = {"门店-技师列表"})
public R> changeStatus(@RequestParam Integer id,@RequestParam@ApiParam("状态(1=下架,2=上架)") Integer status) {
Technician byId = technicianService.getById(id);
byId.setStatus(status);
technicianService.updateById(byId);
return R.ok();
}
@GetMapping("/manage/changesubscri")
@ApiOperation(value = "修改预约状态", tags = {"门店-技师列表"})
public R> changesubscri(@RequestParam Integer id,@RequestParam@ApiParam("预约状态(1=可预约,2=不可预约)") Integer subscribeStatus) {
Technician byId = technicianService.getById(id);
byId.setSubscribeStatus(subscribeStatus);
technicianService.updateById(byId);
return R.ok();
}
@GetMapping("/getById")
@ApiOperation(value = "技师详情", tags = {"技师详情-小程序","门店-技师列表"})
public R getById(@RequestParam("id") Integer id){
Technician byId = technicianService.getById(id);
return R.ok(byId);
}
/**
* 技师详情
*/
@GetMapping("/technicianDetail")
@ApiOperation(value = "技师详情", tags = {"技师详情-小程序"})
public R technicianDetail(@ApiParam("技师id") @RequestParam Long technicianId) {
return R.ok(technicianService.technicianDetail(technicianId));
}
/**
* 打分
*/
@PostMapping("/grade")
@ApiOperation(value = "打分", tags = {"打分-小程序"})
public R grade(@RequestBody TechnicianScore technicianScore) {
Long userid = tokenService.getLoginUserApplet().getUserid();
TechnicianScore technicianScoreServiceOne = technicianScoreService.getOne(new LambdaQueryWrapper()
.eq(TechnicianScore::getAppUserId, userid)
.eq(TechnicianScore::getTechnicianId, technicianScore.getTechnicianId()));
if (technicianScoreServiceOne != null) {
return R.fail("已打过分,无法再次打分");
}
technicianScore.setAppUserId(userid);
technicianScoreService.save(technicianScore);
return R.ok();
}
}