@@ -0,0 +1,42 @@ | |||
package com.hp.user.client.entity; | |||
import java.util.List; | |||
public class AccountPage { | |||
private Long current; // 当前页 | |||
private Integer size; // 当前页size | |||
private Long total; //总条数 | |||
private List<AccountVO> accountList; | |||
public Long getCurrent() { | |||
return current; | |||
} | |||
public void setCurrent(Long current) { | |||
this.current = current; | |||
} | |||
public Integer getSize() { | |||
return size; | |||
} | |||
public void setSize(Integer size) { | |||
this.size = size; | |||
} | |||
public Long getTotal() { | |||
return total; | |||
} | |||
public void setTotal(Long total) { | |||
this.total = total; | |||
} | |||
public List<AccountVO> getAccountList() { | |||
return accountList; | |||
} | |||
public void setAccountList(List<AccountVO> accountList) { | |||
this.accountList = accountList; | |||
} | |||
} |
@@ -53,11 +53,14 @@ public class AccountVO{ | |||
* 对应角色Id | |||
*/ | |||
private String roleId; | |||
/** | |||
* 对应企业/服务商Id | |||
*/ | |||
private String companyId; | |||
public AccountVO(){} | |||
public AccountVO(String userId, String userName, String wxNumber, String phone, Date sysCreateTime, String sysCreator, Date sysUpdateTime, String sysUpdater, Short status, String roleId) { | |||
public AccountVO(String userId, String userName, String wxNumber, String phone, Date sysCreateTime, String sysCreator, Date sysUpdateTime, String sysUpdater, Short status, String roleId, String companyId) { | |||
this.userId = userId; | |||
this.userName = userName; | |||
this.wxNumber = wxNumber; | |||
@@ -68,6 +71,7 @@ public class AccountVO{ | |||
this.sysUpdater = sysUpdater; | |||
this.status = status; | |||
this.roleId = roleId; | |||
this.companyId = companyId; | |||
} | |||
public String getUserId() { | |||
@@ -149,4 +153,12 @@ public class AccountVO{ | |||
public void setRoleId(String roleId) { | |||
this.roleId = roleId; | |||
} | |||
public String getCompanyId() { | |||
return companyId; | |||
} | |||
public void setCompanyId(String companyId) { | |||
this.companyId = companyId; | |||
} | |||
} |
@@ -1,7 +1,10 @@ | |||
package com.hp.user.client.service; | |||
import com.hp.user.client.entity.AccountPage; | |||
import com.hp.user.client.entity.AccountVO; | |||
import java.util.List; | |||
/** | |||
* <p> | |||
* 用户信息表 服务类 | |||
@@ -11,7 +14,12 @@ import com.hp.user.client.entity.AccountVO; | |||
* @since 2020-11-20 | |||
*/ | |||
public interface AccountService { | |||
public boolean insert(AccountVO account); | |||
public boolean delete(String userId); | |||
public boolean update(AccountVO account); | |||
public AccountPage queryAccountsPageByCompanyIdAndUserNameAndPhoneAndStatus(String companyId,String userName,String phone,Integer status,Long current,Integer size); | |||
public boolean batchChangeStatusOfUser(String companyId,String[] userIds,Short status); | |||
/** | |||
* 登陆 | |||
* @param phone 手机号 | |||
@@ -1,52 +1,98 @@ | |||
package com.hp.user.service.controller; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RestController; | |||
import com.hp.user.client.entity.AccountPage; | |||
import com.hp.user.client.entity.AccountVO; | |||
import com.hp.user.client.service.AccountService; | |||
import com.hp.user.service.utils.HttpResult; | |||
import com.hp.user.service.utils.IdWorker; | |||
import io.swagger.annotations.Api; | |||
import io.swagger.annotations.ApiOperation; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
@Api(tags = "账号API接口") | |||
@RestController | |||
@RequestMapping("/user") | |||
public class UserController { | |||
@Autowired | |||
private AccountService accountService; | |||
/** | |||
* 添加用户 | |||
* 需要用户信息 | |||
* | |||
* @param user 用户信息 | |||
* @return HttpResult | |||
*/ | |||
@RequestMapping("/addUser") | |||
public void addUser(){ | |||
@ApiOperation(value = "新增账户", notes = "提示:要指定账号对应的服务商", httpMethod = "POST") | |||
@PostMapping("/addUser") | |||
public HttpResult addUser(@RequestBody AccountVO user) { | |||
user.setUserId(IdWorker.generactorId().toString()); | |||
boolean flag = accountService.insert(user); | |||
if (flag) return HttpResult.success(user.getUserId()); | |||
else return HttpResult.fail("添加失败"); | |||
} | |||
/** | |||
* 更新用户信息 | |||
* 需要用户信息 | |||
* | |||
* @param user 用户信息 | |||
* @return HttpResult | |||
*/ | |||
@RequestMapping("/updateUser") | |||
public void updateUser(){ | |||
@ApiOperation(value = "更新账户信息") | |||
@PostMapping("/updateUser") | |||
public HttpResult updateUser(@RequestBody AccountVO user) { | |||
boolean flag = accountService.update(user); | |||
if (flag) return HttpResult.success(); | |||
else return HttpResult.fail("更新失败"); | |||
} | |||
/** | |||
* 根据用户Id删除用户 | |||
* | |||
* @param userId 用户Id | |||
* @return HttpResult | |||
*/ | |||
@RequestMapping("/deleteUserByUserId") | |||
public void deleteUserByUserId(String userId){ | |||
@ApiOperation(value = "根据用户Id删除用户") | |||
@GetMapping("/deleteUserByUserId") | |||
public HttpResult deleteUserByUserId(String userId) { | |||
boolean flag = accountService.delete(userId); | |||
if (flag) return HttpResult.success(); | |||
else return HttpResult.fail("删除失败"); | |||
} | |||
/** | |||
* 根据用户Id查询某用户信息 | |||
* @param userId 用户Id | |||
* 根据服务商Id、用户姓名、手机号码、启用状态 分页查询账号 | |||
* | |||
* @param companyId 服务商Id | |||
* @param userName 用户姓名 | |||
* @param phone 手机号码 | |||
* @param status 启用状态 | |||
* @param current 要查询页数 | |||
* @param size 一页的行数 | |||
* @return HttpResult | |||
*/ | |||
@RequestMapping("/queryUserByUserId") | |||
public void queryUserByUserId(String userId){ | |||
@ApiOperation(value = "根据服务商Id、用户姓名、手机号码、启用状态 分页查询账号", notes = "启用:status=0,禁用:status=1,全部:status为其他数字") | |||
@GetMapping("/queryAccountsPageByCompanyIdAndUserNameAndPhoneAndStatus") | |||
public HttpResult queryAccountsPageByCompanyIdAndUserNameAndPhoneAndStatus(@RequestParam String companyId, String userName, String phone, @RequestParam Integer status, @RequestParam Long current, @RequestParam Integer size) { | |||
AccountPage accountPage = accountService.queryAccountsPageByCompanyIdAndUserNameAndPhoneAndStatus(companyId, userName, phone, status, current, size); | |||
if (accountPage != null) return HttpResult.success(accountPage); | |||
else return HttpResult.fail("查询失败"); | |||
} | |||
/** | |||
* 查询所有用户信息 | |||
* 批量启用/禁用账号 | |||
* @param companyId 服务商Id | |||
* @param userIds 用户Id数组 | |||
* @param status 启用状态 | |||
* @return HttpResult | |||
*/ | |||
@RequestMapping("/queryAllUser") | |||
public void queryAllUser(){ | |||
@ApiOperation(value = "批量启用/禁用账号", notes = "启用:status=0,禁用:status=1") | |||
@PostMapping("/batchChangeStatusOfUser") | |||
public HttpResult batchChangeStatusOfUser(@RequestParam String companyId,@RequestBody String[] userIds,@RequestParam Short status) { | |||
boolean flag = accountService.batchChangeStatusOfUser(companyId,userIds,status); | |||
if(flag) return HttpResult.success(); | |||
else return HttpResult.fail(); | |||
} | |||
} |
@@ -54,6 +54,10 @@ public class Account implements Serializable { | |||
* 更新用户Id | |||
*/ | |||
private String sysUpdater; | |||
/** | |||
* 系统字段;0:表示正常;1:表示删除 | |||
*/ | |||
private Short sysDeleted; | |||
/** | |||
* 启用状态:0:启用;1:禁用 | |||
*/ | |||
@@ -62,10 +66,14 @@ public class Account implements Serializable { | |||
* 对应角色Id | |||
*/ | |||
private String roleId; | |||
/** | |||
* 对应企业/服务商Id | |||
*/ | |||
private String companyId; | |||
public Account(){} | |||
public Account(String userId, String userName, String wxNumber, String phone, Date sysCreateTime, String sysCreator, Date sysUpdateTime, String sysUpdater, Short status, String roleId) { | |||
public Account(String userId, String userName, String wxNumber, String phone, Date sysCreateTime, String sysCreator, Date sysUpdateTime, String sysUpdater, Short sysDeleted, Short status, String roleId, String companyId) { | |||
this.userId = userId; | |||
this.userName = userName; | |||
this.wxNumber = wxNumber; | |||
@@ -74,8 +82,10 @@ public class Account implements Serializable { | |||
this.sysCreator = sysCreator; | |||
this.sysUpdateTime = sysUpdateTime; | |||
this.sysUpdater = sysUpdater; | |||
this.sysDeleted = sysDeleted; | |||
this.status = status; | |||
this.roleId = roleId; | |||
this.companyId = companyId; | |||
} | |||
public String getUserId() { | |||
@@ -157,4 +167,20 @@ public class Account implements Serializable { | |||
public void setRoleId(String roleId) { | |||
this.roleId = roleId; | |||
} | |||
public String getCompanyId() { | |||
return companyId; | |||
} | |||
public void setCompanyId(String companyId) { | |||
this.companyId = companyId; | |||
} | |||
public Short getSysDeleted() { | |||
return sysDeleted; | |||
} | |||
public void setSysDeleted(Short sysDeleted) { | |||
this.sysDeleted = sysDeleted; | |||
} | |||
} |
@@ -1,19 +1,23 @@ | |||
package com.hp.user.service.impl; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.baomidou.mybatisplus.core.conditions.Wrapper; | |||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||
import com.baomidou.mybatisplus.core.toolkit.IdWorker; | |||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper; | |||
import com.hp.user.client.entity.AccountPage; | |||
import com.hp.user.client.entity.AccountVO; | |||
import com.hp.user.client.service.AccountService; | |||
import com.hp.user.client.service.MessageService; | |||
import com.hp.user.service.dao.AccountMapper; | |||
import com.hp.user.service.entity.Account; | |||
import java.util.ArrayList; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
import javax.servlet.http.HttpUtils; | |||
import com.hp.user.service.utils.IdWorker; | |||
import org.apache.commons.codec.binary.StringUtils; | |||
import org.springframework.beans.BeanUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
@@ -82,7 +86,7 @@ public class AccountServiceImpl implements AccountService { | |||
if(checkPhone(accountVo.getPhone())) { | |||
Account account = new Account(); | |||
BeanUtils.copyProperties(accountVo, account); | |||
account.setUserId(IdWorker.getId()); | |||
account.setUserId(IdWorker.generactorId().toString()); | |||
accountMapper.insert(account); | |||
} | |||
}catch(Exception e) { | |||
@@ -94,9 +98,9 @@ public class AccountServiceImpl implements AccountService { | |||
@Override | |||
public void bindWx(String userIdStr, String wxNumber) { | |||
try { | |||
Long userId = Long.parseLong(userIdStr); | |||
// Long userId = Long.parseLong(userIdStr); | |||
Account account = new Account(); | |||
account.setUserId(userId); | |||
account.setUserId(userIdStr); | |||
account.setWxNumber(wxNumber); | |||
account.setWxNumber(wxNumber); | |||
accountMapper.updateById(account); | |||
@@ -131,4 +135,62 @@ public class AccountServiceImpl implements AccountService { | |||
} | |||
@Override | |||
public boolean insert(AccountVO account) { | |||
Account temp = new Account(); | |||
BeanUtils.copyProperties(account,temp); | |||
return SqlHelper.retBool(accountMapper.insert(temp)); | |||
} | |||
@Override | |||
public boolean delete(String userId) { | |||
Account temp = accountMapper.selectById(userId); | |||
temp.setSysDeleted((short)1); | |||
return SqlHelper.retBool(accountMapper.updateById(temp)); | |||
} | |||
@Override | |||
public boolean update(AccountVO account) { | |||
Account temp = new Account(); | |||
BeanUtils.copyProperties(account,temp); | |||
return SqlHelper.retBool(accountMapper.updateById(temp)); | |||
} | |||
@Override | |||
public AccountPage queryAccountsPageByCompanyIdAndUserNameAndPhoneAndStatus(String companyId, String userName, String phone, Integer status, Long current, Integer size) { | |||
AccountPage accountPage = new AccountPage(); | |||
IPage<Account> page = new Page<>(current,size); | |||
QueryWrapper<Account> wrapper = new QueryWrapper<>(); | |||
wrapper.eq("company_id",companyId); | |||
wrapper.orderByDesc("sys_create_time"); | |||
if(userName!=null) wrapper.like("user_name",userName); | |||
if(phone!=null) wrapper.like("phone",phone); | |||
if(status==0|| status==1) wrapper.eq("status",status); | |||
accountMapper.selectPage(page,wrapper); | |||
List<Account> accounts = page.getRecords(); | |||
List<AccountVO> accountVOs = new ArrayList<>(); | |||
AccountVO temp; | |||
for(Account account:accounts){ | |||
temp = new AccountVO(); | |||
BeanUtils.copyProperties(account,temp); | |||
accountVOs.add(temp); | |||
} | |||
accountPage.setAccountList(accountVOs); | |||
accountPage.setTotal(page.getTotal()); | |||
accountPage.setCurrent(current); | |||
accountPage.setSize(size); | |||
return accountPage; | |||
} | |||
@Override | |||
public boolean batchChangeStatusOfUser(String companyId,String[] userIds,Short status){ | |||
Account account; | |||
for(String userId:userIds){ | |||
account = accountMapper.selectById(userId); | |||
account.setStatus(status); | |||
if(!SqlHelper.retBool(accountMapper.updateById(account))) return false; | |||
} | |||
return true; | |||
} | |||
} |