| package com.dsh.guns.modular.system.controller.code; | 
|   | 
|   | 
| import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
| import com.dsh.course.feignClient.account.CityManagerClient; | 
| import com.dsh.course.feignClient.account.StoreStaffClient; | 
| import com.dsh.course.feignClient.account.model.CityManager; | 
| import com.dsh.course.feignClient.account.model.Coach; | 
| import com.dsh.course.feignClient.account.model.TStoreStaff; | 
| import com.dsh.course.feignClient.activity.BodySideAppointmentClient; | 
| import com.dsh.course.feignClient.activity.model.BodySideAppointment; | 
| import com.dsh.course.feignClient.activity.model.QueryBodySideAppointment; | 
| import com.dsh.course.feignClient.activity.model.QueryBodySideAppointmentVO; | 
| import com.dsh.course.feignClient.other.StoreClient; | 
| import com.dsh.guns.config.UserExt; | 
| import com.dsh.guns.modular.system.model.CoachQuery; | 
| import com.dsh.guns.modular.system.model.Store; | 
| import com.dsh.guns.modular.system.model.TCity; | 
| import com.dsh.guns.modular.system.model.TStore; | 
| import com.dsh.guns.modular.system.service.ICityService; | 
| import com.dsh.guns.modular.system.service.IStoreService; | 
| import com.dsh.guns.modular.system.util.ResultUtil; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Controller; | 
| import org.springframework.ui.Model; | 
| import org.springframework.web.bind.annotation.*; | 
|   | 
| import java.text.SimpleDateFormat; | 
| import java.util.*; | 
| import java.util.stream.Collectors; | 
|   | 
| /** | 
|  * 体测预约管理控制器 | 
|  */ | 
| @Controller | 
| @RequestMapping("/bodySideAppointment") | 
| public class TBodySideAppointmentsController { | 
|     private String PREFIX = "/system/bodySideAppointment/"; | 
|   | 
|     @Autowired | 
|     private StoreClient storeClient; | 
|     @Autowired | 
|     private BodySideAppointmentClient bodySideAppointmentClient; | 
|     @Autowired | 
|     private CityManagerClient cityManagerClient; | 
|     @Autowired | 
|     private StoreStaffClient storeStaffClient; | 
|     @Autowired | 
|     private ICityService cityService; | 
|     /** | 
|      * 跳转体测预约管理首页 | 
|      */ | 
|     @RequestMapping("") | 
|     public String index(Model model) { | 
|         return PREFIX + "TBodySideAppointment.html"; | 
|     } | 
|     /** | 
|      * 跳转体测预约管理添加页面 | 
|      */ | 
|     @RequestMapping("/add") | 
|     public String add(Model model) { | 
|         Integer roleType = UserExt.getUser().getObjectType(); | 
|         List<TCity> list = cityService.list(new LambdaQueryWrapper<TCity>().eq(TCity::getParentId, 0)); | 
|         model.addAttribute("list",list); | 
|         if (roleType == 2){ | 
|             Integer cityManagerId = UserExt.getUser().getObjectId(); | 
|             CityManager cityManager = cityManagerClient.queryCityManagerById(cityManagerId); | 
|             List<Store> stores = storeClient.getStoreByCityManagerId(cityManagerId); | 
|             model.addAttribute("stores",stores); | 
|         } | 
|         model.addAttribute("list",list); | 
|   | 
|         model.addAttribute("roleType",roleType); | 
|         return PREFIX + "TBodySideAppointment_add.html"; | 
|     } | 
|     /** | 
|      * 跳转体测预约管理编辑页面 | 
|      */ | 
|     @RequestMapping("/update/{id}") | 
|     public String update(Model model,@PathVariable("id") Integer id) { | 
|         Integer roleType = UserExt.getUser().getObjectType(); | 
|         Integer objectId = UserExt.getUser().getObjectId(); | 
|         BodySideAppointment data = bodySideAppointmentClient.getInfoById(id); | 
|         if (roleType == 1){ | 
|             List<TCity> list = cityService.list(new LambdaQueryWrapper<TCity>().eq(TCity::getParentId, 0)); | 
|             TCity province1 = cityService.getOne(new QueryWrapper<TCity>().eq("name", data.getProvince())); | 
|             List<TCity> city = cityService.list(new LambdaQueryWrapper<TCity>().eq(TCity::getParentId, province1.getId())); | 
|             model.addAttribute("list",list); | 
|             List<Store> stores = storeClient.getStore(data.getCity()); | 
|             model.addAttribute("stores",stores); | 
|             model.addAttribute("cities",city); | 
|         }else if (roleType == 2){ | 
|             List<Store> stores = storeClient.getStoreByCityManagerId(objectId); | 
|             model.addAttribute("stores",stores); | 
|         } | 
|         String birthday = new SimpleDateFormat("yyyy-MM-dd").format(data.getBirthday()); | 
|         String appointmentTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(data.getAppointmentTime()); | 
|         model.addAttribute("birthday",birthday); | 
|         model.addAttribute("appointmentTime",appointmentTime); | 
|         model.addAttribute("data",data); | 
|         model.addAttribute("roleType",roleType); | 
|         return PREFIX + "TBodySideAppointment_edit.html"; | 
|     } | 
|   | 
|     /** | 
|      * 获取所有体测预约记录 | 
|      * @return | 
|      */ | 
|     @RequestMapping("/listAll") | 
|     @ResponseBody | 
|     public List<QueryBodySideAppointmentVO> listAll(String phone,String parentName,Integer state,Integer day){ | 
|         QueryBodySideAppointment vo = new QueryBodySideAppointment(); | 
|         vo.setParentName(parentName); | 
|         vo.setPhone(phone); | 
|         vo.setState(state); | 
|         vo.setDay(day); | 
|         Integer roleType = UserExt.getUser().getObjectType(); | 
|         Integer objectId = UserExt.getUser().getObjectId(); | 
|         if (roleType == 2){ | 
|             // 获取门店集合 | 
|             List<Integer> collect = storeClient.getStoreByCityManagerId(objectId) | 
|                     .stream().map(Store::getId).collect(Collectors.toList()); | 
|             vo.setIds(collect); | 
|         }else if(roleType == 3){ | 
|             List<Integer> list = new ArrayList<>(); | 
|             list.add(objectId); | 
|             vo.setIds(list); | 
|         } | 
|         List<QueryBodySideAppointmentVO> queryBodySideAppointmentVOS = bodySideAppointmentClient.listAll(vo); | 
|         for (QueryBodySideAppointmentVO queryBodySideAppointmentVO : queryBodySideAppointmentVOS) { | 
|             queryBodySideAppointmentVO.setProvinceAndCity(queryBodySideAppointmentVO.getProvince()+queryBodySideAppointmentVO.getCity()); | 
|         } | 
|   | 
|         return queryBodySideAppointmentVOS; | 
|     } | 
|   | 
|     @Autowired | 
|     private IStoreService storeService; | 
|     /** | 
|      *  添加/修改体测预约记录 | 
|      */ | 
|     @ResponseBody | 
|     @RequestMapping(value = "/addBodySideAppointments") | 
|     public ResultUtil addBodySideAppointments(@RequestBody QueryBodySideAppointmentVO vo) { | 
|         Integer roleType = UserExt.getUser().getObjectType(); | 
|         // 获取当前登录人id | 
|         Integer cityManagerId = UserExt.getUser().getObjectId(); | 
|         if (roleType == 2){ | 
|             TStore cityManager = storeService.getById(vo.getStoreId()); | 
|             vo.setProvince(cityManager.getProvince()); | 
|             vo.setProvinceCode(cityManager.getProvinceCode()); | 
|             vo.setCity(cityManager.getCity()); | 
|             vo.setCityCode(cityManager.getCityCode()); | 
|         }else if (roleType == 3){ | 
| //            TStoreStaff storeByStoreStaffId = storeStaffClient.getStoreByStoreStaffId(cityManagerId); | 
|             Store storeById = storeClient.getStoreById(cityManagerId); | 
|             vo.setProvince(storeById.getProvince()); | 
|             vo.setProvinceCode(storeById.getProvinceCode()); | 
|             vo.setCity(storeById.getCity()); | 
|             vo.setCityCode(storeById.getCityCode()); | 
|             vo.setStoreId(cityManagerId); | 
|         } | 
|         bodySideAppointmentClient.addBodySideAppointments(vo); | 
|         return ResultUtil.success("添加成功"); | 
|     } | 
|   | 
|     /** | 
|      *  添加/修改体测预约记录 | 
|      */ | 
|     @ResponseBody | 
|     @RequestMapping(value = "/getInfoById") | 
|     public BodySideAppointment getInfoById(@RequestBody Integer id) { | 
|         return bodySideAppointmentClient.getInfoById(id); | 
|     } | 
|   | 
|     /** | 
|      *  手动标记用户已经到店并完成体测 | 
|      */ | 
|     @ResponseBody | 
|     @RequestMapping(value = "/changeState") | 
|     public Object changeState(@RequestBody List<Integer> ids) { | 
|         return bodySideAppointmentClient.changeState(ids); | 
|     } | 
|   | 
| } |