1,电子钥匙发送短信、邮件通知API对接及逻辑处理

2,电子钥匙模块发送系统短信、系统邮件通知对接及自测完成
This commit is contained in:
Daisy 2024-06-12 13:53:59 +08:00
parent b3f0794f84
commit cd44d44fb8
8 changed files with 118 additions and 33 deletions

View File

@ -426,12 +426,12 @@ class _SendElectronicKeyViewState extends State<SendElectronicKeyView>
OutLineBtn( OutLineBtn(
btnName: logic.state.userNameType.value == 1 ? '短信通知' : '邮件通知', btnName: logic.state.userNameType.value == 1 ? '短信通知' : '邮件通知',
onClick: () { onClick: () {
if (logic.state.userNameType.value == 2) { Get.toNamed(Routers.sendEmailNotificationPage,
Get.toNamed(Routers.sendEmailNotificationPage, arguments: <String, Object?>{
arguments: <String, String?>{'email': logic.emailOrPhone}); 'receiver': logic.emailOrPhone,
} else { 'userNameType': logic.state.userNameType.value,
logic.sendMsg(isPhone: true); 'keyId': logic.keyId
} });
}, },
), ),
SizedBox( SizedBox(

View File

@ -1,4 +1,4 @@
import 'package:get_storage/get_storage.dart'; import 'package:get/get.dart';
import 'package:star_lock/main/lockDetail/electronicKey/sendEmailNotification/sendEmailNotification_entity.dart'; import 'package:star_lock/main/lockDetail/electronicKey/sendEmailNotification/sendEmailNotification_entity.dart';
import 'package:star_lock/main/lockDetail/electronicKey/sendEmailNotification/sendEmailNotification_state.dart'; import 'package:star_lock/main/lockDetail/electronicKey/sendEmailNotification/sendEmailNotification_state.dart';
import 'package:star_lock/network/api_repository.dart'; import 'package:star_lock/network/api_repository.dart';
@ -13,13 +13,33 @@ class SendEmailNotificationLogic extends BaseGetXController {
final SendEmailNotificationEntity entity = final SendEmailNotificationEntity entity =
await ApiRepository.to.getKeyNoticeTemplate( await ApiRepository.to.getKeyNoticeTemplate(
lockId: CommonDataManage().currentKeyInfo.lockId ?? 0, lockId: CommonDataManage().currentKeyInfo.lockId ?? 0,
keyId: CommonDataManage().currentKeyInfo.keyId ?? 0, keyId: state.getKeyId.value,
channelType: 2, channelType: state.channelType.value,
); );
if (entity.errorCode!.codeIsSuccessful) { if (entity.errorCode!.codeIsSuccessful) {
state.emailTemplateList.value = state.emailTemplateList.value =
entity.data?.list ?? <EmailNotificationItem>[]; entity.data?.list ?? <EmailNotificationItem>[];
state.currentNotifyItem.value = state.emailTemplateList.first;
state.emailController.text = state.currentNotifyItem.value.template ?? '';
state.emailTemplateList.refresh(); state.emailTemplateList.refresh();
state.currentNotifyItem.refresh();
}
}
// channelType--1 2 openDoorType--1 2
Future<void> keyNoticeSubmitRequest() async {
final SendEmailNotificationEntity entity =
await ApiRepository.to.keyNoticeSubmit(
receiverName: state.getReceiver.value,
lockId: CommonDataManage().currentKeyInfo.lockId ?? 0,
keyId: state.getKeyId.value,
channelType: state.channelType.value,
openDoorType: 1,
templateType: state.currentNotifyItem.value.type ?? '',
);
if (entity.errorCode!.codeIsSuccessful) {
showToast('发送成功');
Get.back();
} }
} }
} }

View File

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:star_lock/main/lockDetail/electronicKey/sendEmailNotification/SendEmailNotification_logic.dart'; import 'package:star_lock/main/lockDetail/electronicKey/sendEmailNotification/SendEmailNotification_logic.dart';
import 'package:star_lock/main/lockDetail/electronicKey/sendEmailNotification/sendEmailNotification_entity.dart';
import 'package:star_lock/main/lockDetail/electronicKey/sendEmailNotification/sendEmailNotification_state.dart'; import 'package:star_lock/main/lockDetail/electronicKey/sendEmailNotification/sendEmailNotification_state.dart';
import 'package:star_lock/tools/emailNotifyTypeSelectAlert.dart'; import 'package:star_lock/tools/emailNotifyTypeSelectAlert.dart';
import 'package:star_lock/tools/pickers/pickers.dart'; import 'package:star_lock/tools/pickers/pickers.dart';
@ -39,7 +40,7 @@ class _SendEmailNotificationPageState extends State<SendEmailNotificationPage> {
return Scaffold( return Scaffold(
backgroundColor: AppColors.mainBackgroundColor, backgroundColor: AppColors.mainBackgroundColor,
appBar: TitleAppBar( appBar: TitleAppBar(
barTitle: '邮件通知', barTitle: state.channelType.value == 1 ? '短信通知' : '邮件通知',
haveBack: true, haveBack: true,
backgroundColor: AppColors.mainColor), backgroundColor: AppColors.mainColor),
body: SingleChildScrollView( body: SingleChildScrollView(
@ -47,25 +48,25 @@ class _SendEmailNotificationPageState extends State<SendEmailNotificationPage> {
children: <Widget>[ children: <Widget>[
Obx(() => CommonItem( Obx(() => CommonItem(
leftTitel: TranslationLoader.lanKeys!.receiver!.tr, leftTitel: TranslationLoader.lanKeys!.receiver!.tr,
rightTitle: state.getEmail.value, rightTitle: state.getReceiver.value,
isHaveLine: true, isHaveLine: true,
)), )),
Obx(() => CommonItem( Obx(() => CommonItem(
leftTitel: '类型', leftTitel: '类型',
rightTitle: rightTitle: state.getNotifyTypeText.value,
state.emailNotifyType.value == 1 ? '系统邮件' : '个人邮件',
isHaveDirection: true, isHaveDirection: true,
action: () { action: () {
EmailNotifyTypeSelectAlert.showEmailNotifyTypeSelectAlert( EmailNotifyTypeSelectAlert.showEmailNotifyTypeSelectAlert(
context, (int value) { isEmail: state.channelType.value == 2,
state.emailNotifyType.value = value; onSelected: (int value) {
}); state.notifyTypeSelect.value = value;
});
}, },
)), )),
Container(height: 10.h), Container(height: 10.h),
Obx(() => CommonItem( Obx(() => CommonItem(
leftTitel: '模板', leftTitel: '模板',
rightTitle: state.selectEmailTemplate.value, rightTitle: state.currentNotifyItem.value.name ?? '',
isHaveDirection: true, isHaveDirection: true,
isHaveLine: true, isHaveLine: true,
action: () { action: () {
@ -125,7 +126,9 @@ class _SendEmailNotificationPageState extends State<SendEmailNotificationPage> {
borderRadius: 20.w, borderRadius: 20.w,
margin: EdgeInsets.only(left: 30.w, right: 30.w, top: 30.w), margin: EdgeInsets.only(left: 30.w, right: 30.w, top: 30.w),
padding: EdgeInsets.only(top: 25.w, bottom: 25.w), padding: EdgeInsets.only(top: 25.w, bottom: 25.w),
onClick: () {}), onClick: () {
logic.keyNoticeSubmitRequest();
}),
], ],
), ),
), ),
@ -134,13 +137,15 @@ class _SendEmailNotificationPageState extends State<SendEmailNotificationPage> {
// pickerView // pickerView
void openBottomItemSheet(BuildContext context) { void openBottomItemSheet(BuildContext context) {
final List nameList = final List nameList = state.emailTemplateList
state.emailTemplateList.map((item) => item.name!).toList(); .map((EmailNotificationItem item) => item.name!)
.toList();
Pickers.showSinglePicker(context, Pickers.showSinglePicker(context,
data: nameList, data: nameList,
pickerStyle: DefaultPickerStyle(), onConfirm: (p, int position) { pickerStyle: DefaultPickerStyle(), onConfirm: (p, int position) {
state.selectEmailTemplate.value = nameList[position]; state.currentNotifyItem.value = state.emailTemplateList[position];
state.emailController.text = state.emailTemplateList[position].template!;
}); });
} }
} }

View File

@ -4,14 +4,39 @@ import 'package:star_lock/main/lockDetail/electronicKey/sendEmailNotification/se
class SendEmailNotificationState { class SendEmailNotificationState {
SendEmailNotificationState() { SendEmailNotificationState() {
if (Get.arguments['email'] != null) { if (Get.arguments['receiver'] != null) {
getEmail.value = Get.arguments['email']; getReceiver.value = Get.arguments['receiver'];
}
if (Get.arguments['keyId'] != null) {
getKeyId.value = Get.arguments['keyId'];
}
if (Get.arguments['userNameType'] != null) {
channelType.value = Get.arguments['userNameType'];
if (channelType.value == 1) {
if (notifyTypeSelect.value == 1) {
getNotifyTypeText.value = '系统短信';
} else {
getNotifyTypeText.value = '个人短信';
}
} else {
if (notifyTypeSelect.value == 1) {
getNotifyTypeText.value = '系统邮件';
} else {
getNotifyTypeText.value = '个人邮件';
}
}
} }
} }
RxString getEmail = ''.obs; RxString getReceiver = ''.obs;
final TextEditingController emailController = TextEditingController(); final TextEditingController emailController = TextEditingController();
RxInt emailNotifyType = 1.obs; //1 2 RxInt notifyTypeSelect = 1.obs; //1 2
RxList emailTemplateList = <EmailNotificationItem>[].obs; RxInt channelType = 0.obs; //1 2
RxString selectEmailTemplate = '默认模版'.obs; RxString getNotifyTypeText = ''.obs;
RxList<EmailNotificationItem> emailTemplateList =
<EmailNotificationItem>[].obs;
Rx<EmailNotificationItem> currentNotifyItem = EmailNotificationItem().obs;
RxInt getKeyId = 0.obs; //keyId
} }

View File

@ -255,4 +255,5 @@ abstract class Api {
final String checkIpURL = '/checkIp/ip'; final String checkIpURL = '/checkIp/ip';
final String keyNoticeTemplateURL = '/key/getNoticeTemplate'; // final String keyNoticeTemplateURL = '/key/getNoticeTemplate'; //
final String keyNoticeSubmitURL = '/key/noticeSubmit'; //
} }

View File

@ -2245,6 +2245,21 @@ class ApiProvider extends BaseProvider {
}), }),
isUnShowLoading: true, isUnShowLoading: true,
); );
Future<Response<dynamic>> keyNoticeSubmit(String receiverName, int lockId,
int keyId, int channelType, int openDoorType, String templateType) =>
post(
keyNoticeSubmitURL.toUrl,
jsonEncode(<String, dynamic>{
'receiverName': receiverName,
'lockId': lockId,
'keyId': keyId,
'channelType': channelType,
'openDoorType': openDoorType,
'templateType': templateType,
}),
isUnShowLoading: true,
);
} }
extension ExtensionString on String { extension ExtensionString on String {

View File

@ -2259,4 +2259,18 @@ class ApiRepository {
await apiProvider.getKeyNoticeTemplate(lockId, keyId, channelType); await apiProvider.getKeyNoticeTemplate(lockId, keyId, channelType);
return SendEmailNotificationEntity.fromJson(res.body); return SendEmailNotificationEntity.fromJson(res.body);
} }
//
Future<SendEmailNotificationEntity> keyNoticeSubmit({
required String receiverName,
required int lockId,
required int keyId,
required int channelType,
required int openDoorType,
required String templateType,
}) async {
final Response<dynamic> res = await apiProvider.keyNoticeSubmit(
receiverName, lockId, keyId, channelType, openDoorType, templateType);
return SendEmailNotificationEntity.fromJson(res.body);
}
} }

View File

@ -14,10 +14,10 @@ class EmailNotifyTypeSelectAlert extends StatelessWidget {
} }
static void showEmailNotifyTypeSelectAlert( static void showEmailNotifyTypeSelectAlert(
BuildContext context, Function(int) onSelected) { {required bool isEmail, required Function(int) onSelected}) {
bool isSystemEmailSelected = true; // bool isSystemEmailSelected = true; //
showCupertinoDialog( showCupertinoDialog(
context: context, context: Get.context!,
builder: (BuildContext context) { builder: (BuildContext context) {
return StatefulBuilder( return StatefulBuilder(
builder: (BuildContext context, StateSetter setState) { builder: (BuildContext context, StateSetter setState) {
@ -54,7 +54,7 @@ class EmailNotifyTypeSelectAlert extends StatelessWidget {
Padding( Padding(
padding: EdgeInsets.only(left: 10.w), padding: EdgeInsets.only(left: 10.w),
child: Text( child: Text(
'系统邮件(推荐)', isEmail ? '系统邮件(推荐)' : '系统短信(推荐)',
style: TextStyle( style: TextStyle(
fontSize: 22.sp, fontWeight: FontWeight.bold), fontSize: 22.sp, fontWeight: FontWeight.bold),
), ),
@ -67,7 +67,9 @@ class EmailNotifyTypeSelectAlert extends StatelessWidget {
child: Align( child: Align(
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
child: Text( child: Text(
'邮件将从软件平台直接发给用户,请根据需要在软件那里购买邮件数量', isEmail
? '邮件将从软件平台直接发给用户,请根据需要在软件那里购买邮件数量'
: '短信将从软件平台直接发给用户,请根据需要在软件那里购买短信数量',
style: TextStyle(fontSize: 18.sp), style: TextStyle(fontSize: 18.sp),
textAlign: TextAlign.left, textAlign: TextAlign.left,
), ),
@ -93,7 +95,7 @@ class EmailNotifyTypeSelectAlert extends StatelessWidget {
Padding( Padding(
padding: EdgeInsets.only(left: 10.w), padding: EdgeInsets.only(left: 10.w),
child: Text( child: Text(
'个人邮件', isEmail ? '个人邮件' : '个人短信',
style: TextStyle( style: TextStyle(
fontSize: 22.sp, fontWeight: FontWeight.bold), fontSize: 22.sp, fontWeight: FontWeight.bold),
), ),
@ -106,8 +108,11 @@ class EmailNotifyTypeSelectAlert extends StatelessWidget {
child: Align( child: Align(
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
child: Text( child: Text(
'邮件将从你的个人邮箱发给用户', isEmail
? '邮件将从你的个人邮箱发给用户'
: '短信将从你的个人手机号发给用户,费用由运营商从你的手机号扣除',
style: TextStyle(fontSize: 18.sp), style: TextStyle(fontSize: 18.sp),
textAlign: TextAlign.left,
), ),
), ),
), ),