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.ICityService;
|
import com.dsh.guns.modular.system.service.IUserService;
|
import com.dsh.guns.modular.system.service.TOperatorCityService;
|
import com.dsh.guns.modular.system.service.TOperatorService;
|
import com.dsh.guns.modular.system.util.ResultUtil;
|
import io.swagger.models.auth.In;
|
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 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<TCity> list = cityService.list(new LambdaQueryWrapper<TCity>().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<TCity> provinceList = cityService.list(new LambdaQueryWrapper<TCity>().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<TOperatorCity> list = operatorCityService.list(new QueryWrapper<TOperatorCity>().eq("operatorId", id).eq("pid",0));
|
List<OperatorCityVO> result = new ArrayList<>();
|
|
for (TOperatorCity tOperatorCity : list) {
|
// 拿到省下面的所有市
|
List<TOperatorCity> cities= operatorCityService.list(new QueryWrapper<TOperatorCity>().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<Map<String,Object>> page = new PageFactory<Map<String,Object>>().defaultPage();
|
List<Map<String,Object>> list = operatorService.listAll(page,userName,phone,type);
|
page.setRecords(list);
|
return super.packForBT(page);
|
}
|
|
/**
|
* 批量重置密码
|
* @return
|
*/
|
@RequestMapping(value = "/pwd")
|
@ResponseBody
|
public Object pwd(@RequestBody OperatorRestPwd pwd ) {
|
try {
|
List<TOperator> list = operatorService.list(new QueryWrapper<TOperator>().in("id",pwd.getIds()));
|
List<Integer> userIds = list.stream()
|
.map(TOperator::getUserId)
|
.collect(Collectors.toList());
|
String a123456 = SecureUtil.md5("123456");
|
List<User> users = userService.list(new QueryWrapper<User>().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<User>().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);
|
userService.save(user);
|
TOperator data = new TOperator();
|
data.setUserId(user.getId());
|
data.setName(name);
|
data.setType(type);
|
data.setStatus(1);
|
data.setState(1);
|
operatorService.save(data);
|
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<TOperatorCity>()
|
.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<User>().eq("name", name).eq("phone", phone));
|
if (one!=null){
|
return ResultUtil.error("当前管理员名称和电话已存在!");
|
}
|
operatorCityService.remove(new QueryWrapper<TOperatorCity>().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<TOperatorCity>()
|
.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("添加成功");
|
}
|
}
|