/// <summary> /// 生成TsService /// </summary> private TsServiceModel GetTsServiceModel(ActionModel action) { TsServiceModel tsService = new TsServiceModel() { JcCode = GetTsServiceJcCode(action), CommonCode = GetTsServiceCommonCode(action) }; return(tsService); }
/// <summary> /// 生成TsService /// </summary> private TsServiceModel GetTsServiceModel(ControllerModel controller) { TsServiceModel tsService = new TsServiceModel(); StringBuilder jcCodeBuilder = new StringBuilder(); StringBuilder commonCodeBuilder = new StringBuilder(); StringBuilder headerCodeBuilder = new StringBuilder(); headerCodeBuilder.AppendLine("import {Injectable} from '@angular/core';"); headerCodeBuilder.AppendLine("import {Observable} from 'rxjs/Observable';"); headerCodeBuilder.AppendLine(); jcCodeBuilder.AppendLine("import {Jc} from '@core/jc'"); jcCodeBuilder.AppendLine(); jcCodeBuilder.AppendLine("@Injectable()"); jcCodeBuilder.AppendLine($"export class {controller.ControllerName}Service {{"); jcCodeBuilder.AppendLine(); commonCodeBuilder.AppendLine("import {HttpClient} from '@angular/common/http';"); commonCodeBuilder.AppendLine(); commonCodeBuilder.AppendLine("@Injectable()"); commonCodeBuilder.AppendLine($"export class {controller.ControllerName} {{"); commonCodeBuilder.AppendLine(); commonCodeBuilder.AppendLine(" constructor(private http: HttpClient) {"); commonCodeBuilder.AppendLine(" }"); commonCodeBuilder.AppendLine(); for (int i = 0; i < controller.ActionList.Count; i++) { ActionModel action = controller.ActionList[i]; jcCodeBuilder.AppendLine(GetTsServiceJcCode(action)); commonCodeBuilder.AppendLine(GetTsServiceCommonCode(action)); } jcCodeBuilder.AppendLine("}"); commonCodeBuilder.AppendLine("}"); tsService.JcCode = headerCodeBuilder.ToString() + jcCodeBuilder.ToString(); tsService.CommonCode = headerCodeBuilder.ToString() + commonCodeBuilder.ToString(); return(tsService); }