package com.dsh.guns.modular.system.controller.code; import cn.hutool.crypto.SecureUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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.CityManager; import com.dsh.course.feignClient.account.model.Coach; import com.dsh.course.feignClient.account.model.CoachSerchVO; import com.dsh.course.feignClient.account.model.CoachType; import com.dsh.guns.config.UserExt; import com.dsh.guns.core.base.controller.BaseController; import com.dsh.guns.core.common.constant.factory.PageFactory; import com.dsh.guns.core.util.SinataUtil; import com.dsh.guns.modular.system.model.*; import com.dsh.guns.modular.system.service.*; import com.dsh.guns.modular.system.service.impl.TOperatorUserServiceImpl; import com.dsh.guns.modular.system.util.ResultUtil; import io.swagger.models.auth.In; import org.apache.catalina.valves.RemoteIpValve; 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("/operator") public class OperatorController extends BaseController { private String PREFIX = "/system/operator/"; @Autowired private TOperatorService operatorService; @Autowired private TOperatorCityService operatorCityService; @Autowired private IOperatorUserService operatorUserService; @Autowired private IUserService userService; @Autowired private ICityService cityService; /** * 跳转运营商管理首页 */ @RequestMapping("") public String index(Model model) { return PREFIX + "Operator.html"; } /** * 跳转运营商重置密码页面 */ @RequestMapping("/resetPassword") public String resetPassword(Model model) { return PREFIX + "Operator_resetPassword.html"; } /** * 跳转运营商添加页面 */ @RequestMapping("/add") public String add(Model model) { List list = cityService.list(new LambdaQueryWrapper().eq(TCity::getParentId, 0)); model.addAttribute("provinceList",list); return PREFIX + "Operator_add.html"; } /** * 跳转运营商编辑页面 */ @RequestMapping("/update/{id}") public String update(Model model,@PathVariable("id") Integer id) { List provinceList = cityService.list(new LambdaQueryWrapper().eq(TCity::getParentId, 0)); model.addAttribute("provinceList",provinceList); model.addAttribute("id",id); TOperator byId = operatorService.getById(id); // 运营商名称 model.addAttribute(byId.getName()); User byId1 = userService.getById(byId.getUserId()); model.addAttribute("userName",byId1.getName()); model.addAttribute("phone",byId1.getPhone()); model.addAttribute("data",byId); // 获取全部的省 List list = operatorCityService.list(new QueryWrapper().eq("operatorId", id).eq("pid",0)); List result = new ArrayList<>(); for (TOperatorCity tOperatorCity : list) { // 拿到省下面的所有市 List cities= operatorCityService.list(new QueryWrapper().eq("pid", tOperatorCity.getId())); if (cities.size()==0){ OperatorCityVO operatorCityVO = new OperatorCityVO(); operatorCityVO.setProvince(tOperatorCity.getName()); operatorCityVO.setProvinceCode(tOperatorCity.getCode()); result.add(operatorCityVO); } for (TOperatorCity city : cities) { OperatorCityVO operatorCityVO = new OperatorCityVO(); operatorCityVO.setProvince(tOperatorCity.getName()); operatorCityVO.setProvinceCode(tOperatorCity.getCode()); operatorCityVO.setCity(city.getName()); operatorCityVO.setCityCode(city.getCode()); result.add(operatorCityVO); } } model.addAttribute("list",result); return PREFIX + "Operator_edit.html"; } /** * 获取运营商列表 */ @RequestMapping(value = "/listAll") @ResponseBody public Object listAll(String userName, String phone,Integer type) { Page> page = new PageFactory>().defaultPage(); List> list = operatorService.listAll(page,userName,phone,type); page.setRecords(list); return super.packForBT(page); } /** * 跳转运营商商户去认证页面 */ @RequestMapping("/proportionAuth/{id}") public String proportionAuth(Model model,@PathVariable("id") Integer id) { model.addAttribute("operatorId",id); return PREFIX + "OperatorUser_proportionAuth.html"; } /** * 商户认证提交 */ @RequestMapping(value = "/auth") @ResponseBody public Object auth(Integer alipayType,Integer wechatType,String alipayNum,String wechatNum,Integer operatorId ) { TOperator id = operatorService.getOne(new QueryWrapper().eq("id", operatorId)); OperatorUser operatorUser = new OperatorUser(); operatorUser.setUserId(id.getUserId()); operatorUser.setAlipay("支付宝"); operatorUser.setWechat("微信"); operatorUser.setWechatType(wechatType); operatorUser.setAlipayType(alipayType); operatorUser.setAlipayNum(alipayNum); operatorUser.setWechatNum(wechatNum); operatorUser.setOperatorId(operatorId); operatorUserService.save(operatorUser); // 修改运营商状态为 已认证 id.setStatus(2); operatorService.updateById(id); return SUCCESS_TIP; } /** * 分账比例提交 */ @RequestMapping(value = "/proportion") @ResponseBody public Object auth(String alipayProportion,String wechatProportion,Integer operatorIdOne ) { OperatorUser id = operatorUserService.getOne(new QueryWrapper().eq("id", operatorIdOne)); id.setAlipayProportion(alipayProportion); id.setWechatProportion(wechatProportion); operatorUserService.updateById(id); return SUCCESS_TIP; } /** * 跳转运营商设置分账比例页面 */ @RequestMapping("/proportion/{id}") public String proportion(Model model,@PathVariable("id") Integer id) { OperatorUser o = operatorUserService.getOne(new QueryWrapper().eq("operatorId", id)); model.addAttribute("operatorIdOne",o.getId()); model.addAttribute("alipayProportion",o.getAlipayProportion()); model.addAttribute("wechatProportion",o.getWechatProportion()); return PREFIX + "OperatorUser_proportion.html"; } /** * 批量重置密码 * @return */ @RequestMapping(value = "/pwd") @ResponseBody public Object pwd(@RequestBody OperatorRestPwd pwd ) { try { List list = operatorService.list(new QueryWrapper().in("id",pwd.getIds())); List userIds = list.stream() .map(TOperator::getUserId) .collect(Collectors.toList()); String a123456 = SecureUtil.md5("a123456"); List users = userService.list(new QueryWrapper().in("id", userIds)); for (User user : users) { user.setPassword(a123456); } userService.updateBatchById(users); return SUCCESS_TIP; }catch (Exception e){ e.printStackTrace(); return ERROR; } } /** * 1为解冻 2为冻结 * * @return */ @RequestMapping("/changeState") @ResponseBody public Object changeState(@RequestBody CoachChangeStateVO vo){ operatorService.changeState(vo); return ResultUtil.success(); } /** * 添加运营商 */ @ResponseBody @RequestMapping(value = "/addOperator") public ResultUtil addOperator(String name,String userName,String phone,Integer type ,@RequestParam String comArr) { User one = userService.getOne(new QueryWrapper().eq("name", name).eq("phone", phone)); if (one!=null){ return ResultUtil.error("当前管理员名称和电话已存在!"); } User user = new User(); user.setName(userName); user.setPhone(phone); user.setObjectType(2); TOperator data = new TOperator(); data.setUserId(user.getId()); data.setName(name); data.setType(type); data.setStatus(1); data.setState(1); operatorService.save(data); user.setObjectId(data.getId()); userService.save(user); if (SinataUtil.isNotEmpty(comArr)){ JSONArray jsonArray = JSON.parseArray(comArr); int size = jsonArray.size(); for (int i = 0; i < size; i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); TOperatorCity province = new TOperatorCity(); TOperatorCity city = new TOperatorCity(); TOperatorCity one1 = operatorCityService.getOne(new QueryWrapper() .eq("name", jsonObject.getString("province")) .eq("operatorId", data.getId())); // 省 if (one1==null){ province.setName(jsonObject.getString("province")); province.setCode(jsonObject.getInteger("provinceCode")); province.setPid(0); province.setType(jsonObject.getInteger("areaType")); province.setOperatorId(data.getId()); city.setPid(province.getId()); operatorCityService.save(province); // 市 if (!jsonObject.getString("city").equals("")){ city.setName(jsonObject.getString("city")); city.setCode(jsonObject.getInteger("cityCode")); city.setPid(province.getId()); city.setType(jsonObject.getInteger("areaType")); city.setOperatorId(data.getId()); operatorCityService.save(city); } }else{ // 市 if (!jsonObject.getString("city").equals("")){ city.setName(jsonObject.getString("city")); city.setCode(jsonObject.getInteger("cityCode")); city.setPid(one1.getId()); city.setType(jsonObject.getInteger("areaType")); city.setOperatorId(data.getId()); operatorCityService.save(city); } } } } return ResultUtil.success("添加成功"); } /** * 添加运营商 */ @ResponseBody @RequestMapping(value = "/updateOperator") public ResultUtil updateOperator(Integer id,String name,String userName,String phone,Integer type ,@RequestParam String comArr) { User one = userService.getOne(new QueryWrapper().eq("name", name).eq("phone", phone)); if (one!=null){ return ResultUtil.error("当前管理员名称和电话已存在!"); } operatorCityService.remove(new QueryWrapper().eq("operatorId",id)); User user = new User(); user.setName(userName); user.setPhone(phone); user.setObjectType(2); String a123456 = SecureUtil.md5("a123456"); user.setPassword(a123456); userService.save(user); TOperator data = new TOperator(); data.setId(id); data.setUserId(user.getId()); data.setName(name); data.setType(type); data.setStatus(1); data.setState(1); operatorService.updateById(data); if (type != 1){ if (SinataUtil.isNotEmpty(comArr)){ JSONArray jsonArray = JSON.parseArray(comArr); int size = jsonArray.size(); for (int i = 0; i < size; i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); TOperatorCity province = new TOperatorCity(); TOperatorCity city = new TOperatorCity(); TOperatorCity one1 = operatorCityService.getOne(new QueryWrapper() .eq("name", jsonObject.getString("province")) .eq("operatorId", data.getId())); // 省 if (one1==null){ province.setName(jsonObject.getString("province")); province.setCode(jsonObject.getInteger("provinceCode")); province.setPid(0); province.setType(jsonObject.getInteger("areaType")); province.setOperatorId(data.getId()); city.setPid(province.getId()); operatorCityService.save(province); // 市 if (!jsonObject.getString("city").equals("")){ city.setName(jsonObject.getString("city")); city.setCode(jsonObject.getInteger("cityCode")); city.setPid(province.getId()); city.setType(jsonObject.getInteger("areaType")); city.setOperatorId(data.getId()); operatorCityService.save(city); } }else{ // 市 if (!jsonObject.getString("city").equals("")){ city.setName(jsonObject.getString("city")); city.setCode(jsonObject.getInteger("cityCode")); city.setPid(one1.getId()); city.setType(jsonObject.getInteger("areaType")); city.setOperatorId(data.getId()); operatorCityService.save(city); } } } } } return ResultUtil.success("添加成功"); } }