package com.stylefeng.guns.modular.system.controller.general;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.stylefeng.guns.core.base.controller.BaseController;
|
import com.stylefeng.guns.core.log.LogObjectHolder;
|
import com.stylefeng.guns.modular.system.controller.util.ExcelUtil;
|
import com.stylefeng.guns.modular.system.enums.CouponStatusEnum;
|
import com.stylefeng.guns.modular.system.exports.TAppUserExceptionExport;
|
import com.stylefeng.guns.modular.system.model.TAppUser;
|
import com.stylefeng.guns.modular.system.model.TCoupon;
|
import com.stylefeng.guns.modular.system.service.ITAppUserService;
|
import com.stylefeng.guns.modular.system.service.ITCouponService;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
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.*;
|
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.OutputStream;
|
import java.text.DateFormat;
|
import java.text.SimpleDateFormat;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Objects;
|
import java.util.stream.Collectors;
|
|
/**
|
* 控制器
|
*
|
* @author fengshuonan
|
* @Date 2023-02-14 08:55:42
|
*/
|
@Controller
|
@RequestMapping("/tAppUser")
|
public class TAppUserController extends BaseController {
|
|
private String PREFIX = "/system/tAppUser/";
|
|
@Autowired
|
private ITAppUserService tAppUserService;
|
@Autowired
|
private ITCouponService tCouponService;
|
|
/**
|
* 跳转到首页
|
*/
|
@RequestMapping("")
|
public String index() {
|
return PREFIX + "tAppUser.html";
|
}
|
|
/**
|
* 跳转到添加
|
*/
|
@RequestMapping("/tAppUser_add")
|
public String tAppUserAdd() {
|
return PREFIX + "tAppUser_add.html";
|
}
|
|
/**
|
* 赠送优惠券查询页面
|
* @return
|
*/
|
@RequestMapping("/sendCoupon")
|
public String sendCoupon( String userIds,Model model) {
|
model.addAttribute("userIds",userIds);
|
return PREFIX + "tCoupon.html";
|
}
|
|
/**
|
* 赠送优惠券查询页面
|
* @return
|
*/
|
@RequestMapping("/sendCouponException")
|
public String sendCouponException( String userIds,Model model) {
|
model.addAttribute("userIds",userIds);
|
return PREFIX + "tCouponException.html";
|
}
|
|
/**
|
* 跳转异常用户页面
|
* @return
|
*/
|
@RequestMapping("/tAppUser_exception")
|
public String tAppUserException(Integer isException,Model model) {
|
isException = 2;
|
model.addAttribute("isException",isException);
|
return PREFIX + "tAppUserException.html";
|
}
|
|
/**
|
* 跳转冻结页面
|
* @return
|
*/
|
@RequestMapping("/tAppUser_start_and_stop")
|
public String tAppUserStartAndStop( Integer id,
|
Model model) {
|
TAppUser tAppUser = tAppUserService.selectById(id);
|
|
model.addAttribute("id",id);
|
model.addAttribute("status",tAppUser.getStatus());
|
return PREFIX + "tAppUserStartAndStop.html";
|
}
|
|
/**
|
* 异常页面跳转冻结页面
|
* @return
|
*/
|
@RequestMapping("/tAppUserException_start_and_stop")
|
public String tAppUserExceptionStartAndStop( Integer id,
|
Model model) {
|
TAppUser tAppUser = tAppUserService.selectById(id);
|
|
model.addAttribute("id",id);
|
model.addAttribute("status",tAppUser.getStatus());
|
return PREFIX + "tAppUserStartAndStopException.html";
|
}
|
|
/**
|
* 跳转到修改
|
*/
|
@RequestMapping("/tAppUser_update/{tAppUserId}")
|
public String tAppUserUpdate(@PathVariable Integer tAppUserId, Model model) {
|
TAppUser tAppUser = tAppUserService.selectById(tAppUserId);
|
model.addAttribute("item",tAppUser);
|
LogObjectHolder.me().set(tAppUser);
|
return PREFIX + "tAppUser_edit.html";
|
}
|
|
/**
|
* 跳转详情页面
|
*/
|
@RequestMapping("/userDetail")
|
public String userDetail(Integer tAppUserId, Model model) {
|
tAppUserService.detail(tAppUserId,model);
|
|
return PREFIX + "tAppUserDetail.html";
|
}
|
|
/**
|
* 异常页面跳转详情页面
|
*/
|
@RequestMapping("/userDetailException")
|
public String userDetailException(Integer tAppUserId, Model model) {
|
tAppUserService.detail(tAppUserId,model);
|
return PREFIX + "tAppUserDetailException.html";
|
}
|
|
@ApiOperation(value = "异常用户页面列表")
|
@RequestMapping("/exceptionUserList")
|
@ResponseBody
|
public Object exceptionUserList(String createTime,
|
String nickname,
|
String phone,
|
Integer id,
|
Integer status) {
|
|
EntityWrapper<TAppUser> wrapper = tAppUserService.getUserListWrapper(createTime,nickname,phone,id,status);
|
// 是否异常
|
wrapper.eq("is_exception",2);
|
return tAppUserService.selectList(wrapper);
|
}
|
|
|
/**
|
* 获取列表
|
*/
|
@ApiOperation(value = "用户页面列表")
|
@RequestMapping(value = "/list")
|
@ResponseBody
|
public Object getList(String createTime,
|
String nickname,
|
String phone,
|
Integer id,
|
Integer status) {
|
EntityWrapper<TAppUser> wrapper = tAppUserService.getUserListWrapper(createTime,nickname,phone,id,status);
|
return tAppUserService.selectList(wrapper);
|
}
|
|
/**
|
* 获取列表
|
*/
|
@RequestMapping(value = "/list-back")
|
@ResponseBody
|
public Object list(String condition) {
|
return tAppUserService.selectList(null);
|
}
|
|
/**
|
* 新增
|
*/
|
@RequestMapping(value = "/add")
|
@ResponseBody
|
public Object add(TAppUser tAppUser) {
|
tAppUserService.insert(tAppUser);
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 删除
|
*/
|
@RequestMapping(value = "/delete")
|
@ResponseBody
|
public Object delete(@RequestParam Integer tAppUserId) {
|
tAppUserService.deleteById(tAppUserId);
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 修改用户状态
|
*/
|
@RequestMapping(value = "/update-status")
|
@ResponseBody
|
public Object updateStatus(Integer id,
|
Integer status,
|
String remark) {
|
TAppUser tAppUser = tAppUserService.selectById(id);
|
if(1 == status){
|
tAppUser.setStatus(2);
|
}
|
if(2 == status){
|
tAppUser.setStatus(1);
|
}
|
tAppUser.setRemark(remark);
|
tAppUserService.updateById(tAppUser);
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 修改
|
*/
|
@RequestMapping(value = "/update")
|
@ResponseBody
|
public Object update(TAppUser tAppUser) {
|
tAppUserService.updateById(tAppUser);
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 详情
|
*/
|
@RequestMapping(value = "/detail/{tAppUserId}")
|
@ResponseBody
|
public Object detail(@PathVariable("tAppUserId") Integer tAppUserId) {
|
return tAppUserService.selectById(tAppUserId);
|
}
|
|
@ApiOperation(value = "导出用户列表",notes="导出用户列表")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
|
})
|
@RequestMapping(value = "/export-userInfo")
|
@ResponseBody
|
public void exportUserInfo(String createTime,
|
String nickname,
|
String phone,
|
Integer id,
|
Integer status, HttpServletResponse response) {
|
try {
|
Date date = new Date();
|
DateFormat format = new SimpleDateFormat("yyyyMMdd");
|
String time1 = format.format(date);
|
String fileName = "UserInfo"+time1+".xls";
|
String[] title = new String[] {"用户ID","用户昵称","手机号","性别","头像","微信openid",
|
"微信unionid","紧急联系人","紧急联系电话","账户余额","用户标签id","状态","添加时间"};
|
EntityWrapper<TAppUser> wrapper = tAppUserService.getUserListWrapper(createTime,nickname,phone,id,status);
|
// 是否异常
|
List<TAppUser> list = tAppUserService.selectList(wrapper);
|
|
String[][] values = new String[list.size()][];
|
for (int i = 0; i < list.size(); i++) {
|
TAppUser d = list.get(i);
|
values[i] = new String[title.length];
|
values[i][0] = d.getId().toString();
|
values[i][1] = d.getNickname();
|
values[i][2] = d.getPhone();
|
Integer sex = d.getSex();
|
if(1 == sex){
|
values[i][3] = "男";
|
}else if(2 == sex){
|
values[i][3] = "女";
|
}else {
|
values[i][3] = "未知";
|
}
|
values[i][4] = d.getAvatar();
|
values[i][5] = d.getOpenid();
|
values[i][6] = d.getUnionid();
|
values[i][7] = d.getEmergencyContact();
|
values[i][8] = d.getEmergencyPhone();
|
values[i][9] = d.getAccountBalance().toString();
|
values[i][10] = d.getUserTagId().toString();
|
Integer status1 = d.getStatus();
|
if(1 == status1){
|
values[i][11] = "正常";
|
}else if(2 == status1){
|
values[i][11] = "冻结";
|
}else {
|
values[i][11] = "删除";
|
}
|
values[i][12] = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(d.getCreateTime());
|
}
|
HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook("Variance"+time1, title, values, null);
|
ExcelUtil.setResponseHeader(response, fileName);
|
OutputStream os = response.getOutputStream();
|
wb.write(os);
|
os.flush();
|
os.close();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
|
@ApiOperation(value = "导出异常用户列表",notes="导出异常用户列表")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
|
})
|
@RequestMapping(value = "/export-exceptionUserInfo")
|
@ResponseBody
|
public void exportExceptionUserInfo(String createTime,
|
String nickname,
|
String phone,
|
Integer id,
|
Integer status, HttpServletResponse response) {
|
try {
|
Date date = new Date();
|
DateFormat format = new SimpleDateFormat("yyyyMMdd");
|
String time1 = format.format(date);
|
String fileName = "ExceptionUserInfo"+time1+".xls";
|
String[] title = new String[] {"注册时间","用户ID","用户昵称","手机号","剩余优惠券","优惠券总数",
|
"消费次数","历史消费","最后一次消费时间","状态"};
|
EntityWrapper<TAppUser> wrapper = tAppUserService.getUserListWrapper(createTime,nickname,phone,id,status);
|
// 是否异常
|
wrapper.eq("is_exception",2);
|
List<TAppUser> list = tAppUserService.selectList(wrapper);
|
|
List<TAppUserExceptionExport> exportList = new ArrayList<>(list.size());
|
for (TAppUser tAppUser : list) {
|
TAppUserExceptionExport export = new TAppUserExceptionExport();
|
BeanUtils.copyProperties(tAppUser,export);
|
// 查询优惠券
|
List<TCoupon> tCoupons = tCouponService.selectList(new EntityWrapper<TCoupon>().eq("user_id", tAppUser.getId()));
|
// 优惠券总数
|
export.setCouponsSum(tCoupons.size());
|
tCoupons = tCoupons.stream().filter(coupon->coupon.getCouponStatus().equals(CouponStatusEnum.NOT_USED.getCode())).collect(Collectors.toList());
|
// 剩余优惠券
|
export.setRemainingCoupons(tCoupons.size());
|
// TODO 查询消费记录
|
exportList.add(export);
|
}
|
String[][] values = new String[list.size()][];
|
for (int i = 0; i < list.size(); i++) {
|
TAppUserExceptionExport d = exportList.get(i);
|
values[i] = new String[title.length];
|
values[i][0] = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(d.getCreateTime());
|
values[i][1] = d.getId().toString();
|
values[i][2] = d.getNickname();
|
values[i][3] = d.getPhone();
|
values[i][4] = d.getRemainingCoupons().toString();
|
values[i][5] = d.getCouponsSum().toString();
|
values[i][6] = d.getConsumptionTimes().toString();
|
values[i][7] = d.getHistoricalConsumption().toString();
|
if(Objects.nonNull(d.getLastConsumptionTime())){
|
values[i][8] = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(d.getLastConsumptionTime());
|
}else {
|
values[i][8] = "";
|
}
|
Integer status1 = d.getStatus();
|
if(1 == status1){
|
values[i][9] = "正常";
|
}else if(2 == status1){
|
values[i][9] = "冻结";
|
}else {
|
values[i][9] = "删除";
|
}
|
}
|
HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook("Variance"+time1, title, values, null);
|
ExcelUtil.setResponseHeader(response, fileName);
|
OutputStream os = response.getOutputStream();
|
wb.write(os);
|
os.flush();
|
os.close();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
}
|