-
- {{item.oilNoName}}
-
+
{{item.oilNoName}}
保存
+
+
+
+
+ {{item.oilNoName}}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/app/admin/tuanyou-agent/petrol-station-manage/petrol-station-manage.ts b/src/app/admin/tuanyou-agent/petrol-station-manage/petrol-station-manage.ts
index 2f80e6e..b1bb110 100644
--- a/src/app/admin/tuanyou-agent/petrol-station-manage/petrol-station-manage.ts
+++ b/src/app/admin/tuanyou-agent/petrol-station-manage/petrol-station-manage.ts
@@ -4,11 +4,13 @@ import {NzMessageService, NzModalService} from '_ng-zorro-antd@9.3.0@ng-zorro-an
import {TyAgentService} from '../../../services/ty-agent.service';
import {TyAgentOilStationService} from '../../../services/ty-agent-oil-station.service';
import {Validators} from '@angular/forms';
-import {OrganizationService} from "../../../services/organization.service";
-import {LocalStorageService} from "../../../services/local-storage.service";
+import {OrganizationService} from '../../../services/organization.service';
+import {LocalStorageService} from '../../../services/local-storage.service';
import {ADMIN_INFO_OBJECT} from '../../../services/local-storage.namespace';
-import {TySalesmanService} from "../../../services/ty-salesman.service";
-import {TyAgentPriceService} from "../../../services/ty-agent-price.service";
+import {TySalesmanService} from '../../../services/ty-salesman.service';
+import {TyAgentPriceService} from '../../../services/ty-agent-price.service';
+import {GasService} from '../../../services/gas.service';
+import {CommonsService} from '../../../services/commons.service';
@Component({
selector: 'app-petrol-station-manage',
@@ -27,6 +29,7 @@ export class PetrolStationManageComponent implements OnInit {
tableLoading = true;
searchForm: FormGroup;
pageNum: number;
+ pageSize = 10;
whereObject: any = {};
allChecked = false;
@@ -45,15 +48,27 @@ export class PetrolStationManageComponent implements OnInit {
assignSalesmanModal = false;
assignSalesmanForm: FormGroup;
+ batchDiscountConfigModal = false;
+ batchDiscountConfigForm: FormGroup;
+
+ batchConfigOilNoModal = false;
+ batchConfigOilNoForm: FormGroup;
+
discountConfigModal = false;
discountConfigData: PetrolStationManage[] = [];
+ oilConfigModal = false;
+
+ oilNoArray = [];
+
formatterPercent = (value: number) => `${value} 折`;
parserPercent = (value: string) => value.replace(' 折', '');
constructor(private modal: NzModalService,
private message: NzMessageService,
private tyAgentService: TyAgentService,
+ private commonsService: CommonsService,
+ private gasService: GasService,
private tyAgentPriceService: TyAgentPriceService,
private tySalesmanService: TySalesmanService,
private organizationService: OrganizationService,
@@ -84,6 +99,21 @@ export class PetrolStationManageComponent implements OnInit {
this.assignSalesmanForm = this.form.group({
salesmanId: [null, [Validators.required]],
});
+ this.batchDiscountConfigForm = this.form.group({
+ belongType: [null],
+ oilNo: [null, [Validators.required]],
+ priceRate: [100, [Validators.required]],
+ });
+ this.batchConfigOilNoForm = this.form.group({
+ status: [null, [Validators.required]],
+ oilNo: [null, [Validators.required]],
+ });
+
+ this.commonsService.getDictionary('GAS_OIL_TYPE', data => {
+ if (data['return_code'] === '000000') {
+ this.oilNoArray = data['return_data'];
+ }
+ });
this.requestData(1);
}
@@ -93,7 +123,7 @@ export class PetrolStationManageComponent implements OnInit {
requestData(pageNum) {
this.tableLoading = true;
this.whereObject['pageNum'] = pageNum;
- this.whereObject['pageSize'] = 10;
+ this.whereObject['pageSize'] = this.pageSize;
this.tyAgentOilStationService.getOilStationList(this.whereObject, data => {
if (data['return_code'] === '000000') {
this.dataObject = data['return_data'];
@@ -548,12 +578,80 @@ export class PetrolStationManageComponent implements OnInit {
* 弹出优惠配置模态框
*/
showDiscountConfigModal(oilStationId: number) {
- this.tyAgentPriceService.getOilStationPrice(oilStationId, data => {
+ this.getOilStationPrice(oilStationId);
+ this.discountConfigModal = true;
+ }
+
+ /**
+ * 关闭优惠配置模态框
+ */
+ closeDiscountConfigModal() {
+ this.discountConfigModal = false;
+ }
+
+ /**
+ * 弹出批量优惠配置模态框
+ */
+ showBatchDiscountConfigModal() {
+ this.batchDiscountConfigModal = true;
+ }
+
+ /**
+ * 关闭批量优惠配置模态框
+ */
+ closeBatchDiscountConfigModal() {
+ this.batchDiscountConfigModal = false;
+ }
+
+ /**
+ * 批量设置优惠
+ */
+ submitBatchDiscountConfig() {
+ for (const i in this.batchDiscountConfigForm.controls) {
+ this.batchDiscountConfigForm.controls[i].markAsDirty();
+ this.batchDiscountConfigForm.controls[i].updateValueAndValidity();
+ }
+ if (this.batchDiscountConfigForm.status == null || this.batchDiscountConfigForm.status !== 'VALID') {
+ this.modal.warning({
+ nzTitle: '提示',
+ nzContent: '有必填项未填写',
+ });
+ this.loadingObject.spinning = false;
+ return;
+ }
+ if (this.checkedData.length === 0) {
+ this.modal.warning({
+ nzTitle: '提示',
+ nzContent: '请勾选油站',
+ });
+ return;
+ }
+ this.loadingObject.spinning = true;
+ this.loadingObject.msg = '处理中...';
+ this.batchDiscountConfigModal = false;
+
+ if (this.roleType === 5) {
+ this.batchDiscountConfigForm.value.belongType = 1;
+ } else {
+ this.batchDiscountConfigForm.value.belongType = 2;
+ }
+ const oilStationList = [];
+ for (const data of this.checkedData) {
+ oilStationList.push({ oilStationId: data['storeId'], oilStationName: data['storeName'], tyAgentOilStationId: data['tyAgentOilStationId'] });
+ }
+ this.batchDiscountConfigForm.value['oilStationList'] = oilStationList;
+ this.tyAgentPriceService.batchConfigPrice(this.batchDiscountConfigForm.value, data => {
+ this.loadingObject.spinning = false;
if (data['return_code'] === '000000') {
- this.discountConfigData = data['return_data'];
- this.discountConfigModal = true;
+ this.modal.success({
+ nzTitle: '提示',
+ nzContent: '处理成功',
+ });
+ this.checkedData = [];
+ this.requestData(this.whereObject['pageNum']);
+ this.closeBatchDiscountConfigModal();
} else {
- this.modal.warning({
+ this.modal.error({
nzTitle: '提示',
nzContent: data['return_msg'],
});
@@ -562,10 +660,67 @@ export class PetrolStationManageComponent implements OnInit {
}
/**
- * 关闭优惠配置模态框
+ * 弹出批量优惠配置模态框
*/
- closeDiscountConfigModal() {
- this.discountConfigModal = false;
+ showBatchConfigOilNoModal() {
+ this.batchConfigOilNoModal = true;
+ }
+
+ /**
+ * 关闭批量优惠配置模态框
+ */
+ closeBatchConfigOilNoModal() {
+ this.batchConfigOilNoModal = false;
+ }
+
+ /**
+ * 批量设置优惠
+ */
+ submitBatchConfigOilNo() {
+ for (const i in this.batchConfigOilNoForm.controls) {
+ this.batchConfigOilNoForm.controls[i].markAsDirty();
+ this.batchConfigOilNoForm.controls[i].updateValueAndValidity();
+ }
+ if (this.batchConfigOilNoForm.status == null || this.batchConfigOilNoForm.status !== 'VALID') {
+ this.modal.warning({
+ nzTitle: '提示',
+ nzContent: '有必填项未填写',
+ });
+ return;
+ }
+ if (this.checkedData.length === 0) {
+ this.modal.warning({
+ nzTitle: '提示',
+ nzContent: '请勾选油站',
+ });
+ return;
+ }
+ this.loadingObject.spinning = true;
+ this.loadingObject.msg = '处理中...';
+ this.batchDiscountConfigModal = false;
+
+ const oilStationList = [];
+ for (const data of this.checkedData) {
+ oilStationList.push({ oilStationId: data['storeId'] });
+ }
+ this.batchConfigOilNoForm.value['oilStationList'] = oilStationList;
+ this.tyAgentPriceService.batchConfigOilNo(this.batchConfigOilNoForm.value, data => {
+ this.loadingObject.spinning = false;
+ if (data['return_code'] === '000000') {
+ this.modal.success({
+ nzTitle: '提示',
+ nzContent: '处理成功',
+ });
+ this.checkedData = [];
+ this.requestData(this.whereObject['pageNum']);
+ this.closeBatchConfigOilNoModal();
+ } else {
+ this.modal.error({
+ nzTitle: '提示',
+ nzContent: data['return_msg'],
+ });
+ }
+ });
}
/**
@@ -578,6 +733,15 @@ export class PetrolStationManageComponent implements OnInit {
nzContent: '没有配置优惠数据'
});
}
+ if (this.roleType === 5) {
+ for (const data of this.discountConfigData) {
+ data['belongType'] = 1;
+ }
+ } else {
+ for (const data of this.discountConfigData) {
+ data['belongType'] = 2;
+ }
+ }
this.tyAgentPriceService.editPrice(this.discountConfigData, data => {
if (data['return_code'] === '000000') {
this.modal.success({
@@ -595,6 +759,21 @@ export class PetrolStationManageComponent implements OnInit {
});
}
+ /**
+ * 弹出油品配置模态框
+ */
+ showOilConfigModal(oilStationId: number) {
+ this.getOilStationPrice(oilStationId);
+ this.oilConfigModal = true;
+ }
+
+ /**
+ * 关闭油品配置模态框
+ */
+ closeOilConfigModal() {
+ this.oilConfigModal = false;
+ }
+
/**
* 全选
* @param data
@@ -636,13 +815,91 @@ export class PetrolStationManageComponent implements OnInit {
}
}
+ /**
+ * 油品禁用提示
+ */
+ showOilDisabledConfirm(oilStationId: number, oilNo: string): void {
+ this.modal.confirm({
+ nzTitle: '警告',
+ nzContent: '确定要暂停销售该油品吗',
+ nzOkText: '是',
+ nzCancelText: '否',
+ nzOkType: 'danger',
+ nzOnOk: () => this.submitOilDisabled(oilStationId, oilNo)
+ });
+ }
+
+ submitOilDisabled(oilStationId: number, oilNo: string) {
+ this.gasService.disabledOil({ storeId: oilStationId, oilNo }, data => {
+ if (data['return_code'] === '000000') {
+ this.modal.success({
+ nzTitle: '提示',
+ nzContent: data['return_data'],
+ });
+ this.getOilStationPrice(oilStationId);
+ } else {
+ this.modal.warning({
+ nzTitle: '提示',
+ nzContent: data['return_msg'],
+ });
+ }
+ });
+ }
+
+ /**
+ * 油品启用提示
+ */
+ showOilEnableConfirm(oilStationId: number, oilNo: string): void {
+ this.gasService.enableOil({ storeId: oilStationId, oilNo }, data => {
+ if (data['return_code'] === '000000') {
+ this.modal.success({
+ nzTitle: '提示',
+ nzContent: data['return_data'],
+ });
+ this.getOilStationPrice(oilStationId);
+ } else {
+ this.modal.warning({
+ nzTitle: '提示',
+ nzContent: data['return_msg'],
+ });
+ }
+ });
+ }
+
+ /**
+ * 查询油站价格
+ * @param oilStationId
+ */
+ getOilStationPrice(oilStationId: number) {
+ let belongType = 2;
+ if (this.roleType === 5) {
+ belongType = 1;
+ }
+ this.tyAgentPriceService.getOilStationPrice(belongType, oilStationId, data => {
+ if (data['return_code'] === '000000') {
+ this.discountConfigData = data['return_data'];
+ } else {
+ this.modal.warning({
+ nzTitle: '提示',
+ nzContent: data['return_msg'],
+ });
+ }
+ });
+ }
+
+ pageSizeChange(pageSize: number) {
+ this.pageSize = pageSize;
+ this.requestData(1);
+ }
}
export class PetrolStationManage {
+ belongType: number;
oilStationId: number;
lowPrice: number;
oilNo: string;
oilNoName: string;
priceRate: number;
+ status: number;
}
diff --git a/src/app/app-common.module.ts b/src/app/app-common.module.ts
index 86b5820..43159ee 100644
--- a/src/app/app-common.module.ts
+++ b/src/app/app-common.module.ts
@@ -44,6 +44,7 @@ import {
OilCardRecordTypePipe, OilCardRecordSourceTypePipe
} from './pipes';
import {OilCardStatusPipe} from "./pipes/oil-card/oil-card-status.pipe";
+import { OilTypePipe } from './pipes/store/oil-type.pipe';
@@ -98,6 +99,7 @@ const PIPES = [
],
declarations: [
...PIPES,
+ OilTypePipe,
],
diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts
index 85c3b33..74cf71a 100644
--- a/src/app/app-routing.module.ts
+++ b/src/app/app-routing.module.ts
@@ -112,6 +112,11 @@ const routes: Routes = [
loadChildren: () => import('./admin/oil-card/oil-card.module').then(m => m.OilCardModule),
canActivate: [InitGuardService]
},
+ {
+ path: 'gz-sinopec',
+ loadChildren: () => import('./admin/gz-sinopec/gz-sinopec.module').then(m => m.GzSinopecModule),
+ canActivate: [InitGuardService]
+ },
],
},
];
diff --git a/src/app/pipes/recharge-status.pipe.ts b/src/app/pipes/recharge-status.pipe.ts
index 9a832e2..e659165 100644
--- a/src/app/pipes/recharge-status.pipe.ts
+++ b/src/app/pipes/recharge-status.pipe.ts
@@ -14,9 +14,9 @@ export class RechargeStatusPipe implements PipeTransform {
case 3:
return '已完成';
case 4:
- return '已取消';
- case 5:
return '已退款';
+ case 5:
+ return '已取消';
case 6:
return '退款中';
}
diff --git a/src/app/pipes/store/oil-type.pipe.ts b/src/app/pipes/store/oil-type.pipe.ts
new file mode 100644
index 0000000..e878379
--- /dev/null
+++ b/src/app/pipes/store/oil-type.pipe.ts
@@ -0,0 +1,18 @@
+import { Pipe, PipeTransform } from '@angular/core';
+
+@Pipe({
+ name: 'oilType'
+})
+export class OilTypePipe implements PipeTransform {
+
+ transform(value: number): string {
+ switch (value) {
+ case 1:
+ return '汽油';
+ case 2:
+ return '柴油';
+ case 3:
+ return '天然气';
+ }
+ }
+}
diff --git a/src/app/services/coupon.service.ts b/src/app/services/coupon.service.ts
index 70f41fd..f3a24af 100644
--- a/src/app/services/coupon.service.ts
+++ b/src/app/services/coupon.service.ts
@@ -132,5 +132,28 @@ export class CouponService {
});
}
+ /**
+ * 查询贵州中石化分配列表
+ *
+ * @param id 用户id
+ * @param callBack 返回参数
+ */
+ public getGzSinopecAssignList(params: object, callBack) {
+ this.http.get(environment.baseUrl + 'couponCode/getGzSinopecAssignList?' + this.common.getWhereCondition(params)).subscribe(data => {
+ callBack(data);
+ });
+ }
+
+ /**
+ * 导出贵州中石化分配列表
+ *
+ * @param id 用户id
+ * @param callBack 返回参数
+ */
+ public importGzSinopecAssign(params: object, callBack) {
+ this.http.get(environment.baseUrl + 'couponCode/importGzSinopecAssign?' + this.common.getWhereCondition(params)).subscribe(data => {
+ callBack(data);
+ });
+ }
}
diff --git a/src/app/services/gas.service.ts b/src/app/services/gas.service.ts
new file mode 100644
index 0000000..6dc73e5
--- /dev/null
+++ b/src/app/services/gas.service.ts
@@ -0,0 +1,39 @@
+import { Injectable } from '@angular/core';
+import {HttpClient} from '_@angular_common@9.0.7@@angular/common/http';
+import {CommonsService} from './commons.service';
+import {environment} from "../../environments/environment";
+
+@Injectable({
+ providedIn: 'root'
+})
+export class GasService {
+
+ constructor(
+ private http: HttpClient,
+ private common: CommonsService
+ ) { }
+
+ /**
+ * 禁用油品
+ *
+ * @param param 参数对象
+ * @param callBack 回调
+ */
+ public disabledOil(param: object, callBack) {
+ this.http.post(environment.baseUrl + 'highGas/disabledOil', param).subscribe(data => {
+ callBack(data);
+ });
+ }
+
+ /**
+ * 启用油品
+ *
+ * @param param 参数对象
+ * @param callBack 回调
+ */
+ public enableOil(param: object, callBack) {
+ this.http.post(environment.baseUrl + 'highGas/enableOil', param).subscribe(data => {
+ callBack(data);
+ });
+ }
+}
diff --git a/src/app/services/index.service.ts b/src/app/services/index.service.ts
index 3e22da1..9195faa 100644
--- a/src/app/services/index.service.ts
+++ b/src/app/services/index.service.ts
@@ -53,6 +53,19 @@ export class IndexService {
});
}
+ /**
+ * @Author Sum1Dream
+ * @methodName addHLTBalance
+ * @Description // 新增余额
+ * @Date 12:12 下午 2022/1/10
+ * @Param
+ */
+ public recharge(params: object, callBack) {
+ this.http.post(environment.baseUrl + 'merStoreAccount/recharge', params).subscribe(data => {
+ callBack(data);
+ });
+ }
+
/**
* @Author Sum1Dream
* @methodName queryCompanyAccountInfo2JD
@@ -124,5 +137,47 @@ export class IndexService {
});
}
+ /**
+ * @Author Sum1Dream
+ * @methodName getAccount
+ * @Description // 查询门店账户
+ * @Date 10:00 2022/5/18
+ * @Param
+ */
+
+ public getAccount(callBack) {
+ this.http.get(environment.baseUrl + 'merStoreAccount/getAccount').subscribe(data => {
+ callBack(data);
+ });
+ }
+
+ /**
+ * @Author Sum1Dream
+ * @methodName getGasStatistical
+ * @Description // 查询加油站统计
+ * @Date 10:00 2022/5/18
+ * @Param
+ */
+ public getGasStatistical(callBack) {
+ this.http.post(environment.baseUrl + 'highGas/getGasStatistical', null).subscribe(data => {
+ callBack(data);
+ });
+ }
+
+ /**
+ * @Author Sum1Dream
+ * @methodName getAccountRecordList
+ * @Description // 查询门店账户流失记录
+ * @Date 10:00 2022/5/18
+ * @Param
+ */
+
+ public getAccountRecordList(paramsObject , callBack) {
+ this.http.get(environment.baseUrl + 'merStoreAccount/getAccountRecordList?' + this.common.getWhereCondition(paramsObject)).subscribe(data => {
+ callBack(data);
+ });
+ }
+
+
}
diff --git a/src/app/services/merchant-store.service.ts b/src/app/services/merchant-store.service.ts
index 8c3a479..5854d19 100644
--- a/src/app/services/merchant-store.service.ts
+++ b/src/app/services/merchant-store.service.ts
@@ -25,6 +25,18 @@ export class MerchantStoreService {
});
}
+ /**
+ * 查询门店油品列表
+ *
+ * @param paramsObject 对象
+ * @param callBack 回调
+ */
+ public getOilPriceListByStore(paramsObject: object, callBack) {
+ this.http.get(environment.baseUrl + 'gasOilPrice/getOilPriceListByStore?' + this.common.getWhereCondition(paramsObject)).subscribe(data => {
+ callBack(data);
+ });
+ }
+
/**
* 超级管理员查询门店列表
*
@@ -88,5 +100,80 @@ export class MerchantStoreService {
});
}
+ /**
+ * 查询油站油品详情
+ *
+ * @param paramsObject 对象
+ * @param callBack 回调
+ */
+ public getOilPriceDetail(paramsObject: object, callBack) {
+ this.http.get(environment.baseUrl + 'gasOilPrice/getOilPriceDetail?' + this.common.getWhereCondition(paramsObject)).subscribe(data => {
+ callBack(data);
+ });
+ }
+
+ /**
+ * 编辑油品
+ *
+ * @param params 上传对象
+ * @param callBack 回调
+ * @return data 返回结果
+ */
+ public editGasOilPrice(params: object, callBack) {
+ this.http.post(environment.baseUrl + 'gasOilPrice/editGasOilPrice', params).subscribe(data => {
+ callBack(data);
+ });
+ }
+
+ /**
+ * 删除油品
+ *
+ * @param params 上传对象
+ * @param callBack 回调
+ * @return data 返回结果
+ */
+ public delOilPrice(params: object, callBack) {
+ console.log(params);
+ this.http.post(environment.baseUrl + 'gasOilPrice/delOilPrice', params).subscribe(data => {
+ callBack(data);
+ });
+ }
+
+ /**
+ * 删除油枪
+ *
+ * @param params 上传对象
+ * @param callBack 回调
+ * @return data 返回结果
+ */
+ public delGunNo(params: object, callBack) {
+ this.http.post(environment.baseUrl + 'gasOilGunNo/delGunNo', params).subscribe(data => {
+ callBack(data);
+ });
+ }
+
+ /**
+ * 查询油站油品油枪
+ *
+ * @param oilPriceId 对象
+ * @param callBack 回调
+ */
+ public getGunNoListByOilPrice(oilPriceId: number, callBack) {
+ this.http.get(environment.baseUrl + 'gasOilGunNo/getGunNoListByOilPrice?oilPriceId=' + oilPriceId).subscribe(data => {
+ callBack(data);
+ });
+ }
+ /**
+ * 配置油枪号
+ *
+ * @param params 上传对象
+ * @param callBack 回调
+ * @return data 返回结果
+ */
+ public addGasOilPrice(params: object, callBack) {
+ this.http.post(environment.baseUrl + 'gasOilGunNo/addGasOilPrice', params).subscribe(data => {
+ callBack(data);
+ });
+ }
}
diff --git a/src/app/services/order.service.ts b/src/app/services/order.service.ts
index 977ba3b..fe68ecf 100644
--- a/src/app/services/order.service.ts
+++ b/src/app/services/order.service.ts
@@ -26,6 +26,18 @@ export class OrderService {
});
}
+ /**
+ * 查询油站订单
+ *
+ * @param paramsObject 对象
+ * @param callBack 回调
+ */
+ public getGasOrderListByOil(paramsObject: object, callBack) {
+ this.http.get(environment.baseUrl + 'highGas/getGasOrderList?' + this.common.getWhereCondition(paramsObject)).subscribe(data => {
+ callBack(data);
+ });
+ }
+
/**
* @Author Sum1Dream
* @methodName getDiscountPackageList
@@ -233,4 +245,15 @@ export class OrderService {
});
}
+ public exportGasOrder(params: object , callBack) {
+ this.http.get(environment.baseUrl + 'highGas/exportGasOrder?' + this.common.getWhereCondition(params)).subscribe( data => {
+ callBack(data);
+ });
+ }
+
+ public getGasOrderDetail(orderNo: string , callBack) {
+ this.http.get(environment.baseUrl + 'highGas/getGasOrderDetail?orderNo=' + orderNo).subscribe( data => {
+ callBack(data);
+ });
+ }
}
diff --git a/src/app/services/ty-agent-price.service.ts b/src/app/services/ty-agent-price.service.ts
index 2b10df0..b358bae 100644
--- a/src/app/services/ty-agent-price.service.ts
+++ b/src/app/services/ty-agent-price.service.ts
@@ -24,14 +24,37 @@ export class TyAgentPriceService {
});
}
+ /**
+ * 批量配置价格
+ * @param paramObject 参数
+ * @param callBack
+ */
+ batchConfigPrice(paramObject: object, callBack) {
+ this.http.post(environment.baseUrl + 'tyAgentPrice/batchConfigPrice', paramObject).subscribe(data => {
+ callBack(data);
+ });
+ }
+
+ /**
+ * 批量配置油品
+ * @param paramObject 参数
+ * @param callBack
+ */
+ batchConfigOilNo(paramObject: object, callBack) {
+ this.http.post(environment.baseUrl + 'tyAgentPrice/batchConfigOilNo', paramObject).subscribe(data => {
+ callBack(data);
+ });
+ }
+
/**
* 油站价格
* @param paramObject 参数
* @param callBack
*/
- getOilStationPrice(oilStationId: number, callBack) {
- this.http.get(environment.baseUrl + 'tyAgentPrice/getOilStationPrice?oilStationId=' + oilStationId).subscribe(data => {
+ getOilStationPrice(belongType: number, oilStationId: number, callBack) {
+ this.http.get(environment.baseUrl + 'tyAgentPrice/getOilStationPrice?belongType=' + belongType + '&oilStationId=' + oilStationId).subscribe(data => {
callBack(data);
});
}
+
}
diff --git a/src/app/services/websocket.service.ts b/src/app/services/websocket.service.ts
new file mode 100644
index 0000000..80b6222
--- /dev/null
+++ b/src/app/services/websocket.service.ts
@@ -0,0 +1,239 @@
+import {Component, Injectable} from '@angular/core';
+import {interval, Subject} from 'rxjs';
+import {NzNotificationService} from 'ng-zorro-antd';
+
+@Injectable({
+ providedIn: 'root'
+})
+export class WebsocketService {
+
+ messageSubject; // subject对象,用于发送事件
+ private url; // 默认请求的url
+ private webSocket: WebSocket; // websocket对象
+ connectSuccess = false; // websocket 连接成功
+ period = 60 * 1000 * 10; // 10分钟检查一次
+ serverTimeoutSubscription = null; // 定时检测连接对象
+ reconnectFlag = false; // 重连
+ reconnectPeriod = 5 * 1000; // 重连失败,则5秒钟重连一次
+ reconnectSubscription = null; // 重连订阅对象
+ runTimeSubscription; // 记录运行连接subscription
+ runTimePeriod = 60 * 10000; // 记录运行连接时间
+
+ constructor(private notification: NzNotificationService) {
+ this.messageSubject = new Subject();
+ console.log('开始心跳检测');
+ // 进入程序就进行心跳检测,避免出现开始就连接中断,后续不重连
+ this.heartCheckStart();
+ this.calcRunTime();
+ }
+
+ /**
+ * 发送消息
+ * @author Sum1Dream
+ * @date 2019/1/22
+ * @param message 发送消息
+ */
+ sendMessage(message) {
+ this.webSocket.send(message);
+ }
+
+ /**
+ * 创建新连接
+ * @author Sum1Dream
+ * @date 2019/1/22
+ * @param url 要连接的url
+ */
+ connect(url) {
+ if (!!url) {
+ this.url = url;
+ }
+ // 创建websocket对象
+ this.createWebSocket();
+ }
+
+ /**
+ * 创建连接
+ * @author Sum1Dream
+ * @date 2019/1/22
+ */
+ createWebSocket() {
+ // 如果没有建立过连接,才建立连接并且添加时间监听
+ this.webSocket = new WebSocket(this.url);
+ // 建立连接成功
+ this.webSocket.onopen = (e) => this.onOpen(e);
+ // 接收到消息
+ this.webSocket.onmessage = (e) => this.onMessage(e);
+ // 连接关闭
+ this.webSocket.onclose = (e) => this.onClose(e);
+ // 异常
+ this.webSocket.onerror = (e) => this.onError(e);
+ }
+
+ /**
+ * 连接打开
+ * @author Sum1Dream
+ * @date 2019/1/22
+ * @param e 打开事件
+ */
+ onOpen(e) {
+ console.log('websocket 已连接');
+ // 设置连接成功
+ this.connectSuccess = true;
+ // 如果是重连中
+ if (this.reconnectFlag) {
+ // 1.停止重连
+ this.stopReconnect();
+ // 2.重新开启心跳
+ this.heartCheckStart();
+ // 3.重新开始计算运行时间
+ this.calcRunTime();
+ }
+ }
+
+ /**
+ * 接受到消息
+ * @author Sum1Dream
+ * @date 2019/1/22
+ * @param event 接受消息事件
+ */
+ onMessage(event) {
+ const data = JSON.parse(event.data);
+ // 将接受到的消息发布出去
+ // console.log('接收到消息时间', new Date().getTime());
+ this.notification.success(
+ data['order']['gasName'] + '加油订单',
+ '
订单号:' + data['order']['orderNo'] + '
' +
+ '
加油金额:' + data['order']['totalPrice'] + '
' +
+ '
油号:' + data['order']['gasOilNo'] + '
' +
+ '
油枪号:' + data['order']['gasGunNo'] + '
'
+ );
+ const audio = new Audio();
+ audio.src = data['voice'];
+ audio.load();
+ audio.play().then(r => console.log(r));
+ this.messageSubject.next(true);
+ }
+
+ /**
+ * 连接关闭
+ * @author Sum1Dream
+ * @date 2019/1/22
+ */
+ private onClose(e) {
+ console.log('连接关闭', e);
+ this.connectSuccess = false;
+ this.webSocket.close();
+ // 关闭时开始重连
+ this.reconnect();
+ this.stopRunTime();
+ // throw new Error('webSocket connection closed:)');
+ }
+
+ /**
+ * 连接异常
+ * @author Sum1Dream
+ * @date 2019/1/22
+ */
+ private onError(e) {
+ // 出现异常时一定会进onClose,所以只在onClose做一次重连动作
+ console.log('连接异常', e);
+ this.connectSuccess = false;
+ // throw new Error('webSocket connection error:)');
+ }
+
+ /**
+ * 开始重新连接
+ * @author Sum1Dream
+ * @date 2019/1/22
+ */
+ reconnect() {
+ // 如果已重连,则直接return,避免重复连接
+ if (this.connectSuccess) {
+ this.stopReconnect();
+ console.log('已经连接成功,停止重连');
+ return;
+ }
+ // 如果正在连接中,则直接return,避免产生多个轮训事件
+ if (this.reconnectFlag) {
+ console.log('正在重连,直接返回');
+ return;
+ }
+ // 开始重连
+ this.reconnectFlag = true;
+ // 如果没能成功连接,则定时重连
+ this.reconnectSubscription = interval(this.reconnectPeriod).subscribe(async (val) => {
+ console.log(`重连:${val}次`);
+ const url = this.url;
+ // 重新连接
+ this.connect(url);
+ });
+ }
+
+ /**
+ * 停止重连
+ * @author Sum1Dream
+ * @date 2019/1/22
+ */
+ stopReconnect() {
+ // 连接标识置为false
+ this.reconnectFlag = false;
+ // 取消订阅
+ if (typeof this.reconnectSubscription !== 'undefined' && this.reconnectSubscription != null) {
+ this.reconnectSubscription.unsubscribe();
+ }
+ }
+
+ /**
+ * 开始心跳检测
+ * @author Sum1Dream
+ * @date 2019/1/22
+ */
+ heartCheckStart() {
+ this.serverTimeoutSubscription = interval(this.period).subscribe((val) => {
+ // 保持连接状态,重置下
+ if (this.webSocket != null && this.webSocket.readyState === 1) {
+ console.log(val, '连接状态,发送消息保持连接');
+ } else {
+ // 停止心跳
+ this.heartCheckStop();
+ // 开始重连
+ this.reconnect();
+ console.log('连接已断开,重新连接');
+ }
+ });
+ }
+
+ /**
+ * 停止心跳检测
+ * @author Sum1Dream
+ * @date 2019/1/22
+ */
+ heartCheckStop() {
+ // 取消订阅停止心跳
+ if (typeof this.serverTimeoutSubscription !== 'undefined' && this.serverTimeoutSubscription != null) {
+ this.serverTimeoutSubscription.unsubscribe();
+ }
+ }
+
+ /**
+ * 开始计算运行时间
+ * @author Sum1Dream
+ * @date 2019/1/25
+ */
+ calcRunTime() {
+ this.runTimeSubscription = interval(this.runTimePeriod).subscribe(period => {
+ console.log('运行时间', `${period}分钟`);
+ });
+ }
+
+ /**
+ * 停止计算运行时间
+ * @author Sum1Dream
+ * @date 2019/1/25
+ */
+ stopRunTime() {
+ if (typeof this.runTimeSubscription !== 'undefined' && this.runTimeSubscription !== null) {
+ this.runTimeSubscription.unsubscribe();
+ }
+ }
+}
diff --git a/src/environments/environment.ts b/src/environments/environment.ts
index a2d6d6f..ca22a39 100644
--- a/src/environments/environment.ts
+++ b/src/environments/environment.ts
@@ -4,10 +4,10 @@
export const environment = {
production: false,
- baseUrl: 'http://localhost:9302/brest/', // 测试环境服务器地址(请求数据地址)
- imageUrl: 'http://localhost:9302/filesystem/',
- // baseUrl: 'https://hsgcs.dctpay.com/brest/', // 测试环境服务器地址(请求数据地址)
- // imageUrl: 'https://hsgcs.dctpay.com/filesystem/',
+/* baseUrl: 'http://localhost:9302/brest/', // 测试环境服务器地址(请求数据地址)
+ imageUrl: 'http://localhost:9302/filesystem/',*/
+ baseUrl: 'https://hsgcs.dctpay.com/brest/', // 测试环境服务器地址(请求数据地址)
+ imageUrl: 'https://hsgcs.dctpay.com/filesystem/',
key: 'https://hsgcs.dctpay.com/phone-recharge-H5/index.html?codeValue=',
inviteUrl: 'https://hsgcs.dctpay.com/wx/?action=ic&id=',
};