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(
btnName: logic.state.userNameType.value == 1 ? '短信通知' : '邮件通知',
onClick: () {
if (logic.state.userNameType.value == 2) {
Get.toNamed(Routers.sendEmailNotificationPage,
arguments: <String, String?>{'email': logic.emailOrPhone});
} else {
logic.sendMsg(isPhone: true);
}
Get.toNamed(Routers.sendEmailNotificationPage,
arguments: <String, Object?>{
'receiver': logic.emailOrPhone,
'userNameType': logic.state.userNameType.value,
'keyId': logic.keyId
});
},
),
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_state.dart';
import 'package:star_lock/network/api_repository.dart';
@ -13,13 +13,33 @@ class SendEmailNotificationLogic extends BaseGetXController {
final SendEmailNotificationEntity entity =
await ApiRepository.to.getKeyNoticeTemplate(
lockId: CommonDataManage().currentKeyInfo.lockId ?? 0,
keyId: CommonDataManage().currentKeyInfo.keyId ?? 0,
channelType: 2,
keyId: state.getKeyId.value,
channelType: state.channelType.value,
);
if (entity.errorCode!.codeIsSuccessful) {
state.emailTemplateList.value =
entity.data?.list ?? <EmailNotificationItem>[];
state.currentNotifyItem.value = state.emailTemplateList.first;
state.emailController.text = state.currentNotifyItem.value.template ?? '';
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:get/get.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/tools/emailNotifyTypeSelectAlert.dart';
import 'package:star_lock/tools/pickers/pickers.dart';
@ -39,7 +40,7 @@ class _SendEmailNotificationPageState extends State<SendEmailNotificationPage> {
return Scaffold(
backgroundColor: AppColors.mainBackgroundColor,
appBar: TitleAppBar(
barTitle: '邮件通知',
barTitle: state.channelType.value == 1 ? '短信通知' : '邮件通知',
haveBack: true,
backgroundColor: AppColors.mainColor),
body: SingleChildScrollView(
@ -47,25 +48,25 @@ class _SendEmailNotificationPageState extends State<SendEmailNotificationPage> {
children: <Widget>[
Obx(() => CommonItem(
leftTitel: TranslationLoader.lanKeys!.receiver!.tr,
rightTitle: state.getEmail.value,
rightTitle: state.getReceiver.value,
isHaveLine: true,
)),
Obx(() => CommonItem(
leftTitel: '类型',
rightTitle:
state.emailNotifyType.value == 1 ? '系统邮件' : '个人邮件',
rightTitle: state.getNotifyTypeText.value,
isHaveDirection: true,
action: () {
EmailNotifyTypeSelectAlert.showEmailNotifyTypeSelectAlert(
context, (int value) {
state.emailNotifyType.value = value;
});
isEmail: state.channelType.value == 2,
onSelected: (int value) {
state.notifyTypeSelect.value = value;
});
},
)),
Container(height: 10.h),
Obx(() => CommonItem(
leftTitel: '模板',
rightTitle: state.selectEmailTemplate.value,
rightTitle: state.currentNotifyItem.value.name ?? '',
isHaveDirection: true,
isHaveLine: true,
action: () {
@ -125,7 +126,9 @@ class _SendEmailNotificationPageState extends State<SendEmailNotificationPage> {
borderRadius: 20.w,
margin: EdgeInsets.only(left: 30.w, right: 30.w, top: 30.w),
padding: EdgeInsets.only(top: 25.w, bottom: 25.w),
onClick: () {}),
onClick: () {
logic.keyNoticeSubmitRequest();
}),
],
),
),
@ -134,13 +137,15 @@ class _SendEmailNotificationPageState extends State<SendEmailNotificationPage> {
// pickerView
void openBottomItemSheet(BuildContext context) {
final List nameList =
state.emailTemplateList.map((item) => item.name!).toList();
final List nameList = state.emailTemplateList
.map((EmailNotificationItem item) => item.name!)
.toList();
Pickers.showSinglePicker(context,
data: nameList,
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 {
SendEmailNotificationState() {
if (Get.arguments['email'] != null) {
getEmail.value = Get.arguments['email'];
if (Get.arguments['receiver'] != null) {
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();
RxInt emailNotifyType = 1.obs; //1 2
RxList emailTemplateList = <EmailNotificationItem>[].obs;
RxString selectEmailTemplate = '默认模版'.obs;
RxInt notifyTypeSelect = 1.obs; //1 2
RxInt channelType = 0.obs; //1 2
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 keyNoticeTemplateURL = '/key/getNoticeTemplate'; //
final String keyNoticeSubmitURL = '/key/noticeSubmit'; //
}

View File

@ -2245,6 +2245,21 @@ class ApiProvider extends BaseProvider {
}),
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 {

View File

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