|
@@ -0,0 +1,187 @@
|
|
|
+package com.huimv.admin.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.huimv.admin.entity.User;
|
|
|
+import com.huimv.admin.entity.dto.UserAccountDto;
|
|
|
+import com.huimv.admin.mapper.UserMapper;
|
|
|
+import com.huimv.admin.service.IUserService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author astupidcoder
|
|
|
+ * @since 2021-09-09
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
|
|
|
+ @Autowired
|
|
|
+ private UserMapper userMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JSONObject findUserAccount(String searchStr, int pageNum, int pageSize) {
|
|
|
+ int start = (pageNum-1)*pageSize;
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(searchStr)) {
|
|
|
+ List<UserAccountDto> userAccountList = userMapper.findUserAndAccountByUserName(searchStr, start,pageSize);
|
|
|
+ QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
|
|
|
+ userQueryWrapper.eq("user_name",searchStr);
|
|
|
+ int total = userMapper.selectCount(userQueryWrapper);
|
|
|
+ JSONObject resultJo = new JSONObject();
|
|
|
+ resultJo.put("code",10001);
|
|
|
+ resultJo.put("totalElements",total);
|
|
|
+ resultJo.put("data",userAccountList);
|
|
|
+ return resultJo;
|
|
|
+ }
|
|
|
+ List<UserAccountDto> allUserAccountList = userMapper.findUserAndAccount(start,pageSize);
|
|
|
+ Integer total = userMapper.selectCount(null);
|
|
|
+ JSONObject resultJo = new JSONObject();
|
|
|
+ resultJo.put("code",10001);
|
|
|
+ resultJo.put("totalElements",total);
|
|
|
+ resultJo.put("data",allUserAccountList);
|
|
|
+ return resultJo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 封装对象
|
|
|
+ */
|
|
|
+ private Object packageUserAccountRelatedObj(Object[] userAccountObj) {
|
|
|
+ JSONObject dataJo = new JSONObject();
|
|
|
+ dataJo.put("id",userAccountObj[0].toString());
|
|
|
+ dataJo.put("userName",userAccountObj[1].toString());
|
|
|
+ if(userAccountObj[2] == null){
|
|
|
+ dataJo.put("male","");
|
|
|
+ }else{
|
|
|
+ dataJo.put("male",userAccountObj[2].toString());
|
|
|
+ }
|
|
|
+ if(userAccountObj[3] == null){
|
|
|
+ dataJo.put("birthday","");
|
|
|
+ }else{
|
|
|
+ dataJo.put("birthday",userAccountObj[3].toString());
|
|
|
+ }
|
|
|
+ if(userAccountObj[4] == null){
|
|
|
+ dataJo.put("mobile","");
|
|
|
+ }else{
|
|
|
+ dataJo.put("mobile",userAccountObj[4].toString());
|
|
|
+ }
|
|
|
+ if(userAccountObj[5] == null){
|
|
|
+ dataJo.put("address","");
|
|
|
+ }else{
|
|
|
+ dataJo.put("address",userAccountObj[5].toString());
|
|
|
+ }
|
|
|
+ if(userAccountObj[6] == null){
|
|
|
+ dataJo.put("job","");
|
|
|
+ }else{
|
|
|
+ dataJo.put("job",userAccountObj[6].toString());
|
|
|
+ }
|
|
|
+ if(userAccountObj[7] == null){
|
|
|
+ dataJo.put("remark","");
|
|
|
+ }else{
|
|
|
+ dataJo.put("remark",userAccountObj[7].toString());
|
|
|
+ }
|
|
|
+ if(userAccountObj[8] == null)
|
|
|
+ {
|
|
|
+ dataJo.put("userId","");
|
|
|
+ }else{
|
|
|
+ dataJo.put("userId",userAccountObj[8].toString());
|
|
|
+ }
|
|
|
+ if(userAccountObj[9] == null){
|
|
|
+ dataJo.put("accountName","");
|
|
|
+ }else{
|
|
|
+ dataJo.put("accountName",userAccountObj[9].toString());
|
|
|
+ }
|
|
|
+ if(userAccountObj[10] == null)
|
|
|
+ {dataJo.put("accountStatus","");
|
|
|
+
|
|
|
+ }else{
|
|
|
+ dataJo.put("accountStatus", Integer.parseInt(userAccountObj[10].toString()));
|
|
|
+ }
|
|
|
+ return dataJo;
|
|
|
+ }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public Result addUser(User user) {
|
|
|
+// try {
|
|
|
+// int count = 0;
|
|
|
+// count = this.count(new QueryWrapper<User>().eq("user_name", user.getUserName()));
|
|
|
+// if (count > 0){
|
|
|
+// return new Result(10001,"该用户名已存在",false);
|
|
|
+// }
|
|
|
+//
|
|
|
+// count = this.count(new QueryWrapper<User>().eq("mobile", user.getMobile()));
|
|
|
+// if (count > 0){
|
|
|
+// return new Result(10001,"该手机号已注册",false);
|
|
|
+// }
|
|
|
+// SnowflakeSequence idWorker = new SnowflakeSequence();
|
|
|
+// long userId = idWorker.nextId();
|
|
|
+// // 添加用户信息
|
|
|
+// user.setUserId(userId+"");
|
|
|
+// userMapper.insert(user);
|
|
|
+//
|
|
|
+// // 添加账号信息
|
|
|
+// String mobile = user.getMobile();
|
|
|
+// String userName = user.getUserName();
|
|
|
+// Account Account = new Account();
|
|
|
+// if (mobile != null && !"".equals(mobile) ){
|
|
|
+// Account.setAccountName(mobile);
|
|
|
+// }else if (userName != null && !"".equals(userName)){
|
|
|
+// Account.setAccountName(userName);
|
|
|
+// }
|
|
|
+// Account.setAccountStatus(0);
|
|
|
+// Account.setRemark("");
|
|
|
+// Account.setPassword("123456");
|
|
|
+// Account.setUserId(userId+"");
|
|
|
+// Account.setMobile(mobile);
|
|
|
+// accountMapper.insert(Account);
|
|
|
+// return new Result(10000,"添加成功",true);
|
|
|
+// }catch (Exception e){
|
|
|
+// return new Result(10001,"添加失败",false);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public Result updateUser(User user) {
|
|
|
+// if (user == null) {
|
|
|
+// return new Result(ResultCode.FAIL);
|
|
|
+// }
|
|
|
+// User byId = this.getById(user);
|
|
|
+// QueryWrapper<Account> accountQueryWrapper = new QueryWrapper<>();
|
|
|
+// accountQueryWrapper.eq("user_id",byId.getUserId());
|
|
|
+// Account account = accountMapper.selectOne(accountQueryWrapper);
|
|
|
+// out.println(byId);
|
|
|
+// out.println(account);
|
|
|
+// account.setMobile(byId.getMobile());
|
|
|
+// account.setAccountName(byId.getUserName());
|
|
|
+// accountMapper.updateById(account);
|
|
|
+//
|
|
|
+// userMapper.updateById(user);
|
|
|
+// return new Result(10000,"修改成功",true);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public Result removeUser(List<Integer> userIds) {
|
|
|
+// for (Integer userId : userIds) {
|
|
|
+// try {
|
|
|
+// User user = this.userMapper.selectById(userId);
|
|
|
+// if (user == null) {
|
|
|
+// return new Result(10002,"请选择数据",false);
|
|
|
+// }
|
|
|
+// this.userMapper.deleteById(userId);
|
|
|
+// // 删除账号
|
|
|
+// this.accountMapper.deleteById(userId);
|
|
|
+// }catch (Exception e){
|
|
|
+// return new Result(10001,"删除失败",false);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return new Result(10000,"删除成功",false);
|
|
|
+// }
|
|
|
+
|
|
|
+}
|