ソースを参照

修改:<公海,我的客户业务开发>

张旭锋 1 ヶ月 前
親
コミット
1df28f92a7

+ 12 - 9
src/main/java/com/jtzx/crm/module/api/web/sys/AdminSysUserController.java

@@ -48,9 +48,9 @@ public class AdminSysUserController {
     }
 
     @Operation(summary = "编辑")
-    @PostMapping(value = "/sys/users/update/{id}")
-    public ApiResult<Void> update(@Valid InsertOrUpdateSysUserDTO dto) {
-        if (dto.getId() == 1 && UserContextHolder.getUserId() != 1) {
+    @PostMapping(value = "/sys/users/update")
+    public ApiResult<Void> update(@RequestBody @Valid InsertOrUpdateSysUserDTO dto) {
+        if (dto.getId().equals(1L) && UserContextHolder.getUserId() != 1) {
             throw new BusinessException(400, "无权修改系统默认管理员账号信息");
         }
         sysUserService.adminUpdate(dto);
@@ -60,9 +60,12 @@ public class AdminSysUserController {
     @Operation(summary = "删除")
     @GetMapping(value = "/sys/users/delete/{userId}")
     public ApiResult<Void> delete(@PathVariable Long userId) {
-        if (userId == 1) {
+        if (userId.equals(1L)) {
             throw new BusinessException(400, "无权删除默认管理员账号");
         }
+        if(userId.equals(UserContextHolder.getUserId())){
+            throw new BusinessException(400, "不能操作自己账号");
+        }
         sysUserService.adminDelete(Lists.newArrayList(userId));
         // 连带踢出登录
         CrmAdminStpUtil.kickout(userId);
@@ -72,7 +75,7 @@ public class AdminSysUserController {
     @Operation(summary = "重置某用户密码")
     @PostMapping(value = "/sys/users/updatePwd")
     public ApiResult<Void> resetPassword(@RequestBody @Valid UpdateSysUserPasswordDTO dto) {
-        if (dto.getUserId() == 1 && UserContextHolder.getUserId() != 1) {
+        if (dto.getUserId().equals(1L) && UserContextHolder.getUserId() != 1) {
             throw new BusinessException(400, "无权修改系统默认管理员账号密码");
         }
         sysUserService.UpdateUserPassword(dto);
@@ -86,7 +89,7 @@ public class AdminSysUserController {
     @Operation(summary = "启用,禁用用户")
     @GetMapping(value = "/sys/users/status/{userId}")
     public ApiResult<Integer> updateUserStatus(@PathVariable Long userId) {
-        if (userId == 1) {
+        if (userId.equals(1L)) {
             throw new BusinessException(400, "无权修改系统默认管理员账号状态");
         }
         Integer result = sysUserService.updateUserStatus(userId);
@@ -98,7 +101,7 @@ public class AdminSysUserController {
     @Operation(summary = "启用,关闭,公海,历史跟进状态", description = "公海跟进固定值(publicFollow),历史跟进固定值(historyFollow)")
     @GetMapping(value = "/sys/users/follow/{userId}/{followType}")
     public ApiResult<Integer> updateUserFollow(@PathVariable Long userId, @PathVariable String followType) {
-        if (userId == 1 && UserContextHolder.getUserId() != 1) {
+        if (userId.equals(1L) && UserContextHolder.getUserId() != 1) {
             throw new BusinessException(400, "无权修改系统默认管理员账号状态");
         }
         Integer result = sysUserService.updateUserFollow(userId, followType);
@@ -108,11 +111,11 @@ public class AdminSysUserController {
     @Operation(summary = "踢某用户下线")
     @PostMapping(value = "/sys/users/{userId}:kick-out")
     public ApiResult<Void> kickOut(@PathVariable Long userId) {
-        if(userId == 1){
+        if(userId.equals(1L)){
             throw new BusinessException(400, "无权下线系统默认管理员");
         }
         if(userId.equals(UserContextHolder.getUserId())){
-            throw new BusinessException(400, "不能下线自己");
+            throw new BusinessException(400, "不能操作自己账号");
         }
         CrmAdminStpUtil.kickout(userId);
         return ApiResult.success();

+ 20 - 3
src/main/java/com/jtzx/crm/module/sys/entity/SysCustomerDataEntity.java

@@ -3,7 +3,6 @@ package com.jtzx.crm.module.sys.entity;
 import cc.uncarbon.framework.crud.entity.HelioBaseEntity;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
-import com.google.common.collect.Lists;
 import com.jtzx.crm.module.sys.model.request.AdminSysCustomerDataInsertOrUpdateDTO;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.AllArgsConstructor;
@@ -14,7 +13,6 @@ import lombok.experimental.Accessors;
 import lombok.experimental.SuperBuilder;
 
 import java.time.LocalDateTime;
-import java.util.List;
 
 
 /**
@@ -110,7 +108,7 @@ public class SysCustomerDataEntity extends HelioBaseEntity<Long> {
     private Integer delFlag;
 
     /**
-     * 比较实体变化
+     * 比较实体变化,修改时使用
      * @param dto 更新的数据
      * @return 变化的字符串,分为两个部分,前部分为原来的信息,后部分为修改后的信息,用","隔开
      *         例如:学校名称【ABC】学段名称【初中】, 学校名称【XYZ】学段名称【高中】
@@ -149,9 +147,28 @@ public class SysCustomerDataEntity extends HelioBaseEntity<Long> {
         return original + "," + update;
     }
 
+    /**
+     * 删除时使用
+     * @return
+     */
     public String getStr() {
         //把参数名和值转为字符串
         return "学校名称【" + this.name + "】学段名称【" + this.stageName + "】省份名称【" + this.provinceName
                 + "】城市名称【" + this.cityName + "】地址【" + this.address + "】";
     }
+
+    /**
+     * 从公海认领的记录
+     */
+    public String getCustomString() {
+        return "将【" + this.name + "】从公海认领";
+    }
+
+
+    /**
+     * 退回公海的记录
+     */
+    public String returnCustomString() {
+        return "将【" + this.name + "】转至公海";
+    }
 }

+ 1 - 18
src/main/java/com/jtzx/crm/module/sys/entity/SysCustomerFollowEntity.java

@@ -1,12 +1,8 @@
 package com.jtzx.crm.module.sys.entity;
 
-import cc.uncarbon.framework.core.exception.BusinessException;
 import cc.uncarbon.framework.crud.entity.HelioBaseEntity;
 import com.baomidou.mybatisplus.annotation.TableField;
-import com.jtzx.crm.module.sys.model.request.AdmcnSysCustomerDataInsertOrUpdateDTO;
-import iom.baomidou.mybatisplus.annotation.TableName;
-import com.jtzx.crm.module.sys.model.request.AdminSysCustomerFollowInsertOrUpdateDTO;
-
+import com.baomidou.mybatisplus.annotation.TableName;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.AllArgsConstructor;
 import lombok.Data;
@@ -138,18 +134,5 @@ public class SysCustomerFollowEntity extends HelioBaseEntity<Long> {
     @TableField("del_flag")
     private Integer delFlag;
 
-    /**
-     * 从公海认领的记录
-     */
-    public String getCustomString() {
-        return "将【" + this.productName + "】从公海认领";
-    }
-
 
-    /**
-     * 退回公海的记录
-     */
-    public String returnCustomString() {
-        return "将【" + this.productName + "】转至公海";
-    }
 }

+ 7 - 0
src/main/java/com/jtzx/crm/module/sys/mapper/SysCustomerDataMapper.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Mapper;
 
 import com.jtzx.crm.module.sys.entity.SysCustomerDataEntity;
+import org.apache.ibatis.annotations.Param;
 
 
 /**
@@ -12,4 +13,10 @@ import com.jtzx.crm.module.sys.entity.SysCustomerDataEntity;
 @Mapper
 public interface SysCustomerDataMapper extends BaseMapper<SysCustomerDataEntity> {
 
+
+    /**
+     * 退回公海
+     * @param customerId
+     */
+    void returnCustomerData(@Param(value = "customerId")Long customerId);
 }

+ 12 - 0
src/main/java/com/jtzx/crm/module/sys/mapper/xml/SysCustomerDataMapper.xml

@@ -2,4 +2,16 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.jtzx.crm.module.sys.mapper.SysCustomerDataMapper">
 
+    <!-- 退回公海 -->
+    <update id="returnCustomerData" parameterType="java.lang.Long">
+        update sys_customer_data
+        set
+            claim_user_id = null,
+            claim_user_name = null,
+            claim_datetime = null,
+            claim_user_group_id = null,
+            claim_status = 0
+        where id = #{customerId}
+    </update>
+
 </mapper>

+ 4 - 1
src/main/java/com/jtzx/crm/module/sys/model/request/AdminSysCustomerDataInsertOrUpdateDTO.java

@@ -9,7 +9,6 @@ import lombok.experimental.Accessors;
 import lombok.experimental.SuperBuilder;
 
 import java.io.Serializable;
-import java.time.LocalDateTime;
 
 
 /**
@@ -54,6 +53,10 @@ public class AdminSysCustomerDataInsertOrUpdateDTO implements Serializable {
     @Size(max = 255, message = "【地址】最长255位")
     private String address;
 
+    /**
+     * 新增时使用
+     * @return
+     */
     public String getStr() {
         return "学校名称【" + this.name + "】学段名称【" + this.stageName + "】省份名称【" + this.provinceName
                 + "】城市名称【" + this.cityName + "】地址【" + this.address + "】";

+ 10 - 7
src/main/java/com/jtzx/crm/module/sys/model/response/SysCustomerPersonBO.java

@@ -9,8 +9,8 @@ import lombok.NoArgsConstructor;
 import lombok.experimental.Accessors;
 import lombok.experimental.SuperBuilder;
 import org.springframework.format.annotation.DateTimeFormat;
+
 import java.io.Serializable;
-import java.time.LocalDate;
 import java.time.LocalDateTime;
 
 
@@ -28,14 +28,17 @@ public class SysCustomerPersonBO implements Serializable {
     private Long id;
 
     @Schema(description = "创建时刻")
-    @DateTimeFormat(pattern = HelioConstant.Jackson.DATE_TIME_FORMAT)
-    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = HelioConstant.Jackson.DATE_TIME_FORMAT)
+    @DateTimeFormat(pattern = HelioConstant.Jackson.DATE_FORMAT)
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = HelioConstant.Jackson.DATE_FORMAT)
     private LocalDateTime createdAt;
 
-    @Schema(description = "更新时刻")
-    @DateTimeFormat(pattern = HelioConstant.Jackson.DATE_TIME_FORMAT)
-    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = HelioConstant.Jackson.DATE_TIME_FORMAT)
-    private LocalDateTime updatedAt;
+    @Schema(description = "上次跟进时间")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm")
+    private LocalDateTime lastFollowDate;
+
+    @Schema(description = "创建人")
+    private String createdBy;
 
     @Schema(description = "客户表主id")
     private Long customerId;

+ 88 - 4
src/main/java/com/jtzx/crm/module/sys/service/SysCustomerDataPrivateService.java

@@ -1,6 +1,8 @@
 package com.jtzx.crm.module.sys.service;
 
 
+import cc.uncarbon.framework.core.context.UserContextHolder;
+import cc.uncarbon.framework.core.exception.BusinessException;
 import cc.uncarbon.framework.core.page.PageResult;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
@@ -17,14 +19,14 @@ import com.jtzx.crm.module.sys.mapper.SysCustomerDataMapper;
 import com.jtzx.crm.module.sys.mapper.SysCustomerFollowMapper;
 import com.jtzx.crm.module.sys.mapper.SysGroupMapper;
 import com.jtzx.crm.module.sys.mapper.SysParamBaseDataMapper;
+import com.jtzx.crm.module.sys.model.request.AdminSysCustomerDataInsertOrUpdateDTO;
 import com.jtzx.crm.module.sys.model.request.AdminSysCustomerDataPrivateListDTO;
-import com.jtzx.crm.module.sys.model.response.BindUserBO;
-import com.jtzx.crm.module.sys.model.response.SysCustomerDataPrivateBO;
-import com.jtzx.crm.module.sys.model.response.SysCustomerPrivateSelectBO;
-import com.jtzx.crm.module.sys.model.response.SysCustomerSelectBO;
+import com.jtzx.crm.module.sys.model.request.AdminSysCustomerPersonInsertOrUpdateDTO;
+import com.jtzx.crm.module.sys.model.response.*;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.*;
 
@@ -46,6 +48,9 @@ public class SysCustomerDataPrivateService {
 
     private final SysCustomerUserCommonService sysCustomerUserCommonService;
 
+    private final SysCustomerDataService sysCustomerDataService;
+
+    private final SysCustomerPersonService  sysCustomerPersonService;
 
     /**
      * 查询私域(我的)客户页面顶部筛选条件数据
@@ -134,6 +139,85 @@ public class SysCustomerDataPrivateService {
         return this.entityPage2BOPage(entityPage);
     }
 
+
+    /**
+     * 我的客户修改
+     * @param dto
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public void adminUpdateCustomerData(AdminSysCustomerDataInsertOrUpdateDTO dto) {
+        List<String> roles = UserContextHolder.getUserContext().getRoles();
+        if (!roles.contains("admin") && !roles.contains("Member")) {
+            throw new BusinessException(400, "无权操作");
+        }
+        sysCustomerDataService.adminUpdate(dto);
+    }
+
+
+    /**
+     * 客户退回公海
+     * @param customerId
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public void returnCustomerData(Long customerId) {
+        sysCustomerDataService.returnCustomerData(customerId);
+    }
+
+
+    /**
+     * 我的客户添加联系人
+     * @param dto
+     * @return
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public Long adminInsertCustomerPerson(AdminSysCustomerPersonInsertOrUpdateDTO dto) {
+        List<String> roles = UserContextHolder.getUserContext().getRoles();
+        if (!roles.contains("admin") && !roles.contains("Member")) {
+            throw new BusinessException(400, "无权操作");
+        }
+        return sysCustomerPersonService.adminInsert(dto);
+    }
+
+
+    /**
+     * 我的客户修改联系人
+     * @param dto
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public void adminUpdateCustomerPerson(AdminSysCustomerPersonInsertOrUpdateDTO dto) {
+        List<String> roles = UserContextHolder.getUserContext().getRoles();
+        if (!roles.contains("admin") && !roles.contains("Member")) {
+            throw new BusinessException(400, "无权操作");
+        }
+        sysCustomerPersonService.adminUpdate(dto);
+    }
+
+    /**
+     * 我的客户删除联系人
+     * @param id
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public void adminDeleteCustomerPerson(Long id) {
+        List<String> roles = UserContextHolder.getUserContext().getRoles();
+        if (!roles.contains("admin") && !roles.contains("Member")) {
+            throw new BusinessException(400, "无权操作");
+        }
+        sysCustomerPersonService.adminDelete(id);
+    }
+
+
+    /**
+     * 查询我的客户联系人
+     */
+    public List<SysCustomerPersonBO> adminListCustomerPerson(Long customerId, Long positionId) {
+        List<String> roles = UserContextHolder.getUserContext().getRoles();
+        if (!roles.contains("admin") && !roles.contains("Member")) {
+            throw new BusinessException(400, "无权操作");
+        }
+        return sysCustomerPersonService.adminList(customerId,positionId,UserContextHolder.getUserId());
+    }
+
+
     /**
      * 实体分页转 BO 分页
      *

+ 105 - 0
src/main/java/com/jtzx/crm/module/sys/service/SysCustomerDataPublicService.java

@@ -1,6 +1,8 @@
 package com.jtzx.crm.module.sys.service;
 
 
+import cc.uncarbon.framework.core.context.UserContextHolder;
+import cc.uncarbon.framework.core.exception.BusinessException;
 import cc.uncarbon.framework.core.page.PageResult;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
@@ -12,13 +14,17 @@ import com.jtzx.crm.module.sys.entity.SysCustomerDataEntity;
 import com.jtzx.crm.module.sys.entity.SysParamBaseDataEntity;
 import com.jtzx.crm.module.sys.mapper.SysCustomerDataMapper;
 import com.jtzx.crm.module.sys.mapper.SysParamBaseDataMapper;
+import com.jtzx.crm.module.sys.model.request.AdminSysCustomerDataInsertOrUpdateDTO;
 import com.jtzx.crm.module.sys.model.request.AdminSysCustomerDataPublicListDTO;
+import com.jtzx.crm.module.sys.model.request.AdminSysCustomerPersonInsertOrUpdateDTO;
 import com.jtzx.crm.module.sys.model.response.SysCustomerDataPublicBO;
+import com.jtzx.crm.module.sys.model.response.SysCustomerPersonBO;
 import com.jtzx.crm.module.sys.model.response.SysCustomerPublicSelectBO;
 import com.jtzx.crm.module.sys.model.response.SysCustomerSelectBO;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
@@ -40,6 +46,10 @@ public class SysCustomerDataPublicService {
 
     private final SysCustomerUserCommonService sysCustomerUserCommonService;
 
+    private final SysCustomerDataService sysCustomerDataService;
+
+    private final SysCustomerPersonService  sysCustomerPersonService;
+
     /**
      * 查询公海客户页面顶部筛选条件数据
      * @return
@@ -85,6 +95,101 @@ public class SysCustomerDataPublicService {
         return this.entityPage2BOPage(entityPage);
     }
 
+    /**
+     * 新增公海客户
+     * @param dto
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public void adminInsertCustomerData(AdminSysCustomerDataInsertOrUpdateDTO dto) {
+        if (CollUtil.isEmpty(UserContextHolder.getUserContext().getRoles()) || !UserContextHolder.getUserContext().getRoles().contains("admin")) {
+            throw new BusinessException(400, "无权操作");
+        }
+        sysCustomerDataService.adminInsert(dto);
+    }
+
+    /**
+     * 公海客户修改
+     * @param dto
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public void adminUpdateCustomerData(AdminSysCustomerDataInsertOrUpdateDTO dto) {
+        if (CollUtil.isEmpty(UserContextHolder.getUserContext().getRoles()) || !UserContextHolder.getUserContext().getRoles().contains("admin")) {
+            throw new BusinessException(400, "无权操作");
+        }
+        sysCustomerDataService.adminUpdate(dto);
+    }
+
+    /**
+     * 删除公海客户
+     * @param id
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public void adminDeleteCustomerData(Long id) {
+        if (CollUtil.isEmpty(UserContextHolder.getUserContext().getRoles()) || !UserContextHolder.getUserContext().getRoles().contains("admin")) {
+            throw new BusinessException(400, "无权操作");
+        }
+        sysCustomerDataService.adminDelete(id);
+    }
+
+    /**
+     * 公海认领客户
+     * @param customerId
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public void claimCustomer(Long customerId) {
+        sysCustomerDataService.claimCustomer(customerId);
+    }
+
+
+
+    /**
+     * 公海添加客户联系人
+     * @param dto
+     * @return
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public Long adminInsertCustomerPerson(AdminSysCustomerPersonInsertOrUpdateDTO dto) {
+        if (CollUtil.isEmpty(UserContextHolder.getUserContext().getRoles()) || !UserContextHolder.getUserContext().getRoles().contains("admin")) {
+            throw new BusinessException(400, "无权操作");
+        }
+       return sysCustomerPersonService.adminInsert(dto);
+    }
+
+
+    /**
+     * 公海修改客户联系人
+     * @param dto
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public void adminUpdateCustomerPerson(AdminSysCustomerPersonInsertOrUpdateDTO dto) {
+        if (CollUtil.isEmpty(UserContextHolder.getUserContext().getRoles()) || !UserContextHolder.getUserContext().getRoles().contains("admin")) {
+            throw new BusinessException(400, "无权操作");
+        }
+        sysCustomerPersonService.adminUpdate(dto);
+    }
+
+    /**
+     * 公海删除联系人
+     * @param id
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public void adminDeleteCustomerPerson(Long id) {
+        if (CollUtil.isEmpty(UserContextHolder.getUserContext().getRoles()) || !UserContextHolder.getUserContext().getRoles().contains("admin")) {
+            throw new BusinessException(400, "无权操作");
+        }
+        sysCustomerPersonService.adminDelete(id);
+    }
+
+    /**
+     * 查询公海客户联系人
+     */
+    public List<SysCustomerPersonBO> adminListCustomerPerson(Long customerId, Long positionId) {
+        if (CollUtil.isEmpty(UserContextHolder.getUserContext().getRoles()) || !UserContextHolder.getUserContext().getRoles().contains("admin")) {
+            throw new BusinessException(400, "无权操作");
+        }
+       return sysCustomerPersonService.adminList(customerId,positionId,null);
+    }
+
 
      /*
     ----------------------------------------------------------------

+ 119 - 42
src/main/java/com/jtzx/crm/module/sys/service/SysCustomerDataService.java

@@ -3,12 +3,14 @@ package com.jtzx.crm.module.sys.service;
 import cc.uncarbon.framework.core.context.UserContextHolder;
 import cc.uncarbon.framework.core.exception.BusinessException;
 import cn.hutool.core.bean.BeanUtil;
-
+import cn.hutool.core.collection.CollUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.jtzx.crm.module.sys.entity.SysCustomerDataEntity;
+import com.jtzx.crm.module.sys.entity.SysCustomerFollowEntity;
 import com.jtzx.crm.module.sys.entity.SysCustomerOperLogEntity;
 import com.jtzx.crm.module.sys.entity.SysUserGroupRelationEntity;
 import com.jtzx.crm.module.sys.mapper.SysCustomerDataMapper;
+import com.jtzx.crm.module.sys.mapper.SysCustomerFollowMapper;
 import com.jtzx.crm.module.sys.mapper.SysCustomerOperLogMapper;
 import com.jtzx.crm.module.sys.mapper.SysUserGroupRelationMapper;
 import com.jtzx.crm.module.sys.model.request.AdminSysCustomerDataInsertOrUpdateDTO;
@@ -19,7 +21,6 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.time.LocalDateTime;
-import java.util.Collection;
 
 
 /**
@@ -36,6 +37,8 @@ public class SysCustomerDataService {
 
     private final SysUserGroupRelationMapper sysUserGroupRelationMapper;
 
+    private final SysCustomerFollowMapper sysCustomerFollowMapper;
+
 
     /**
      * 根据 ID 取详情
@@ -57,6 +60,7 @@ public class SysCustomerDataService {
     @Transactional(rollbackFor = Exception.class)
     public Long adminInsert(AdminSysCustomerDataInsertOrUpdateDTO dto) {
         log.info("[后台管理-客户(学校)数据-新增] >> DTO={}", dto);
+
         dto.setId(null);
         SysCustomerDataEntity entity = new SysCustomerDataEntity();
         BeanUtil.copyProperties(dto, entity);
@@ -64,20 +68,7 @@ public class SysCustomerDataService {
         entity.setClaimStatus(0);
         entity.setSuccessStatus(0);
         sysCustomerDataMapper.insert(entity);
-
-        SysUserGroupRelationEntity userGroupRelation = sysUserGroupRelationMapper.selectOne(
-                new LambdaQueryWrapper<SysUserGroupRelationEntity>()
-                        .select(
-                                SysUserGroupRelationEntity::getId,
-                                SysUserGroupRelationEntity::getGroupId
-                        )
-                        .eq(SysUserGroupRelationEntity::getUserId, UserContextHolder.getUserId())
-                        .eq(SysUserGroupRelationEntity::getProvinceId, entity.getProvinceId())
-                        .eq(SysUserGroupRelationEntity::getCityId, entity.getCityId())
-        );
-
         //添加操作日志
-        String operData = dto.getStr();
         SysCustomerOperLogEntity logEntity = SysCustomerOperLogEntity.builder()
                 .customerId(entity.getId())
                 .customerName(entity.getName())
@@ -89,11 +80,8 @@ public class SysCustomerDataService {
                 .provinceName(entity.getProvinceName())
                 .cityId(entity.getCityId())
                 .cityName(entity.getCityName())
-                .content(operData)
+                .content(dto.getStr())
                 .build();
-        if (userGroupRelation != null) {
-            logEntity.setOperUserGroupId(userGroupRelation.getGroupId());
-        }
         sysCustomerOperLogMapper.insert(logEntity);
         return entity.getId();
     }
@@ -108,11 +96,7 @@ public class SysCustomerDataService {
         if (entity == null) {
             throw new BusinessException(400, "无效客户(学校)数据ID");
         }
-        String compareTo = entity.compareTo(dto);
-        BeanUtil.copyProperties(dto, entity);
-        sysCustomerDataMapper.updateById(entity);
-
-        //添加操作日志
+        //查询用户的小组信息
         SysUserGroupRelationEntity userGroupRelation = sysUserGroupRelationMapper.selectOne(
                 new LambdaQueryWrapper<SysUserGroupRelationEntity>()
                         .select(
@@ -120,9 +104,13 @@ public class SysCustomerDataService {
                                 SysUserGroupRelationEntity::getGroupId
                         )
                         .eq(SysUserGroupRelationEntity::getUserId, UserContextHolder.getUserId())
-                        .eq(SysUserGroupRelationEntity::getProvinceId, entity.getProvinceId())
-                        .eq(SysUserGroupRelationEntity::getCityId, entity.getCityId())
+                        .eq(SysUserGroupRelationEntity::getProvinceId, dto.getProvinceId())
+                        .eq(SysUserGroupRelationEntity::getCityId, dto.getCityId())
+                        .last("limit 1")
         );
+        BeanUtil.copyProperties(dto, entity);
+        sysCustomerDataMapper.updateById(entity);
+
         SysCustomerOperLogEntity logEntity = SysCustomerOperLogEntity.builder()
                 .customerId(entity.getId())
                 .customerName(entity.getName())
@@ -134,7 +122,7 @@ public class SysCustomerDataService {
                 .provinceName(entity.getProvinceName())
                 .cityId(entity.getCityId())
                 .cityName(entity.getCityName())
-                .content(compareTo)
+                .content(entity.compareTo(dto))
                 .build();
         if (userGroupRelation != null) {
             logEntity.setOperUserGroupId(userGroupRelation.getGroupId());
@@ -150,18 +138,18 @@ public class SysCustomerDataService {
         log.info("[后台管理-客户(学校)数据-删除] >> id={}", id);
         SysCustomerDataEntity entity = sysCustomerDataMapper.selectById(id);
         if (entity != null) {
-            sysCustomerDataMapper.deleteById(id);
-
-            SysUserGroupRelationEntity userGroupRelation = sysUserGroupRelationMapper.selectOne(
-                    new LambdaQueryWrapper<SysUserGroupRelationEntity>()
-                            .select(
-                                    SysUserGroupRelationEntity::getId,
-                                    SysUserGroupRelationEntity::getGroupId
-                            )
-                            .eq(SysUserGroupRelationEntity::getUserId, UserContextHolder.getUserId())
-                            .eq(SysUserGroupRelationEntity::getProvinceId, entity.getProvinceId())
-                            .eq(SysUserGroupRelationEntity::getCityId, entity.getCityId())
-            );
+            //查询有没有跟进,有跟进就不能删
+            long count =
+                    sysCustomerFollowMapper.selectCount(
+                            new LambdaQueryWrapper<>(SysCustomerFollowEntity.class)
+                                    .select(
+                                            SysCustomerFollowEntity::getCustomerId
+                                    )
+                                    .eq(SysCustomerFollowEntity::getCustomerId, entity.getId())
+                    );
+            if (count > 0) {
+                throw new BusinessException(400, "不能删除");
+            }
             SysCustomerOperLogEntity logEntity = SysCustomerOperLogEntity.builder()
                     .customerId(entity.getId())
                     .customerName(entity.getName())
@@ -175,13 +163,102 @@ public class SysCustomerDataService {
                     .cityName(entity.getCityName())
                     .content(entity.getStr())
                     .build();
-            if (userGroupRelation != null) {
-                logEntity.setOperUserGroupId(userGroupRelation.getGroupId());
-            }
             sysCustomerOperLogMapper.insert(logEntity);
+            sysCustomerDataMapper.deleteById(id);
         }
     }
 
+    /**
+     * 认领操作
+     * @param customerId
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public void claimCustomer(Long customerId) {
+        SysCustomerDataEntity sysCustomerDataEntity = sysCustomerDataMapper.selectById(customerId);
+        if (sysCustomerDataEntity == null) {
+            throw new BusinessException(400, "客户不存在");
+        }
+        //查询用户的小组信息
+        SysUserGroupRelationEntity userGroupRelation = sysUserGroupRelationMapper.selectOne(
+                new LambdaQueryWrapper<SysUserGroupRelationEntity>()
+                        .select(
+                                SysUserGroupRelationEntity::getId,
+                                SysUserGroupRelationEntity::getGroupId
+                        )
+                        .eq(SysUserGroupRelationEntity::getUserId, UserContextHolder.getUserId())
+                        .eq(SysUserGroupRelationEntity::getProvinceId, sysCustomerDataEntity.getProvinceId())
+                        .eq(SysUserGroupRelationEntity::getCityId, sysCustomerDataEntity.getCityId())
+                        .last("limit 1")
+        );
+        if (CollUtil.isEmpty(UserContextHolder.getUserContext().getRoles()) || !UserContextHolder.getUserContext().getRoles().contains("admin")) {
+            if (userGroupRelation == null) {
+                throw new BusinessException(400, "无权操作");
+            }
+        }
+        sysCustomerDataEntity.setClaimUserId(UserContextHolder.getUserId());
+        sysCustomerDataEntity.setClaimUserName(UserContextHolder.getUserName());
+        sysCustomerDataEntity.setClaimStatus(1);
+        sysCustomerDataEntity.setClaimDatetime(LocalDateTime.now());
+        if (userGroupRelation != null) {
+            sysCustomerDataEntity.setClaimUserGroupId(userGroupRelation.getGroupId());
+        }
+        sysCustomerDataMapper.updateById(sysCustomerDataEntity);
+        //添加认领日志
+        SysCustomerOperLogEntity logEntity = SysCustomerOperLogEntity.builder()
+                .customerId(sysCustomerDataEntity.getId())
+                .customerName(sysCustomerDataEntity.getName())
+                .operUserId(UserContextHolder.getUserId())
+                .operName(UserContextHolder.getUserName())
+                .operAction(0)
+                .operDatetime(LocalDateTime.now())
+                .provinceId(sysCustomerDataEntity.getProvinceId())
+                .provinceName(sysCustomerDataEntity.getProvinceName())
+                .cityId(sysCustomerDataEntity.getCityId())
+                .cityName(sysCustomerDataEntity.getCityName())
+                .content(sysCustomerDataEntity.getCustomString())
+                .operUserGroupId(sysCustomerDataEntity.getClaimUserGroupId())
+                .build();
+        sysCustomerOperLogMapper.insert(logEntity);
+    }
+
+
+    /**
+     * 客户退回公海
+     * @param customerId
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public void returnCustomerData(Long customerId) {
+        //先查询有没有赢单
+        SysCustomerDataEntity sysCustomerDataEntity = sysCustomerDataMapper.selectById(customerId);
+        if (sysCustomerDataEntity == null) {
+            throw new BusinessException(400,"客户不存在");
+        }
+        if(sysCustomerDataEntity.getSuccessStatus()==1){
+            throw new BusinessException(400,"客户已赢单,不能退回公海");
+        }
+        if(CollUtil.isEmpty(UserContextHolder.getUserContext().getRoles()) || !UserContextHolder.getUserContext().getRoles().contains("admin")){
+            if(!sysCustomerDataEntity.getClaimUserId().equals(UserContextHolder.getUserId())){
+                throw new BusinessException(400,"认领人不正确,无权操作");
+            }
+        }
+        sysCustomerDataMapper.returnCustomerData(customerId);
+        //添加认领日志
+        SysCustomerOperLogEntity logEntity = SysCustomerOperLogEntity.builder()
+                .customerId(sysCustomerDataEntity.getId())
+                .customerName(sysCustomerDataEntity.getName())
+                .operUserId(UserContextHolder.getUserId())
+                .operName(UserContextHolder.getUserName())
+                .operAction(3)
+                .operDatetime(LocalDateTime.now())
+                .provinceId(sysCustomerDataEntity.getProvinceId())
+                .provinceName(sysCustomerDataEntity.getProvinceName())
+                .cityId(sysCustomerDataEntity.getCityId())
+                .cityName(sysCustomerDataEntity.getCityName())
+                .content(sysCustomerDataEntity.returnCustomString())
+                .operUserGroupId(sysCustomerDataEntity.getClaimUserGroupId())
+                .build();
+        sysCustomerOperLogMapper.insert(logEntity);
+    }
 
     /*
     ----------------------------------------------------------------

+ 151 - 38
src/main/java/com/jtzx/crm/module/sys/service/SysCustomerPersonService.java

@@ -1,24 +1,27 @@
 package com.jtzx.crm.module.sys.service;
 
+import cc.uncarbon.framework.core.context.UserContextHolder;
 import cc.uncarbon.framework.core.exception.BusinessException;
-import cc.uncarbon.framework.core.page.PageParam;
 import cc.uncarbon.framework.core.page.PageResult;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
-import cn.hutool.core.text.CharSequenceUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.jtzx.crm.module.sys.entity.SysCustomerPersonEntity;
-import com.jtzx.crm.module.sys.mapper.SysCustomerPersonMapper;
+import com.jtzx.crm.module.sys.entity.*;
+import com.jtzx.crm.module.sys.mapper.*;
 import com.jtzx.crm.module.sys.model.request.AdminSysCustomerPersonInsertOrUpdateDTO;
-import com.jtzx.crm.module.sys.model.request.AdminSysCustomerPersonListDTO;
 import com.jtzx.crm.module.sys.model.response.SysCustomerPersonBO;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.*;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
 
 
 /**
@@ -31,36 +34,29 @@ public class SysCustomerPersonService {
 
     private final SysCustomerPersonMapper sysCustomerPersonMapper;
 
+    private final SysCustomerDataMapper sysCustomerDataMapper;
+
+    private final SysUserGroupRelationMapper sysUserGroupRelationMapper;
+
+    private final SysCustomerOperLogMapper sysCustomerOperLogMapper;
+
+    private final SysCustomerFollowMapper sysCustomerFollowMapper;
 
     /**
-     * 后台管理-分页列表
+     * 后台管理-联系人列表
      */
-    public PageResult<SysCustomerPersonBO> adminList(PageParam pageParam, AdminSysCustomerPersonListDTO dto) {
-        Page<SysCustomerPersonEntity> entityPage = sysCustomerPersonMapper.selectPage(
-                new Page<>(pageParam.getPageNum(), pageParam.getPageSize()),
+    public List<SysCustomerPersonBO> adminList(Long customerId, Long positionId,Long userId) {
+        List<SysCustomerPersonEntity> entityPage = sysCustomerPersonMapper.selectList(
                 new QueryWrapper<SysCustomerPersonEntity>()
                         .lambda()
                         // 客户表主id
-                        .eq(Objects.nonNull(dto.getCustomerId()), SysCustomerPersonEntity::getCustomerId, dto.getCustomerId())
-                        // 姓名
-                        .like(CharSequenceUtil.isNotBlank(dto.getName()), SysCustomerPersonEntity::getName, CharSequenceUtil.cleanBlank(dto.getName()))
+                        .eq(SysCustomerPersonEntity::getCustomerId, customerId)
+                        //创建人过滤
+                        .eq(userId!=null,SysCustomerPersonEntity::getCreatedBy,userId)
                         // 职务id(param_base_data表主id)
-                        .eq(Objects.nonNull(dto.getPositionId()), SysCustomerPersonEntity::getPositionId, dto.getPositionId())
-                        // 职务名称
-                        .like(CharSequenceUtil.isNotBlank(dto.getPositionName()), SysCustomerPersonEntity::getPositionName, CharSequenceUtil.cleanBlank(dto.getPositionName()))
-                        // 手机号
-                        .like(CharSequenceUtil.isNotBlank(dto.getPhoneNo()), SysCustomerPersonEntity::getPhoneNo, CharSequenceUtil.cleanBlank(dto.getPhoneNo()))
-                        // 办公电话
-                        .like(CharSequenceUtil.isNotBlank(dto.getOfficePhoneNo()), SysCustomerPersonEntity::getOfficePhoneNo, CharSequenceUtil.cleanBlank(dto.getOfficePhoneNo()))
-                        // 备注
-                        .like(CharSequenceUtil.isNotBlank(dto.getRemark()), SysCustomerPersonEntity::getRemark, CharSequenceUtil.cleanBlank(dto.getRemark()))
-                        // 时间区间
-                        .between(Objects.nonNull(dto.getBeginAt()) && Objects.nonNull(dto.getEndAt()), SysCustomerPersonEntity::getCreatedAt, dto.getBeginAt(), dto.getEndAt())
-                        // 排序
-                        .orderByDesc(SysCustomerPersonEntity::getCreatedAt)
+                        .eq(positionId != null, SysCustomerPersonEntity::getPositionId, positionId)
         );
-
-        return this.entityPage2BOPage(entityPage);
+        return this.entityList2BOs(entityPage);
     }
 
 
@@ -84,12 +80,32 @@ public class SysCustomerPersonService {
     @Transactional(rollbackFor = Exception.class)
     public Long adminInsert(AdminSysCustomerPersonInsertOrUpdateDTO dto) {
         log.info("[后台管理-客户(学校)联系人数据-新增] >> DTO={}", dto);
+        SysCustomerDataEntity sysCustomerDataEntity = sysCustomerDataMapper.selectById(dto.getCustomerId());
+        if (sysCustomerDataEntity == null) {
+            throw new BusinessException(400, "客户不存在");
+        }
         dto.setId(null);
         SysCustomerPersonEntity entity = new SysCustomerPersonEntity();
         BeanUtil.copyProperties(dto, entity);
 
         sysCustomerPersonMapper.insert(entity);
 
+        //新增联系人日志
+        SysCustomerOperLogEntity logEntity = SysCustomerOperLogEntity.builder()
+                .customerId(entity.getId())
+                .customerName(entity.getName())
+                .operUserId(UserContextHolder.getUserId())
+                .operName(UserContextHolder.getUserName())
+                .operAction(11)
+                .operDatetime(LocalDateTime.now())
+                .provinceId(sysCustomerDataEntity.getProvinceId())
+                .provinceName(sysCustomerDataEntity.getProvinceName())
+                .cityId(sysCustomerDataEntity.getCityId())
+                .cityName(sysCustomerDataEntity.getCityName())
+                .content(dto.getStr())
+                .build();
+        sysCustomerOperLogMapper.insert(logEntity);
+
         return entity.getId();
     }
 
@@ -99,20 +115,92 @@ public class SysCustomerPersonService {
     @Transactional(rollbackFor = Exception.class)
     public void adminUpdate(AdminSysCustomerPersonInsertOrUpdateDTO dto) {
         log.info("[后台管理-客户(学校)联系人数据-编辑] >> DTO={}", dto);
+        SysCustomerDataEntity entity = sysCustomerDataMapper.selectById(dto.getId());
+        if (entity == null) {
+            throw new BusinessException(400, "无效客户(学校)数据ID");
+        }
+        //查询用户的小组数据
+        SysUserGroupRelationEntity userGroupRelation = sysUserGroupRelationMapper.selectOne(
+                new LambdaQueryWrapper<SysUserGroupRelationEntity>()
+                        .select(
+                                SysUserGroupRelationEntity::getId,
+                                SysUserGroupRelationEntity::getGroupId
+                        )
+                        .eq(SysUserGroupRelationEntity::getUserId, UserContextHolder.getUserId())
+                        .eq(SysUserGroupRelationEntity::getProvinceId, entity.getProvinceId())
+                        .eq(SysUserGroupRelationEntity::getCityId, entity.getCityId())
+                        .last("limit 1")
+        );
+        SysCustomerPersonEntity sysCustomerPersonEntity = sysCustomerPersonMapper.selectById(dto.getId());
+        BeanUtil.copyProperties(dto, sysCustomerPersonEntity);
+        sysCustomerPersonEntity.setId(null);
+        sysCustomerPersonMapper.updateById(sysCustomerPersonEntity);
 
-        SysCustomerPersonEntity entity = new SysCustomerPersonEntity();
-        BeanUtil.copyProperties(dto, entity);
-
-        sysCustomerPersonMapper.updateById(entity);
+        SysCustomerOperLogEntity logEntity = SysCustomerOperLogEntity.builder()
+                .customerId(entity.getId())
+                .customerName(entity.getName())
+                .operUserId(UserContextHolder.getUserId())
+                .operName(UserContextHolder.getUserName())
+                .operAction(12)
+                .operDatetime(LocalDateTime.now())
+                .provinceId(entity.getProvinceId())
+                .provinceName(entity.getProvinceName())
+                .cityId(entity.getCityId())
+                .cityName(entity.getCityName())
+                .content(sysCustomerPersonEntity.compareTo(dto))
+                .build();
+        if (userGroupRelation != null) {
+            logEntity.setOperUserGroupId(userGroupRelation.getGroupId());
+        }
+        sysCustomerOperLogMapper.insert(logEntity);
     }
 
     /**
      * 后台管理-删除
      */
     @Transactional(rollbackFor = Exception.class)
-    public void adminDelete(Collection<Long> ids) {
-        log.info("[后台管理-客户(学校)联系人数据-删除] >> ids={}", ids);
-        sysCustomerPersonMapper.deleteByIds(ids);
+    public void adminDelete(Long id) {
+        log.info("[后台管理-客户(学校)联系人数据-删除] >> id={}", id);
+        SysCustomerPersonEntity sysCustomerPersonEntity = sysCustomerPersonMapper.selectById(id);
+        if (sysCustomerPersonEntity == null) {
+            throw new BusinessException(400, "联系人不存在");
+        }
+        SysCustomerDataEntity entity = sysCustomerDataMapper.selectById(sysCustomerPersonEntity.getCustomerId());
+        if (entity == null) {
+            throw new BusinessException(400, "无效客户(学校)数据ID");
+        }
+        //查询用户的小组数据
+        SysUserGroupRelationEntity userGroupRelation = sysUserGroupRelationMapper.selectOne(
+                new LambdaQueryWrapper<SysUserGroupRelationEntity>()
+                        .select(
+                                SysUserGroupRelationEntity::getId,
+                                SysUserGroupRelationEntity::getGroupId
+                        )
+                        .eq(SysUserGroupRelationEntity::getUserId, UserContextHolder.getUserId())
+                        .eq(SysUserGroupRelationEntity::getProvinceId, entity.getProvinceId())
+                        .eq(SysUserGroupRelationEntity::getCityId, entity.getCityId())
+                        .last("limit 1")
+        );
+        SysCustomerOperLogEntity logEntity = SysCustomerOperLogEntity.builder()
+                .customerId(entity.getId())
+                .customerName(entity.getName())
+                .operUserId(UserContextHolder.getUserId())
+                .operName(UserContextHolder.getUserName())
+                .operAction(13)
+                .operDatetime(LocalDateTime.now())
+                .provinceId(entity.getProvinceId())
+                .provinceName(entity.getProvinceName())
+                .cityId(entity.getCityId())
+                .cityName(entity.getCityName())
+                .content(sysCustomerPersonEntity.getStr())
+                .build();
+        if (userGroupRelation != null) {
+            logEntity.setOperUserGroupId(userGroupRelation.getGroupId());
+        }
+        sysCustomerOperLogMapper.insert(logEntity);
+
+
+        sysCustomerPersonMapper.deleteById(id);
     }
 
 
@@ -152,12 +240,37 @@ public class SysCustomerPersonService {
             return Collections.emptyList();
         }
 
+        //查询上次跟进
+        List<SysCustomerFollowEntity> lastFollowEntityList =
+                sysCustomerFollowMapper.selectList(
+                        new LambdaQueryWrapper<>(SysCustomerFollowEntity.class)
+                                .select(
+                                        SysCustomerFollowEntity::getCustomerId,
+                                        SysCustomerFollowEntity::getPositionId,
+                                        SysCustomerFollowEntity::getCreatedAt
+                                )
+                                .eq(SysCustomerFollowEntity::getCustomerId, entityList.getFirst().getCustomerId())
+                                .in(SysCustomerFollowEntity::getPositionId, entityList.stream().map(SysCustomerPersonEntity::getPositionId).distinct().toList())
+                                .orderByDesc(SysCustomerFollowEntity::getCreatedAt)
+                );
+
         // 深拷贝
         List<SysCustomerPersonBO> ret = new ArrayList<>(entityList.size());
         entityList.forEach(
-                entity -> ret.add(this.entity2BO(entity))
-        );
-
+                entity -> {
+                    SysCustomerPersonBO bo = this.entity2BO(entity);
+                    if(CollUtil.isNotEmpty(lastFollowEntityList)){
+                        List<SysCustomerFollowEntity> list = lastFollowEntityList.stream()
+                                .filter(lastFollowEntity -> lastFollowEntity.getPositionId().equals(entity.getPositionId()))
+                                .sorted(Comparator.comparing(SysCustomerFollowEntity::getCreatedAt).reversed())
+                                .toList();
+                        if(CollUtil.isNotEmpty(list)){
+                            bo.setLastFollowDate(
+                            list.getFirst().getCreatedAt());
+                        }
+                    }
+                    ret.add(bo);
+                });
         return ret;
     }
 

+ 9 - 1
src/main/java/com/jtzx/crm/module/sys/service/SysUserService.java

@@ -63,7 +63,10 @@ public class SysUserService {
                         .and(
                                 CharSequenceUtil.isNotBlank(dto.getQueryStr()),
                                 z -> z.like(SysUserEntity::getPhoneNo, CharSequenceUtil.cleanBlank(dto.getQueryStr()))
-                                        .or(x -> x.like(SysUserEntity::getUserName, dto.getQueryStr()))
+                                        .or()
+                                        .like(SysUserEntity::getUserName, dto.getQueryStr())
+                                        .or()
+                                        .like(SysUserEntity::getPin, dto.getQueryStr())
                         )
                         // 排序
                         .orderByDesc(SysUserEntity::getCreatedAt)
@@ -101,6 +104,7 @@ public class SysUserService {
         entity.setStatus(1);
         String salt = IdUtil.randomUUID();
         entity
+                .setUserName(dto.getUsername())
                 .setSalt(salt)
                 .setPin(dto.getAccount())
                 .setPwd(PwdUtil.encrypt(dto.getAccount(), salt));
@@ -119,6 +123,7 @@ public class SysUserService {
         BeanUtil.copyProperties(dto, entity);
         // 手动处理异名字段
         entity.setPin(dto.getAccount());
+        entity.setUserName(dto.getUsername());
         sysUserMapper.updateById(entity);
     }
 
@@ -239,6 +244,7 @@ public class SysUserService {
         } else {
             sysUserEntity.setStatus(1);
         }
+        sysUserMapper.updateById(sysUserEntity);
         return sysUserEntity.getStatus();
     }
 
@@ -259,6 +265,7 @@ public class SysUserService {
             } else {
                 sysUserEntity.setPublicFollowStatus(1);
             }
+            sysUserMapper.updateById(sysUserEntity);
             return sysUserEntity.getPublicFollowStatus();
         }
         if (followType.equals("historyFollow")) {
@@ -267,6 +274,7 @@ public class SysUserService {
             } else {
                 sysUserEntity.setHistoryFollowStatus(1);
             }
+            sysUserMapper.updateById(sysUserEntity);
             return sysUserEntity.getHistoryFollowStatus();
         }
         return null;