From ea689dd91eaa72425dc01759042c3b4eb2186512 Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期三, 17 六月 2026 10:14:44 +0800
Subject: [PATCH] 新增智能电表、空调管理

---
 server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/SmsEmailServiceImpl.java |  193 +++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 166 insertions(+), 27 deletions(-)

diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/SmsEmailServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/SmsEmailServiceImpl.java
index bc2311a..4129a20 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/SmsEmailServiceImpl.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/SmsEmailServiceImpl.java
@@ -8,6 +8,7 @@
 import com.doumee.biz.system.SystemDictDataBiz;
 import com.doumee.core.constants.ResponseStatus;
 import com.doumee.core.exception.BusinessException;
+import com.doumee.core.model.LoginUserInfo;
 import com.doumee.core.model.PageData;
 import com.doumee.core.model.PageWrap;
 import com.doumee.core.utils.*;
@@ -15,7 +16,11 @@
 import com.doumee.dao.business.dao.SmsConfigMapper;
 import com.doumee.dao.business.dao.SmsEmailMapper;
 import com.doumee.dao.business.model.*;
+import com.doumee.dao.system.SystemUserMapper;
+import com.doumee.dao.system.model.SystemDictData;
+import com.doumee.dao.system.model.SystemUser;
 import com.doumee.service.business.SmsEmailService;
+import com.doumee.service.business.third.EmailService;
 import com.doumee.service.business.third.EmayService;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -44,6 +49,12 @@
     private EmayService emayService;
     @Autowired
     private SmsConfigMapper smsConfigMapper;
+    @Autowired
+    private SystemUserMapper systemUserMapper;
+    @Autowired
+    private YwCustomerMapper ywCustomerMapper;
+    @Autowired
+    private MemberMapper memberMapper;
 
     @Value("${debug_model}")
     private boolean debugModel;
@@ -82,39 +93,117 @@
     }
 
     @Override
-    public Integer sendSms(SmsEmail smsEmail) {
-        if(StringUtils.isBlank(smsEmail.getPhone())){
-            throw  new BusinessException(ResponseStatus.BAD_REQUEST);
+    public Integer sendMerchantLoginSms(String phone) {
+        if (StringUtils.isBlank(phone)) {
+            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鎵嬫満鍙蜂笉鑳戒负绌�");
         }
-        String nowDate = DateUtil.getFomartDate(new Date(),"yyyy-MM-dd HH:mm:ss");
-        if(smsEmailMapper.selectCount(new QueryWrapper<SmsEmail>().lambda()
-                .eq(SmsEmail::getPhone,smsEmail.getPhone())
-                .eq(SmsEmail::getType,Constants.ZERO)
-                .between(SmsEmail::getCreateDate, DateUtil.getFomartDate(DateUtil.afterMinutesDate(-5),"yyyy-MM-dd HH:mm:ss"),nowDate)
-        )>=3){
-            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"瀵逛笉璧凤紝瓒呭嚭鍙戦�佹鏁帮紝璇风◢鍚庨噸璇曪紒");
+        return doSendH5LoginSms(phone.trim(), LoginUserInfo.H5_USER_CUSTOMER);
+    }
+
+    @Override
+    public Integer sendSms(SmsEmail smsEmail) {
+        if (StringUtils.isBlank(smsEmail.getPhone())) {
+            throw new BusinessException(ResponseStatus.BAD_REQUEST);
+        }
+        return doSendH5LoginSms(smsEmail.getPhone().trim(), LoginUserInfo.H5_USER_OPS);
+    }
+
+    private Integer doSendH5LoginSms(String phone, Integer h5UserType) {
+        assertH5LoginAccountExists(phone, h5UserType);
+        String nowDate = DateUtil.getFomartDate(new Date(), "yyyy-MM-dd HH:mm:ss");
+        if (smsEmailMapper.selectCount(new QueryWrapper<SmsEmail>().lambda()
+                .eq(SmsEmail::getPhone, phone)
+                .eq(SmsEmail::getType, Constants.ZERO)
+                .between(SmsEmail::getCreateDate, DateUtil.getFomartDate(DateUtil.afterMinutesDate(-5), "yyyy-MM-dd HH:mm:ss"), nowDate)
+        ) >= 3) {
+            throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "瀵逛笉璧凤紝瓒呭嚭鍙戦�佹鏁帮紝璇风◢鍚庨噸璇曪紒");
         }
         String code = Constants.getRandom6Num();
         SmsConfig smsConfig = smsConfigMapper.selectOne(new QueryWrapper<SmsConfig>().lambda().eq(SmsConfig::getObjType,
                 SmsConstants.inventCode).last(" limit 1 "));
-        //寮�鍚煭淇¢�氱煡
-        if(Objects.nonNull(smsConfig) || Constants.equalsInteger(smsConfig.getStatus(),Constants.ZERO)){
-            if(StringUtils.isNotBlank(smsConfig.getContent())){
-                String content  = smsConfig.getContent().replace("{楠岃瘉鐮亇",code);
-                emayService.sendSmsByHk(smsEmail.getPhone(),content);
-                smsEmail.setRemark(code);
-                smsEmail.setIsdeleted(Constants.ZERO);
-                smsEmail.setCreateDate(new Date());
-                smsEmail.setStatus(Constants.ZERO);
-                smsEmail.setType(Constants.ZERO);
-                smsEmail.setTitle("鐭俊楠岃瘉鐮�");
-                smsEmail.setContent(content);
-                smsEmail.setObjType(Constants.ZERO+"");
-                smsEmailMapper.insert(smsEmail);
-                return smsEmail.getId();
-            }
+        SystemDictData comNameDict = systemDictDataBiz.queryByCode(Constants.SMS, Constants.SMS_COMNAME);
+        if (comNameDict == null || StringUtils.isBlank(comNameDict.getCode())) {
+            throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "鐭俊绛惧悕鏈厤缃紝璇疯仈绯荤鐞嗗憳");
         }
-        return null;
+        String comName = comNameDict.getCode();
+        if (smsConfig == null || StringUtils.isBlank(smsConfig.getContent())) {
+            throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "鐭俊鏈嶅姟鏈厤缃紝璇疯仈绯荤鐞嗗憳");
+        }
+        if (!Constants.equalsInteger(smsConfig.getStatus(), Constants.ZERO)) {
+            throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "鐭俊鏈嶅姟鏈紑鍚紝璇疯仈绯荤鐞嗗憳");
+        }
+        String content = comName + smsConfig.getContent().replace("{楠岃瘉鐮亇", code);
+        if (!emayService.sendSingleSms(phone, content)) {
+            throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "鐭俊鍙戦�佸け璐ワ紝璇风◢鍚庨噸璇�");
+        }
+        SmsEmail record = new SmsEmail();
+        record.setPhone(phone);
+        record.setRemark(code);
+        record.setIsdeleted(Constants.ZERO);
+        record.setCreateDate(new Date());
+        record.setStatus(Constants.ZERO);
+        record.setType(Constants.ZERO);
+        record.setTitle("鐭俊楠岃瘉鐮�");
+        record.setContent(content);
+        record.setObjType(Constants.ZERO + "");
+        smsEmailMapper.insert(record);
+        return record.getId();
+    }
+
+    /**
+     * H5 鐧诲綍鍙戠煭淇″墠鏍¢獙锛氬晢鎴锋煡 yw_customer锛岃繍缁存煡 system_user
+     */
+    private void assertH5LoginAccountExists(String phone, Integer h5UserType) {
+        if (Constants.equalsInteger(h5UserType, LoginUserInfo.H5_USER_CUSTOMER)) {
+            assertMerchantAccountExists(phone);
+            return;
+        }
+        if (systemUserMapper.selectCount(new QueryWrapper<SystemUser>().lambda()
+                .eq(SystemUser::getMobile, phone)
+                .eq(SystemUser::getDeleted, Boolean.FALSE)) == Constants.ZERO) {
+            throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "瀵逛笉璧凤紝鎵嬫満鍙锋棤鏁堣妫�鏌ュ悗閲嶈瘯!");
+        }
+    }
+
+    private void assertMerchantAccountExists(String phone) {
+        YwCustomer customer = findMerchantByPhone(phone);
+        if (customer == null) {
+            throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT.getCode(), "鍟嗘埛涓嶅瓨鍦ㄦ垨鏈敞鍐�");
+        }
+        if (customer.getStatus() != null && Constants.equalsInteger(customer.getStatus(), Constants.ONE)) {
+            throw new BusinessException(ResponseStatus.NO_ALLOW_LOGIN.getCode(), "鍟嗘埛璐﹀彿宸茬鐢�");
+        }
+    }
+
+    private YwCustomer findMerchantByPhone(String phone) {
+        YwCustomer byCustomerPhone = ywCustomerMapper.selectOne(new QueryWrapper<YwCustomer>().lambda()
+                .eq(YwCustomer::getIsdeleted, Constants.ZERO)
+                .eq(YwCustomer::getPhone, phone)
+                .last(" limit 1 "));
+        if (byCustomerPhone != null) {
+            return byCustomerPhone;
+        }
+        Member member = memberMapper.selectOne(new QueryWrapper<Member>().lambda()
+                .eq(Member::getIsdeleted, Constants.ZERO)
+                .eq(Member::getType, Constants.memberType.customer)
+                .eq(Member::getPhone, phone)
+                .isNotNull(Member::getCustomerId)
+                .orderByDesc(Member::getId)
+                .last(" limit 1 "));
+        if (member == null || member.getCustomerId() == null) {
+            return null;
+        }
+        YwCustomer customer = ywCustomerMapper.selectOne(new QueryWrapper<YwCustomer>().lambda()
+                .eq(YwCustomer::getId, member.getCustomerId())
+                .eq(YwCustomer::getIsdeleted, Constants.ZERO)
+                .last(" limit 1 "));
+        if (customer != null) {
+            return customer;
+        }
+        return ywCustomerMapper.selectOne(new QueryWrapper<YwCustomer>().lambda()
+                .eq(YwCustomer::getIsdeleted, Constants.ZERO)
+                .eq(YwCustomer::getMemberId, member.getId())
+                .last(" limit 1 "));
     }
 
 
@@ -571,4 +660,54 @@
         }
     }
 
+
+
+    @Override
+    public Integer sendBillSms(String content,String mobile,Integer billId) {
+        boolean result = true;
+        if(StringUtils.isBlank(mobile)){
+            result = false;
+        }
+        if(result){
+            result = emayService.sendSingleSms(mobile,content);
+        }
+        SmsEmail smsEmail = new SmsEmail();
+        smsEmail.setIsdeleted(Constants.ZERO);
+        smsEmail.setCreateDate(new Date());
+        smsEmail.setStatus(result?Constants.ONE:Constants.TWO);
+        smsEmail.setType(Constants.ZERO);
+        smsEmail.setRemark(result?"鐭俊鍙戦�佹垚鍔�":"鐭俊鍙戦�佸け璐�");
+        smsEmail.setTitle("璐﹀崟鍌垂");
+        smsEmail.setObjId(billId);
+        smsEmail.setObjType(Constants.ONE+"");
+        smsEmail.setContent(content);
+        smsEmailMapper.insert(smsEmail);
+        return smsEmail.getId();
+    }
+
+    @Autowired
+    private EmailService emailService;
+
+    @Override
+    public Integer sendEmail(String email,String content,Integer billId) {
+        boolean result = true;
+        if(StringUtils.isBlank(email)){
+            result = false;
+        }
+        if(result){
+            result=   emailService.sendEmail(email,"璐﹀崟鍌垂",content,null);
+        }
+        SmsEmail smsEmail = new SmsEmail();
+        smsEmail.setRemark(result?"閭欢鍙戦�佹垚鍔�":"閭欢鍙戦�佸け璐�");
+        smsEmail.setIsdeleted(Constants.ZERO);
+        smsEmail.setTitle("璐﹀崟鍌垂");
+        smsEmail.setCreateDate(new Date());
+        smsEmail.setStatus(result?Constants.ONE:Constants.TWO);
+        smsEmail.setType(Constants.ONE);
+        smsEmail.setObjId(billId);
+        smsEmail.setObjType(Constants.TWO+"");
+        smsEmail.setContent(content);
+        smsEmailMapper.insert(smsEmail);
+        return smsEmail.getId();
+    }
 }

--
Gitblit v1.9.3