|  |  |  | 
|---|
|  |  |  | package com.dsh.guns.modular.system.controller.code; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.druid.sql.visitor.functions.If; | 
|---|
|  |  |  | 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.CoachClient; | 
|---|
|  |  |  | import com.dsh.course.feignClient.account.CoachTypeClient; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.dsh.course.feignClient.account.model.CoachType; | 
|---|
|  |  |  | import com.dsh.course.feignClient.other.model.Site; | 
|---|
|  |  |  | import com.dsh.guns.config.UserExt; | 
|---|
|  |  |  | import com.dsh.guns.modular.system.model.CoachChangeStateVO; | 
|---|
|  |  |  | import com.dsh.guns.modular.system.model.CoachQuery; | 
|---|
|  |  |  | import com.dsh.guns.modular.system.model.Store; | 
|---|
|  |  |  | import com.dsh.guns.modular.system.model.*; | 
|---|
|  |  |  | import com.dsh.guns.modular.system.service.*; | 
|---|
|  |  |  | import com.dsh.guns.modular.system.util.ResultUtil; | 
|---|
|  |  |  | import org.bouncycastle.math.raw.Mod; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Controller; | 
|---|
|  |  |  | import org.springframework.ui.Model; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.text.SimpleDateFormat; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | private CoachClient coachClient; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private CityManagerClient cityManagerClient; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ICityService cityService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TOperatorService operatorService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TOperatorCityService operatorCityService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private IUserService userService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 跳转教练管理首页 | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer objectType = UserExt.getUser().getObjectType(); | 
|---|
|  |  |  | Integer objectId = UserExt.getUser().getObjectId(); | 
|---|
|  |  |  | List<Coach> list1=coachClient.getProvince(); | 
|---|
|  |  |  | CoachQuery coachQuery = new CoachQuery(); | 
|---|
|  |  |  | coachQuery.setStoreIds(new ArrayList<>()); | 
|---|
|  |  |  | List<CoachSerchVO> data = coachClient.listAll(coachQuery); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<String> province = new ArrayList<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (CoachSerchVO coach : data) { | 
|---|
|  |  |  | province.add(coach.getProvince()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | HashSet<String> set = new HashSet<String>(province); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String roleid = UserExt.getUser().getRoleid(); | 
|---|
|  |  |  | model.addAttribute("role",roleid); | 
|---|
|  |  |  | model.addAttribute("data",data); | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @RequestMapping("/addCoach") | 
|---|
|  |  |  | public String addCoach(Model model) { | 
|---|
|  |  |  | List<CityManager> province = cityManagerClient.listAll(); | 
|---|
|  |  |  | Set<String> seenNames = new HashSet<>(); | 
|---|
|  |  |  | List<CityManager> result = new ArrayList<>(); | 
|---|
|  |  |  | for (CityManager cityManager : province) { | 
|---|
|  |  |  | if(!seenNames.contains(cityManager.getProvince())){ | 
|---|
|  |  |  | result.add(cityManager); | 
|---|
|  |  |  | seenNames.add(cityManager.getProvince()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<TCity> list1 = cityService.list(new LambdaQueryWrapper<TCity>().eq(TCity::getParentId, 0)); | 
|---|
|  |  |  | model.addAttribute("list",list1); | 
|---|
|  |  |  | Integer objectType = UserExt.getUser().getObjectType(); | 
|---|
|  |  |  | Integer objectId = UserExt.getUser().getObjectId(); | 
|---|
|  |  |  | CoachQuery coachQuery = new CoachQuery(); | 
|---|
|  |  |  | List<CoachSerchVO> data = coachClient.listAll(coachQuery); | 
|---|
|  |  |  | List<CoachType> list = coachTypeClient.list(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String roleid = UserExt.getUser().getRoleid(); | 
|---|
|  |  |  | model.addAttribute("role",roleid); | 
|---|
|  |  |  | model.addAttribute("data",data); | 
|---|
|  |  |  | model.addAttribute("list",result); | 
|---|
|  |  |  | model.addAttribute("objectType",objectType); | 
|---|
|  |  |  | model.addAttribute("objectId",objectId); | 
|---|
|  |  |  | model.addAttribute("coachType",list); | 
|---|
|  |  |  | return PREFIX + "TCoach_add.html"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | *  添加教练 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @ResponseBody | 
|---|
|  |  |  | @RequestMapping(value = "/add") | 
|---|
|  |  |  | public ResultUtil addCoach(@RequestBody Coach coach) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer objectId = UserExt.getUser().getObjectId(); | 
|---|
|  |  |  | if (UserExt.getUser().getObjectType() == 2){ | 
|---|
|  |  |  | CityManager cityManager = cityManagerClient.queryCityManagerById(objectId); | 
|---|
|  |  |  | coach.setProvince(cityManager.getProvince()); | 
|---|
|  |  |  | coach.setProvinceCode(cityManager.getProvinceCode()); | 
|---|
|  |  |  | coach.setCity(cityManager.getCity()); | 
|---|
|  |  |  | coach.setCityCode(cityManager.getCityCode()); | 
|---|
|  |  |  | coach.setCityManagerId(objectId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (coach.getDiploma().equals("")) coach.setDiploma(null); | 
|---|
|  |  |  | if (coach.getDiploma().equals("")) { | 
|---|
|  |  |  | coach.setDiploma(null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (coach.getCertificateImg().equals("") ){ | 
|---|
|  |  |  | coach.setCertificateImg(null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | return ResultUtil.success(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | *  根据选择的市 查询有哪些运营商管理了所选的市 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @RequestMapping("/getYys") | 
|---|
|  |  |  | @ResponseBody | 
|---|
|  |  |  | public Object getYys(String pCode,String cCode){ | 
|---|
|  |  |  | // 先获取管理全国的运营商 | 
|---|
|  |  |  | List<TOperator> type = operatorService.list(new QueryWrapper<TOperator>().eq("type", 1)); | 
|---|
|  |  |  | // 根据所选市 查询管理了这个市的运营商 | 
|---|
|  |  |  | // 获取管理指定区域的运营商的ID 然后去重 | 
|---|
|  |  |  | List<Integer> collect = operatorCityService.list(new QueryWrapper<TOperatorCity>()).stream().map(TOperatorCity::getOperatorId) | 
|---|
|  |  |  | .distinct().collect(Collectors.toList()); | 
|---|
|  |  |  | // 遍历 判断当前运营商是否管理了所选市 | 
|---|
|  |  |  | for (Integer integer : collect) { | 
|---|
|  |  |  | // 查询是否管理了省 | 
|---|
|  |  |  | TOperatorCity code = operatorCityService.getOne(new QueryWrapper<TOperatorCity>().eq("code", pCode).eq("operatorId",integer)); | 
|---|
|  |  |  | if (code==null)continue; | 
|---|
|  |  |  | List<TOperatorCity> pid = operatorCityService.list(new QueryWrapper<TOperatorCity>().eq("pid", code.getId())); | 
|---|
|  |  |  | // 如果pid长度为0 则说明管理整个省 | 
|---|
|  |  |  | if (pid.size()==0){ | 
|---|
|  |  |  | type.add(operatorService.getOne(new QueryWrapper<TOperator>() | 
|---|
|  |  |  | .eq("id",integer))); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (TOperatorCity tOperatorCity : pid) { | 
|---|
|  |  |  | if (tOperatorCity.getCode().toString().equals(cCode)){ | 
|---|
|  |  |  | TOperator id = operatorService.getOne(new QueryWrapper<TOperator>() | 
|---|
|  |  |  | .eq("id", tOperatorCity.getOperatorId())); | 
|---|
|  |  |  | if (id!=null)type.add(id); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return type; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 跳转修改教练页面 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @RequestMapping("/updateCoach/{id}") | 
|---|
|  |  |  | 
|---|
|  |  |  | CoachQuery coachQuery = new CoachQuery(); | 
|---|
|  |  |  | coachQuery.setId(id); | 
|---|
|  |  |  | List<CoachSerchVO> data = coachClient.listAll(coachQuery); | 
|---|
|  |  |  | List<CityManager> province = cityManagerClient.listAll(); | 
|---|
|  |  |  | Set<String> seenNames = new HashSet<>(); | 
|---|
|  |  |  | List<CityManager> result = new ArrayList<>(); | 
|---|
|  |  |  | List<CityManager> city = new ArrayList<>(); | 
|---|
|  |  |  | for (CityManager cityManager : province) { | 
|---|
|  |  |  | if(!seenNames.contains(cityManager.getProvince())){ | 
|---|
|  |  |  | result.add(cityManager); | 
|---|
|  |  |  | seenNames.add(cityManager.getProvince()); | 
|---|
|  |  |  | List<TCity> list1 = cityService.list(new LambdaQueryWrapper<TCity>().eq(TCity::getParentId, 0)); | 
|---|
|  |  |  | // 省 | 
|---|
|  |  |  | model.addAttribute("list",list1); | 
|---|
|  |  |  | // 市 | 
|---|
|  |  |  | Integer code = cityService.getOne(new QueryWrapper<TCity>() | 
|---|
|  |  |  | .eq("code", data.get(0).getProvinceCode())).getId(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<TCity> pid = cityService.list(new QueryWrapper<TCity>().eq("parent_id", code)); | 
|---|
|  |  |  | model.addAttribute("city",pid); | 
|---|
|  |  |  | // 获取所选省市下的运营商列表 | 
|---|
|  |  |  | // 先获取管理全国的运营商 | 
|---|
|  |  |  | List<TOperator> type = operatorService.list(new QueryWrapper<TOperator>().eq("type", 1)); | 
|---|
|  |  |  | // 根据所选市 查询管理了这个市的运营商 | 
|---|
|  |  |  | // 获取管理指定区域的运营商的ID 然后去重 | 
|---|
|  |  |  | List<Integer> collect = operatorCityService.list(new QueryWrapper<TOperatorCity>()).stream().map(TOperatorCity::getOperatorId) | 
|---|
|  |  |  | .distinct().collect(Collectors.toList()); | 
|---|
|  |  |  | // 遍历 判断当前运营商是否管理了所选市 | 
|---|
|  |  |  | for (Integer integer : collect) { | 
|---|
|  |  |  | // 查询是否管理了省 | 
|---|
|  |  |  | TOperatorCity code1 = operatorCityService.getOne(new QueryWrapper<TOperatorCity>() | 
|---|
|  |  |  | .eq("code", data.get(0).getProvinceCode()) | 
|---|
|  |  |  | .eq("operatorId",integer) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if (code1==null)continue; | 
|---|
|  |  |  | List<TOperatorCity> pid1 = operatorCityService.list(new QueryWrapper<TOperatorCity>().eq("pid", code1.getId())); | 
|---|
|  |  |  | // 如果pid长度为0 则说明管理整个省 | 
|---|
|  |  |  | if (pid1.size()==0){ | 
|---|
|  |  |  | type.add(operatorService.getOne(new QueryWrapper<TOperator>() | 
|---|
|  |  |  | .eq("id",integer))); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(data.get(0).getProvince().equals(cityManager.getProvince())){ | 
|---|
|  |  |  | city.add(cityManager); | 
|---|
|  |  |  | for (TOperatorCity tOperatorCity : pid1) { | 
|---|
|  |  |  | if (tOperatorCity.getCode().toString().equals(data.get(0).getCityCode())){ | 
|---|
|  |  |  | TOperator id1 = operatorService.getOne(new QueryWrapper<TOperator>() | 
|---|
|  |  |  | .eq("id", tOperatorCity.getOperatorId())); | 
|---|
|  |  |  | if (id1!=null)type.add(id1); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer objectType = UserExt.getUser().getObjectType(); | 
|---|
|  |  |  | Integer objectId = UserExt.getUser().getObjectId(); | 
|---|
|  |  |  | List<CityManager> accounts = cityManagerClient.getAccount(data.get(0).getCity()); | 
|---|
|  |  |  | List<CoachType> list = coachTypeClient.list(); | 
|---|
|  |  |  | String roleid = UserExt.getUser().getRoleid(); | 
|---|
|  |  |  | model.addAttribute("role",roleid); | 
|---|
|  |  |  | model.addAttribute("data",data.get(0)); | 
|---|
|  |  |  | model.addAttribute("list",result); | 
|---|
|  |  |  | model.addAttribute("city",city); | 
|---|
|  |  |  | model.addAttribute("cityManagers",accounts); | 
|---|
|  |  |  | model.addAttribute("cityManagers",type); | 
|---|
|  |  |  | model.addAttribute("objectType",objectType); | 
|---|
|  |  |  | model.addAttribute("objectId",objectId); | 
|---|
|  |  |  | model.addAttribute("coachType",list); | 
|---|
|  |  |  | 
|---|
|  |  |  | model.addAttribute("type",0); | 
|---|
|  |  |  | String[] split = data.get(0).getCertificateImg().split(","); | 
|---|
|  |  |  | List<String> pictures = new ArrayList<>(Arrays.asList(split)); | 
|---|
|  |  |  | model.addAttribute("pictures",pictures); | 
|---|
|  |  |  | model.addAttribute("pictures",data.get(0).getCertificateImg()); | 
|---|
|  |  |  | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); | 
|---|
|  |  |  | String birthday = format.format(data.get(0).getBirthday()); | 
|---|
|  |  |  | model.addAttribute("birthday",birthday); | 
|---|
|  |  |  | model.addAttribute("diploma",data.get(0).getDiploma()); | 
|---|
|  |  |  | return PREFIX + "TCoach_edit.html"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); | 
|---|
|  |  |  | String birthday = format.format(data.get(0).getBirthday()); | 
|---|
|  |  |  | model.addAttribute("birthday",birthday); | 
|---|
|  |  |  | return PREFIX + "Operator_edit.html"; | 
|---|
|  |  |  | return PREFIX + "TCoach_edit.html"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取教练列表 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private IStoreService storeService; | 
|---|
|  |  |  | @RequestMapping(value = "/list") | 
|---|
|  |  |  | @ResponseBody | 
|---|
|  |  |  | public List<CoachSerchVO> list(String province, String city, String name, String phone) { | 
|---|
|  |  |  | 
|---|
|  |  |  | coachQuery.setCity(city); | 
|---|
|  |  |  | coachQuery.setName(name); | 
|---|
|  |  |  | coachQuery.setPhone(phone); | 
|---|
|  |  |  | return coachClient.listAll(coachQuery); | 
|---|
|  |  |  | Integer objectType = UserExt.getUser().getObjectType(); | 
|---|
|  |  |  | if (objectType == 1){ | 
|---|
|  |  |  | Integer objectId = UserExt.getUser().getObjectId(); | 
|---|
|  |  |  | coachQuery.setOperatorId(objectId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (objectType == 2){ | 
|---|
|  |  |  | Integer objectId = UserExt.getUser().getObjectId(); | 
|---|
|  |  |  | coachQuery.setOperatorId(objectId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<CoachSerchVO> coachSerchVOS = coachClient.listAll(coachQuery); | 
|---|
|  |  |  | for (CoachSerchVO coachSerchVO : coachSerchVOS) { | 
|---|
|  |  |  | Integer cityManagerId = coachSerchVO.getCityManagerId(); | 
|---|
|  |  |  | if(0 == cityManagerId){ | 
|---|
|  |  |  | coachSerchVO.setNameAndPhone("平台"); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | TOperator byId = operatorService.getById(cityManagerId); | 
|---|
|  |  |  | Integer userId = byId.getUserId(); | 
|---|
|  |  |  | User byId1 = userService.getById(userId); | 
|---|
|  |  |  | coachSerchVO.setNameAndPhone(byId.getName()+""+byId1.getPhone()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return coachSerchVOS; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|