|  |  |  | 
|---|
|  |  |  | package com.matrix.system.app.action; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.matrix.component.rabbitmq.RabiitMqTemplate; | 
|---|
|  |  |  | import com.matrix.core.constance.MatrixConstance; | 
|---|
|  |  |  | import com.matrix.core.exception.GlobleException; | 
|---|
|  |  |  | import com.matrix.core.pojo.AjaxResult; | 
|---|
|  |  |  | import com.matrix.core.pojo.PaginationVO; | 
|---|
|  |  |  | import com.matrix.core.pojo.VerifyResult; | 
|---|
|  |  |  | import com.matrix.core.tools.DateUtil; | 
|---|
|  |  |  | import com.matrix.core.tools.StringUtils; | 
|---|
|  |  |  | import com.matrix.core.tools.WebUtil; | 
|---|
|  |  |  | import com.matrix.system.app.dto.CreateServiceOrderDto; | 
|---|
|  |  |  | import com.matrix.system.app.dto.IdSubmitDto; | 
|---|
|  |  |  | import com.matrix.system.app.dto.ServiceOrderListDto; | 
|---|
|  |  |  | import com.matrix.system.app.dto.ServiceVipProjDto; | 
|---|
|  |  |  | import com.matrix.system.app.mapper.SysBeauticianStateMapper; | 
|---|
|  |  |  | import com.matrix.system.app.mapper.SysProjServiceMapper; | 
|---|
|  |  |  | import com.matrix.system.app.mapper.SysProjUseMapper; | 
|---|
|  |  |  | import com.matrix.system.app.vo.*; | 
|---|
|  |  |  | import com.matrix.system.common.bean.SysUsers; | 
|---|
|  |  |  | import com.matrix.system.common.tools.DataAuthUtil; | 
|---|
|  |  |  | import com.matrix.system.constance.Dictionary; | 
|---|
|  |  |  | import com.matrix.system.hive.action.util.QueryUtil; | 
|---|
|  |  |  | import com.matrix.system.hive.bean.SysBeauticianState; | 
|---|
|  |  |  | import com.matrix.system.hive.bean.SysProjServices; | 
|---|
|  |  |  | import com.matrix.system.hive.bean.SysProjUse; | 
|---|
|  |  |  | import com.matrix.system.hive.bean.SysVipInfo; | 
|---|
|  |  |  | import com.matrix.system.hive.plugin.util.CollectionUtils; | 
|---|
|  |  |  | import com.matrix.system.hive.service.SysBeauticianStateService; | 
|---|
|  |  |  | import com.matrix.system.hive.service.SysProjServicesService; | 
|---|
|  |  |  | import com.matrix.system.hive.service.SysProjUseService; | 
|---|
|  |  |  | import com.matrix.system.hive.service.SysVipInfoService; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.mqTask.MQTaskRouting; | 
|---|
|  |  |  | import com.matrix.system.wechart.templateMsg.UniformMsgParam; | 
|---|
|  |  |  | import io.swagger.annotations.Api; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RestController; | 
|---|
|  |  |  | import io.swagger.annotations.ApiOperation; | 
|---|
|  |  |  | import io.swagger.annotations.ApiResponse; | 
|---|
|  |  |  | import io.swagger.annotations.ApiResponses; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | import org.springframework.validation.annotation.Validated; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author wzy | 
|---|
|  |  |  | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @RequestMapping(value = "/api/serviceOrder") | 
|---|
|  |  |  | public class ApiServiceOrderAction { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SysProjUseService projUseService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SysVipInfoService sysVipInfoService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SysProjServicesService projServicesService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SysBeauticianStateService sysBeauticianStateService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private RabiitMqTemplate rabiitMqTemplate; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${evn}") | 
|---|
|  |  |  | private  String evn; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value ="获取用户项目/套餐列表", notes = "获取用户项目/套餐列表") | 
|---|
|  |  |  | @ApiResponses({ | 
|---|
|  |  |  | @ApiResponse(code = 200, message = "ok", response = ServiceProductListVo.class) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @PostMapping(value = "/findVipProject") | 
|---|
|  |  |  | public AjaxResult findVipProject(@RequestBody @Validated ServiceVipProjDto serviceVipProjDto) { | 
|---|
|  |  |  | SysVipInfo vipInfo = sysVipInfoService.findById(serviceVipProjDto.getVipId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (vipInfo == null) { | 
|---|
|  |  |  | throw new GlobleException("会员不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ServiceProductListVo productListVo = new ServiceProductListVo(); | 
|---|
|  |  |  | productListVo.setName(vipInfo.getVipName()); | 
|---|
|  |  |  | productListVo.setVipId(serviceVipProjDto.getVipId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | SysProjUse queryUse = new SysProjUse(); | 
|---|
|  |  |  | queryUse.setVipId(serviceVipProjDto.getVipId()); | 
|---|
|  |  |  | queryUse.setType(Dictionary.SHOPPING_GOODS_TYPE_XM); | 
|---|
|  |  |  | queryUse.setTaocanId(-1L); | 
|---|
|  |  |  | if (serviceVipProjDto.getType() != null) { | 
|---|
|  |  |  | switch (serviceVipProjDto.getType()) { | 
|---|
|  |  |  | case "0": | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case "1": | 
|---|
|  |  |  | queryUse.setStatus(Dictionary.TAOCAN_STATUS_YX); | 
|---|
|  |  |  | //                    queryUse.setIsOver(Dictionary.FLAG_NO_N); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case "2": | 
|---|
|  |  |  | queryUse.setTargetFailTime(DateUtil.getDateAfterMonth(new Date(), 1)); | 
|---|
|  |  |  | queryUse.setStatus(Dictionary.TAOCAN_STATUS_YX); | 
|---|
|  |  |  | //                    queryUse.setIsOver(Dictionary.FLAG_NO_N); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case "3": | 
|---|
|  |  |  | queryUse.setStatus(Dictionary.TAOCAN_STATUS_WX); | 
|---|
|  |  |  | //                    queryUse.setIsOver(Dictionary.FLAG_YES_Y); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | default: | 
|---|
|  |  |  | queryUse.setStatus(Dictionary.TAOCAN_STATUS_YX); | 
|---|
|  |  |  | //                    queryUse.setIsOver(Dictionary.FLAG_NO_N); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | queryUse.setStatus(Dictionary.TAOCAN_STATUS_YX); | 
|---|
|  |  |  | queryUse.setIsOver(Dictionary.FLAG_NO_N); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | queryUse.setQueryKey(serviceVipProjDto.getQueryKey()); | 
|---|
|  |  |  | List<SysProjUse> projList = projUseService.findInPage(queryUse, null); | 
|---|
|  |  |  | List<ServiceProjVo> serviceProjVos = SysProjUseMapper.INSTANCE.entityListToProjVoList(projList); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | queryUse.setTaocanId(null); | 
|---|
|  |  |  | queryUse.setType(Dictionary.SHOPPING_GOODS_TYPE_TC); | 
|---|
|  |  |  | //        List<SysProjUse> taoCanList = projUseService.findInPage(queryUse, null); | 
|---|
|  |  |  | List<SysProjUse> taoCanList = projUseService.findTaocaoProjUseWithProj(queryUse); | 
|---|
|  |  |  | List<ServiceTcVo> serviceTcVos = SysProjUseMapper.INSTANCE.entityListToTcVoList(taoCanList); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (CollectionUtils.isNotEmpty(serviceTcVos)) { | 
|---|
|  |  |  | serviceTcVos.forEach(item -> { | 
|---|
|  |  |  | //                List<SysProjUse> sysProjUses = projUseService.selectTaocanProjUse(item.getId(), queryUse.getStatus()); | 
|---|
|  |  |  | List<ServiceProjVo> taocanProj = SysProjUseMapper.INSTANCE.entityListToProjVoList(item.getTaocanProjUse()); | 
|---|
|  |  |  | item.setTaocanProjUse(null); | 
|---|
|  |  |  | item.setProj(taocanProj); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | productListVo.setProj(serviceProjVos); | 
|---|
|  |  |  | productListVo.setComposeProj(serviceTcVos); | 
|---|
|  |  |  | AjaxResult ajaxResult = AjaxResult.buildSuccessInstance("获取成功"); | 
|---|
|  |  |  | ajaxResult.putInMap("proj", productListVo); | 
|---|
|  |  |  | return ajaxResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "提交服务单", notes = "提交服务单") | 
|---|
|  |  |  | @PostMapping(value = "/createServiceOrder") | 
|---|
|  |  |  | public AjaxResult createServiceOrder(@RequestBody @Validated CreateServiceOrderDto serviceOrderDto) { | 
|---|
|  |  |  | if (CollectionUtils.isEmpty(serviceOrderDto.getProjItems())) { | 
|---|
|  |  |  | throw new GlobleException("请选择服务"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | SysVipInfo vipInfo = sysVipInfoService.findById(serviceOrderDto.getVipId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (StringUtils.isNotBlank(vipInfo.getPassWord())) { | 
|---|
|  |  |  | if (!vipInfo.getPassWord().equals(serviceOrderDto.getPassword())) { | 
|---|
|  |  |  | return AjaxResult.buildFailInstance("资金密码错误"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | SysProjServices sysProjServices = new SysProjServices(); | 
|---|
|  |  |  | sysProjServices.setVipId(serviceOrderDto.getVipId()); | 
|---|
|  |  |  | sysProjServices.setYyTime(serviceOrderDto.getYyTime()); | 
|---|
|  |  |  | sysProjServices.setRemark(serviceOrderDto.getRemark()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<SysBeauticianState> sysBeauticianStates = new ArrayList<>(); | 
|---|
|  |  |  | serviceOrderDto.getProjItems().forEach(item ->{ | 
|---|
|  |  |  | SysBeauticianState sysBeauticianState = SysBeauticianStateMapper.INSTANCE.serviceOrderItemVoToEntity(item); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | sysBeauticianState.setBeginTime(serviceOrderDto.getYyTime()); | 
|---|
|  |  |  | sysBeauticianState.setEndTime(DateUtil.getDateAfterMinute(serviceOrderDto.getYyTime(), serviceOrderDto.getTotalTime())); | 
|---|
|  |  |  | sysBeauticianState.setStaffId(serviceOrderDto.getBeautyId()); | 
|---|
|  |  |  | sysBeauticianStates.add(sysBeauticianState); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | sysProjServices.setServiceItems(sysBeauticianStates); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //检测欠款 | 
|---|
|  |  |  | VerifyResult arrearsVerifyResult = projServicesService.checkArrears(sysProjServices); | 
|---|
|  |  |  | if (arrearsVerifyResult.isError()) { | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_FAIL, arrearsVerifyResult.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //检测余次 | 
|---|
|  |  |  | VerifyResult balanceverifyResult = projServicesService.checkBalance(sysProjServices); | 
|---|
|  |  |  | if (balanceverifyResult.isError()) { | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_FAIL, balanceverifyResult.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 设置状态为待预约 | 
|---|
|  |  |  | sysProjServices.setState(Dictionary.SERVICE_STATU_DYY); | 
|---|
|  |  |  | SysProjServices newSysProjServices = projServicesService.addSysProjServices(sysProjServices); | 
|---|
|  |  |  | if (newSysProjServices != null) { | 
|---|
|  |  |  | return AjaxResult.buildSuccessInstance("下单成功"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_FAIL, "下单失败!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "查询服务单列表", notes = "查询服务单列表") | 
|---|
|  |  |  | @ApiResponses({ | 
|---|
|  |  |  | @ApiResponse(code = 200, message = "ok", response = ServiceOrderListVo.class) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @PostMapping(value = "/findServiceOrderList") | 
|---|
|  |  |  | public AjaxResult findServiceOrderList(@RequestBody @Validated ServiceOrderListDto orderListDto) { | 
|---|
|  |  |  | PaginationVO pageVo = new PaginationVO(); | 
|---|
|  |  |  | int offset = (orderListDto.getPageNum() - 1) * orderListDto.getPageSize(); | 
|---|
|  |  |  | int limit = orderListDto.getPageSize(); | 
|---|
|  |  |  | pageVo.setOffset(offset); | 
|---|
|  |  |  | pageVo.setLimit(limit); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!DataAuthUtil.hasAllShopAuth()) { | 
|---|
|  |  |  | SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); | 
|---|
|  |  |  | orderListDto.setShopId(user.getShopId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | QueryUtil.setQueryLimitCom(orderListDto); | 
|---|
|  |  |  | return AjaxResult.buildSuccessInstance(projServicesService.findApiServiceOrderListInPage(orderListDto, pageVo), projServicesService.findApiServiceOrderListTotal(orderListDto)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "获取服务单详情", notes = "获取服务单详情") | 
|---|
|  |  |  | @ApiResponses({ | 
|---|
|  |  |  | @ApiResponse(code = 200, message = "ok", response = ServiceOrderDetailVo.class) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(value = "/findServiceOrderDetail/{id}") | 
|---|
|  |  |  | public AjaxResult findServiceOrderDetail(@PathVariable("id") Long id) { | 
|---|
|  |  |  | SysProjServices projServices = projServicesService.findById(id); | 
|---|
|  |  |  | if (projServices == null) { | 
|---|
|  |  |  | return AjaxResult.buildFailInstance("服务单不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ServiceOrderDetailVo detailVo = SysProjServiceMapper.INSTANCE.projServiceToDetailVo(projServices); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<SysBeauticianState> beauticianStates = sysBeauticianStateService.findBySerId(projServices.getId()); | 
|---|
|  |  |  | List<ServiceOrderDetailItemVo> items = SysBeauticianStateMapper.INSTANCE.entitiesToDetailItemsVo(beauticianStates); | 
|---|
|  |  |  | detailVo.setItems(items); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AjaxResult ajaxResult = AjaxResult.buildSuccessInstance("获取成功"); | 
|---|
|  |  |  | ajaxResult.putInMap("detail", detailVo); | 
|---|
|  |  |  | return ajaxResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "开始服务", notes = "开始服务") | 
|---|
|  |  |  | @GetMapping(value = "/startService/{id}") | 
|---|
|  |  |  | public AjaxResult startService(@PathVariable("id") Long id) { | 
|---|
|  |  |  | SysProjServices sysProjServices = new SysProjServices(); | 
|---|
|  |  |  | sysProjServices.setId(id); | 
|---|
|  |  |  | int i = projServicesService.modifyFWKSProjServices(sysProjServices); | 
|---|
|  |  |  | if (i > 0) { | 
|---|
|  |  |  | return AjaxResult.buildSuccessInstance("开始服务成功"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return AjaxResult.buildFailInstance("开始服务失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "结束服务", notes = "结束服务") | 
|---|
|  |  |  | @GetMapping(value = "/stopService/{id}") | 
|---|
|  |  |  | public AjaxResult stopService(@PathVariable("id") Long id) { | 
|---|
|  |  |  | SysProjServices projServvices = new SysProjServices(); | 
|---|
|  |  |  | projServvices.setId(id); | 
|---|
|  |  |  | int result = projServicesService.modifyFWJSrojServices(projServvices); | 
|---|
|  |  |  | if (result > 0) { | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_SUCCESS, "结束服务成功"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_FAIL, "结束服务失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "取消服务", notes = "取消服务") | 
|---|
|  |  |  | @GetMapping(value = "/cancelService/{id}") | 
|---|
|  |  |  | public AjaxResult cancelService(@PathVariable("id") Long id) { | 
|---|
|  |  |  | SysProjServices services = new SysProjServices(); | 
|---|
|  |  |  | services.setId(id); | 
|---|
|  |  |  | int i = projServicesService.modifyCancelProjServices(services); | 
|---|
|  |  |  | if (i > 0) { | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_SUCCESS, "取消预约成功"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_FAIL, "取消预约失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "确认服务", notes = "确认服务") | 
|---|
|  |  |  | @PostMapping(value = "/confirmServiceOrder") | 
|---|
|  |  |  | public AjaxResult confirmServiceOrder(@RequestBody @Validated IdSubmitDto idSubmitDto) { | 
|---|
|  |  |  | SysProjServices services = new SysProjServices(); | 
|---|
|  |  |  | services.setId(idSubmitDto.getId()); | 
|---|
|  |  |  | services.setState(Dictionary.BEATUI_STATE_DYY); | 
|---|
|  |  |  | int i = projServicesService.modify(services); | 
|---|
|  |  |  | if (i > 0) { | 
|---|
|  |  |  | //发送微信公众号提醒 | 
|---|
|  |  |  | services=projServicesService.findById(services.getId()); | 
|---|
|  |  |  | UniformMsgParam uniformMsgParam=new UniformMsgParam(services.getCompanyId(),UniformMsgParam.GZH_YYCG); | 
|---|
|  |  |  | uniformMsgParam.put("serviceId",services.getId()); | 
|---|
|  |  |  | rabiitMqTemplate.sendMsg(MQTaskRouting.SEND_UNIFORM_TEMPLATE_MSG+evn,uniformMsgParam.toJSONString()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return AjaxResult.buildSuccessInstance("确认成功"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return AjaxResult.buildFailInstance("确认失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|