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.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.dsh.course.feignClient.account.AppUserClient;
|
import com.dsh.course.feignClient.account.CityManagerClient;
|
import com.dsh.course.feignClient.account.StoreStaffClient;
|
import com.dsh.course.feignClient.account.StudentClient;
|
import com.dsh.course.feignClient.account.model.*;
|
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.competition.CompetitionClient;
|
import com.dsh.course.feignClient.competition.model.Competition;
|
import com.dsh.course.feignClient.competition.model.ListQuery;
|
import com.dsh.course.feignClient.course.CoursePackageClient;
|
import com.dsh.course.feignClient.other.BallClient;
|
import com.dsh.course.feignClient.other.StoreClient;
|
import com.dsh.course.feignClient.other.model.SiteChangeStateVO;
|
import com.dsh.guns.config.UserExt;
|
import com.dsh.guns.modular.system.controller.util.MD5;
|
import com.dsh.guns.modular.system.model.*;
|
import com.dsh.guns.modular.system.service.*;
|
import com.dsh.guns.modular.system.util.ResultUtil;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.ui.Model;
|
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import java.text.SimpleDateFormat;
|
import java.util.ArrayList;
|
import java.util.HashSet;
|
import java.util.List;
|
import java.util.Set;
|
import java.util.stream.Collectors;
|
|
/**
|
* 用户管理控制器
|
*/
|
@Controller
|
@RequestMapping("/appUser")
|
public class TAppUserController {
|
private String PREFIX = "/system/appUser/";
|
@Autowired
|
private IUserService userService;
|
@Autowired
|
private StoreClient storeClient;
|
@Autowired
|
private BodySideAppointmentClient bodySideAppointmentClient;
|
@Autowired
|
private CityManagerClient cityManagerClient;
|
@Autowired
|
private StoreStaffClient storeStaffClient;
|
@Autowired
|
private AppUserClient appUserClient;
|
@Autowired
|
private ICityService cityService;
|
@Autowired
|
private IRoleService roleService;
|
@Autowired
|
private StudentClient studentClient;
|
@Autowired
|
private IStoreService storeService;
|
@Autowired
|
private CompetitionClient competitionClient;
|
@Autowired
|
private ISiteBookingService siteBookingService;
|
@Autowired
|
private CoursePackageClient coursePackageClient;
|
@Autowired
|
private BallClient ballClient;
|
|
/**
|
* 跳转体测预约管理首页
|
*/
|
@RequestMapping("")
|
public String index(Model model) {
|
Integer roleType = UserExt.getUser().getObjectType();
|
List<TCity> list = cityService.list(new LambdaQueryWrapper<TCity>().eq(TCity::getParentId, 0));
|
List<Role> deptid = roleService.list(new QueryWrapper<Role>().eq("deptid", 2));
|
model.addAttribute("roleType",roleType);
|
model.addAttribute("sales",deptid);
|
model.addAttribute("list",list);
|
return PREFIX + "TAppUser.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));
|
List<User> sales = userService.list(new QueryWrapper<User>().eq("deptid", 2));
|
if(UserExt.getUser().getObjectType()==3){
|
sales = userService.list(new QueryWrapper<User>().eq("deptid", 2).eq("objectType",3).eq("objectId",UserExt.getUser().getObjectId()));
|
}
|
model.addAttribute("list",list);
|
model.addAttribute("roleType",roleType);
|
model.addAttribute("sales",sales);
|
return PREFIX + "TAppUser_add.html";
|
}
|
|
|
/**
|
* 跳转体测预约管理添加页面
|
*/
|
@RequestMapping("/addStudent/{appUserId}")
|
public String addStudent(Model model,@PathVariable("appUserId") Integer appUserId) {
|
Integer roleType = UserExt.getUser().getObjectType();
|
TAppUser tAppUser = appUserClient.queryById(appUserId);
|
model.addAttribute("data",tAppUser);
|
model.addAttribute("name",tAppUser.getName());
|
return PREFIX + "TAppUser_addStudent.html";
|
}
|
/**
|
* 跳转体测预约管理编辑页面
|
* @param type 1 = 用户管理编辑 2 = 用户管理详情
|
*/
|
@RequestMapping("/update/{id}/{type}")
|
public String update(Model model,@PathVariable("id") Integer id,@PathVariable("type") Integer type) {
|
Integer roleType = UserExt.getUser().getObjectType();
|
TAppUser data = appUserClient.queryById(id);
|
List<TCity> list = cityService.list(new LambdaQueryWrapper<TCity>().eq(TCity::getParentId, 0));
|
String province = data.getProvince();
|
TCity province1 = cityService.getOne(new QueryWrapper<TCity>().eq("name", data.getProvince()));
|
|
if (province1!=null){
|
List<TCity> city = cityService.list(new LambdaQueryWrapper<TCity>().eq(TCity::getParentId, province1.getId()));
|
model.addAttribute("city",city);
|
|
}
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
if (data.getBirthday()!=null){
|
String format1 = format.format(data.getBirthday());
|
model.addAttribute("birthday",format1);
|
}
|
List<User> sales = userService.list(new QueryWrapper<User>().eq("deptid", 2));
|
model.addAttribute("list",list);
|
model.addAttribute("roleType",roleType);
|
model.addAttribute("sales",sales);
|
model.addAttribute("data",data);
|
|
model.addAttribute("type",type);
|
model.addAttribute("isVip",data.getIsVip());
|
if (data.getVipEndTime()!=null){
|
SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");
|
String format3 = format2.format(data.getVipEndTime());
|
model.addAttribute("vipEndTime",format3);
|
}else {
|
model.addAttribute("vipEndTime","");
|
|
}
|
if (data.getViplevelId()!=null){
|
|
model.addAttribute("level","黄金");
|
}
|
model.addAttribute("level","黄金");
|
List<TStudent> tStudents = studentClient.queryStudentList(data.getId());
|
model.addAttribute("students",tStudents);
|
return PREFIX + "TAppUser_edit.html";
|
}
|
|
/**
|
* 获取所有用户信息
|
* @return
|
*/
|
@RequestMapping("/listAll")
|
@ResponseBody
|
public List<QueryAppUserVO> listAll(String province, String city,String name,
|
String phone,Integer isVip, String salesmanUserName){
|
Integer objectType = UserExt.getUser().getObjectType();
|
Integer objectId = UserExt.getUser().getObjectId();
|
|
QueryAppUser queryAppUser = new QueryAppUser();
|
queryAppUser.setProvince(province);
|
queryAppUser.setCity(city);
|
queryAppUser.setName(name);
|
queryAppUser.setPhone(phone);
|
queryAppUser.setIsVip(isVip);
|
// queryAppUser.setSalesmanUser(salesmanUserName);
|
if (province!=null && (!province.equals(""))){
|
TCity p = cityService.getOne(new QueryWrapper<TCity>().eq("code", province));
|
queryAppUser.setProvince(p.getName());
|
}
|
if (city!=null && (!city.equals(""))){
|
TCity c = cityService.getOne(new QueryWrapper<TCity>().eq("code", city));
|
queryAppUser.setCity(c.getName());
|
}
|
queryAppUser.setInsertType(objectType);
|
queryAppUser.setTypeId(UserExt.getUser().getObjectId());
|
if (objectType == 2){
|
// 获取运营商下的所有门店id集合
|
List<Integer> storeIds = storeService.list(new QueryWrapper<TStore>().eq("operatorId", objectId))
|
.stream().map(TStore::getId).collect(Collectors.toList());
|
// 根据门店id集合查询 属于该运营商下的门店举办的赛事
|
ListQuery listQuery = new ListQuery();
|
listQuery.setIds(storeIds);
|
// 通过门店ids 获取赛事的支付记录 获取到用户的ids
|
List<Integer> list = competitionClient.getUserIds(listQuery);
|
|
// 获取场地预约记录 拿到用户ids
|
List<Integer> siteUsers = siteBookingService.list(new QueryWrapper<SiteBooking>().in("storeId", storeIds))
|
.stream().map(SiteBooking::getAppUserId).collect(Collectors.toList());
|
// 获取课程购买记录 拿到用户ids
|
List<Integer> cpUsers = coursePackageClient.getCoursePackageByStoreIds(storeIds);
|
// 获取游戏记录 拿到用户ids
|
List<Integer> gameUsers = ballClient.getGameByStoreIds(storeIds);
|
// 用户ids
|
List<Integer> users = new ArrayList<>();
|
users.addAll(list);
|
users.addAll(siteUsers);
|
users.addAll(cpUsers);
|
users.addAll(gameUsers);
|
// 去重后的用户id
|
List<Integer> collect = users.stream().distinct().collect(Collectors.toList());
|
queryAppUser.setUserIds(collect);
|
// List<QueryAppUserVO> queryAppUserVOS1 = new ArrayList<>();
|
// // 根据用户消费记录 去查询用户ids
|
// for (Integer integer : collect) {
|
// if (!collect1.contains(integer)){
|
// TAppUser tAppUser = appUserClient.queryAppUser1(integer);
|
// QueryAppUserVO queryAppUserVO = new QueryAppUserVO();
|
// BeanUtils.copyProperties(tAppUser,queryAppUserVO);
|
// queryAppUserVOS.add(queryAppUserVO);
|
// }
|
// }
|
}
|
List<QueryAppUserVO> queryAppUserVOS = appUserClient.listAll(queryAppUser);
|
List<Integer> collect1 = queryAppUserVOS.stream().map(QueryAppUserVO::getId).collect(Collectors.toList());
|
for (QueryAppUserVO queryAppUserVO : queryAppUserVOS) {
|
if (queryAppUserVO.getSalesmanUserId()!=null){
|
User byId = userService.getById(queryAppUserVO.getSalesmanUserId());
|
if (byId!=null){
|
queryAppUserVO.setSalesmanUserName(byId.getName());
|
}
|
}
|
}
|
if (salesmanUserName!=null && (!salesmanUserName.equals(""))){
|
List<QueryAppUserVO> result = new ArrayList<>();
|
List<User> sales = userService.list(new QueryWrapper<User>().like("name", salesmanUserName));
|
for (QueryAppUserVO queryAppUserVO : queryAppUserVOS) {
|
if (queryAppUserVO.getSalesmanUserId()!=null){
|
for (User sale : sales) {
|
if (queryAppUserVO.getSalesmanUserId().equals(sale.getId())){
|
result.add(queryAppUserVO);
|
}
|
}
|
}
|
}
|
return result;
|
}
|
return queryAppUserVOS;
|
}
|
/**
|
* 新增用户信息
|
* @return
|
*/
|
@RequestMapping("/addAppUser")
|
@ResponseBody
|
public Object addAppUser(@RequestBody TAppUser appUser){
|
Integer objectType = UserExt.getUser().getObjectType();
|
appUser.setPassword(MD5.md5("111111"));
|
appUser.setProvince("");
|
appUser.setProvinceCode("");
|
appUser.setCity("");
|
appUser.setCityCode("");
|
appUser.setInsertType(objectType);
|
appUser.setAddUserId(UserExt.getUser().getObjectId());
|
Object o = appUserClient.addAppUser1(appUser);
|
return o;
|
}
|
|
/**
|
* 新增学员
|
* @return
|
*/
|
@RequestMapping("/addAppUserStudent")
|
@ResponseBody
|
public Object addAppUser(@RequestBody TStudent student){
|
Double height = student.getHeight();
|
Double weight = student.getWeight();
|
double v = weight / (height * height);
|
student.setBmi(v);
|
return studentClient.addStudent(student);
|
}
|
/**
|
* 上/下架 1为上架 2为下架 3为删除
|
*
|
* @return
|
*/
|
@RequestMapping("/changeState")
|
@ResponseBody
|
public Object changeState(@RequestBody AdvertisementChangeStateDTO dto){
|
appUserClient.changeState(dto);
|
return ResultUtil.success();
|
}
|
|
}
|