Browse Source

crm 顾客追加农家ID

zdsong 2 weeks ago
parent
commit
56340870de

+ 1 - 0
farm-crm-biz/src/main/java/jp/yamoto/farm/crm/biz/bss/service/impl/BssAskServiceImpl.java

@@ -306,6 +306,7 @@ public class BssAskServiceImpl implements IBssAskService {
             MastCustomerBo mastCustomerBo = new MastCustomerBo();
             mastCustomerBo.setAskAddCustomerFlg(true);
             mastCustomerBo.setCustomerId(bssAskBo.getCustomerId());
+            mastCustomerBo.setFarmerId(bssAskBo.getFarmerId());
             mastCustomerBo.setPhoneNumber(bssAskBo.getPhoneNumber());
             mastCustomerBo.setCustomerName(bssAskBo.getAskUser());
             String customerId = mastCustomerService.saveCustomerWithBssAsk(mastCustomerBo);

+ 5 - 0
farm-crm-biz/src/main/java/jp/yamoto/farm/crm/biz/master/domain/bo/MastCustomerSearchBo.java

@@ -46,4 +46,9 @@ public class MastCustomerSearchBo implements Serializable {
      */
     private String insertFlg;
 
+    /**
+     * 農家ID
+     */
+    private String farmerId;
+
 }

+ 5 - 0
farm-crm-biz/src/main/java/jp/yamoto/farm/crm/biz/master/domain/vo/MastCustomerVo.java

@@ -26,6 +26,11 @@ public class MastCustomerVo {
     private String customerName;
 
     /**
+     * 農家ID
+     */
+    private String farmerId;
+
+    /**
      * 電話番号
      */
     private String phoneNumber;

+ 11 - 2
farm-crm-biz/src/main/java/jp/yamoto/farm/crm/biz/master/mapper/MastCustomerMapper.java

@@ -24,6 +24,14 @@ public interface MastCustomerMapper {
     public List<MastCustomerVo> selectList(MastCustomerSearchBo mastCustomer);
 
     /**
+     * 顧客マスタを検索データ
+     *
+     * @param mastCustomer 顧客マスタ検索パラメータ
+     * @return 顧客マスタデータ
+     */
+    public MastCustomerVo selectDetails(MastCustomerSearchBo mastCustomer);
+
+    /**
      * 顧客CDの件数のクエリ
      *
      * @param mastCustomer 顧客マスタパラメータ
@@ -34,10 +42,11 @@ public interface MastCustomerMapper {
     /**
      * 電話番号で顧客がいるかどうかを確認します
      *
-     * @param phoneNumber 顧客ID
+     * @param farmerId  農家ID
+     * @param phoneNumber 電話番号
      * @return 結果
      */
-    public int getCustomerCntByPhoneNumber(String phoneNumber);
+    public int getCustomerCntByPhoneNumber(String farmerId ,String phoneNumber);
 
     /**
      * 一覧表示項目スタの論理削除

+ 2 - 1
farm-crm-biz/src/main/java/jp/yamoto/farm/crm/biz/master/service/IMastCustomerService.java

@@ -58,8 +58,9 @@ public interface IMastCustomerService {
     /**
      * 電話番号で顧客がいるかどうかを確認します
      *
+     * @param farmerId  農家ID
      * @param phoneNumber 電話番号
      * @return 結果
      */
-    public boolean checkExistCustomerByPhoneNumber(String phoneNumber);
+    public boolean checkExistCustomerByPhoneNumber(String farmerId,String phoneNumber);
 }

+ 19 - 20
farm-crm-biz/src/main/java/jp/yamoto/farm/crm/biz/master/service/impl/MastCustomerServiceImpl.java

@@ -22,7 +22,6 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.CollectionUtils;
 
 import java.util.List;
 
@@ -113,35 +112,34 @@ public class MastCustomerServiceImpl extends MastCustomerBaseServiceImpl impleme
 
         MastCustomerSearchBo mastCustomer = new MastCustomerSearchBo();
         mastCustomer.setDiscontinuedFlg(DelFlgEnum.OFF.getCode());
-        mastCustomer.setPhoneNumber( DecryptUtils.encryptAES(mastCustomerBo.getPhoneNumber()));
+        mastCustomer.setFarmerId(mastCustomerBo.getFarmerId());
+        mastCustomer.setPhoneNumber(DecryptUtils.encryptAES(mastCustomerBo.getPhoneNumber()));
 
         // データを取得
-        List<MastCustomerVo> list = mastCustomerMapper.selectList(mastCustomer);
+        MastCustomerVo mastCustomerVo = mastCustomerMapper.selectDetails(mastCustomer);
         // 顧客マスタの追加時
-        if (CollectionUtils.isEmpty(list)) {
+        if (ValueUtils.isEmpty(mastCustomerVo)) {
             // お問い合わせ者顧客を増やすフラグ
-            String autoCustomerId = rangedSeqService.generateSerialNo(IRangedSeqService.SERIAL_TYPE_CUSTOMER);
-            mastCustomerBo.setCustomerId(autoCustomerId);
             this.insertInfo(mastCustomerBo);
-            return autoCustomerId;
-        }
+            return mastCustomerBo.getCustomerId();
+        } else {
+            // 顧客マスタの更新時
+            String customerId = mastCustomerVo.getCustomerId();
+            if (ValueUtils.isEqual(mastCustomerBo.getCustomerName(), mastCustomerVo.getCustomerName())) {
 
-        // 顧客マスタの更新時
-        String customerId = "";
-        for (MastCustomerVo item : list) {
-            if (ValueUtils.isEqual(mastCustomerBo.getCustomerName(), item.getCustomerName())) {
-                customerId = item.getCustomerId();
-                continue;
+                return customerId;
             }
             // 関連付けを設定
-            mastCustomerBo.setId(item.getId());
-            mastCustomerBo.setCustomerId(item.getCustomerId());
-            mastCustomerBo.setVersion(item.getVersion());
+            mastCustomerBo.setId(mastCustomerVo.getId());
+            mastCustomerBo.setCustomerId(mastCustomerVo.getCustomerId());
+            mastCustomerBo.setVersion(mastCustomerVo.getVersion());
+            mastCustomerBo.setFarmerId(mastCustomerVo.getFarmerId());
             mastCustomerBo.setPhoneNoCheckFlg(true);
             mastCustomerBo.setCustomerName(mastCustomerBo.getCustomerName());
             this.updateInfo(mastCustomerBo);
+            return customerId;
+
         }
-        return customerId;
 
     }
 
@@ -223,11 +221,12 @@ public class MastCustomerServiceImpl extends MastCustomerBaseServiceImpl impleme
     /**
      * 電話番号で顧客がいるかどうかを確認します
      *
+     * @param farmerId    農家ID
      * @param phoneNumber 電話番号
      * @return 結果
      */
-    public boolean checkExistCustomerByPhoneNumber(String phoneNumber) {
-        int mastCustomerCount = mastCustomerMapper.getCustomerCntByPhoneNumber(phoneNumber);
+    public boolean checkExistCustomerByPhoneNumber(String farmerId, String phoneNumber) {
+        int mastCustomerCount = mastCustomerMapper.getCustomerCntByPhoneNumber(farmerId, phoneNumber);
         return mastCustomerCount > 0;
     }
 

+ 1 - 0
farm-crm-biz/src/main/resources/mapper/crm/BssOrderMapper.xml

@@ -163,6 +163,7 @@
             </if>
 
         </where>
+        order by bo.order_time desc
     </select>
 
     <select id="selectByOrderId" parameterType="String"  resultMap="BssOrderResult">

+ 36 - 1
farm-crm-biz/src/main/resources/mapper/crm/MastCustomerMapper.xml

@@ -7,6 +7,7 @@
         <result property="id" column="id"/>
         <result property="customerId" column="customer_id"/>
         <result property="customerName" column="customer_name"/>
+        <result property="farmerId" column="farmer_id"/>
         <result property="phoneNumber" column="phone_number"/>
         <result property="postalCode" column="postal_code"/>
         <result property="address" column="address"/>
@@ -47,6 +48,9 @@
             <if test="customerId != null  and customerId != ''">
                 and customer_id like CONCAT('%', #{customerId}, '%')
             </if>
+            <if test="farmerId != null  and farmerId != ''">
+                and farmer_id like CONCAT('%', #{farmerId}, '%')
+            </if>
             <if test="customerName != null  and customerName != ''">
                 and customer_name like CONCAT('%', #{customerName}, '%')
             </if>
@@ -61,6 +65,32 @@
         </where>
     </select>
 
+    <select id="selectDetails" parameterType="MastCustomerSearchBo" resultMap="MastCustomerResult">
+        <include refid="selectMastCustomerVo"/>
+        <where>
+            <if test="id != null  and id != ''">
+                and id = #{id}
+            </if>
+            <if test="customerId != null  and customerId != ''">
+                and customer_id = #{customerId}
+            </if>
+            <if test="farmerId != null  and farmerId != ''">
+                and farmer_id  = #{farmerId}
+            </if>
+            <if test="customerName != null  and customerName != ''">
+                and customer_name  = #{customerName}
+            </if>
+            <if test="phoneNumber != null  and phoneNumber != ''">
+                and phone_number = #{phoneNumber}
+            </if>
+
+            <if test="discontinuedFlg != null ">
+                and discontinued_flg = #{discontinuedFlg}
+            </if>
+
+        </where>
+    </select>
+
     <select id="getCustomerInfoCount" parameterType="MastCustomerSearchBo" resultType="java.lang.Integer">
         SELECT
         count(1)
@@ -82,7 +112,9 @@
                 </if>
                 and customer_id !=#{customerId}
             </if>
-
+            <if test="farmerId != null  and farmerId != ''">
+                and farmer_id  = #{farmerId}
+            </if>
         </where>
     </select>
 
@@ -95,6 +127,9 @@
             <if test="phoneNumber != null  and phoneNumber != ''">
                 and phone_number = #{phoneNumber}
             </if>
+            <if test="farmerId != null  and farmerId != ''">
+                and farmer_id  = #{farmerId}
+            </if>
         </where>
     </select>
 

+ 2 - 2
farm-crm/src/main/java/jp/yamoto/farm/crm/web/controller/master/MastCustomerController.java

@@ -75,7 +75,7 @@ public class MastCustomerController extends BaseController {
      * 電話番号で顧客がいるかどうかを確認します(顧客情報を登録)
      */
     @GetMapping(value = "/check/exists/with/phone")
-    public AjaxResult checkExistCustomerByPhoneNumber(@RequestParam("phoneNumber") String phoneNumber) {
-        return success(mastCustomerService.checkExistCustomerByPhoneNumber(phoneNumber));
+    public AjaxResult checkExistCustomerByPhoneNumber(@RequestParam("farmerId") String farmerId,@RequestParam("phoneNumber") String phoneNumber) {
+        return success(mastCustomerService.checkExistCustomerByPhoneNumber(farmerId ,phoneNumber));
     }
 }