package com.stylefeng.guns.modular.system.controller.general;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.plugins.Page;
|
import com.stylefeng.guns.core.base.controller.BaseController;
|
import com.stylefeng.guns.core.base.tips.ErrorTip;
|
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
|
import com.stylefeng.guns.core.shiro.ShiroKit;
|
import com.stylefeng.guns.core.util.*;
|
import com.stylefeng.guns.modular.system.model.TCompany;
|
import com.stylefeng.guns.modular.system.model.TPubTransactionDetails;
|
import com.stylefeng.guns.modular.system.model.TUser;
|
import com.stylefeng.guns.modular.system.service.ITCompanyService;
|
import com.stylefeng.guns.modular.system.service.ITPubTransactionDetailsService;
|
import com.stylefeng.guns.modular.system.service.ITUserService;
|
import com.stylefeng.guns.modular.system.util.HttpRequestUtil;
|
import com.stylefeng.guns.modular.system.util.PushURL;
|
import com.stylefeng.guns.modular.system.util.RedisUtil;
|
import org.apache.commons.lang.time.DateUtils;
|
import org.apache.poi.ss.usermodel.Cell;
|
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.ss.usermodel.Sheet;
|
import org.apache.poi.ss.usermodel.Workbook;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.ui.Model;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import java.math.BigDecimal;
|
import java.text.DateFormat;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
|
/**
|
* 用户管理控制器
|
*
|
* @author fengshuonan
|
* @Date 2020-06-01 15:47:58
|
*/
|
@Controller
|
@RequestMapping("/tUser")
|
public class TUserController extends BaseController {
|
|
private String PREFIX = "/system/tUser/";
|
|
@Autowired
|
private ITUserService tUserService;
|
|
@Autowired
|
private ITPubTransactionDetailsService pubTransactionDetailsService;
|
|
/**
|
* 跳转到用户管理首页
|
*/
|
@RequestMapping("")
|
public String index() {
|
return PREFIX + "tUser.html";
|
}
|
|
/**
|
* 跳转到修改用户管理
|
*/
|
@RequestMapping("/tUser_userDetail/{tUserId}")
|
public String tUser_userDetail(@PathVariable Integer tUserId, Model model) {
|
Map<String,Object> tUser = tUserService.getUserDetailById(tUserId);
|
model.addAttribute("item",tUser);
|
return PREFIX + "tUser_userDetail.html";
|
}
|
|
/**
|
* 跳转到修改用户余额页面
|
*/
|
@RequestMapping("/tUser_updateBalance/{tUserId}")
|
public String tUser_updateBalance(@PathVariable Integer tUserId, Model model) {
|
model.addAttribute("tUserId",tUserId);
|
return PREFIX + "tUser_updateBalance.html";
|
}
|
|
/**
|
* 跳转到修改用户密码页面
|
*/
|
@RequestMapping("/tUser_updatePassword/{tUserId}")
|
public String tUser_updatePassword(@PathVariable Integer tUserId, Model model) {
|
model.addAttribute("tUserId",tUserId);
|
return PREFIX + "tUser_updatePassword.html";
|
}
|
|
/**
|
* 跳转到邀请信息页面
|
* @author yxh
|
* @date 2021/3/25 15:11
|
* @param tUserId
|
* @param model
|
*/
|
@RequestMapping("/inviteInfo/{tUserId}")
|
public String inviteInfo(@PathVariable Integer tUserId,Model model){
|
model.addAttribute("tUserId",tUserId);
|
return PREFIX+"tUser_inviteInfo.html";
|
}
|
|
/**
|
* 用户邀请信息列表
|
* @author yxh
|
* @date 2021/3/25 15:31
|
* @param tUserId
|
* @return java.lang.Object
|
*/
|
@RequestMapping(value = "/InviteInfoList")
|
@ResponseBody
|
public Object inviteInfolist(Integer tUserId,String time) {
|
String start = null;
|
String end = null;
|
if(ToolUtil.isNotEmpty(time)){
|
start = time.split(" - ")[0];
|
end = time.split(" - ")[1];
|
}
|
Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
|
page.setRecords(tUserService.getUserInviteList(page,tUserId,start, end));
|
return super.packForBT(page);
|
}
|
|
/**
|
* 跳转到修改用户状态页面
|
*/
|
@RequestMapping("/tUser_optUser/{tUserId}/{optType}")
|
public String tUser_optUser(@PathVariable Integer tUserId,@PathVariable Integer optType, Model model) {
|
model.addAttribute("tUserId",tUserId);
|
model.addAttribute("optType",optType);
|
return PREFIX + "tUser_optUser.html";
|
}
|
|
/**
|
* 获取用户管理列表
|
*/
|
@RequestMapping(value = "/list")
|
@ResponseBody
|
public Object list(String insertTime,
|
String id,
|
String nickName,
|
String phone,
|
Integer isAuth,
|
Integer state,String companyName) {
|
String beginTime = null;
|
String endTime = null;
|
if (SinataUtil.isNotEmpty(insertTime)){
|
String[] timeArray = insertTime.split(" - ");
|
beginTime = timeArray[0];
|
endTime = timeArray[1];
|
}
|
Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
|
page.setRecords(tUserService.getUserList(page,beginTime,endTime,ShiroKit.getUser().getRoleType(),ShiroKit.getUser().getObjectId(),isAuth,state,id,nickName,phone,companyName));
|
return super.packForBT(page);
|
}
|
|
/**
|
* 修改余额操作
|
*/
|
@RequestMapping(value = "/updateBalance")
|
@ResponseBody
|
public Object updateBalance(@RequestParam Integer tUserId,
|
@RequestParam Integer updateType,
|
@RequestParam BigDecimal money) {
|
TUser tUser = tUserService.selectById(tUserId);
|
if (SinataUtil.isNotEmpty(tUser)){
|
if (1 == updateType.intValue()){ //增加
|
tUser.setBalance(tUser.getBalance().add(money));
|
}else if (2 == updateType.intValue()){ //减少
|
if((tUser.getBalance().subtract(money)).compareTo(new BigDecimal(0)) == -1){
|
tUser.setBalance(new BigDecimal(0));
|
}else{
|
tUser.setBalance(tUser.getBalance().subtract(money));
|
}
|
}
|
tUser.setUpdateTime(new Date());
|
tUser.setUpdateUser(ShiroKit.getUser().getId());
|
tUserService.updateById(tUser);
|
//插入交易明细记录
|
TPubTransactionDetails pubTransactionDetails=new TPubTransactionDetails();
|
pubTransactionDetails.setInsertTime(new Date());
|
pubTransactionDetails.setUserId(tUserId);
|
pubTransactionDetails.setRemark("修改用户余额插入");
|
pubTransactionDetails.setMoney(money);
|
pubTransactionDetails.setState(updateType.intValue());
|
pubTransactionDetails.setType(1);//金额
|
pubTransactionDetails.setUserType(1);//用户
|
pubTransactionDetails.setOrderType(5);
|
pubTransactionDetailsService.insert(pubTransactionDetails);
|
}
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 修改密码操作
|
*/
|
@RequestMapping(value = "/updatePassword")
|
@ResponseBody
|
public Object updatePassword(@RequestParam Integer tUserId,
|
@RequestParam String password) {
|
TUser tUser = tUserService.selectById(tUserId);
|
if (SinataUtil.isNotEmpty(tUser)){
|
// tUser.setPassWord(MD5Util.encrypt(password));
|
tUser.setPassWord(ShiroKit.md5(password, "&a.s"));
|
tUser.setUpdateTime(new Date());
|
tUser.setUpdateUser(ShiroKit.getUser().getId());
|
tUserService.updateById(tUser);
|
}
|
return SUCCESS_TIP;
|
}
|
|
@Autowired
|
private RedisUtil redisUtil;
|
/**
|
* 操作用户
|
*/
|
@RequestMapping(value = "/optUser")
|
@ResponseBody
|
public Object optUser(@RequestParam Integer tUserId,@RequestParam Integer optType,@RequestParam String remark) {
|
TUser tUser = tUserService.selectById(tUserId);
|
if (SinataUtil.isNotEmpty(tUser)){
|
if (1 == optType.intValue()){ //冻结
|
tUser.setState(2);
|
tUser.setRemark(remark);
|
String key = redisUtil.getValue("USER_" + tUser.getPhone());
|
redisUtil.remove(key);//删除个人信息数据
|
redisUtil.remove("USER_" + tUser.getPhone());//删除后台冻结相关缓存
|
redisUtil.remove("USER_" + tUserId);//清除存储的token
|
//增加推送
|
Map<String,String> map = new HashMap<>();
|
map.put("uid", tUser.getId().toString());
|
String result = HttpRequestUtil.postRequest(PushURL.freeze_user_url, map);
|
System.out.println("冻结用户:【userId="+tUser.getId().toString()+"】,调用接口:"+result);
|
|
}else if (2 == optType.intValue()){ //解冻
|
tUser.setState(1);
|
tUser.setRemark(remark);
|
}
|
tUser.setUpdateTime(new Date());
|
tUser.setUpdateUser(ShiroKit.getUser().getId());
|
tUserService.updateById(tUser);
|
}
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 下载模板
|
* @param request
|
* @param response
|
*/
|
@RequestMapping(value = "/uploadUserModel")
|
public void uploadUserModel(HttpServletRequest request, HttpServletResponse response) {
|
// 表格数据【封装】
|
List<List<String>> dataList = new ArrayList<List<String>>();
|
|
// 首行【封装】
|
List<String> shellList = new ArrayList<String>();
|
shellList.add("昵称");
|
shellList.add("手机号");
|
shellList.add("生日[例如:1995-09-09]");
|
shellList.add("性别[男/女]");
|
shellList.add("紧急联系人[选填]");
|
shellList.add("紧急联系电话[选填]");
|
shellList.add("是否实名认证[是/否]");
|
shellList.add("真实姓名");
|
shellList.add("身份证号");
|
shellList.add("余额");
|
shellList.add("密码[6-18个长度]");
|
dataList.add(shellList);
|
|
try {
|
// 调用工具类进行导出
|
ExcelExportUtil.easySheet("平台导入用户模板"+DateUtil.formatDate(new Date(), "YYYYMMddHHmmss"), "平台导入用户模板", dataList, request, response);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
/**
|
* 导入操作
|
* @param request
|
* @return
|
*/
|
@RequestMapping(value="/exportUser",method = RequestMethod.POST)
|
@ResponseBody
|
public Object exportUser(HttpServletRequest request){
|
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
MultipartFile file = (MultipartFile) multipartRequest.getFile("myfile");
|
try {
|
//定时五秒后执行
|
/*Map<String,Object> maps=new HashMap<>();
|
Workbook book = WoUtil.ImportFile(file);
|
maps.put("book",book);
|
QuartzManager.addJob(AddContract.class, (AddContract.name+new Date().getTime()).toUpperCase(), TimeJobType.ADMIN,DateUtil.getDate_strYMdHms(new Date().getTime() + 1*1000) , maps);*/
|
|
Workbook book = WoUtil.ImportFile(file);
|
Sheet sh = book.getSheetAt(0); //获取到第一个表
|
for (int i = 1; i <= sh.getLastRowNum(); i++) {
|
Row row = sh.getRow(i);
|
|
Cell cell0 = row.getCell(0); //昵称
|
String nickName = null;
|
if (SinataUtil.isNotEmpty(cell0)){
|
nickName = String.valueOf(cell0.getStringCellValue()).trim();
|
}
|
|
Cell cell1 = row.getCell(1); //手机号
|
String phone = null;
|
if (SinataUtil.isNotEmpty(cell1)){
|
phone = String.valueOf(cell1.getStringCellValue()).trim();
|
}
|
|
Cell cell2 = row.getCell(2); //生日[例如:1995-09-09]
|
String birthday = null;
|
if (SinataUtil.isNotEmpty(cell2)){
|
birthday = String.valueOf(cell2.getStringCellValue()).trim();
|
}
|
|
Cell cell3 = row.getCell(3); //性别[男/女]
|
String sex = null;
|
if (SinataUtil.isNotEmpty(cell3)){
|
sex = String.valueOf(cell3.getStringCellValue()).trim();
|
}
|
|
Cell cell4 = row.getCell(4); //紧急联系人[选填]
|
String emergencyContact = null;
|
if (SinataUtil.isNotEmpty(cell4)){
|
emergencyContact = String.valueOf(cell4.getStringCellValue()).trim();
|
}
|
|
Cell cell5 = row.getCell(5); //紧急联系电话[选填]
|
String emergencyContactNumber = null;
|
if (SinataUtil.isNotEmpty(cell5)){
|
emergencyContactNumber = String.valueOf(cell5.getStringCellValue()).trim();
|
}
|
|
Cell cell6 = row.getCell(6); //是否实名认证[是/否]
|
String isAuth = null;
|
if (SinataUtil.isNotEmpty(cell6)){
|
isAuth = String.valueOf(cell6.getStringCellValue()).trim();
|
}
|
|
Cell cell7 = row.getCell(7); //真实姓名
|
String name = null;
|
if (SinataUtil.isNotEmpty(cell7)){
|
name = String.valueOf(cell7.getStringCellValue()).trim();
|
}
|
|
Cell cell8 = row.getCell(8); //身份证号
|
String idCard = null;
|
if (SinataUtil.isNotEmpty(cell8)){
|
idCard = String.valueOf(cell8.getStringCellValue()).trim();
|
}
|
|
Cell cell9 = row.getCell(9); //余额
|
String balance = null;
|
if (SinataUtil.isNotEmpty(cell9)){
|
balance = String.valueOf(cell9.getStringCellValue()).trim();
|
}
|
|
Cell cell10 = row.getCell(10); //密码
|
String passWord = null;
|
if (SinataUtil.isNotEmpty(cell10)){
|
passWord = String.valueOf(cell10.getStringCellValue()).trim();
|
}
|
|
if (SinataUtil.isEmpty(nickName) || SinataUtil.isEmpty(phone) || SinataUtil.isEmpty(birthday)
|
|| SinataUtil.isEmpty(sex) || SinataUtil.isEmpty(isAuth) || SinataUtil.isEmpty(balance)
|
|| SinataUtil.isEmpty(passWord) ){
|
return new ErrorTip(500, "单元格不能为空");
|
}else{
|
int count = tUserService.selectCount(new EntityWrapper<TUser>().eq("phone", phone).notIn("flag", 3));
|
if (count > 0){
|
return new ErrorTip(500, "手机号已存在,请重新填写");
|
}
|
//判断性别
|
if (!sex.equals("男") && !sex.equals("女")){
|
return new ErrorTip(500, "性别内容不正确");
|
}
|
//判断是否实名认证
|
if (!isAuth.equals("是") && !isAuth.equals("否")){
|
return new ErrorTip(500, "是否实名认证内容不正确");
|
}
|
if ("是".equals(isAuth)){
|
//判断紧急联系电话
|
if (SinataUtil.isNotEmpty(emergencyContactNumber)){
|
if (!isPhone(emergencyContactNumber)){
|
return new ErrorTip(500, "紧急联系电话格式不正确");
|
}
|
}
|
}
|
//判断生日格式
|
try {
|
if (!isValidDate(birthday)) {
|
birthday = importByExcelForDate(birthday);
|
}
|
}catch (Exception e){
|
return new ErrorTip(500, "年检到期时间格式不正确");
|
}
|
//判断手机号
|
if (!isPhone(phone)){
|
return new ErrorTip(500, "手机号格式不正确");
|
}
|
//判断余额
|
if (!isDouble(balance)){
|
return new ErrorTip(500, "余额格式不正确");
|
}
|
//判断登录密码
|
if (!isPassword(passWord)){
|
return new ErrorTip(500, "登录密码格式不正确");
|
}
|
TUser user = new TUser();
|
TCompany company = itCompanyService.selectOne(new EntityWrapper<TCompany>().eq("type", 1).notIn("flag", 3).last(" limit 1"));
|
user.setCompanyId(company.getId());
|
user.setPhone(phone);
|
user.setNickName(nickName);
|
user.setBirthday(DateUtil.parseDate(birthday));
|
if (sex.equals("男")){
|
user.setSex(1);
|
}else if (sex.equals("女")){
|
user.setSex(2);
|
}
|
user.setEmergencyContact(emergencyContact);
|
user.setEmergencyContactNumber(emergencyContactNumber);
|
if ("是".equals(isAuth)){
|
user.setIsAuth(2);
|
}else if ("否".equals(isAuth)){
|
user.setIsAuth(1);
|
}
|
user.setFirstName(name);
|
user.setIdCard(idCard);
|
user.setBalance(new BigDecimal(balance));
|
user.setPassWord(ShiroKit.md5(passWord, "&a.s"));
|
user.setState(1);
|
user.setFlag("1");
|
user.setInsertTime(new Date());
|
user.setInsertUser(ShiroKit.getUser().getId());
|
tUserService.insert(user);
|
}
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return SUCCESS_TIP;
|
}
|
|
@Autowired
|
private ITCompanyService itCompanyService;
|
|
/**
|
* 判断日期是否满足yyyy-MM-dd格式
|
* @param str
|
* @return
|
*/
|
public static boolean isValidDate(String str) {
|
boolean convertSuccess=true;
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
try {
|
format.setLenient(false);
|
format.parse(str);
|
} catch (Exception e) {
|
convertSuccess=false;
|
}
|
return convertSuccess;
|
}
|
|
|
/**
|
* 转换日期
|
* @return
|
*/
|
public static String importByExcelForDate(String value) {//value就是它的天数
|
String currentCellValue = "";
|
if(value != null && !value.equals("")){
|
Calendar calendar = new GregorianCalendar(1900,0,-1);
|
Date d = calendar.getTime();
|
Date dd = DateUtils.addDays(d,Integer.valueOf(value));
|
DateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
|
currentCellValue = formater.format(dd);
|
}
|
return currentCellValue;
|
}
|
|
/**
|
* 验证手机号格式是否正确
|
* @param str
|
* @return
|
*/
|
public static boolean isPhone(String str) {
|
try{
|
String reg = "^1\\d{10}$";
|
boolean flag = str.matches(reg);
|
return flag;
|
}catch(NumberFormatException e) {
|
System.out.println("异常:\"" + str + "\"...");
|
return false;
|
}
|
}
|
|
/**
|
* 验证密码长度是否正确
|
* @param str
|
* @return
|
*/
|
public static boolean isPassword(String str) {
|
try{
|
String reg = "^.{6,18}$";
|
boolean flag = str.matches(reg);
|
return flag;
|
}catch(NumberFormatException e) {
|
System.out.println("异常:\"" + str + "\"...");
|
return false;
|
}
|
}
|
|
/**
|
* 验证是否可以字符转为金额值
|
* @param str
|
* @return
|
*/
|
public static boolean isDouble(String str) {
|
try{
|
Double.parseDouble(str);
|
return true;
|
}catch(NumberFormatException e) {
|
System.out.println("异常:\"" + str + "\"不是数字/整数/小数...");
|
return false;
|
}
|
}
|
|
/**
|
* 导出用户信息
|
*/
|
@RequestMapping(value = "/outUser")
|
public void outUser(HttpServletRequest request, HttpServletResponse response) {
|
List<Map<String,Object>> listMap = tUserService.getUserListNoPage(ShiroKit.getUser().getRoleType(),ShiroKit.getUser().getObjectId());
|
|
// 表格数据【封装】
|
List<List<String>> dataList = new ArrayList<>();
|
|
//第一行显示【封装】
|
List<String> twoList = new ArrayList<String>();
|
twoList.add("总计:");
|
twoList.add(String.valueOf(listMap.size())+"条");
|
dataList.add(twoList);
|
|
// 列【封装】
|
List<String> shellList = new ArrayList<String>();
|
shellList.add("注册时间");
|
shellList.add("用户ID");
|
shellList.add("注册地所属分公司");
|
shellList.add("昵称");
|
shellList.add("手机号");
|
shellList.add("紧急联系人姓名");
|
shellList.add("紧急联系人电话");
|
shellList.add("是否实名认证");
|
shellList.add("历史出行次数");
|
shellList.add("历史消费");
|
shellList.add("积分");
|
shellList.add("备注");
|
shellList.add("状态");
|
dataList.add(shellList);
|
|
for (Map<String,Object> object : listMap){
|
// 详细数据列【封装】
|
shellList = new ArrayList<String>();
|
if(SinataUtil.isNotEmpty(object.get("insertTime"))){
|
shellList.add(DateUtil.formatDate(DateUtil.parse(object.get("insertTime").toString(),"YYYY-MM-dd HH:mm:ss.S"), "YYYY-MM-dd HH:mm:ss"));
|
}else{
|
shellList.add("-");
|
}
|
shellList.add(String.valueOf(object.get("id")));
|
if(SinataUtil.isNotEmpty(object.get("companyName"))){
|
shellList.add(object.get("companyName").toString());
|
}else{
|
shellList.add("-");
|
}
|
if(SinataUtil.isNotEmpty(object.get("nickName"))){
|
shellList.add(object.get("nickName").toString());
|
}else{
|
shellList.add("-");
|
}
|
if(SinataUtil.isNotEmpty(object.get("phone"))){
|
shellList.add(object.get("phone").toString());
|
}else{
|
shellList.add("-");
|
}
|
if(SinataUtil.isNotEmpty(object.get("emergencyContact"))){
|
shellList.add(object.get("emergencyContact").toString());
|
}else{
|
shellList.add("-");
|
}
|
if(SinataUtil.isNotEmpty(object.get("emergencyContactNumber"))){
|
shellList.add(object.get("emergencyContactNumber").toString());
|
}else{
|
shellList.add("-");
|
}
|
if(SinataUtil.isNotEmpty(object.get("isAuth"))){
|
shellList.add(object.get("isAuth").toString().equals("是")?"是":"否");
|
}else{
|
shellList.add("-");
|
}
|
if(SinataUtil.isNotEmpty(object.get("historyNum"))){
|
shellList.add(object.get("historyNum").toString());
|
}else{
|
shellList.add("-");
|
}
|
if(SinataUtil.isNotEmpty(object.get("consumptionNum"))){
|
shellList.add(object.get("consumptionNum").toString());
|
}else{
|
shellList.add("-");
|
}
|
if(SinataUtil.isNotEmpty(object.get("integral"))){
|
shellList.add(object.get("integral").toString());
|
}else{
|
shellList.add("-");
|
}
|
if(SinataUtil.isNotEmpty(object.get("remark"))){
|
shellList.add(object.get("remark").toString());
|
}else{
|
shellList.add("-");
|
}
|
if(SinataUtil.isNotEmpty(object.get("state"))){
|
shellList.add(Integer.valueOf(object.get("state").toString()) == 1?"正常":"冻结");
|
}else{
|
shellList.add("-");
|
}
|
dataList.add(shellList);
|
}
|
try {
|
// 调用工具类进行导出
|
ExcelExportUtil.easySheet("用户信息导出记录"+DateUtil.formatDate(new Date(), "YYYYMMddHHmmss"), "用户信息导出记录", dataList,request, response);
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
|
|
|
}
|