Przeglądaj źródła

客户新建跟进

于继渤 2 lat temu
rodzic
commit
4e4514d414

+ 35 - 0
src/main/java/com/dk/mdm/controller/mst/CusFollowController.java

@@ -1,8 +1,19 @@
 package com.dk.mdm.controller.mst;
 package com.dk.mdm.controller.mst;
 
 
+import com.dk.common.model.pojo.PageList;
+import com.dk.common.response.ResponseResultVO;
 import com.dk.mdm.model.pojo.mst.CusFollow;
 import com.dk.mdm.model.pojo.mst.CusFollow;
 import com.dk.common.controller.BaseController;
 import com.dk.common.controller.BaseController;
 import com.dk.common.service.BaseService;
 import com.dk.common.service.BaseService;
+import com.dk.mdm.model.query.mst.CusFollowQuery;
+import com.dk.mdm.model.query.mst.CustomerQuery;
+import com.dk.mdm.model.response.mst.CusFollowResponse;
+import com.dk.mdm.model.response.mst.CustomerResponse;
+import com.dk.mdm.model.vo.mst.CusFollowVO;
+import com.dk.mdm.model.vo.mst.CustomerVO;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.bind.annotation.RestController;
@@ -21,4 +32,28 @@ public class CusFollowController{
     @Autowired
     @Autowired
     private CusFollowService cusFollowService;
     private CusFollowService cusFollowService;
 
 
+
+    /**
+     * @desc : 条件查询
+     * @author : 于继渤
+     * @date : 2024/2/26 10:36
+     */
+    @ApiOperation(value = "分页、关联、条件查询", notes = "分页、关联、条件查询")
+    @PostMapping({"list_by"})
+    public ResponseResultVO<PageList<CusFollowResponse>> selectByCond(@RequestBody CusFollowQuery customerQuery) {
+        return cusFollowService.selectByCond(customerQuery);
+    }
+
+    /**
+     * @desc : 新建
+     * @author : 于继渤
+     * @date : 2023/1/5 9:39
+     */
+    @ApiOperation( value = "新建", notes = "v" )
+    @PostMapping({"insert"})
+    public ResponseResultVO<?> insert(@RequestBody CusFollowVO cusFollowVO) {
+        return cusFollowService.insert(cusFollowVO);
+    }
+
+
 }
 }

+ 21 - 0
src/main/java/com/dk/mdm/mapper/mst/CusFollowMapper.java

@@ -2,13 +2,34 @@ package com.dk.mdm.mapper.mst;
 
 
 import com.dk.mdm.model.pojo.mst.CusFollow;
 import com.dk.mdm.model.pojo.mst.CusFollow;
 import com.dk.common.mapper.BaseMapper;
 import com.dk.common.mapper.BaseMapper;
+import com.dk.mdm.model.query.mst.CusFollowQuery;
+import com.dk.mdm.model.query.mst.CustomerQuery;
+import com.dk.mdm.model.response.mst.CusFollowResponse;
+import com.dk.mdm.model.response.mst.CustomerResponse;
 import org.springframework.stereotype.Repository;
 import org.springframework.stereotype.Repository;
 
 
+import java.util.List;
+
 /**
 /**
 *  客户跟进 Mapper
 *  客户跟进 Mapper
 */
 */
 @Repository
 @Repository
 public interface CusFollowMapper extends BaseMapper<CusFollow>{
 public interface CusFollowMapper extends BaseMapper<CusFollow>{
+
+
+    /**
+     * @desc   : 根据条件进行查询
+     * @author : 于继渤
+     * @date : 2024/2/26 10:36
+     */
+    List<CusFollowResponse> selectByCond(CusFollowQuery cusFollowQuery);
+
+    /**
+     * @desc   : 根据条件进行查询(数量)
+     * @author : 于继渤
+     * @date : 2024/2/26 10:36
+     */
+    Long countByCond(CusFollowQuery cusFollowQuery);
 	
 	
 }
 }
 
 

+ 122 - 12
src/main/java/com/dk/mdm/mapper/mst/CusFollowMapper.xml

@@ -7,7 +7,12 @@
     <sql id="Base_Column_List">
     <sql id="Base_Column_List">
         follow_id, cus_id, follow_status, follow_type, follow_org, follow_staff, follow_time, follow_data, follow_time_len, stay_time_len, intention, invite_result, invite_time, design_staff, next_follow_plan, next_follow_time, annex_paths, measure_status, remarks, flg_valid, cp_id, op_create_time, op_create_user_id, op_update_time, op_update_user_id, op_app_code, op_timestamp, op_db_user
         follow_id, cus_id, follow_status, follow_type, follow_org, follow_staff, follow_time, follow_data, follow_time_len, stay_time_len, intention, invite_result, invite_time, design_staff, next_follow_plan, next_follow_time, annex_paths, measure_status, remarks, flg_valid, cp_id, op_create_time, op_create_user_id, op_update_time, op_update_user_id, op_app_code, op_timestamp, op_db_user
     </sql>
     </sql>
-
+    <sql id="Base_Column_List_Join">
+        tccf.follow_id, tccf.cus_id, tccf.follow_status, tccf.follow_type, tccf.follow_org, tccf.follow_staff, tccf.follow_time, tccf.follow_data,
+                 tccf.follow_time_len, tccf.stay_time_len, tccf.intention, tccf.invite_result, tccf.invite_time, tccf.design_staff,
+                 tccf.next_follow_plan, tccf.next_follow_time,tccf.annex_paths, tccf.measure_status, tccf.remarks, tccf.flg_valid,
+                 tccf.cp_id
+    </sql>
     <!-- 通用查询映射结果 -->
     <!-- 通用查询映射结果 -->
     <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.mst.CusFollow">
     <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.mst.CusFollow">
         <id column="follow_id" property="followId"/>
         <id column="follow_id" property="followId"/>
@@ -39,9 +44,40 @@
             <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
             <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
                 <result column="op_db_user" property="opDbUser"/>
                 <result column="op_db_user" property="opDbUser"/>
     </resultMap>
     </resultMap>
+    <resultMap id="BaseResultMapResponse" type="com.dk.mdm.model.response.mst.CusFollowResponse">
+        <id column="follow_id" property="followId"/>
+        <result column="cus_id" property="cusId" typeHandler="UuidTypeHandler"/>
+        <result column="follow_status" property="followStatus"/>
+        <result column="follow_type" property="followType"/>
+        <result column="follow_org" property="followOrg" typeHandler="UuidTypeHandler"/>
+        <result column="follow_staff" property="followStaff" typeHandler="UuidTypeHandler"/>
+        <result column="follow_time" property="followTime" typeHandler="TimestampTypeHandler"/>
+        <result column="follow_data" property="followData"/>
+        <result column="follow_time_len" property="followTimeLen"/>
+        <result column="stay_time_len" property="stayTimeLen"/>
+        <result column="intention" property="intention"/>
+        <result column="invite_result" property="inviteResult"/>
+        <result column="invite_time" property="inviteTime" typeHandler="TimestampTypeHandler"/>
+        <result column="design_staff" property="designStaff" typeHandler="UuidTypeHandler"/>
+        <result column="next_follow_plan" property="nextFollowPlan"/>
+        <result column="next_follow_time" property="nextFollowTime" typeHandler="TimestampTypeHandler"/>
+        <result column="annex_paths" property="annexPaths" typeHandler="JsonTypeHandler"/>
+        <result column="measure_status" property="measureStatus"/>
+        <result column="remarks" property="remarks"/>
+        <result column="flg_valid" property="flgValid"/>
+        <result column="cp_id" property="cpId"/>
+        <result column="cusName" property="cusName"/>
+        <result column="orgName" property="orgName"/>
+        <result column="staffName" property="staffName"/>
+        <result column="cusPhone" property="cusPhone"/>
+        <result column="addressFull" property="addressFull"/>
+
+
+
+    </resultMap>
 
 
     <!-- 通用条件列 -->
     <!-- 通用条件列 -->
-    <sql id="Condition">
+      <sql id="Condition">
         <where>
         <where>
             <if test="cusId != null and cusId != ''">
             <if test="cusId != null and cusId != ''">
                 AND cus_id = #{cusId}
                 AND cus_id = #{cusId}
@@ -127,6 +163,72 @@
         </where>
         </where>
     </sql>
     </sql>
 
 
+    <sql id="Condition_Join">
+        <where>
+            <if test="cusId != null and cusId != ''">
+                AND tccf.cus_id = #{cusId}
+            </if>
+            <if test="followStatus != null and followStatus != ''">
+                AND tccf.follow_status = #{followStatus}
+            </if>
+            <if test="followType != null and followType != ''">
+                AND tccf.follow_type = #{followType}
+            </if>
+            <if test="followOrg != null and followOrg != ''">
+                AND tccf.follow_org = #{followOrg}
+            </if>
+            <if test="followStaff != null and followStaff != ''">
+                AND tccf.follow_staff = #{followStaff}
+            </if>
+            <if test="followTime != null">
+                AND tccf.follow_time = #{followTime}
+            </if>
+            <if test="followData != null and followData != ''">
+                AND tccf.follow_data = #{followData}
+            </if>
+            <if test="followTimeLen != null">
+                AND tccf.follow_time_len = #{followTimeLen}
+            </if>
+            <if test="stayTimeLen != null and stayTimeLen != ''">
+                AND tccf.stay_time_len = #{stayTimeLen}
+            </if>
+            <if test="intention != null and intention != ''">
+                AND tccf.intention = #{intention}
+            </if>
+            <if test="inviteResult != null and inviteResult != ''">
+                AND tccf.invite_result = #{inviteResult}
+            </if>
+            <if test="inviteTime != null">
+                AND tccf.invite_time = #{inviteTime}
+            </if>
+            <if test="designStaff != null and designStaff != ''">
+                AND tccf.design_staff = #{designStaff}
+            </if>
+            <if test="nextFollowPlan != null and nextFollowPlan != ''">
+                AND tccf.next_follow_plan = #{nextFollowPlan}
+            </if>
+            <if test="nextFollowTime != null">
+                AND tccf.next_follow_time = #{nextFollowTime}
+            </if>
+            <if test="annexPaths != null and annexPaths != ''">
+                AND tccf.annex_paths = #{annexPaths}
+            </if>
+            <if test="measureStatus != null and measureStatus != ''">
+                AND tccf.measure_status = #{measureStatus}
+            </if>
+            <if test="remarks != null and remarks != ''">
+                AND tccf.remarks = #{remarks}
+            </if>
+            <if test="flgValid != null">
+                AND tccf.flg_valid = #{flgValid}
+            </if>
+            <if test="cpId != null">
+                AND tccf.cp_id = #{cpId}
+            </if>
+
+        </where>
+    </sql>
+
     <sql id="idsForeach">
     <sql id="idsForeach">
         <!-- 根据主键followId批量操作 -->
         <!-- 根据主键followId批量操作 -->
         WHERE follow_id in
         WHERE follow_id in
@@ -136,11 +238,19 @@
     </sql>
     </sql>
 
 
     <!-- 查询表t_crm_cus_follow,(条件查询+分页)列表 -->
     <!-- 查询表t_crm_cus_follow,(条件查询+分页)列表 -->
-    <select id="selectByCond" resultMap="BaseResultMap">
+    <select id="selectByCond" resultMap="BaseResultMapResponse">
         SELECT
         SELECT
-        <include refid="Base_Column_List"/>
-        FROM t_crm_cus_follow
-        <include refid="Condition"/>
+        <include refid="Base_Column_List_Join"/>,
+        tmc.cus_name AS "cusName",
+        tmc.cus_phone AS "cusPhone",
+        tmc.address_full AS "addressFull",
+        tmo.org_name  AS  "orgName",
+        tms.staff_name  AS  "staffName"
+        FROM dkic_b.t_crm_cus_follow tccf
+        LEFT JOIN dkic_b.t_mst_customer tmc ON tmc.cus_id = tccf.cus_id
+        LEFT JOIN dkic_b.t_mst_org tmo on tmo.org_id = tccf.follow_org
+        LEFT JOIN dkic_b.t_mst_staff tms on tms.staff_id = tccf.follow_staff
+        <include refid="Condition_Join"/>
         <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
         <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
             limit #{end} offset #{start}
             limit #{end} offset #{start}
         </if>
         </if>
@@ -150,15 +260,15 @@
     <select id="countByCond" resultType="Long">
     <select id="countByCond" resultType="Long">
         SELECT
         SELECT
         count(1)
         count(1)
-        FROM t_crm_cus_follow
-        <include refid="Condition"/>
+        FROM dkic_b.t_crm_cus_follow tccf
+        <include refid="Condition_Join"/>
     </select>
     </select>
 
 
     <!-- 根据主键查询表t_crm_cus_follow的一行数据 -->
     <!-- 根据主键查询表t_crm_cus_follow的一行数据 -->
     <select id="selectById" resultMap="BaseResultMap">
     <select id="selectById" resultMap="BaseResultMap">
         SELECT
         SELECT
         <include refid="Base_Column_List"/>
         <include refid="Base_Column_List"/>
-        FROM t_crm_cus_follow
+        FROM dkic_b.t_crm_cus_follow
         WHERE follow_id = #{followId}::uuid
         WHERE follow_id = #{followId}::uuid
     </select>
     </select>
 
 
@@ -166,7 +276,7 @@
     <select id="selectByIdForUpdate" resultMap="BaseResultMap">
     <select id="selectByIdForUpdate" resultMap="BaseResultMap">
         SELECT
         SELECT
         <include refid="Base_Column_List"/>
         <include refid="Base_Column_List"/>
-        FROM t_crm_cus_follow
+        FROM dkic_b.t_crm_cus_follow
         WHERE follow_id = #{followId}
         WHERE follow_id = #{followId}
         for update
         for update
     </select>
     </select>
@@ -175,13 +285,13 @@
     <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
     <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
         SELECT
         SELECT
         <include refid="Base_Column_List"/>
         <include refid="Base_Column_List"/>
-        FROM t_crm_cus_follow
+        FROM dkic_b.t_crm_cus_follow
         <include refid="idsForeach"/>
         <include refid="idsForeach"/>
         for update
         for update
     </select>
     </select>
 
 
     <insert id="insertBatch">
     <insert id="insertBatch">
-        insert into t_crm_cus_follow
+        insert into dkic_b.t_crm_cus_follow
         (
         (
         <trim suffixOverrides=",">
         <trim suffixOverrides=",">
             cus_id,
             cus_id,

+ 2 - 1
src/main/java/com/dk/mdm/mapper/mst/CusFollowStaffMapper.java

@@ -2,6 +2,7 @@ package com.dk.mdm.mapper.mst;
 
 
 import com.dk.mdm.model.pojo.mst.CusFollowStaff;
 import com.dk.mdm.model.pojo.mst.CusFollowStaff;
 import com.dk.common.mapper.BaseMapper;
 import com.dk.common.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 import org.springframework.stereotype.Repository;
 
 
 /**
 /**
@@ -9,6 +10,6 @@ import org.springframework.stereotype.Repository;
 */
 */
 @Repository
 @Repository
 public interface CusFollowStaffMapper extends BaseMapper<CusFollowStaff>{
 public interface CusFollowStaffMapper extends BaseMapper<CusFollowStaff>{
-	
+    CusFollowStaff selectByCusFollowStaffId(@Param("cusId") String cusId, @Param("followStaff") String followStaff);
 }
 }
 
 

+ 7 - 0
src/main/java/com/dk/mdm/mapper/mst/CusFollowStaffMapper.xml

@@ -122,4 +122,11 @@
             )
             )
         </foreach>
         </foreach>
     </insert>
     </insert>
+
+    <select id="selectByCusFollowStaffId" resultMap="BaseResultMap">
+        SELECT
+        <include refid="Base_Column_List"/>
+        FROM dkic_b.t_crm_cus_follow_staff
+        where cus_id = #{cusId} and follow_staff = #{followStaff}
+    </select>
 </mapper>
 </mapper>

+ 9 - 0
src/main/java/com/dk/mdm/mapper/mst/CustomerMapper.java

@@ -4,6 +4,7 @@ import com.dk.mdm.model.pojo.mst.Customer;
 import com.dk.common.mapper.BaseMapper;
 import com.dk.common.mapper.BaseMapper;
 import com.dk.mdm.model.query.mst.CustomerQuery;
 import com.dk.mdm.model.query.mst.CustomerQuery;
 import com.dk.mdm.model.response.mst.CustomerResponse;
 import com.dk.mdm.model.response.mst.CustomerResponse;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 import org.springframework.stereotype.Repository;
 
 
 import java.util.List;
 import java.util.List;
@@ -26,5 +27,13 @@ public interface CustomerMapper extends BaseMapper<Customer>{
      * @date : 2024/2/26 10:36
      * @date : 2024/2/26 10:36
      */
      */
     Long countByCond(CustomerQuery customerQuery);
     Long countByCond(CustomerQuery customerQuery);
+
+
+    /**
+     * @desc : 查询跟进人
+     * @author : 于继渤
+     * @date : 2022-05-26 14:05
+     */
+    Object selectFollowStaffs(@Param("cusId") String customerId);
 }
 }
 
 

+ 8 - 0
src/main/java/com/dk/mdm/mapper/mst/CustomerMapper.xml

@@ -321,4 +321,12 @@
             )
             )
         </foreach>
         </foreach>
     </insert>
     </insert>
+
+    <!--    查询跟进人-->
+    <select id="selectFollowStaffs" resultType="Object">
+        SELECT follow_staffs
+        from dkic_b.t_mst_customer
+        WHERE cus_id = #{cusId}
+    </select>
+
 </mapper>
 </mapper>

+ 7 - 1
src/main/java/com/dk/mdm/model/response/mst/CusFollowVOResponse.java → src/main/java/com/dk/mdm/model/response/mst/CusFollowResponse.java

@@ -30,7 +30,7 @@ import java.time.LocalDateTime;
 @ExportTitle("客户跟进")
 @ExportTitle("客户跟进")
 @TableName(value = "t_crm_cus_follow", autoResultMap = true)
 @TableName(value = "t_crm_cus_follow", autoResultMap = true)
 @ApiModel(value="实体类:客户跟进", description="表名:t_crm_cus_follow")
 @ApiModel(value="实体类:客户跟进", description="表名:t_crm_cus_follow")
-public class CusFollowVOResponse implements Serializable {
+public class CusFollowResponse implements Serializable {
 
 
     /*
     /*
      * 数据库字段
      * 数据库字段
@@ -216,6 +216,12 @@ public class CusFollowVOResponse implements Serializable {
     private Integer cpId;
     private Integer cpId;
 
 
 
 
+    private String cusName;
+    private String cusPhone;
+    private String orgName;
+    private String staffName;
+    private String addressFull;
+
 
 
 
 
     private static final long serialVersionUID = 1L;
     private static final long serialVersionUID = 1L;

+ 52 - 6
src/main/java/com/dk/mdm/model/vo/mst/CusFollowVO.java

@@ -280,16 +280,62 @@ public class CusFollowVO implements Serializable {
     private String opDbUser;
     private String opDbUser;
 
 
 
 
-    /*
-     * 相关属性
-     * @TableField(exist = false)
+    /**
+     * 客户名称
      */
      */
+    @Excel(name = "客户名称")
+    @ApiModelProperty(value = "客户名称")
+    private String cusName;
 
 
-    /*
-     * 关联属性 + 查询条件
-     * @TableField(exist = false)
+
+    /**
+     * 客户电话
+     */
+    @Excel(name = "客户电话")
+    @ApiModelProperty(value = "客户电话")
+    private String cusPhone;
+
+
+    /**
+     * 行政区划 (a1:省 a2:市 a3:区)
+     */
+    @Excel(name = "行政区划 (a1:省 a2:市 a3:区)")
+    @ApiModelProperty(value = "行政区划 (a1:省 a2:市 a3:区)")
+    @TableField(typeHandler = JsonTypeHandler.class)
+    private JSONObject addressArea;
+
+
+    /**
+     * 小区或POI
      */
      */
+    @Excel(name = "小区或POI")
+    @ApiModelProperty(value = "小区或POI")
+    private String addressName;
+
 
 
+    /**
+     * 门牌号
+     */
+    @Excel(name = "门牌号")
+    @ApiModelProperty(value = "门牌号")
+    private String addressNo;
+
+
+    /**
+     * 地址坐标(gcj02) (LAT:纬度的值 LON:经度的值)
+     */
+    @Excel(name = "地址坐标(gcj02) (LAT:纬度的值 LON:经度的值)")
+    @ApiModelProperty(value = "地址坐标(gcj02) (LAT:纬度的值 LON:经度的值)")
+    @TableField(typeHandler = JsonTypeHandler.class)
+    private JSONObject addressGcj02;
+
+
+    /**
+     * 详细地址
+     */
+    @Excel(name = "详细地址")
+    @ApiModelProperty(value = "详细地址")
+    private String addressFull;
 
 
     private static final long serialVersionUID = 1L;
     private static final long serialVersionUID = 1L;
 
 

+ 5 - 0
src/main/java/com/dk/mdm/service/common/CommonService.java

@@ -725,6 +725,11 @@ public class CommonService extends BaseService<Map<String, Object>> {
             map.put("kindType","量尺状态");
             map.put("kindType","量尺状态");
             list = commonMapper.getDataKind(map);
             list = commonMapper.getDataKind(map);
         }
         }
+        //跟进方式
+        if (dataSourceCode.equals("followType")) {
+            map.put("kindType","跟进方式");
+            list = commonMapper.getDataKind(map);
+        }
         return ResponseResultUtil.success(list);
         return ResponseResultUtil.success(list);
     }
     }
 }
 }

+ 283 - 6
src/main/java/com/dk/mdm/service/mst/CusFollowService.java

@@ -1,23 +1,300 @@
 package com.dk.mdm.service.mst;
 package com.dk.mdm.service.mst;
 
 
+import com.dk.common.exception.BaseBusinessException;
+import com.dk.common.infrastructure.annotaiton.Pagination;
+import com.dk.common.infrastructure.constant.Constant;
+import com.dk.common.infrastructure.enums.ErrorCodeEnum;
+import com.dk.common.model.pojo.PageList;
+import com.dk.common.response.ResponseResultUtil;
+import com.dk.common.response.ResponseResultVO;
+import com.dk.mdm.infrastructure.convert.mst.CusFollowConvert;
+import com.dk.mdm.infrastructure.util.AuthUtils;
+import com.dk.mdm.mapper.mst.CusFollowStaffMapper;
+import com.dk.mdm.mapper.mst.CustomerMapper;
+import com.dk.mdm.mapper.mst.StaffMapper;
 import com.dk.mdm.model.pojo.mst.CusFollow;
 import com.dk.mdm.model.pojo.mst.CusFollow;
 import com.dk.mdm.mapper.mst.CusFollowMapper;
 import com.dk.mdm.mapper.mst.CusFollowMapper;
 import com.dk.common.service.BaseService;
 import com.dk.common.service.BaseService;
 import com.dk.common.mapper.BaseMapper;
 import com.dk.common.mapper.BaseMapper;
+import com.dk.mdm.model.pojo.mst.CusFollowStaff;
+import com.dk.mdm.model.pojo.mst.Customer;
+import com.dk.mdm.model.query.mst.CusFollowQuery;
+import com.dk.mdm.model.query.mst.CustomerQuery;
+import com.dk.mdm.model.response.mst.CusFollowResponse;
+import com.dk.mdm.model.response.mst.CustomerResponse;
+import com.dk.mdm.model.response.mst.StaffResponse;
+import com.dk.mdm.model.vo.mst.CusFollowVO;
+import com.dk.mdm.service.common.CommonService;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
 
 
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
+import java.util.*;
+
 @Service
 @Service
 @Transactional
 @Transactional
 public class CusFollowService extends BaseService<CusFollow> {
 public class CusFollowService extends BaseService<CusFollow> {
 
 
-	@Override
-	public BaseMapper<CusFollow> getRepository() {
-		return cusFollowMapper;
-	}
+    @Override
+    public BaseMapper<CusFollow> getRepository() {
+        return cusFollowMapper;
+    }
+
+    @Autowired
+    private CusFollowMapper cusFollowMapper;
+
+    @Autowired
+    private CustomerMapper customerMapper;
+
+    @Autowired
+    private CustomerService customerService;
+
+    @Autowired
+    private CusFollowStaffMapper cusFollowStaffMapper;
+
+    @Autowired
+    private CommonService commonService;
+
+    @Autowired
+    private CusFollowConvert cusFollowConvert;
+
+    @Autowired
+    private StaffMapper staffMapper;
+
+
+    @Autowired
+    private AuthUtils authUtils;
+
+    /**
+     * @desc : 重写主键
+     * @author : 于继渤
+     * @date : 2024/2/29 20:29
+     */
+    @Override
+    public String getPrimaryKey() {
+        return "follow_id";
+    }
+
+
+    /**
+     * @desc : 查询
+     * @author : 于继渤
+     * @date : 2023/1/5 9:39
+     */
+    @Pagination
+    public ResponseResultVO<PageList<CusFollowResponse>> selectByCond(CusFollowQuery cusFollowQuery) {
+        return super.mergeListWithCount(cusFollowQuery, cusFollowMapper.selectByCond(cusFollowQuery),
+                cusFollowMapper.countByCond(cusFollowQuery));
+    }
+
+    /**
+     * @desc : 新建
+     * @author : 于继渤
+     * @date : 2023/1/5 9:39
+     */
+    @Transactional(
+            rollbackFor = {Exception.class}
+    )
+    public ResponseResultVO<?> insert(CusFollowVO cusFollowVO) {
+
+        if (cusFollowVO.getCusId() != null) {
+            //查询客户
+            Customer customer = customerMapper.selectById(cusFollowVO.getCusId());
+
+            // 查询跟进人是否存在
+            CusFollowStaff followStaff = cusFollowStaffMapper.selectByCusFollowStaffId(cusFollowVO.getCusId(), cusFollowVO.getFollowStaff());
+            //追加跟进人表
+            if (followStaff == null) {
+                cusFollowStaffMapper.insert(new CusFollowStaff()
+                        .setCusId(cusFollowVO.getCusId())
+                        .setFollowStaff(cusFollowVO.getFollowStaff())
+                        .setLastFollowId(authUtils.getStaff().getStaffId())
+                        .setLastFollowTime(LocalDateTime.now())
+                        .setCpId(authUtils.getStaff().getCpId())
+                        .setLastFollowStatus(cusFollowVO.getFollowStatus())
+                        .setFollowCount(1)
+                );
+            }
+            //追加跟进人
+            List<Long> users = new ArrayList<>();
+            Object o = customerMapper.selectFollowStaffs(cusFollowVO.getCusId());
+            if (o != null && o instanceof Long[]) {
+                users = Arrays.asList((Long[]) o);
+            }
+
+            if (users == null || users.size() == 0 || (users != null && users.stream().allMatch(Objects::isNull))) {
+                users = new ArrayList<>();
+            }
+            //公海客户跟进后 变成潜客状态
+            if (Constant.saleCustomerStatusConstant.SALE_STATUS_INTE.getName().equals(customer.getSaleStatus())) {
+                customer.setSaleStatus(Constant.saleCustomerStatusConstant.SALE_STATUS_POTE.getName());
+            }
+            //已流失客户重新接待后应该变成潜客
+            if (Constant.saleCustomerStatusConstant.SALE_STATUS_LOST.getName().equals(customer.getSaleStatus())) {
+                customer.setSaleStatus(Constant.saleCustomerStatusConstant.SALE_STATUS_POTE.getName());
+            }
+
+            //放入公海客户,清除跟进人
+            if (Constant.IntentionConstant.SEA.getValue().equals(cusFollowVO.getIntention())) {
+                customer.setFollowStaffs(new ArrayList<>());
+                customer.setSaleStatus(Constant.saleCustomerStatusConstant.SALE_STATUS_INTE.getName());
+            } else {
+                if (!users.contains(authUtils.getStaff().getStaffId())) {
+                    List arrList = new ArrayList(users);
+                    arrList.add(authUtils.getStaff().getStaffId());
+                    customer.setFollowStaffs(arrList);
+                }
+            }
+            //已流失客户,修改状态为流失
+            if (Constant.IntentionConstant.LOST.getValue().equals(cusFollowVO.getIntention())) {
+                customer.setSaleStatus(Constant.saleCustomerStatusConstant.SALE_STATUS_LOST.getName());
+            }
+
+            //如果不是留资接待 修改客户信息
+            if (!Constant.BasicDataConstant.FOLLOW_STATUS_4.getValue().equals(cusFollowVO.getFollowStatus())) {
+                customer.setCusName(cusFollowVO.getCusName());
+                customer.setCusPhone(cusFollowVO.getCusPhone());
+                customer.setAddressName(cusFollowVO.getAddressName());
+                customer.setAddressNo(cusFollowVO.getAddressNo());
+                customer.setAddressGcj02(cusFollowVO.getAddressGcj02());
+                customer.setAddressFull(cusFollowVO.getAddressFull());
+                customer.setAddressArea(cusFollowVO.getAddressArea());
+            }
+            customer.setCpId(authUtils.getStaff().getCpId());
+            // 同商户 电话不同
+            List<CustomerResponse> cusList = customerMapper.selectByCond(
+                    new CustomerQuery().setCpId(customer.getCpId()).setCusPhone(customer.getCusPhone()).setFlgValid(true)
+            );
+            if (cusList != null && cusList.size() > 0 && cusList.stream().anyMatch(a -> !a.getCusId().equals(customer.getCusId()))) {
+                throw new BaseBusinessException(ErrorCodeEnum.CUSTOMER_SAME_COMPANY_TELEPHONE.getCode(),
+                        ErrorCodeEnum.CUSTOMER_SAME_COMPANY_TELEPHONE.getMessage());
+            }
+            customerService.updateByUuid(customer);
+        } else if (cusFollowVO.getCusPhone() != null && cusFollowVO.getCusName() != null) {
+            //留资接待 新建客户
+            Customer customer = new Customer();
+            customer.setCusName(cusFollowVO.getCusName());
+            customer.setCusPhone(cusFollowVO.getCusPhone());
+            customer.setAddressName(cusFollowVO.getAddressName());
+            customer.setAddressNo(cusFollowVO.getAddressNo());
+            customer.setAddressGcj02(cusFollowVO.getAddressGcj02());
+            customer.setAddressFull(cusFollowVO.getAddressFull());
+            customer.setAddressArea(cusFollowVO.getAddressArea());
+            customer.setReportStaff(authUtils.getStaff().getStaffId());
+            customer.setReportTime(LocalDateTime.now());
+            customer.setCpId(authUtils.getStaff().getCpId());
+            customer.setOrgId(authUtils.getStaff().getOrgId());
+//            customer.setCustomerFrom(-1L);
+
+            // 同商户 电话不同
+            Long count = customerMapper.countByCond(
+                    new CustomerQuery().setCpId(customer.getCpId()).setCusPhone(customer.getCusPhone()).setFlgValid(true)
+            );
+            if (count > 0) {
+                return ResponseResultUtil.error(ErrorCodeEnum.CUSTOMER_SAME_COMPANY_TELEPHONE.getCode(),
+                        ErrorCodeEnum.CUSTOMER_SAME_COMPANY_TELEPHONE.getMessage());
+            }
+
+            //放入公海客户,清除跟进人
+            if (Constant.IntentionConstant.SEA.getValue().equals(cusFollowVO.getIntention())) {
+                customer.setFollowStaffs(new ArrayList<>());
+                customer.setSaleStatus(Constant.saleCustomerStatusConstant.SALE_STATUS_INTE.getName());
+            } else {
+                //当前跟进人(业务员)
+                customer.setFollowStaffs(new ArrayList<String>() {{
+                    add(authUtils.getStaff().getStaffId());
+                }});
+                customer.setSaleStatus(Constant.saleCustomerStatusConstant.SALE_STATUS_POTE.getName());
+            }
+
+            customer.setFollowCount(0);
+            //新建客户或编辑客户
+            customerMapper.insert(customer);
+
+            cusFollowVO.setCusId(customer.getCusId());
+        }
+
+
+        CusFollow cusFollow = cusFollowConvert.convertToPo(cusFollowVO);
+        //设置ID
+        Map<String, Object> uniqueNoteCode = commonService.getUniqueNoteCode(Constant.docNameConstant.CUSTOMERFOLLOW.getName(), true);
+        cusFollow.setFollowId(uniqueNoteCode.get("outId").toString());
+        //跟进时间
+        cusFollow.setFollowTime(LocalDateTime.now());
+        //跟进人
+        cusFollow.setFollowStaff(authUtils.getStaff().getStaffId());
+        //跟进部门
+        cusFollow.setFollowOrg(authUtils.getStaff().getOrgId());
+
+        // 约量尺
+        if (Constant.BasicDataConstant.FOLLOW_STATUS_3.getValue().equals(cusFollow.getFollowStatus())) {
+            // 量尺状态:待量尺
+            cusFollow.setMeasureStatus(Constant.BasicDataConstant.MEASURE_STATUS_2.getValue());
+        }
+        if (cusFollow.getFollowData() == null) {
+            cusFollow.setFollowData("无");
+        }
+        super.insert(cusFollow);
+
+
+        //设计师
+        StaffResponse designStaff = null;
+        if (cusFollow.getDesignStaff() != null) {
+
+            designStaff = staffMapper.selectById(cusFollow.getDesignStaff());
+
+        }
+
+        // 约尺 同意邀约 有设计师 设计师绑定企微
+        boolean pushFlag = Constant.BasicDataConstant.FOLLOW_STATUS_3.getValue().equals(cusFollow.getFollowStatus()) &&
+                Constant.BasicDataConstant.FOLLOW_INVITE_RESULT.getValue().equals(cusFollow.getInviteResult()) &&
+                designStaff != null;
+
+        if (cusFollow.getNextFollowTime() != null || pushFlag) {
+            // 保存跟进信息
+            //  saveToXxlJob(cusFollow);
+        }
+
+        return ResponseResultUtil.success();
+    }
+
 
 
-	@Autowired
-	private CusFollowMapper cusFollowMapper;
+    /**
+     * @desc : 保存跟进信息到xxl job
+     * @author : 于继渤海
+     * @date : 2022-05-27 09:53
+     */
+//    @Transactional(rollbackFor = {Exception.class})
+//    public void saveToXxlJob(CusFollow cusFollow) {
+//
+//        Long nextId = followPlanMapper.getNextId();
+//
+//
+//        // 约量尺 && 接受邀约
+////        预约量尺,邀约结果接受,通知设计师提醒时间是(服务时间);邀约结果拒绝,通知创建者提醒时间是(提醒时间)
+//        if (Constant.BasicDataConstant.FOLLOW_STATUS_3.getValue().equals(follow.getFollowStatus()) &&
+//                Constant.BasicDataConstant.FOLLOW_INVITE_RESULT.getValue().equals(follow.getInviteResult())) {
+//            follow.setNextFollowTime(follow.getInviteTime()).setFollowUser(follow.getDesignUser());
+//        }
+//
+//        int id = xxlJobUtils.create(Math.toIntExact(
+//                (follow.getNextFollowTime().toInstant(ZoneOffset.of("+8")).toEpochMilli() - System.currentTimeMillis()) / 1000
+//        ), nextId, Constant.XxlJobInfo.FOLLOW.getValue());
+//
+//
+//        // 生成主键
+//        followPlanMapper.insert(
+//                new FollowPlan().setPlanId(nextId).setCustomerId(follow.getCustomerId())
+//                        .setPlanType(Constant.IntegerConstant.PLAN_TYPE_FOLLOW.getValue())
+//                        .setFollowId(follow.getFollowId())
+//                        .setFollowUser(follow.getFollowUser())
+//                        .setNextFollowPlan(follow.getNextFollowPlan())
+//                        .setNextFollowTime(follow.getNextFollowTime())
+//                        .setXxlJobId(id)
+//                        .setCpId(follow.getCpId())
+//        );
+//    }
 
 
 }
 }

+ 33 - 6
src/main/java/com/dk/mdm/service/mst/CustomerService.java

@@ -2,8 +2,10 @@ package com.dk.mdm.service.mst;
 
 
 import com.dk.common.infrastructure.annotaiton.Pagination;
 import com.dk.common.infrastructure.annotaiton.Pagination;
 import com.dk.common.infrastructure.constant.Constant;
 import com.dk.common.infrastructure.constant.Constant;
+import com.dk.common.infrastructure.enums.ErrorCodeEnum;
 import com.dk.common.infrastructure.util.LocalDateTimeUtils;
 import com.dk.common.infrastructure.util.LocalDateTimeUtils;
 import com.dk.common.model.pojo.PageList;
 import com.dk.common.model.pojo.PageList;
+import com.dk.common.response.ResponseCodeEnum;
 import com.dk.common.response.ResponseResultUtil;
 import com.dk.common.response.ResponseResultUtil;
 import com.dk.common.response.ResponseResultVO;
 import com.dk.common.response.ResponseResultVO;
 import com.dk.mdm.infrastructure.convert.mst.CustomerConvert;
 import com.dk.mdm.infrastructure.convert.mst.CustomerConvert;
@@ -12,6 +14,7 @@ import com.dk.mdm.model.pojo.mst.Customer;
 import com.dk.mdm.mapper.mst.CustomerMapper;
 import com.dk.mdm.mapper.mst.CustomerMapper;
 import com.dk.common.service.BaseService;
 import com.dk.common.service.BaseService;
 import com.dk.common.mapper.BaseMapper;
 import com.dk.common.mapper.BaseMapper;
+import com.dk.mdm.model.pojo.mst.Org;
 import com.dk.mdm.model.query.mst.CustomerQuery;
 import com.dk.mdm.model.query.mst.CustomerQuery;
 import com.dk.mdm.model.response.mst.CustomerResponse;
 import com.dk.mdm.model.response.mst.CustomerResponse;
 import com.dk.mdm.model.vo.mst.CustomerVO;
 import com.dk.mdm.model.vo.mst.CustomerVO;
@@ -21,7 +24,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
 
 
 import java.time.LocalDateTime;
 import java.time.LocalDateTime;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.Date;
+import java.util.List;
 import java.util.Map;
 import java.util.Map;
 
 
 @Service
 @Service
@@ -43,6 +48,9 @@ public class CustomerService extends BaseService<Customer> {
     @Autowired
     @Autowired
     private CommonService commonService;
     private CommonService commonService;
 
 
+    @Autowired
+    private OrgService orgService;
+
 
 
     @Autowired
     @Autowired
     private AuthUtils authUtils;
     private AuthUtils authUtils;
@@ -83,16 +91,35 @@ public class CustomerService extends BaseService<Customer> {
         Map<String, Object> uniqueNoteCode = commonService.getUniqueNoteCode(Constant.docNameConstant.CUSTOMER.getName(), true);
         Map<String, Object> uniqueNoteCode = commonService.getUniqueNoteCode(Constant.docNameConstant.CUSTOMER.getName(), true);
         customer.setCusId(uniqueNoteCode.get("outId").toString());
         customer.setCusId(uniqueNoteCode.get("outId").toString());
         customer.setCusCode(uniqueNoteCode.get("outNote").toString());
         customer.setCusCode(uniqueNoteCode.get("outNote").toString());
+
+        // 同商户 电话不同
+        Long count = customerMapper.countByCond(
+                new CustomerQuery().setCpId(customer.getCpId()).setCusPhone(customer.getCusPhone()).setFlgValid(true)
+        );
+        if (count > 0) {
+            return ResponseResultUtil.error(ErrorCodeEnum.CUSTOMER_SAME_COMPANY_TELEPHONE.getCode(),
+                    ErrorCodeEnum.CUSTOMER_SAME_COMPANY_TELEPHONE.getMessage());
+        }
+        List<String> followStaff = new ArrayList<>();
+        followStaff.add(authUtils.getStaff().getStaffId());
+        customer.setFollowStaffs(followStaff);
+        if (customer.getSaleStatus() == null) {
+            //新建默认就是潜客
+            customer.setSaleStatus(Constant.saleCustomerStatusConstant.SALE_STATUS_POTE.getName());
+        }
+
+
         //设置公司id
         //设置公司id
         customer.setCpId(authUtils.getStaff().getCpId());
         customer.setCpId(authUtils.getStaff().getCpId());
-        //设置报备人
-        customer.setReportStaff(authUtils.getStaff().getStaffId());
         //报备日期
         //报备日期
         customer.setReportTime(LocalDateTime.now());
         customer.setReportTime(LocalDateTime.now());
-        //销售状态 (【系统字典】客销状态:公海、潜客、成
-        customer.setSaleStatus(Constant.SaleStatus.QIANKE.getName());
-        customerMapper.insert(customer);
-        return ResponseResultUtil.success();
+        ResponseResultVO<?> insert = super.insert(customer);
+        if (insert.getCode() == ResponseCodeEnum.SUCCESS.getCode()) {
+            return ResponseResultUtil.success(customer);
+        } else {
+            return insert;
+        }
+
     }
     }
 
 
     /**
     /**