mirror of https://github.com/jeecgboot/jeecg-boot
Merge pull request #174 from LQYBill/feat/create-user-init-balance
feat: add user client support and init balance on creationpull/8547/head
commit
dc08cdb4f2
|
@ -4,22 +4,20 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.aspect.annotation.AutoLog;
|
||||
import org.jeecg.common.system.query.QueryGenerator;
|
||||
import org.jeecg.common.system.vo.LoginUser;
|
||||
import org.jeecg.common.util.SpringContextUtils;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.business.entity.Balance;
|
||||
import org.jeecg.modules.business.entity.Client;
|
||||
import org.jeecg.modules.business.entity.ClientSku;
|
||||
import org.jeecg.modules.business.entity.Shop;
|
||||
import org.jeecg.modules.business.service.IClientService;
|
||||
import org.jeecg.modules.business.service.IClientSkuService;
|
||||
import org.jeecg.modules.business.service.IShopService;
|
||||
import org.jeecg.modules.business.service.*;
|
||||
import org.jeecg.modules.business.vo.ClientPage;
|
||||
import org.jeecg.modules.business.vo.PlatformOrderOption;
|
||||
import org.jeecg.modules.online.cgform.mapper.OnlCgformFieldMapper;
|
||||
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
||||
|
@ -56,11 +54,17 @@ public class ClientController {
|
|||
|
||||
private final IClientSkuService clientSkuService;
|
||||
|
||||
private final IBalanceService balanceService;
|
||||
|
||||
private final IPlatformOrderService platformOrderService;
|
||||
|
||||
@Autowired
|
||||
public ClientController(IClientService clientService, IShopService shopService, IClientSkuService clientSkuService) {
|
||||
public ClientController(IClientService clientService, IShopService shopService, IClientSkuService clientSkuService, IBalanceService balanceService, IPlatformOrderService platformOrderService) {
|
||||
this.clientService = clientService;
|
||||
this.shopService = shopService;
|
||||
this.clientSkuService = clientSkuService;
|
||||
this.balanceService = balanceService;
|
||||
this.platformOrderService = platformOrderService;
|
||||
}
|
||||
|
||||
|
||||
|
@ -73,8 +77,6 @@ public class ClientController {
|
|||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "客户-分页列表查询")
|
||||
@ApiOperation(value = "客户-分页列表查询", notes = "客户-分页列表查询")
|
||||
@GetMapping(value = "/list")
|
||||
public Result<?> queryPageList(Client client,
|
||||
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
|
@ -92,13 +94,16 @@ public class ClientController {
|
|||
* @param clientPage
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "客户-添加")
|
||||
@ApiOperation(value = "客户-添加", notes = "客户-添加")
|
||||
@PostMapping(value = "/add")
|
||||
public Result<?> add(@RequestBody ClientPage clientPage) {
|
||||
Client client = new Client();
|
||||
BeanUtils.copyProperties(clientPage, client);
|
||||
clientService.saveMain(client, clientPage.getShopList(), clientPage.getClientSkuList());
|
||||
String useBalance = clientPage.getUseBalance();
|
||||
log.info("useBalance:{}", useBalance);
|
||||
if ("1".equals(useBalance)) {
|
||||
balanceService.initBalance(client.getId());
|
||||
}
|
||||
return Result.OK("添加成功!");
|
||||
}
|
||||
|
||||
|
@ -121,9 +126,7 @@ public class ClientController {
|
|||
* @param clientPage
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "客户-编辑")
|
||||
@ApiOperation(value = "客户-编辑", notes = "客户-编辑")
|
||||
@PutMapping(value = "/edit")
|
||||
@PostMapping(value = "/edit")
|
||||
public Result<?> edit(@RequestBody ClientPage clientPage) {
|
||||
Client client = new Client();
|
||||
BeanUtils.copyProperties(clientPage, client);
|
||||
|
@ -131,8 +134,13 @@ public class ClientController {
|
|||
if (clientEntity == null) {
|
||||
return Result.error("未找到对应数据");
|
||||
}
|
||||
if (client.getUseBalance() != null && "1".equals(clientPage.getUseBalance())){
|
||||
// If useBalance is set to 1, initialize balance for the client
|
||||
balanceService.initBalance(client.getId());
|
||||
}
|
||||
clientService.updateMain(client, clientPage.getShopList(), clientPage.getClientSkuList());
|
||||
updateShopId();
|
||||
log.info("useBalance from clientPage: {}, useBalance updated for client: {}", clientPage.getUseBalance(), client.getUseBalance());
|
||||
log.info("Shop names replaced by new created shop IDs");
|
||||
return Result.OK("编辑成功!");
|
||||
}
|
||||
|
@ -155,11 +163,32 @@ public class ClientController {
|
|||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "客户-通过id删除")
|
||||
@ApiOperation(value = "客户-通过id删除", notes = "客户-通过id删除")
|
||||
@DeleteMapping(value = "/delete")
|
||||
public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
|
||||
// check if the client has any shops with orders
|
||||
List<String> deletedShopIds = new ArrayList<>();
|
||||
List<String> deletedBalanceIds;
|
||||
List<Shop> shopList = shopService.listByClient(id);
|
||||
if (shopList != null && !shopList.isEmpty()) {
|
||||
for (Shop shop : shopList) {
|
||||
Integer ordersAmount = platformOrderService.countOrdersByShop(shop.getId());
|
||||
log.info("checking shop: {}, ordersAmount: {}", shop.getName(), ordersAmount);
|
||||
if (ordersAmount != 0) {
|
||||
return Result.error("客户的店铺" + shop.getName() + "存在订单,无法删除");
|
||||
}
|
||||
}
|
||||
deletedShopIds = shopList.stream().map(Shop::getId).collect(Collectors.toList());
|
||||
shopService.removeByIds(deletedShopIds);
|
||||
}
|
||||
// delete client balance
|
||||
List<Balance> balances = balanceService.list(
|
||||
new QueryWrapper<Balance>().eq("client_id", id)
|
||||
);
|
||||
deletedBalanceIds = balances.stream().map(Balance::getId).collect(Collectors.toList());
|
||||
balanceService.deleteBalanceByClientId(id);
|
||||
clientService.delMain(id);
|
||||
log.info("Deleted Client: {}, Deleted Shops: {}, Deleted Balances: {}",
|
||||
id, deletedShopIds, deletedBalanceIds);
|
||||
return Result.OK("删除成功!");
|
||||
}
|
||||
|
||||
|
@ -169,11 +198,41 @@ public class ClientController {
|
|||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "客户-批量删除")
|
||||
@ApiOperation(value = "客户-批量删除", notes = "客户-批量删除")
|
||||
@DeleteMapping(value = "/deleteBatch")
|
||||
public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
|
||||
this.clientService.delBatchMain(Arrays.asList(ids.split(",")));
|
||||
List<String> clientIds = Arrays.asList(ids.split(","));
|
||||
List<String> deletedClientIds = new ArrayList<>();
|
||||
|
||||
for (String clientId : clientIds) {
|
||||
Client client = clientService.getById(clientId);
|
||||
if (client == null) {
|
||||
continue;
|
||||
}
|
||||
// check if the client has any shops with orders
|
||||
List<String> deletedShopIds = new ArrayList<>();
|
||||
List<String> deletedBalanceIds;
|
||||
List<Shop> shopList = shopService.listByClient(clientId);
|
||||
if (shopList != null && !shopList.isEmpty()) {
|
||||
for (Shop shop : shopList) {
|
||||
Integer ordersAmount = platformOrderService.countOrdersByShop(shop.getId());
|
||||
log.info("checking shop: {}, ordersAmount: {}", shop.getName(), ordersAmount);
|
||||
if (ordersAmount > 0) {
|
||||
return Result.error("客户的店铺" + shop.getName() + "存在订单,无法删除");
|
||||
}
|
||||
}
|
||||
deletedShopIds = shopList.stream().map(Shop::getId).collect(Collectors.toList());
|
||||
shopService.removeByIds(deletedShopIds);
|
||||
}
|
||||
// delete client balance
|
||||
List<Balance> balances = balanceService.list(
|
||||
new QueryWrapper<Balance>().eq("client_id", clientId)
|
||||
);
|
||||
deletedBalanceIds = balances.stream().map(Balance::getId).collect(Collectors.toList());
|
||||
balanceService.deleteBalanceByClientId(clientId);
|
||||
log.info("Deleted Client: {}, Deleted Shops: {}, Deleted Balances: {}",
|
||||
clientId, deletedShopIds, deletedBalanceIds);
|
||||
}
|
||||
this.clientService.delBatchMain(clientIds);
|
||||
return Result.OK("批量删除成功!");
|
||||
}
|
||||
|
||||
|
@ -183,8 +242,6 @@ public class ClientController {
|
|||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "客户-通过id查询")
|
||||
@ApiOperation(value = "客户-通过id查询", notes = "客户-通过id查询")
|
||||
@GetMapping(value = "/queryById")
|
||||
public Result<?> queryById(@RequestParam(name = "id", required = true) String id) {
|
||||
Client client = clientService.getById(id);
|
||||
|
@ -201,8 +258,6 @@ public class ClientController {
|
|||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "店铺-通过主表ID查询")
|
||||
@ApiOperation(value = "店铺-通过主表ID查询", notes = "店铺-通过主表ID查询")
|
||||
@GetMapping(value = "/queryShopByMainId")
|
||||
public Result<?> queryShopListByMainId(@RequestParam(name = "id", required = true) String id) {
|
||||
List<Shop> shopList = shopService.selectByMainId(id);
|
||||
|
@ -218,8 +273,6 @@ public class ClientController {
|
|||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "客户名下SKU-通过主表ID查询")
|
||||
@ApiOperation(value = "客户名下SKU-通过主表ID查询", notes = "客户名下SKU-通过主表ID查询")
|
||||
@GetMapping(value = "/queryClientSkuByMainId")
|
||||
public Result<?> queryClientSkuListByMainId(@RequestParam(name = "id", required = true) String id) {
|
||||
log.info(id);
|
||||
|
|
|
@ -200,6 +200,14 @@ public class Client implements Serializable {
|
|||
@ApiModelProperty(value = "invoice in chronological order or first can invoice")
|
||||
private java.lang.String isChronologicalOrder;
|
||||
|
||||
/**
|
||||
* 是否使用余额
|
||||
*/
|
||||
@Excel(name = "是否使用余额", width = 15, dicCode = "yn")
|
||||
@Dict(dicCode = "yn")
|
||||
@ApiModelProperty(value = "是否使用余额")
|
||||
private String useBalance;
|
||||
|
||||
public String fullName() {
|
||||
return firstName + " " + surname;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ public interface ClientMapper extends BaseMapper<Client> {
|
|||
String getActiveClientIdByCode(@Param("code") String code);
|
||||
List<Client> getClientByType(@Param("type") String type);
|
||||
Client getClientByCode(@Param("code") String internalCode);
|
||||
Client getClientById(@Param("id") String clientId);
|
||||
Client getClientFromOrder(@Param("orderId")String orderId);
|
||||
|
||||
Client getClientFromPurchase(@Param("purchaseId") String purchaseId);
|
||||
|
|
|
@ -263,4 +263,5 @@ public interface PlatformOrderMapper extends BaseMapper<PlatformOrder> {
|
|||
PlatformOrder selectForUpdateSkipLock(@Param("id") String orderId);
|
||||
|
||||
List<String> fetchPlatformOrderIdsByShopifyNote(String shopifyNote);
|
||||
Integer countOrdersByShop(@Param("shopId") String shopId);
|
||||
}
|
||||
|
|
|
@ -107,6 +107,11 @@
|
|||
JOIN credit ON c.id = credit.client_id
|
||||
WHERE credit.invoice_number = #{invoiceNumber};
|
||||
</select>
|
||||
<select id="getClientById" resultType="org.jeecg.modules.business.entity.Client">
|
||||
SELECT *
|
||||
FROM client
|
||||
WHERE id = #{id};
|
||||
</select>
|
||||
<select id="getClientsByCode" resultType="java.lang.String">
|
||||
SELECT c.id
|
||||
FROM client c
|
||||
|
|
|
@ -1412,4 +1412,9 @@
|
|||
WHERE shopify_note LIKE #{shopifyNote}
|
||||
AND erp_status in (1,2);
|
||||
</select>
|
||||
<select id="countOrdersByShop" resultType="java.lang.Integer">
|
||||
SELECT COUNT(*)
|
||||
FROM platform_order
|
||||
WHERE shop_id = #{shopId}
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
@ -17,6 +17,9 @@ import java.util.List;
|
|||
public interface IBalanceService extends IService<Balance> {
|
||||
|
||||
BigDecimal getBalanceByClientIdAndCurrency(String clientId, String currency);
|
||||
|
||||
void initBalance(String clientId);
|
||||
|
||||
void updateBalance(String clientId, String invoiceCode, String invoiceType);
|
||||
void updateBalance(String clientId, String CreditId, BigDecimal amount, String currencyId);
|
||||
|
||||
|
@ -27,6 +30,8 @@ public interface IBalanceService extends IService<Balance> {
|
|||
*/
|
||||
void deleteBalance(String operationId, String operationType);
|
||||
|
||||
void deleteBalanceByClientId(String clientId);
|
||||
|
||||
/**
|
||||
* Edit balance record
|
||||
* @param operationId operation id : invoice id or credit id
|
||||
|
@ -47,4 +52,4 @@ public interface IBalanceService extends IService<Balance> {
|
|||
List<BalanceData> getLowBalanceClients(List<InvoiceMetaData> metaDataList);
|
||||
|
||||
void cancelBalance(String invoiceId, String originalOperationType, String operationType, BigDecimal amount, String currencyId, String clientId);
|
||||
}
|
||||
}
|
|
@ -298,4 +298,6 @@ public interface IPlatformOrderService extends IService<PlatformOrder> {
|
|||
PlatformOrder selectForUpdateSkipLock(String orderId);
|
||||
|
||||
List<String> fetchPlatformOrderIdsByShopifyNote(String shopifyNote);
|
||||
|
||||
Integer countOrdersByShop(String shopId);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.jeecg.modules.business.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.modules.business.entity.*;
|
||||
import org.jeecg.modules.business.mapper.BalanceMapper;
|
||||
|
@ -45,6 +46,30 @@ public class BalanceServiceImpl extends ServiceImpl<BalanceMapper, Balance> impl
|
|||
public BigDecimal getBalanceByClientIdAndCurrency(String clientId, String currency) {
|
||||
return balanceMapper.getBalanceByClientIdAndCurrency(clientId, currency);
|
||||
}
|
||||
@Override
|
||||
public void initBalance(String clientId) {
|
||||
// TODO : check if the balance already exists for this client
|
||||
Client client = clientMapper.getClientById(clientId);
|
||||
if(client == null) {
|
||||
throw new RuntimeException("Client not found for id: " + clientId);
|
||||
}
|
||||
String currency = client.getCurrency();
|
||||
if(currency == null) {
|
||||
throw new RuntimeException("Client currency is not set for client id: " + clientId);
|
||||
}
|
||||
String currencyId = currencyService.getIdByCode(currency);
|
||||
BigDecimal previousBalance = balanceMapper.getBalanceByClientIdAndCurrency(clientId, currency);
|
||||
if(previousBalance != null) {
|
||||
log.info("Balance already exists for client: {}, currency: {}, balance: {}", clientId, currency, previousBalance);
|
||||
return;
|
||||
}
|
||||
// initialize balance to zero
|
||||
SysUser sysUser = new SysUser();
|
||||
Balance balance = Balance.of(sysUser.getUsername(), clientId, currencyId, Balance.OperationType.Init.name(), null, BigDecimal.ZERO)
|
||||
.setCreateBy(sysUser.getUsername());
|
||||
balanceMapper.insert(balance);
|
||||
log.info("Initialized balance for client: {}, currency: {}, , currencyId: {},balance: {}", clientId, currency, currencyId, BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateBalance(String clientId, String invoiceCode, String invoiceType) {
|
||||
|
@ -106,6 +131,13 @@ public class BalanceServiceImpl extends ServiceImpl<BalanceMapper, Balance> impl
|
|||
public void deleteBatchBalance(List<String> operationIds, String operationType) {
|
||||
balanceMapper.deleteBatchBalance(operationIds, operationType);
|
||||
}
|
||||
@Override
|
||||
public void deleteBalanceByClientId(String clientId) {
|
||||
QueryWrapper<Balance> query = new QueryWrapper<>();
|
||||
query.eq("client_id", clientId);
|
||||
this.remove(query);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void editBalance(String operationId, String operationType, String clientId, BigDecimal amount, String currencyId) throws Exception {
|
||||
|
@ -153,4 +185,4 @@ public class BalanceServiceImpl extends ServiceImpl<BalanceMapper, Balance> impl
|
|||
Balance balanceAdjustment = Balance.of("system", clientId, currencyId, operationType, invoiceId, balanceAmount.subtract(amount));
|
||||
balanceMapper.insert(balanceAdjustment);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -619,4 +619,10 @@ public class PlatformOrderServiceImpl extends ServiceImpl<PlatformOrderMapper, P
|
|||
public List<String> fetchPlatformOrderIdsByShopifyNote(String shopifyNote) {
|
||||
return platformOrderMap.fetchPlatformOrderIdsByShopifyNote(shopifyNote);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer countOrdersByShop(String shopId) {
|
||||
return platformOrderMap.countOrdersByShop(shopId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -155,6 +155,22 @@ public class ClientPage {
|
|||
@Excel(name = "账户余额", width = 15)
|
||||
@ApiModelProperty(value = "账户余额")
|
||||
private java.math.BigDecimal balance;
|
||||
/**
|
||||
* 是否初始化余额
|
||||
*/
|
||||
@Excel(name = "是否使用余额", width = 15, dicCode = "yn")
|
||||
@Dict(dicCode = "yn")
|
||||
@ApiModelProperty("是否使用余额")
|
||||
private java.lang.String useBalance;
|
||||
|
||||
/**
|
||||
* 客户类型
|
||||
*/
|
||||
@Excel(name = "客户类型", width = 15, dictTable = "client_category", dicText = "name", dicCode = "id")
|
||||
@Dict(dictTable = "client_category", dicText = "name", dicCode = "id")
|
||||
@ApiModelProperty(value = "客户类型")
|
||||
private java.lang.String clientCategoryId;
|
||||
|
||||
/**
|
||||
* IOSS号码
|
||||
*/
|
||||
|
|
|
@ -26,6 +26,10 @@ import org.jeecg.common.system.query.QueryGenerator;
|
|||
import org.jeecg.common.system.util.JwtUtil;
|
||||
import org.jeecg.common.system.vo.LoginUser;
|
||||
import org.jeecg.common.util.*;
|
||||
import org.jeecg.modules.business.entity.Client;
|
||||
import org.jeecg.modules.business.entity.UserClient;
|
||||
import org.jeecg.modules.business.service.IBalanceService;
|
||||
import org.jeecg.modules.business.service.IUserClientService;
|
||||
import org.jeecg.modules.system.entity.*;
|
||||
import org.jeecg.modules.system.model.DepartIdModel;
|
||||
import org.jeecg.modules.system.model.SysUserSysDepartModel;
|
||||
|
@ -65,17 +69,17 @@ import java.util.stream.Collectors;
|
|||
@RequestMapping("/sys/user")
|
||||
public class SysUserController {
|
||||
|
||||
@Autowired
|
||||
private ISysUserService sysUserService;
|
||||
@Autowired
|
||||
private ISysUserService sysUserService;
|
||||
|
||||
@Autowired
|
||||
private ISysDepartService sysDepartService;
|
||||
|
||||
@Autowired
|
||||
private ISysUserRoleService sysUserRoleService;
|
||||
@Autowired
|
||||
private ISysUserRoleService sysUserRoleService;
|
||||
|
||||
@Autowired
|
||||
private ISysUserDepartService sysUserDepartService;
|
||||
@Autowired
|
||||
private ISysUserDepartService sysUserDepartService;
|
||||
|
||||
@Autowired
|
||||
private ISysDepartRoleUserService departRoleUserService;
|
||||
|
@ -83,8 +87,8 @@ public class SysUserController {
|
|||
@Autowired
|
||||
private ISysDepartRoleService departRoleService;
|
||||
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@Value("${jeecg.path.upload}")
|
||||
private String upLoadPath;
|
||||
|
@ -101,6 +105,11 @@ public class SysUserController {
|
|||
@Autowired
|
||||
private ISysUserTenantService userTenantService;
|
||||
|
||||
@Autowired
|
||||
private IUserClientService userClientService;
|
||||
@Autowired
|
||||
private IBalanceService balanceService;
|
||||
|
||||
/**
|
||||
* 获取租户下用户数据(支持租户隔离)
|
||||
* @param user
|
||||
|
@ -110,10 +119,10 @@ public class SysUserController {
|
|||
* @return
|
||||
*/
|
||||
@PermissionData(pageComponent = "system/UserList")
|
||||
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||
public Result<IPage<SysUser>> queryPageList(SysUser user,@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,HttpServletRequest req) {
|
||||
QueryWrapper<SysUser> queryWrapper = QueryGenerator.initQueryWrapper(user, req.getParameterMap());
|
||||
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||
public Result<IPage<SysUser>> queryPageList(SysUser user,@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,HttpServletRequest req) {
|
||||
QueryWrapper<SysUser> queryWrapper = QueryGenerator.initQueryWrapper(user, req.getParameterMap());
|
||||
//------------------------------------------------------------------------------------------------
|
||||
//是否开启系统管理模块的多租户数据隔离【SAAS多租户模式】
|
||||
if (MybatisPlusSaasConfig.OPEN_SYSTEM_TENANT_CONTROL) {
|
||||
|
@ -127,7 +136,7 @@ public class SysUserController {
|
|||
}
|
||||
//------------------------------------------------------------------------------------------------
|
||||
return sysUserService.queryPageList(req, queryWrapper, pageSize, pageNo);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统用户数据(查询全部用户,不做租户隔离)
|
||||
|
@ -147,50 +156,62 @@ public class SysUserController {
|
|||
}
|
||||
|
||||
@RequiresPermissions("system:user:add")
|
||||
@RequestMapping(value = "/add", method = RequestMethod.POST)
|
||||
public Result<SysUser> add(@RequestBody JSONObject jsonObject) {
|
||||
Result<SysUser> result = new Result<SysUser>();
|
||||
String selectedRoles = jsonObject.getString("selectedroles");
|
||||
String selectedDeparts = jsonObject.getString("selecteddeparts");
|
||||
try {
|
||||
SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class);
|
||||
user.setCreateTime(new Date());//设置创建时间
|
||||
String salt = oConvertUtils.randomGen(8);
|
||||
user.setSalt(salt);
|
||||
String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), salt);
|
||||
user.setPassword(passwordEncode);
|
||||
user.setStatus(1);
|
||||
user.setDelFlag(CommonConstant.DEL_FLAG_0);
|
||||
//用户表字段org_code不能在这里设置他的值
|
||||
@RequestMapping(value = "/add", method = RequestMethod.POST)
|
||||
public Result<SysUser> add(@RequestBody JSONObject payload) {
|
||||
Result<SysUser> result = new Result<SysUser>();
|
||||
String selectedRoles = payload.getString("selectedroles");
|
||||
String selectedDeparts = payload.getString("selecteddeparts");
|
||||
try {
|
||||
SysUser user = JSON.parseObject(payload.toJSONString(), SysUser.class);
|
||||
user.setCreateTime(new Date());//设置创建时间
|
||||
String salt = oConvertUtils.randomGen(8);
|
||||
user.setSalt(salt);
|
||||
String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), salt);
|
||||
user.setPassword(passwordEncode);
|
||||
user.setStatus(1);
|
||||
user.setDelFlag(CommonConstant.DEL_FLAG_0);
|
||||
//用户表字段org_code不能在这里设置他的值
|
||||
user.setOrgCode(null);
|
||||
// 保存用户走一个service 保证事务
|
||||
// 保存用户走一个service 保证事务
|
||||
//获取租户ids
|
||||
String relTenantIds = jsonObject.getString("relTenantIds");
|
||||
String relTenantIds = payload.getString("relTenantIds");
|
||||
sysUserService.saveUser(user, selectedRoles, selectedDeparts, relTenantIds);
|
||||
// 判断是否为 WIA客户(通过部门名称)
|
||||
String departId = selectedDeparts.split(",")[0]; // 取第一个部门ID
|
||||
SysDepart depart = sysDepartService.getDepartById(departId);
|
||||
|
||||
if (depart != null && "WIA客户".equals(depart.getDepartName())) {
|
||||
String clientId = payload.getString("client");
|
||||
log.info("Add user client association for user ID: {}", user.getId());
|
||||
UserClient userClient = new UserClient();
|
||||
userClient.setUser_id(user.getId());
|
||||
userClient.setClient_id(clientId);
|
||||
userClientService.save(userClient);
|
||||
}
|
||||
baseCommonService.addLog("添加用户,username: " +user.getUsername() ,CommonConstant.LOG_TYPE_2, 2);
|
||||
result.success("添加成功!");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
result.error500("操作失败");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
result.success("添加成功!");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
result.error500("操作失败");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequiresPermissions("system:user:edit")
|
||||
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
|
||||
public Result<SysUser> edit(@RequestBody JSONObject jsonObject) {
|
||||
Result<SysUser> result = new Result<SysUser>();
|
||||
try {
|
||||
SysUser sysUser = sysUserService.getById(jsonObject.getString("id"));
|
||||
baseCommonService.addLog("编辑用户,username: " +sysUser.getUsername() ,CommonConstant.LOG_TYPE_2, 2);
|
||||
if(sysUser==null) {
|
||||
result.error500("未找到对应实体");
|
||||
}else {
|
||||
SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class);
|
||||
user.setUpdateTime(new Date());
|
||||
//String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), sysUser.getSalt());
|
||||
user.setPassword(sysUser.getPassword());
|
||||
String roles = jsonObject.getString("selectedroles");
|
||||
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
|
||||
public Result<SysUser> edit(@RequestBody JSONObject jsonObject) {
|
||||
Result<SysUser> result = new Result<SysUser>();
|
||||
try {
|
||||
SysUser sysUser = sysUserService.getById(jsonObject.getString("id"));
|
||||
baseCommonService.addLog("编辑用户,username: " +sysUser.getUsername() ,CommonConstant.LOG_TYPE_2, 2);
|
||||
if(sysUser==null) {
|
||||
result.error500("未找到对应实体");
|
||||
}else {
|
||||
SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class);
|
||||
user.setUpdateTime(new Date());
|
||||
//String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), sysUser.getSalt());
|
||||
user.setPassword(sysUser.getPassword());
|
||||
String roles = jsonObject.getString("selectedroles");
|
||||
String departs = jsonObject.getString("selecteddeparts");
|
||||
if(oConvertUtils.isEmpty(departs)){
|
||||
//vue3.0前端只传递了departIds
|
||||
|
@ -201,65 +222,65 @@ public class SysUserController {
|
|||
// 修改用户走一个service 保证事务
|
||||
//获取租户ids
|
||||
String relTenantIds = jsonObject.getString("relTenantIds");
|
||||
sysUserService.editUser(user, roles, departs, relTenantIds);
|
||||
result.success("修改成功!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
result.error500("操作失败");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
sysUserService.editUser(user, roles, departs, relTenantIds);
|
||||
result.success("修改成功!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
result.error500("操作失败");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*/
|
||||
/**
|
||||
* 删除用户
|
||||
*/
|
||||
@RequiresPermissions("system:user:delete")
|
||||
@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
|
||||
public Result<?> delete(@RequestParam(name="id",required=true) String id) {
|
||||
baseCommonService.addLog("删除用户,id: " +id ,CommonConstant.LOG_TYPE_2, 3);
|
||||
this.sysUserService.deleteUser(id);
|
||||
return Result.ok("删除用户成功");
|
||||
}
|
||||
@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
|
||||
public Result<?> delete(@RequestParam(name="id",required=true) String id) {
|
||||
baseCommonService.addLog("删除用户,id: " +id ,CommonConstant.LOG_TYPE_2, 3);
|
||||
this.sysUserService.deleteUser(id);
|
||||
return Result.ok("删除用户成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除用户
|
||||
*/
|
||||
/**
|
||||
* 批量删除用户
|
||||
*/
|
||||
@RequiresPermissions("system:user:deleteBatch")
|
||||
@RequestMapping(value = "/deleteBatch", method = RequestMethod.DELETE)
|
||||
public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
||||
baseCommonService.addLog("批量删除用户, ids: " +ids ,CommonConstant.LOG_TYPE_2, 3);
|
||||
this.sysUserService.deleteBatchUsers(ids);
|
||||
return Result.ok("批量删除用户成功");
|
||||
}
|
||||
@RequestMapping(value = "/deleteBatch", method = RequestMethod.DELETE)
|
||||
public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
||||
baseCommonService.addLog("批量删除用户, ids: " +ids ,CommonConstant.LOG_TYPE_2, 3);
|
||||
this.sysUserService.deleteBatchUsers(ids);
|
||||
return Result.ok("批量删除用户成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 冻结&解冻用户
|
||||
* @param jsonObject
|
||||
* @return
|
||||
*/
|
||||
/**
|
||||
* 冻结&解冻用户
|
||||
* @param jsonObject
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("system:user:frozenBatch")
|
||||
@RequestMapping(value = "/frozenBatch", method = RequestMethod.PUT)
|
||||
public Result<SysUser> frozenBatch(@RequestBody JSONObject jsonObject) {
|
||||
Result<SysUser> result = new Result<SysUser>();
|
||||
try {
|
||||
String ids = jsonObject.getString("ids");
|
||||
sysUserService.checkUserAdminRejectDel(ids);
|
||||
String status = jsonObject.getString("status");
|
||||
String[] arr = ids.split(",");
|
||||
@RequestMapping(value = "/frozenBatch", method = RequestMethod.PUT)
|
||||
public Result<SysUser> frozenBatch(@RequestBody JSONObject jsonObject) {
|
||||
Result<SysUser> result = new Result<SysUser>();
|
||||
try {
|
||||
String ids = jsonObject.getString("ids");
|
||||
sysUserService.checkUserAdminRejectDel(ids);
|
||||
String status = jsonObject.getString("status");
|
||||
String[] arr = ids.split(",");
|
||||
for (String id : arr) {
|
||||
if(oConvertUtils.isNotEmpty(id)) {
|
||||
if(oConvertUtils.isNotEmpty(id)) {
|
||||
//update-begin---author:liusq ---date:20230620 for:[QQYUN-5577]用户列表-冻结用户,再解冻之后,用户还是无法登陆,有缓存问题 #5066------------
|
||||
sysUserService.updateStatus(id,status);
|
||||
//update-end---author:liusq ---date:20230620 for:[QQYUN-5577]用户列表-冻结用户,再解冻之后,用户还是无法登陆,有缓存问题 #5066------------
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
result.error500("操作失败"+e.getMessage());
|
||||
}
|
||||
result.success("操作成功!");
|
||||
return result;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
result.error500("操作失败"+e.getMessage());
|
||||
}
|
||||
result.success("操作成功!");
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
@ -297,8 +318,8 @@ public class SysUserController {
|
|||
|
||||
|
||||
/**
|
||||
* 校验用户账号是否唯一<br>
|
||||
* 可以校验其他 需要检验什么就传什么。。。
|
||||
* 校验用户账号是否唯一<br>
|
||||
* 可以校验其他 需要检验什么就传什么。。。
|
||||
*
|
||||
* @param sysUser
|
||||
* @return
|
||||
|
@ -366,7 +387,7 @@ public class SysUserController {
|
|||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
log.error(e.getMessage(), e);
|
||||
result.setSuccess(false);
|
||||
result.setMessage("查找过程中出现了异常: " + e.getMessage());
|
||||
return result;
|
||||
|
@ -374,6 +395,25 @@ public class SysUserController {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据部门ID获取部门详情
|
||||
* @param departId 部门ID
|
||||
* @return SysDepart
|
||||
*/
|
||||
@RequestMapping(value = "/getDepartById", method = RequestMethod.GET)
|
||||
public Result<SysDepart> getDepartById(@RequestParam(name = "departId", required = true) String departId) {
|
||||
try {
|
||||
SysDepart depart = sysDepartService.getDepartById(departId);
|
||||
if (depart == null) {
|
||||
return Result.error("未找到对应部门信息");
|
||||
}
|
||||
return Result.ok(depart);
|
||||
} catch (Exception e) {
|
||||
log.error("查询部门出错:", e);
|
||||
return Result.error("查询失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成在添加用户情况下没有主键的问题,返回给前端,根据该id绑定部门数据
|
||||
*
|
||||
|
@ -419,7 +459,7 @@ public class SysUserController {
|
|||
result.setResult(userList);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
log.error(e.getMessage(), e);
|
||||
result.setSuccess(false);
|
||||
return result;
|
||||
}
|
||||
|
@ -463,16 +503,16 @@ public class SysUserController {
|
|||
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
||||
//update-begin--Author:kangxiaolin Date:20180825 for:[03]用户导出,如果选择数据则只导出相关数据--------------------
|
||||
String selections = request.getParameter("selections");
|
||||
if(!oConvertUtils.isEmpty(selections)){
|
||||
queryWrapper.in("id",selections.split(","));
|
||||
}
|
||||
if(!oConvertUtils.isEmpty(selections)){
|
||||
queryWrapper.in("id",selections.split(","));
|
||||
}
|
||||
//update-end--Author:kangxiaolin Date:20180825 for:[03]用户导出,如果选择数据则只导出相关数据----------------------
|
||||
List<SysUser> pageList = sysUserService.list(queryWrapper);
|
||||
|
||||
//导出文件名称
|
||||
mv.addObject(NormalExcelConstants.FILE_NAME, "用户列表");
|
||||
mv.addObject(NormalExcelConstants.CLASS, SysUser.class);
|
||||
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
ExportParams exportParams = new ExportParams("用户列表数据", "导出人:"+user.getRealname(), "导出信息");
|
||||
exportParams.setImageBasePath(upLoadPath);
|
||||
mv.addObject(NormalExcelConstants.PARAMS, exportParams);
|
||||
|
@ -557,7 +597,7 @@ public class SysUserController {
|
|||
try {
|
||||
file.getInputStream().close();
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -565,20 +605,20 @@ public class SysUserController {
|
|||
}
|
||||
|
||||
/**
|
||||
* @功能:根据id 批量查询
|
||||
* @param userIds
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/queryByIds", method = RequestMethod.GET)
|
||||
public Result<Collection<SysUser>> queryByIds(@RequestParam(name = "userIds") String userIds) {
|
||||
Result<Collection<SysUser>> result = new Result<>();
|
||||
String[] userId = userIds.split(",");
|
||||
Collection<String> idList = Arrays.asList(userId);
|
||||
Collection<SysUser> userRole = sysUserService.listByIds(idList);
|
||||
result.setSuccess(true);
|
||||
result.setResult(userRole);
|
||||
return result;
|
||||
}
|
||||
* @功能:根据id 批量查询
|
||||
* @param userIds
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/queryByIds", method = RequestMethod.GET)
|
||||
public Result<Collection<SysUser>> queryByIds(@RequestParam(name = "userIds") String userIds) {
|
||||
Result<Collection<SysUser>> result = new Result<>();
|
||||
String[] userId = userIds.split(",");
|
||||
Collection<String> idList = Arrays.asList(userId);
|
||||
Collection<SysUser> userRole = sysUserService.listByIds(idList);
|
||||
result.setSuccess(true);
|
||||
result.setResult(userRole);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -598,30 +638,30 @@ public class SysUserController {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 首页用户重置密码
|
||||
*/
|
||||
/**
|
||||
* 首页用户重置密码
|
||||
*/
|
||||
@RequiresPermissions("system:user:updatepwd")
|
||||
@RequestMapping(value = "/updatePassword", method = RequestMethod.PUT)
|
||||
public Result<?> updatePassword(@RequestBody JSONObject json) {
|
||||
String username = json.getString("username");
|
||||
String oldpassword = json.getString("oldpassword");
|
||||
String password = json.getString("password");
|
||||
String confirmpassword = json.getString("confirmpassword");
|
||||
public Result<?> updatePassword(@RequestBody JSONObject json) {
|
||||
String username = json.getString("username");
|
||||
String oldpassword = json.getString("oldpassword");
|
||||
String password = json.getString("password");
|
||||
String confirmpassword = json.getString("confirmpassword");
|
||||
LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
|
||||
if(!sysUser.getUsername().equals(username)){
|
||||
return Result.error("只允许修改自己的密码!");
|
||||
}
|
||||
SysUser user = this.sysUserService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUsername, username));
|
||||
if(user==null) {
|
||||
return Result.error("用户不存在!");
|
||||
}
|
||||
SysUser user = this.sysUserService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUsername, username));
|
||||
if(user==null) {
|
||||
return Result.error("用户不存在!");
|
||||
}
|
||||
//update-begin---author:wangshuai ---date:20220316 for:[VUEN-234]修改密码添加敏感日志------------
|
||||
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
baseCommonService.addLog("修改密码,username: " +loginUser.getUsername() ,CommonConstant.LOG_TYPE_2, 2);
|
||||
//update-end---author:wangshuai ---date:20220316 for:[VUEN-234]修改密码添加敏感日志------------
|
||||
return sysUserService.resetPassword(username,oldpassword,password,confirmpassword);
|
||||
}
|
||||
return sysUserService.resetPassword(username,oldpassword,password,confirmpassword);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/userRoleList", method = RequestMethod.GET)
|
||||
public Result<IPage<SysUser>> userRoleList(@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
|
@ -677,7 +717,7 @@ public class SysUserController {
|
|||
@RequiresPermissions("system:user:deleteRole")
|
||||
@RequestMapping(value = "/deleteUserRole", method = RequestMethod.DELETE)
|
||||
public Result<SysUserRole> deleteUserRole(@RequestParam(name="roleId") String roleId,
|
||||
@RequestParam(name="userId",required=true) String userId
|
||||
@RequestParam(name="userId",required=true) String userId
|
||||
) {
|
||||
Result<SysUserRole> result = new Result<SysUserRole>();
|
||||
try {
|
||||
|
@ -910,16 +950,16 @@ public class SysUserController {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询当前用户的所有部门/当前部门编码
|
||||
* 查询当前用户的所有部门/当前部门编码
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/getCurrentUserDeparts", method = RequestMethod.GET)
|
||||
public Result<Map<String,Object>> getCurrentUserDeparts() {
|
||||
Result<Map<String,Object>> result = new Result<Map<String,Object>>();
|
||||
try {
|
||||
LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
|
||||
LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
|
||||
List<SysDepart> list = this.sysDepartService.queryUserDeparts(sysUser.getId());
|
||||
Map<String,Object> map = new HashMap(5);
|
||||
map.put("list", list);
|
||||
|
@ -933,52 +973,52 @@ public class SysUserController {
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 用户注册接口
|
||||
*
|
||||
* @param jsonObject
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/register")
|
||||
public Result<JSONObject> userRegister(@RequestBody JSONObject jsonObject, SysUser user) {
|
||||
Result<JSONObject> result = new Result<JSONObject>();
|
||||
String phone = jsonObject.getString("phone");
|
||||
String smscode = jsonObject.getString("smscode");
|
||||
|
||||
/**
|
||||
* 用户注册接口
|
||||
*
|
||||
* @param jsonObject
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/register")
|
||||
public Result<JSONObject> userRegister(@RequestBody JSONObject jsonObject, SysUser user) {
|
||||
Result<JSONObject> result = new Result<JSONObject>();
|
||||
String phone = jsonObject.getString("phone");
|
||||
String smscode = jsonObject.getString("smscode");
|
||||
|
||||
//update-begin-author:taoyan date:2022-9-13 for: VUEN-2245 【漏洞】发现新漏洞待处理20220906
|
||||
String redisKey = CommonConstant.PHONE_REDIS_KEY_PRE+phone;
|
||||
Object code = redisUtil.get(redisKey);
|
||||
String redisKey = CommonConstant.PHONE_REDIS_KEY_PRE+phone;
|
||||
Object code = redisUtil.get(redisKey);
|
||||
//update-end-author:taoyan date:2022-9-13 for: VUEN-2245 【漏洞】发现新漏洞待处理20220906
|
||||
|
||||
String username = jsonObject.getString("username");
|
||||
//未设置用户名,则用手机号作为用户名
|
||||
if(oConvertUtils.isEmpty(username)){
|
||||
String username = jsonObject.getString("username");
|
||||
//未设置用户名,则用手机号作为用户名
|
||||
if(oConvertUtils.isEmpty(username)){
|
||||
username = phone;
|
||||
}
|
||||
//未设置密码,则随机生成一个密码
|
||||
String password = jsonObject.getString("password");
|
||||
if(oConvertUtils.isEmpty(password)){
|
||||
String password = jsonObject.getString("password");
|
||||
if(oConvertUtils.isEmpty(password)){
|
||||
password = RandomUtil.randomString(8);
|
||||
}
|
||||
String email = jsonObject.getString("email");
|
||||
SysUser sysUser1 = sysUserService.getUserByName(username);
|
||||
if (sysUser1 != null) {
|
||||
result.setMessage("用户名已注册");
|
||||
result.setSuccess(false);
|
||||
return result;
|
||||
}
|
||||
SysUser sysUser2 = sysUserService.getUserByPhone(phone);
|
||||
if (sysUser2 != null) {
|
||||
result.setMessage("该手机号已注册");
|
||||
result.setSuccess(false);
|
||||
return result;
|
||||
}
|
||||
String email = jsonObject.getString("email");
|
||||
SysUser sysUser1 = sysUserService.getUserByName(username);
|
||||
if (sysUser1 != null) {
|
||||
result.setMessage("用户名已注册");
|
||||
result.setSuccess(false);
|
||||
return result;
|
||||
}
|
||||
SysUser sysUser2 = sysUserService.getUserByPhone(phone);
|
||||
if (sysUser2 != null) {
|
||||
result.setMessage("该手机号已注册");
|
||||
result.setSuccess(false);
|
||||
return result;
|
||||
}
|
||||
|
||||
if(oConvertUtils.isNotEmpty(email)){
|
||||
if(oConvertUtils.isNotEmpty(email)){
|
||||
SysUser sysUser3 = sysUserService.getUserByEmail(email);
|
||||
if (sysUser3 != null) {
|
||||
result.setMessage("邮箱已被注册");
|
||||
|
@ -991,37 +1031,37 @@ public class SysUserController {
|
|||
result.setSuccess(false);
|
||||
return result;
|
||||
}
|
||||
if (!smscode.equals(code.toString())) {
|
||||
result.setMessage("手机验证码错误");
|
||||
result.setSuccess(false);
|
||||
return result;
|
||||
}
|
||||
if (!smscode.equals(code.toString())) {
|
||||
result.setMessage("手机验证码错误");
|
||||
result.setSuccess(false);
|
||||
return result;
|
||||
}
|
||||
|
||||
String realname = jsonObject.getString("realname");
|
||||
if(oConvertUtils.isEmpty(realname)){
|
||||
realname = username;
|
||||
}
|
||||
|
||||
try {
|
||||
user.setCreateTime(new Date());// 设置创建时间
|
||||
String salt = oConvertUtils.randomGen(8);
|
||||
String passwordEncode = PasswordUtil.encrypt(username, password, salt);
|
||||
user.setSalt(salt);
|
||||
user.setUsername(username);
|
||||
user.setRealname(realname);
|
||||
user.setPassword(passwordEncode);
|
||||
user.setEmail(email);
|
||||
user.setPhone(phone);
|
||||
user.setStatus(CommonConstant.USER_UNFREEZE);
|
||||
user.setDelFlag(CommonConstant.DEL_FLAG_0);
|
||||
user.setActivitiSync(CommonConstant.ACT_SYNC_1);
|
||||
sysUserService.addUserWithRole(user,"");//默认临时角色 test
|
||||
result.success("注册成功");
|
||||
} catch (Exception e) {
|
||||
result.error500("注册失败");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
try {
|
||||
user.setCreateTime(new Date());// 设置创建时间
|
||||
String salt = oConvertUtils.randomGen(8);
|
||||
String passwordEncode = PasswordUtil.encrypt(username, password, salt);
|
||||
user.setSalt(salt);
|
||||
user.setUsername(username);
|
||||
user.setRealname(realname);
|
||||
user.setPassword(passwordEncode);
|
||||
user.setEmail(email);
|
||||
user.setPhone(phone);
|
||||
user.setStatus(CommonConstant.USER_UNFREEZE);
|
||||
user.setDelFlag(CommonConstant.DEL_FLAG_0);
|
||||
user.setActivitiSync(CommonConstant.ACT_SYNC_1);
|
||||
sysUserService.addUserWithRole(user,"");//默认临时角色 test
|
||||
result.success("注册成功");
|
||||
} catch (Exception e) {
|
||||
result.error500("注册失败");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 根据用户名或手机号查询用户信息
|
||||
|
@ -1059,28 +1099,28 @@ public class SysUserController {
|
|||
// return result;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 用户手机号验证
|
||||
*/
|
||||
@PostMapping("/phoneVerification")
|
||||
public Result<Map<String,String>> phoneVerification(@RequestBody JSONObject jsonObject) {
|
||||
Result<Map<String,String>> result = new Result<Map<String,String>>();
|
||||
String phone = jsonObject.getString("phone");
|
||||
String smscode = jsonObject.getString("smscode");
|
||||
/**
|
||||
* 用户手机号验证
|
||||
*/
|
||||
@PostMapping("/phoneVerification")
|
||||
public Result<Map<String,String>> phoneVerification(@RequestBody JSONObject jsonObject) {
|
||||
Result<Map<String,String>> result = new Result<Map<String,String>>();
|
||||
String phone = jsonObject.getString("phone");
|
||||
String smscode = jsonObject.getString("smscode");
|
||||
//update-begin-author:taoyan date:2022-9-13 for: VUEN-2245 【漏洞】发现新漏洞待处理20220906
|
||||
String redisKey = CommonConstant.PHONE_REDIS_KEY_PRE+phone;
|
||||
Object code = redisUtil.get(redisKey);
|
||||
if (!smscode.equals(code)) {
|
||||
result.setMessage("手机验证码错误");
|
||||
result.setSuccess(false);
|
||||
return result;
|
||||
}
|
||||
//设置有效时间
|
||||
redisUtil.set(redisKey, smscode,600);
|
||||
Object code = redisUtil.get(redisKey);
|
||||
if (!smscode.equals(code)) {
|
||||
result.setMessage("手机验证码错误");
|
||||
result.setSuccess(false);
|
||||
return result;
|
||||
}
|
||||
//设置有效时间
|
||||
redisUtil.set(redisKey, smscode,600);
|
||||
//update-end-author:taoyan date:2022-9-13 for: VUEN-2245 【漏洞】发现新漏洞待处理20220906
|
||||
|
||||
//新增查询用户名
|
||||
LambdaQueryWrapper<SysUser> query = new LambdaQueryWrapper<>();
|
||||
//新增查询用户名
|
||||
LambdaQueryWrapper<SysUser> query = new LambdaQueryWrapper<>();
|
||||
query.eq(SysUser::getPhone,phone);
|
||||
SysUser user = sysUserService.getOne(query);
|
||||
Map<String,String> map = new HashMap(5);
|
||||
|
@ -1093,18 +1133,18 @@ public class SysUserController {
|
|||
}
|
||||
map.put("username",user.getUsername());
|
||||
result.setResult(map);
|
||||
result.setSuccess(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户更改密码
|
||||
*/
|
||||
@GetMapping("/passwordChange")
|
||||
public Result<SysUser> passwordChange(@RequestParam(name="username")String username,
|
||||
@RequestParam(name="password")String password,
|
||||
@RequestParam(name="smscode")String smscode,
|
||||
@RequestParam(name="phone") String phone) {
|
||||
result.setSuccess(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户更改密码
|
||||
*/
|
||||
@GetMapping("/passwordChange")
|
||||
public Result<SysUser> passwordChange(@RequestParam(name="username")String username,
|
||||
@RequestParam(name="password")String password,
|
||||
@RequestParam(name="smscode")String smscode,
|
||||
@RequestParam(name="phone") String phone) {
|
||||
Result<SysUser> result = new Result<SysUser>();
|
||||
if(oConvertUtils.isEmpty(username) || oConvertUtils.isEmpty(password) || oConvertUtils.isEmpty(smscode) || oConvertUtils.isEmpty(phone) ) {
|
||||
result.setMessage("重置密码失败!");
|
||||
|
@ -1118,12 +1158,12 @@ public class SysUserController {
|
|||
Object object= redisUtil.get(redisKey);
|
||||
//update-end-author:taoyan date:2022-9-13 for: VUEN-2245 【漏洞】发现新漏洞待处理20220906
|
||||
if(null==object) {
|
||||
result.setMessage("短信验证码失效!");
|
||||
result.setMessage("短信验证码失效!");
|
||||
result.setSuccess(false);
|
||||
return result;
|
||||
}
|
||||
if(!smscode.equals(object.toString())) {
|
||||
result.setMessage("短信验证码不匹配!");
|
||||
result.setMessage("短信验证码不匹配!");
|
||||
result.setSuccess(false);
|
||||
return result;
|
||||
}
|
||||
|
@ -1146,65 +1186,65 @@ public class SysUserController {
|
|||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据TOKEN获取用户的部分信息(返回的数据是可供表单设计器使用的数据)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getUserSectionInfoByToken")
|
||||
public Result<?> getUserSectionInfoByToken(HttpServletRequest request, @RequestParam(name = "token", required = false) String token) {
|
||||
try {
|
||||
String username = null;
|
||||
// 如果没有传递token,就从header中获取token并获取用户信息
|
||||
if (oConvertUtils.isEmpty(token)) {
|
||||
username = JwtUtil.getUserNameByToken(request);
|
||||
} else {
|
||||
username = JwtUtil.getUsername(token);
|
||||
}
|
||||
|
||||
log.debug(" ------ 通过令牌获取部分用户信息,当前用户: " + username);
|
||||
/**
|
||||
* 根据TOKEN获取用户的部分信息(返回的数据是可供表单设计器使用的数据)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getUserSectionInfoByToken")
|
||||
public Result<?> getUserSectionInfoByToken(HttpServletRequest request, @RequestParam(name = "token", required = false) String token) {
|
||||
try {
|
||||
String username = null;
|
||||
// 如果没有传递token,就从header中获取token并获取用户信息
|
||||
if (oConvertUtils.isEmpty(token)) {
|
||||
username = JwtUtil.getUserNameByToken(request);
|
||||
} else {
|
||||
username = JwtUtil.getUsername(token);
|
||||
}
|
||||
|
||||
// 根据用户名查询用户信息
|
||||
SysUser sysUser = sysUserService.getUserByName(username);
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("sysUserId", sysUser.getId());
|
||||
map.put("sysUserCode", sysUser.getUsername()); // 当前登录用户登录账号
|
||||
map.put("sysUserName", sysUser.getRealname()); // 当前登录用户真实名称
|
||||
map.put("sysOrgCode", sysUser.getOrgCode()); // 当前登录用户部门编号
|
||||
log.debug(" ------ 通过令牌获取部分用户信息,当前用户: " + username);
|
||||
|
||||
log.debug(" ------ 通过令牌获取部分用户信息,已获取的用户信息: " + map);
|
||||
// 根据用户名查询用户信息
|
||||
SysUser sysUser = sysUserService.getUserByName(username);
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("sysUserId", sysUser.getId());
|
||||
map.put("sysUserCode", sysUser.getUsername()); // 当前登录用户登录账号
|
||||
map.put("sysUserName", sysUser.getRealname()); // 当前登录用户真实名称
|
||||
map.put("sysOrgCode", sysUser.getOrgCode()); // 当前登录用户部门编号
|
||||
|
||||
return Result.ok(map);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Result.error(500, "查询失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 【APP端接口】获取用户列表 根据用户名和真实名 模糊匹配
|
||||
* @param keyword
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/appUserList")
|
||||
public Result<?> appUserList(@RequestParam(name = "keyword", required = false) String keyword,
|
||||
@RequestParam(name = "username", required = false) String username,
|
||||
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
||||
@RequestParam(name = "syncFlow", required = false) String syncFlow) {
|
||||
try {
|
||||
//TODO 从查询效率上将不要用mp的封装的page分页查询 建议自己写分页语句
|
||||
LambdaQueryWrapper<SysUser> query = new LambdaQueryWrapper<SysUser>();
|
||||
if(oConvertUtils.isNotEmpty(syncFlow)){
|
||||
log.debug(" ------ 通过令牌获取部分用户信息,已获取的用户信息: " + map);
|
||||
|
||||
return Result.ok(map);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Result.error(500, "查询失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 【APP端接口】获取用户列表 根据用户名和真实名 模糊匹配
|
||||
* @param keyword
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/appUserList")
|
||||
public Result<?> appUserList(@RequestParam(name = "keyword", required = false) String keyword,
|
||||
@RequestParam(name = "username", required = false) String username,
|
||||
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
||||
@RequestParam(name = "syncFlow", required = false) String syncFlow) {
|
||||
try {
|
||||
//TODO 从查询效率上将不要用mp的封装的page分页查询 建议自己写分页语句
|
||||
LambdaQueryWrapper<SysUser> query = new LambdaQueryWrapper<SysUser>();
|
||||
if(oConvertUtils.isNotEmpty(syncFlow)){
|
||||
query.eq(SysUser::getActivitiSync, CommonConstant.ACT_SYNC_1);
|
||||
}
|
||||
query.eq(SysUser::getDelFlag,CommonConstant.DEL_FLAG_0);
|
||||
if(oConvertUtils.isNotEmpty(username)){
|
||||
if(username.contains(",")){
|
||||
query.eq(SysUser::getDelFlag,CommonConstant.DEL_FLAG_0);
|
||||
if(oConvertUtils.isNotEmpty(username)){
|
||||
if(username.contains(",")){
|
||||
query.in(SysUser::getUsername,username.split(","));
|
||||
}else{
|
||||
query.eq(SysUser::getUsername,username);
|
||||
|
@ -1212,15 +1252,15 @@ public class SysUserController {
|
|||
}else{
|
||||
query.and(i -> i.like(SysUser::getUsername, keyword).or().like(SysUser::getRealname, keyword));
|
||||
}
|
||||
Page<SysUser> page = new Page<>(pageNo, pageSize);
|
||||
IPage<SysUser> res = this.sysUserService.page(page, query);
|
||||
return Result.ok(res);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Result.error(500, "查询失败:" + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
Page<SysUser> page = new Page<>(pageNo, pageSize);
|
||||
IPage<SysUser> res = this.sysUserService.page(page, query);
|
||||
return Result.ok(res);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Result.error(500, "查询失败:" + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取被逻辑删除的用户列表,无分页
|
||||
|
@ -1513,7 +1553,7 @@ public class SysUserController {
|
|||
}
|
||||
return ls;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 聊天 创建聊天组件专用 根据用户账号、用户姓名、部门id分页查询
|
||||
* @param departId 部门id
|
||||
|
@ -1642,7 +1682,7 @@ public class SysUserController {
|
|||
//获取用户id通过职位数据
|
||||
List<SysPosition> sysPositionList = sysPositionService.getPositionList(user.getId());
|
||||
if(null != sysPositionList && sysPositionList.size()>0){
|
||||
//update-end---author:wangshuai ---date:20230220 for:[QQYUN-3980]组织管理中 职位功能 职位表加租户id 加职位-用户关联表------------
|
||||
//update-end---author:wangshuai ---date:20230220 for:[QQYUN-3980]组织管理中 职位功能 职位表加租户id 加职位-用户关联表------------
|
||||
StringBuilder nameBuilder = new StringBuilder();
|
||||
StringBuilder idBuilder = new StringBuilder();
|
||||
String verticalBar = " | ";
|
||||
|
@ -1676,7 +1716,7 @@ public class SysUserController {
|
|||
String username = JwtUtil.getUserNameByToken(request);
|
||||
SysUser user = sysUserService.getById(sysUser.getId());
|
||||
if(user==null) {
|
||||
return Result.error("未找到该用户数据");
|
||||
return Result.error("未找到该用户数据");
|
||||
}
|
||||
if(!username.equals(user.getUsername())){
|
||||
return Result.error("只能修改自己的数据");
|
||||
|
@ -1814,7 +1854,7 @@ public class SysUserController {
|
|||
return sysUserService.exportAppUser(request);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 应用用户导入
|
||||
* @param request
|
||||
* @return
|
||||
|
|
Loading…
Reference in New Issue