|
@@ -0,0 +1,190 @@
|
|
|
+package org.jeecg.modules.adweb.enterprise.controller;
|
|
|
+
|
|
|
+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.v3.oas.annotations.Operation;
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import jakarta.servlet.http.HttpServletRequest;
|
|
|
+import java.util.*;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.shiro.SecurityUtils;
|
|
|
+import org.jeecg.common.api.vo.Result;
|
|
|
+import org.jeecg.common.aspect.annotation.AutoLog;
|
|
|
+import org.jeecg.common.system.api.ISysBaseAPI;
|
|
|
+import org.jeecg.common.system.query.QueryGenerator;
|
|
|
+import org.jeecg.common.system.vo.LoginUser;
|
|
|
+import org.jeecg.modules.adweb.common.mapper.CommonMapper;
|
|
|
+import org.jeecg.modules.adweb.enquiry.service.IAdwebEnquiryService;
|
|
|
+import org.jeecg.modules.adweb.enquiry.service.ISubUserEmailService;
|
|
|
+import org.jeecg.modules.adweb.enterprise.service.SysUserPermissionService;
|
|
|
+import org.jeecg.modules.adweb.enterprise.vo.User;
|
|
|
+import org.jeecg.modules.adweb.site.entity.AdwebSite;
|
|
|
+import org.jeecg.modules.adweb.site.service.IAdwebSiteService;
|
|
|
+import org.jeecg.modules.adweb.site.service.IAdwebUserWpsiteService;
|
|
|
+import org.jeecg.modules.adweb.site.service.ISiteUserPermissionService;
|
|
|
+import org.jeecg.modules.adweb.system.service.IMasterSubAccountRelationService;
|
|
|
+import org.jeecg.modules.system.entity.SysUser;
|
|
|
+import org.jeecg.modules.system.service.*;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description: 企业用户管理 @Author: jeecg-boot @Date: 2022-06-10 @Version: V1.0
|
|
|
+ */
|
|
|
+@Tag(name = "企业用户管理")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/enterprise/user")
|
|
|
+@Slf4j
|
|
|
+public class EnterpriseUserManageController {
|
|
|
+ @Autowired private ISysUserService sysUserService;
|
|
|
+
|
|
|
+ @Autowired private IMasterSubAccountRelationService masterSubAccountRelationService;
|
|
|
+
|
|
|
+ @Autowired private ISysRoleService sysRoleService;
|
|
|
+
|
|
|
+ @Autowired private ISysUserRoleService sysUserRoleService;
|
|
|
+
|
|
|
+ @Autowired private ISiteUserPermissionService siteUserPermissionService;
|
|
|
+
|
|
|
+ @Autowired private IAdwebSiteService adwebSiteService;
|
|
|
+
|
|
|
+ @Resource private SysUserPermissionService sysUserPermissionService;
|
|
|
+
|
|
|
+ @Resource private CommonMapper adwebCommonMapper;
|
|
|
+
|
|
|
+ @Resource private IAdwebEnquiryService adwebEnquiryService;
|
|
|
+
|
|
|
+ @Autowired private ISysBaseAPI sysBaseAPI;
|
|
|
+
|
|
|
+ @Autowired private IAdwebUserWpsiteService adwebUserWpsiteService;
|
|
|
+
|
|
|
+ @Autowired private ISubUserEmailService subUserEmailService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 子账户分页列表查询
|
|
|
+ *
|
|
|
+ * @param user
|
|
|
+ * @param pageNo
|
|
|
+ * @param pageSize
|
|
|
+ * @param req
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "企业用户管理-子账户分页列表查询")
|
|
|
+ @Operation(summary = "企业用户管理-子账户分页列表查询")
|
|
|
+ @GetMapping(value = "/sub/list")
|
|
|
+ public Result<IPage<User>> querySubPageList(
|
|
|
+ SysUser user,
|
|
|
+ @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
|
|
+ @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
|
|
+ @RequestParam String siteCode,
|
|
|
+ HttpServletRequest req) {
|
|
|
+ Map<String, String[]> map = new HashMap(req.getParameterMap());
|
|
|
+ map.put("order", new String[] {"asc"});
|
|
|
+
|
|
|
+ LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ List<String> idList =
|
|
|
+ masterSubAccountRelationService.getSubAccountIdByMaster(loginUser.getId());
|
|
|
+ // 获取当前站点主账号
|
|
|
+ QueryWrapper<AdwebSite> adwebSiteQueryWrapper = new QueryWrapper<>();
|
|
|
+ adwebSiteQueryWrapper.eq("code", siteCode);
|
|
|
+ AdwebSite adwebSite = adwebSiteService.getOne(adwebSiteQueryWrapper);
|
|
|
+ if (adwebSite != null) {
|
|
|
+ idList.add(adwebSite.getUid());
|
|
|
+ }
|
|
|
+ // idList.add(loginUser.getId());
|
|
|
+ if (CollectionUtils.isEmpty(idList)) {
|
|
|
+ return Result.OK();
|
|
|
+ }
|
|
|
+ QueryWrapper<SysUser> queryWrapper = QueryGenerator.initQueryWrapper(user, map);
|
|
|
+ queryWrapper.ne("username", "_reserve_user_external");
|
|
|
+ queryWrapper.in("id", idList);
|
|
|
+ queryWrapper.eq("status", 1);
|
|
|
+ String queryCondition = req.getParameter("queryCondition");
|
|
|
+ if (StringUtils.isNotEmpty(queryCondition)) {
|
|
|
+ queryWrapper.and(
|
|
|
+ wrapper ->
|
|
|
+ wrapper
|
|
|
+ .like("username", queryCondition)
|
|
|
+ .or()
|
|
|
+ .like("realname", queryCondition)
|
|
|
+ .or()
|
|
|
+ .like("phone", queryCondition));
|
|
|
+ }
|
|
|
+ Page<SysUser> page = new Page<SysUser>(pageNo, pageSize);
|
|
|
+ IPage<SysUser> pageList = sysUserService.page(page, queryWrapper);
|
|
|
+ // 类型转换
|
|
|
+ IPage<User> pageList2 = converseType(pageList);
|
|
|
+ // 序号
|
|
|
+ this.addSeqNumber(pageList2.getRecords(), pageNo, pageSize);
|
|
|
+ // 统计管理的询盘和产品数量
|
|
|
+ /*Map<String, Integer> map1 = adwebEnquiryService.getEnquiryCount(idList);
|
|
|
+ Map<String, Integer> map2 = adwebMaterialProductService.getProductCount(idList);
|
|
|
+ for (User user1 : pageList2.getRecords()) {
|
|
|
+ if (map1.get(user1.getId()) != null) {
|
|
|
+ user1.setEnquiryNum(map1.get(user1.getId()));
|
|
|
+ }
|
|
|
+ if (map2.get(user1.getId()) != null) {
|
|
|
+ user1.setProductNum(map2.get(user1.getId()));
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+ // 主账户产品和询盘数量统计规则不同
|
|
|
+ if (pageNo == 1 && CollectionUtils.isNotEmpty(pageList2.getRecords())) {
|
|
|
+ User user1 = pageList2.getRecords().get(0);
|
|
|
+ if (user1.getId().equals(adwebSite.getUid())) {
|
|
|
+ user1.setPrimaryAccount(true);
|
|
|
+ user1.setIsInquiry(2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result.OK(pageList2);
|
|
|
+ }
|
|
|
+
|
|
|
+ private IPage<User> converseType(IPage<SysUser> pageList) {
|
|
|
+ IPage<User> pageList2 = new Page<>();
|
|
|
+ pageList2.setPages(pageList.getPages());
|
|
|
+ pageList2.setCurrent(pageList.getCurrent());
|
|
|
+ pageList2.setSize(pageList.getSize());
|
|
|
+ pageList2.setTotal(pageList.getTotal());
|
|
|
+ if (CollectionUtils.isEmpty(pageList.getRecords())) {
|
|
|
+ pageList2.setRecords(new ArrayList<>());
|
|
|
+ return pageList2;
|
|
|
+ }
|
|
|
+ List<User> users = new ArrayList<>();
|
|
|
+ for (SysUser sysUser : pageList.getRecords()) {
|
|
|
+ User user = new User();
|
|
|
+ user.setId(sysUser.getId());
|
|
|
+ user.setUsername(sysUser.getUsername());
|
|
|
+ user.setRealname(sysUser.getRealname());
|
|
|
+ user.setAvatar(sysUser.getAvatar());
|
|
|
+ user.setPhone(sysUser.getPhone());
|
|
|
+ user.setEmail(sysUser.getEmail());
|
|
|
+ user.setUpdateTime(sysUser.getUpdateTime());
|
|
|
+ user.setCreateTime(sysUser.getCreateTime());
|
|
|
+ // user.setIsInquiry(sysUser.getIsInquiry());
|
|
|
+ user.setSex(sysUser.getSex());
|
|
|
+ users.add(user);
|
|
|
+ }
|
|
|
+ pageList2.setRecords(users);
|
|
|
+ return pageList2;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 增加序号
|
|
|
+ *
|
|
|
+ * @param productList 结果集合
|
|
|
+ * @param pageNum 页号
|
|
|
+ * @param pageSize 页长
|
|
|
+ */
|
|
|
+ public void addSeqNumber(List<User> productList, int pageNum, int pageSize) {
|
|
|
+ if (CollectionUtils.isEmpty(productList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int index = (pageNum - 1) * pageSize + 1;
|
|
|
+ for (User user : productList) {
|
|
|
+ user.setSeqNumber(index++);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|