Prechádzať zdrojové kódy

客户转移&客户转移申请

xdd 2 týždňov pred
rodič
commit
a428fb7786

+ 1 - 1
fs-company-app/src/main/java/com/fs/app/exception/FSExceptionHandler.java

@@ -62,7 +62,7 @@ public class FSExceptionHandler {
 
 			return R.error(defaultMessage);
 		}else {
-			return R.error();
+			return R.error(e.getMessage());
 		}
 
 	}

+ 1 - 1
fs-company/src/main/java/com/fs/core/exception/FSExceptionHandler.java

@@ -57,7 +57,7 @@ public class FSExceptionHandler {
 	@ExceptionHandler(Exception.class)
 	public R handleException(Exception e){
 		logger.error(e.getMessage(), e);
-		return R.error();
+		return R.error(e.getMessage());
 	}
 
 

+ 81 - 0
fs-company/src/main/java/com/fs/users/controller/MyCompanyCustomerController.java

@@ -0,0 +1,81 @@
+package com.fs.users.controller;
+
+import com.alibaba.fastjson.JSON;
+import com.fs.common.core.domain.R;
+import com.fs.common.core.page.TableDataInfo;
+import com.fs.common.utils.ServletUtils;
+import com.fs.core.security.LoginUser;
+import com.fs.core.web.service.TokenService;
+import com.fs.qw.domain.CustomerTransferApproval;
+import com.fs.qw.service.ICustomerTransferApprovalService;
+import com.fs.store.dto.FsUserTransferParamDTO;
+import com.fs.store.param.SelectCusListPageParam;
+import com.fs.store.service.IFsUserService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Date;
+
+/**
+ * 客户转移审批Controller
+ *
+ * @author fs
+ * @date 2025-04-01
+ */
+@Slf4j
+@RestController
+@RequestMapping("/fsuser/user")
+public class MyCompanyCustomerController {
+
+    @Autowired
+    private ICustomerTransferApprovalService transferApprovalService;
+
+    @Autowired
+    private IFsUserService fsUserService;
+
+    @Autowired
+    private TokenService tokenService;
+
+
+    /**
+     * 列出当前公司的客户
+     * @param param 参数
+     * @return 返回数据
+     */
+    @GetMapping("/list")
+    public TableDataInfo list(SelectCusListPageParam param){
+        return fsUserService.selectCusListPage(param);
+    }
+    /**
+     * 导出
+     */
+    @PostMapping("/export")
+    public void export(){
+
+    }
+    /**
+     * 转移
+     * @param param
+     */
+    @PostMapping("/transfer")
+    public R transfer(@RequestBody FsUserTransferParamDTO param){
+        log.info("客户转移: {}",param);
+        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
+        param.setSourceCompanyUserId(loginUser.getUser().getUserId());
+        CustomerTransferApproval customerTransferApproval = new CustomerTransferApproval();
+        customerTransferApproval.setCorpId(String.valueOf(loginUser.getCompany().getCompanyId()));
+        customerTransferApproval.setCustomerIds(JSON.toJSONString(param.getUserIds()));
+        customerTransferApproval.setOriginalUserId(param.getSourceCompanyUserId());
+        customerTransferApproval.setTargetUserId(param.getTargetCompanyUserId());
+        customerTransferApproval.setInitiatorUserId(param.getSourceCompanyUserId());
+        customerTransferApproval.setContent(param.getContent());
+        customerTransferApproval.setCreatedAt(new Date());
+        customerTransferApproval.setUpdatedAt(new Date());
+        customerTransferApproval.setApprovalStatus(0);
+        customerTransferApproval.setTransferType(2);
+        transferApprovalService.insertCustomerTransferApproval(customerTransferApproval);
+        return R.ok("转移申请已经提交,等待总后台审核!");
+    }
+
+}

+ 0 - 52
fs-company/src/main/java/com/fs/users/controller/MyCustoController.java

@@ -1,52 +0,0 @@
-package com.fs.users.controller;
-
-import com.fs.common.core.page.TableDataInfo;
-import com.fs.store.domain.FsUser;
-import com.fs.store.param.SelectCusListPageParam;
-import com.fs.store.service.IFsUserService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * 客户转移审批Controller
- *
- * @author fs
- * @date 2025-04-01
- */
-@RestController
-@RequestMapping("/company/user")
-public class MyCustoController {
-
-    @Autowired
-    private IFsUserService fsUserService;
-
-
-    /**
-     * 列出当前公司的客户
-     * @param param 参数
-     * @return 返回数据
-     */
-    @GetMapping("/list")
-    public TableDataInfo list(SelectCusListPageParam param){
-        return fsUserService.selectCusListPage(param);
-    }
-    /**
-     * 导出
-     */
-    @PostMapping("/export")
-    public void export(){
-
-    }
-    /**
-     * 转移
-     * @param user
-     */
-    @PostMapping("/transfer")
-    public void transfer(FsUser user){
-
-    }
-
-}

+ 22 - 2
fs-service-system/src/main/java/com/fs/qw/domain/CustomerTransferApproval.java

@@ -1,11 +1,17 @@
 package com.fs.qw.domain;
 
 import java.util.Date;
+import java.util.List;
+
+import cn.hutool.core.lang.Pair;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fs.common.annotation.Excel;
 import com.fs.common.core.domain.BaseEntity;
+import com.fs.qw.vo.TransferCustomDTO;
+import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 import org.apache.commons.lang3.builder.ToStringStyle;
 
@@ -17,6 +23,8 @@ import org.apache.commons.lang3.builder.ToStringStyle;
  */
 @EqualsAndHashCode(callSuper = true)
 @Data
+@AllArgsConstructor
+@NoArgsConstructor
 public class CustomerTransferApproval extends BaseEntity
 {
     private static final long serialVersionUID = 1L;
@@ -27,26 +35,37 @@ public class CustomerTransferApproval extends BaseEntity
     /** 企业 ID */
     @Excel(name = "企业 ID")
     private String corpId;
+    private String companyName;
 
     /** 转移类型: 1=离职继承, 2=在职转接 */
     @Excel(name = "转移类型: 1=离职继承, 2=在职转接")
-    private Long transferType;
+    private Integer transferType;
+    private String transferTypeText;
 
     /** 客户 ID 列表 (JSON 数组字符串或逗号分隔) */
     @Excel(name = "客户 ID 列表 (JSON 数组字符串或逗号分隔)")
     private String customerIds;
+    private List<TransferCustomDTO> customerList;
 
     /** 原负责人用户 ID (离职继承时为离职人员ID,在职转接时为转出人员ID) */
     @Excel(name = "原负责人用户 ID (离职继承时为离职人员ID,在职转接时为转出人员ID)")
     private Long originalUserId;
+    private String originalUserName;
 
     /** 目标接收销售用户 ID */
     @Excel(name = "目标接收销售用户 ID")
     private Long targetUserId;
+    private String targetUserName;
 
     /** 发起此转移请求的用户 ID */
     @Excel(name = "发起此转移请求的用户 ID")
     private Long initiatorUserId;
+    private String initiatorUserName;
+
+    /**
+     * 转移前数据
+     */
+    private String transferBefore;
 
     /** 转移提示内容/原因 */
     @Excel(name = "转移提示内容/原因")
@@ -54,7 +73,8 @@ public class CustomerTransferApproval extends BaseEntity
 
     /** 审批状态: 0=待审批, 1=审批通过, 2=审批驳回, 3=已撤销 */
     @Excel(name = "审批状态: 0=待审批, 1=审批通过, 2=审批驳回, 3=已撤销")
-    private Long approvalStatus;
+    private Integer approvalStatus;
+    private String approvalStatusText;
 
     /** 审批人用户 ID */
     @Excel(name = "审批人用户 ID")

+ 181 - 6
fs-service-system/src/main/java/com/fs/qw/service/impl/CustomerTransferApprovalServiceImpl.java

@@ -1,12 +1,35 @@
 package com.fs.qw.service.impl;
 
+import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
+import java.util.Optional;
 
+import cn.hutool.core.lang.Pair;
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.fs.common.utils.DictUtils;
+import com.fs.company.cache.ICompanyCacheService;
+import com.fs.company.cache.ICompanyUserCacheService;
+import com.fs.company.domain.Company;
+import com.fs.company.domain.CompanyUser;
 import com.fs.qw.domain.CustomerTransferApproval;
 import com.fs.qw.mapper.CustomerTransferApprovalMapper;
 import com.fs.qw.service.ICustomerTransferApprovalService;
+import com.fs.qw.vo.TransferCustomDTO;
+import com.fs.store.domain.FsUser;
+import com.fs.store.dto.FsUserTransferParamDTO;
+import com.fs.store.service.IFsUserService;
+import com.fs.store.service.cache.IFsUserCacheService;
+import com.hc.openapi.tool.util.StringUtils;
+import org.apache.http.util.Asserts;
+import org.springframework.aop.framework.AopContext;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
 
 /**
  * 客户转移审批Service业务层处理
@@ -15,11 +38,24 @@ import org.springframework.stereotype.Service;
  * @date 2025-04-01
  */
 @Service
+@EnableAspectJAutoProxy(proxyTargetClass = true,exposeProxy = true)
 public class CustomerTransferApprovalServiceImpl implements ICustomerTransferApprovalService
 {
     @Autowired
     private CustomerTransferApprovalMapper customerTransferApprovalMapper;
 
+    @Autowired
+    private ICompanyUserCacheService companyUserCacheService;
+
+    @Autowired
+    private ICompanyCacheService companyCacheService;
+
+    @Autowired
+    private IFsUserCacheService fsUserCacheService;
+
+    @Autowired
+    private IFsUserService fsUserService;
+
     /**
      * 查询客户转移审批
      *
@@ -27,9 +63,87 @@ public class CustomerTransferApprovalServiceImpl implements ICustomerTransferApp
      * @return 客户转移审批
      */
     @Override
-    public CustomerTransferApproval selectCustomerTransferApprovalById(Long id)
+    public synchronized CustomerTransferApproval selectCustomerTransferApprovalById(Long id)
     {
-        return customerTransferApprovalMapper.selectCustomerTransferApprovalById(id);
+        CustomerTransferApproval item = customerTransferApprovalMapper.selectCustomerTransferApprovalById(id);
+
+        if(ObjectUtils.isNotNull(item.getCorpId())){
+            Company company = companyCacheService.selectCompanyById(Long.valueOf(item.getCorpId()));
+            if(ObjectUtils.isNotNull(company)){
+                item.setCompanyName(String.format("%s_%s",company.getCompanyName(),company.getCompanyId()));
+            }
+        }
+        if(ObjectUtils.isNotNull(item.getTransferType())){
+            String transferType = DictUtils.getDictLabel("transfer_type", String.valueOf(item.getTransferType()));
+            if(ObjectUtils.isNotEmpty(transferType)){
+                item.setTransferTypeText(transferType);
+            }
+        }
+        if(ObjectUtils.isNotNull(item.getApprovalStatus())){
+            String approvalStatus = DictUtils.getDictLabel("transfer_approval_status", String.valueOf(item.getApprovalStatus()));
+            if(ObjectUtils.isNotEmpty(approvalStatus)){
+                item.setApprovalStatusText(approvalStatus);
+            }
+        }
+
+        if(ObjectUtils.isNotNull(item.getOriginalUserId())){
+            CompanyUser companyUser = companyUserCacheService.selectCompanyUserById(item.getOriginalUserId());
+            if(ObjectUtils.isNotNull(companyUser)){
+                item.setOriginalUserName(String.format("%s_%d",companyUser.getUserName(),companyUser.getUserId()));
+            }
+        }
+
+        // 目标接收销售用户
+        if(ObjectUtils.isNotNull(item.getTargetUserId())){
+            CompanyUser companyUser = companyUserCacheService.selectCompanyUserById(item.getTargetUserId());
+            if(ObjectUtils.isNotNull(companyUser)){
+                item.setTargetUserName(String.format("%s_%d", companyUser.getUserName(), companyUser.getUserId()));
+            }
+        }
+
+        // 发起此转移请求的用户
+        if(ObjectUtils.isNotNull(item.getInitiatorUserId())){
+            CompanyUser companyUser = companyUserCacheService.selectCompanyUserById(item.getInitiatorUserId());
+            if(ObjectUtils.isNotNull(companyUser)){
+                item.setInitiatorUserName(String.format("%s_%d", companyUser.getUserName(), companyUser.getUserId()));
+            }
+        }
+
+        if(StringUtils.isBlank(item.getTransferBefore()) && StringUtils.isNotBlank(item.getCustomerIds())){
+            List<Long> customerIds = JSON.parseArray(item.getCustomerIds(), Long.class);
+            List<TransferCustomDTO> customerList = getCustomerList(customerIds, item);
+            item.setCustomerList(customerList);
+        } else {
+            List<TransferCustomDTO> customerList = JSON.parseArray(item.getTransferBefore(), TransferCustomDTO.class);
+            item.setCustomerList(customerList);
+        }
+        return item;
+    }
+
+    private List<TransferCustomDTO> getCustomerList(List<Long> customerIds, CustomerTransferApproval item) {
+        List<TransferCustomDTO> customerList = new ArrayList<>();
+
+        for (Long customerId : customerIds) {
+
+            FsUser fsUser = fsUserCacheService.selectFsUserById(customerId);
+            if(ObjectUtils.isNotNull(fsUser)){
+                String companyUserName = "无";
+                if(ObjectUtils.isNotNull(fsUser.getCompanyUserId())){
+                    CompanyUser companyUser = companyUserCacheService.selectCompanyUserById(fsUser.getCompanyUserId());
+                    companyUserName = String.format("%s_%d", companyUser.getUserName(), companyUser.getUserId());
+                }
+
+                customerList.add(TransferCustomDTO.builder()
+                        .userName(String.format("%s_%d", fsUser.getNickname(), fsUser.getUserId()))
+                        .userId(fsUser.getUserId())
+                        .beforeCompanyUserName(companyUserName)
+                        .beforeCompanyUserId(fsUser.getCompanyUserId())
+                        .afterCompanyUserName(item.getTargetUserName())
+                        .afterCompanyUserId(item.getTargetUserId())
+                        .build());
+            }
+        }
+        return customerList;
     }
 
     /**
@@ -41,7 +155,49 @@ public class CustomerTransferApprovalServiceImpl implements ICustomerTransferApp
     @Override
     public List<CustomerTransferApproval> selectCustomerTransferApprovalList(CustomerTransferApproval customerTransferApproval)
     {
-        return customerTransferApprovalMapper.selectCustomerTransferApprovalList(customerTransferApproval);
+        List<CustomerTransferApproval> list = customerTransferApprovalMapper.selectCustomerTransferApprovalList(customerTransferApproval);
+        for (CustomerTransferApproval item : list) {
+            if(ObjectUtils.isNotNull(item.getCorpId())){
+                Company company = companyCacheService.selectCompanyById(Long.valueOf(item.getCorpId()));
+                if(ObjectUtils.isNotNull(company)){
+                    item.setCompanyName(String.format("%s_%s",company.getCompanyName(),company.getCompanyId()));
+                }
+            }
+            if(ObjectUtils.isNotNull(item.getTransferType())){
+                String transferType = DictUtils.getDictLabel("transfer_type", String.valueOf(item.getTransferType()));
+                if(ObjectUtils.isNotEmpty(transferType)){
+                    item.setTransferTypeText(transferType);
+                }
+            }
+            if(ObjectUtils.isNotNull(item.getApprovalStatus())){
+                String approvalStatus = DictUtils.getDictLabel("transfer_approval_status", String.valueOf(item.getApprovalStatus()));
+                if(ObjectUtils.isNotEmpty(approvalStatus)){
+                    item.setApprovalStatusText(approvalStatus);
+                }
+            }
+
+            if(ObjectUtils.isNotNull(item.getOriginalUserId())){
+                CompanyUser companyUser = companyUserCacheService.selectCompanyUserById(item.getOriginalUserId());
+                if(ObjectUtils.isNotNull(companyUser)){
+                    item.setOriginalUserName(String.format("%s_%d",companyUser.getUserName(),companyUser.getUserId()));
+                }
+            }
+
+            if(ObjectUtils.isNotNull(item.getTargetUserId())){
+                CompanyUser companyUser = companyUserCacheService.selectCompanyUserById(item.getTargetUserId());
+                if(ObjectUtils.isNotNull(companyUser)){
+                    item.setTargetUserName(String.format("%s_%d", companyUser.getUserName(), companyUser.getUserId()));
+                }
+            }
+
+            if(ObjectUtils.isNotNull(item.getInitiatorUserId())){
+                CompanyUser companyUser = companyUserCacheService.selectCompanyUserById(item.getInitiatorUserId());
+                if(ObjectUtils.isNotNull(companyUser)){
+                    item.setInitiatorUserName(String.format("%s_%d", companyUser.getUserName(), companyUser.getUserId()));
+                }
+            }
+        }
+        return list;
     }
 
     /**
@@ -59,13 +215,32 @@ public class CustomerTransferApprovalServiceImpl implements ICustomerTransferApp
     /**
      * 修改客户转移审批
      *
-     * @param customerTransferApproval 客户转移审批
+     * @param item 客户转移审批
      * @return 结果
      */
     @Override
-    public int updateCustomerTransferApproval(CustomerTransferApproval customerTransferApproval)
+    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
+    public int updateCustomerTransferApproval(CustomerTransferApproval item)
     {
-        return customerTransferApprovalMapper.updateCustomerTransferApproval(customerTransferApproval);
+        item.setProcessedAt(new Date());
+//        审批状态: 0=待审批, 1=审批通过, 2=审批驳回, 3=已撤销
+        // 如果审批通过 进行转移
+        if(ObjectUtil.equal(1,item.getApprovalStatus())){
+            FsUserTransferParamDTO transferParam = new FsUserTransferParamDTO();
+            transferParam.setContent(item.getContent());
+            transferParam.setTargetCompanyUserId(item.getTargetUserId());
+
+            Asserts.check(StringUtils.isNotBlank(item.getCustomerIds()),"转移客户不能为空!");
+            List<Long> customerIds = JSON.parseArray(item.getCustomerIds(), Long.class);
+            transferParam.setUserIds(customerIds);
+            transferParam.setSourceCompanyUserId(item.getOriginalUserId());
+
+            fsUserService.transfer(transferParam);
+        }
+        List<Long> customerIds = JSON.parseArray(item.getCustomerIds(), Long.class);
+        List<TransferCustomDTO> customerList = getCustomerList(customerIds, item);
+        item.setTransferBefore(JSON.toJSONString(customerList));
+        return customerTransferApprovalMapper.updateCustomerTransferApproval(item);
     }
 
     /**

+ 30 - 0
fs-service-system/src/main/java/com/fs/qw/vo/TransferCustomDTO.java

@@ -0,0 +1,30 @@
+package com.fs.qw.vo;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+public class TransferCustomDTO implements Serializable {
+    /**
+     * 用户名
+     */
+    private String userName;
+    private Long userId;
+    /**
+     * 转移前销售
+     */
+    private String beforeCompanyUserName;
+    private Long beforeCompanyUserId;
+    /**
+     * 转移后销售
+     */
+    private String afterCompanyUserName;
+    private Long afterCompanyUserId;
+}

+ 18 - 0
fs-service-system/src/main/java/com/fs/store/domain/FsUser.java

@@ -73,6 +73,7 @@ public class FsUser extends BaseEntity
     /** 1为正常,0为禁止 */
     @Excel(name = "状态:1为正常,0为禁止")
     private Integer status;
+    private String statusText;
 
     /** 等级 */
     private Integer level;
@@ -113,6 +114,7 @@ public class FsUser extends BaseEntity
     private Long companyId;
 
     private Long companyUserId;
+    private String companyUserName;
 
     @JsonFormat(pattern = "yyyy-MM-dd")
     @Excel(name = "推线日期", width = 30, dateFormat = "yyyy-MM-dd")
@@ -137,6 +139,22 @@ public class FsUser extends BaseEntity
 
     private Integer isShow;//是否展示购买以及订单状态
 
+    public String getStatusText() {
+        return statusText;
+    }
+
+    public void setStatusText(String statusText) {
+        this.statusText = statusText;
+    }
+
+    public String getCompanyUserName() {
+        return companyUserName;
+    }
+
+    public void setCompanyUserName(String companyUserName) {
+        this.companyUserName = companyUserName;
+    }
+
     public Integer getIsAddQw() {
         return isAddQw;
     }

+ 31 - 0
fs-service-system/src/main/java/com/fs/store/dto/FsUserTransferParamDTO.java

@@ -0,0 +1,31 @@
+package com.fs.store.dto;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * 客户转移dto
+ */
+@Data
+public class FsUserTransferParamDTO implements Serializable {
+
+    /**
+     * 来源销售id
+     */
+    private Long sourceCompanyUserId;
+    /**
+     * 目标销售id
+     */
+    private Long targetCompanyUserId;
+    /**
+     * 客户id
+     */
+    private List<Long> userIds;
+
+    /**
+     * 转移提示内容/原因
+     */
+    private String content;
+}

+ 3 - 0
fs-service-system/src/main/java/com/fs/store/mapper/FsUserMapper.java

@@ -6,6 +6,7 @@ import com.fs.qw.param.QwFsUserParam;
 import com.fs.qw.vo.QwFsUserVO;
 import com.fs.store.domain.FsStorePayment;
 import com.fs.store.domain.FsUser;
+import com.fs.store.dto.FsUserTransferParamDTO;
 import com.fs.store.param.SelectCusListPageParam;
 import com.fs.store.vo.FSUserVO;
 
@@ -212,4 +213,6 @@ public interface FsUserMapper
      */
     List<FsUser> selectCusListPage(SelectCusListPageParam param);
     Long selectCusListPageCount(SelectCusListPageParam param);
+
+    void transferCompanyUser(FsUserTransferParamDTO param);
 }

+ 3 - 0
fs-service-system/src/main/java/com/fs/store/param/SelectCusListPageParam.java

@@ -20,4 +20,7 @@ public class SelectCusListPageParam extends BaseEntity {
      * 手机号码
      */
     private String phone;
+
+    private Long pageNum;
+    private Long pageSize;
 }

+ 4 - 0
fs-service-system/src/main/java/com/fs/store/service/IFsUserService.java

@@ -10,6 +10,7 @@ import com.fs.store.domain.FsStoreOrder;
 import com.fs.store.domain.FsStoreOrderItem;
 import com.fs.store.domain.FsUser;
 
+import com.fs.store.dto.FsUserTransferParamDTO;
 import com.fs.store.param.SelectCusListPageParam;
 import com.fs.store.vo.FSUserVO;
 import com.fs.store.vo.FsCompanyUserListQueryVO;
@@ -127,4 +128,7 @@ public interface IFsUserService
     FsUser selectFsUserByUnionid(String unionId);
 
     List<FsUser> getUserListLimit(FsUser fsUser);
+
+    void transfer(FsUserTransferParamDTO param);
+
 }

+ 37 - 5
fs-service-system/src/main/java/com/fs/store/service/impl/FsUserServiceImpl.java

@@ -1,19 +1,23 @@
 package com.fs.store.service.impl;
 
 import java.math.BigDecimal;
-import java.util.Collections;
 import java.util.List;
+
+import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.fs.common.core.domain.R;
 import com.fs.common.core.page.TableDataInfo;
 import com.fs.common.utils.DateUtils;
+import com.fs.company.cache.ICompanyUserCacheService;
+import com.fs.company.domain.CompanyUser;
 import com.fs.qw.param.QwFsUserParam;
 import com.fs.qw.vo.QwFsUserVO;
 import com.fs.store.domain.FsStoreOrder;
 import com.fs.store.domain.FsStoreOrderItem;
 import com.fs.store.domain.FsUserBill;
 import com.fs.store.dto.FsStoreCartDTO;
+import com.fs.store.dto.FsUserTransferParamDTO;
 import com.fs.store.enums.BillDetailEnum;
 import com.fs.store.mapper.FsStoreOrderMapper;
 import com.fs.store.mapper.FsStoreProductAttrValueMapper;
@@ -22,12 +26,14 @@ import com.fs.store.service.IFsUserBillService;
 import com.fs.store.vo.FSUserVO;
 import com.fs.store.vo.FsCompanyUserListQueryVO;
 import com.fs.store.vo.FsUserTuiVO;
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.http.util.Asserts;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.fs.store.mapper.FsUserMapper;
 import com.fs.store.domain.FsUser;
 import com.fs.store.service.IFsUserService;
+import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
 import static com.fs.store.enums.BillDetailEnum.CATEGORY_1;
@@ -52,6 +58,9 @@ public class FsUserServiceImpl implements IFsUserService
     private IFsUserBillService billService;
     @Autowired
     private FsStoreOrderMapper storeOrderMapper;
+
+    @Autowired
+    private ICompanyUserCacheService companyUserCacheService;
     /**
      * 查询用户
      *
@@ -155,12 +164,25 @@ public class FsUserServiceImpl implements IFsUserService
 
     @Override
     public TableDataInfo selectCusListPage(SelectCusListPageParam param) {
-        Asserts.notNull(param,"请求参数不能为空!");
-        Asserts.notNull(param.getParams(),"分页参数不能为空");
-        Asserts.notNull(param.getParams().get("pageNum"), "页数不能为空");
-        Asserts.notNull(param.getParams().get("pageSize"), "页大小不能为空");
+        Asserts.check(ObjectUtils.isNotNull(param.getPageNum()), "页数不能为空");
+        Asserts.check(ObjectUtils.isNotNull(param.getPageSize()), "页大小不能为空");
 
         List<FsUser> fsUsers = fsUserMapper.selectCusListPage(param);
+        for (FsUser fsUser : fsUsers) {
+            if(ObjectUtils.isNotNull(fsUser.getStatus())){
+                if(ObjectUtil.equal(0,fsUser.getStatus())){
+                    fsUser.setStatusText("禁止");
+                } else {
+                    fsUser.setStatusText("正常");
+                }
+            }
+            if(ObjectUtils.isNotNull(fsUser.getCompanyUserId())){
+                CompanyUser companyUser = companyUserCacheService.selectCompanyUserById(fsUser.getUserId());
+                if(ObjectUtils.isNotNull(companyUser)){
+                    fsUser.setCompanyUserName(companyUser.getNickName());
+                }
+            }
+        }
         TableDataInfo tableDataInfo = new TableDataInfo();
         tableDataInfo.setRows(fsUsers);
         tableDataInfo.setTotal(fsUserMapper.selectCusListPageCount(param));
@@ -371,4 +393,14 @@ public class FsUserServiceImpl implements IFsUserService
     public List<FsUser> getUserListLimit(FsUser fsUser) {
         return fsUserMapper.selectFsUserListLimit(fsUser);
     }
+
+    @Override
+    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
+    public void transfer(FsUserTransferParamDTO param) {
+        Asserts.check(ObjectUtils.isNotNull(param.getSourceCompanyUserId()), "来源用户不能为空!");
+        Asserts.check(ObjectUtils.isNotNull(param.getTargetCompanyUserId()), "转移用户不能为空!");
+        Asserts.check(CollectionUtils.isNotEmpty(param.getUserIds()), "要转移的客户列表不能为空!");
+
+        fsUserMapper.transferCompanyUser(param);
+    }
 }

+ 5 - 1
fs-service-system/src/main/resources/mapper/qw/CustomerTransferApprovalMapper.xml

@@ -19,10 +19,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="processedAt"    column="processed_at"    />
         <result property="createdAt"    column="created_at"    />
         <result property="updatedAt"    column="updated_at"    />
+        <result property="transferBefore"    column="transfer_before"    />
     </resultMap>
 
     <sql id="selectCustomerTransferApprovalVo">
-        select id, corp_id, transfer_type, customer_ids, original_user_id, target_user_id, initiator_user_id, content, approval_status, approver_user_id, approval_remark, processed_at, created_at, updated_at from customer_transfer_approval
+        select id, corp_id, transfer_type, customer_ids, original_user_id, target_user_id, initiator_user_id, content, approval_status, approver_user_id, approval_remark, processed_at, created_at, updated_at,transfer_before from customer_transfer_approval
     </sql>
 
     <select id="selectCustomerTransferApprovalList" parameterType="CustomerTransferApproval" resultMap="CustomerTransferApprovalResult">
@@ -65,6 +66,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="processedAt != null">processed_at,</if>
             <if test="createdAt != null">created_at,</if>
             <if test="updatedAt != null">updated_at,</if>
+            <if test="transferBefore != null">transfer_before,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="corpId != null and corpId != ''">#{corpId},</if>
@@ -80,6 +82,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="processedAt != null">#{processedAt},</if>
             <if test="createdAt != null">#{createdAt},</if>
             <if test="updatedAt != null">#{updatedAt},</if>
+            <if test="transferBefore != null">#{transferBefore},</if>
          </trim>
     </insert>
 
@@ -99,6 +102,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="processedAt != null">processed_at = #{processedAt},</if>
             <if test="createdAt != null">created_at = #{createdAt},</if>
             <if test="updatedAt != null">updated_at = #{updatedAt},</if>
+            <if test="transferBefore != null">transfer_before = #{transferBefore},</if>
         </trim>
         where id = #{id}
     </update>

+ 25 - 12
fs-service-system/src/main/resources/mapper/store/FsUserMapper.xml

@@ -173,17 +173,18 @@
         limit 10
     </select>
     <select id="selectCusListPage" resultType="com.fs.store.domain.FsUser">
-        select user_id,
-        username,
-        real_name,
-        id_card,
-        phone,
-        addres,
-        nick_name,
-        status,
-        sex,
-        company_id,
-        company_user_id from
+        select user.user_id,
+        user.username,
+        user.real_name,
+        user.id_card,
+        user.phone,
+        user.addres,
+        user.nickname,
+        user.status,
+        user.company_id,
+        user.company_user_id,
+        user.create_time
+        from
         fs_user `user` join (
         select user_id from fs_user
         <where>
@@ -197,7 +198,8 @@
                phone = #{phone}
            </if>
         </where>
-        limit ${params.pageNum*params.pageSize} ${params.pageSize}
+        order by user_id desc
+        limit ${(pageNum-1)*pageSize},${pageSize}
         ) t on t.user_id = `user`.user_id
     </select>
     <select id="selectCusListPageCount" resultType="java.lang.Long">
@@ -341,6 +343,17 @@
         </trim>
         where user_id = #{userId}
     </update>
+    <update id="transferCompanyUser">
+        update fs_user
+
+        set company_user_id=#{targetCompanyUserId}
+
+        where
+            user_id in
+        <foreach collection="userIds" open="(" close=")" separator="," item="item">
+            ${item}
+        </foreach>
+    </update>
 
     <delete id="deleteFsUserById" parameterType="Long">
         delete