private void setInDTO(Worksheet sheet, HcServiceInfo serviceInfo, ref int irow) { var inDto = new HcDTOInfo(); inDto.Caption = serviceInfo.Caption + "的InDTO"; var range = (Range)sheet.Cells[19, 2]; inDto.Name = range.Value.ToString(); range = (Range)sheet.Cells[20, 15]; var cellValue = range.Value; inDto.FieldArray = new List<HcFieldInfo>(); while (cellValue != null && !string.IsNullOrEmpty(cellValue.ToString())) { var field = new HcFieldInfo(); field.name = cellValue.ToString(); range = (Range)sheet.Cells[irow, 3]; field.caption = range.Value.ToString(); range = (Range)sheet.Cells[irow, 22]; field.FieldTypeString = range.Value.ToString(); inDto.FieldArray.Add(field); irow += 1; range = (Range)sheet.Cells[irow, 15]; cellValue = range.Value; } serviceInfo.InDTO = inDto; }
private void createOutEntity(string path, HcServiceInfo service) { var file = new FileStream(string.Format(@"{0}\{1}Entity.java", path, service.Name), FileMode.Create, FileAccess.Write); using (StreamWriter writer = new StreamWriter(file, System.Text.Encoding.UTF8)) { writer.WriteLine(@"/**"); writer.WriteLine(@" * "); writer.WriteLine(@" */"); writer.WriteLine(@"package com.xl.frame.entity;"); writer.WriteLine(@""); service.OutDTO.FieldArray.FindAll(d => d.FieldType == EmFieldType.DTO).ForEach(item => { writer.WriteLine(@"import com.xl.frame.entity.{0};", item.FieldTypeString); }); writer.WriteLine(@""); writer.WriteLine(@"public class {0}Entity extends BaseEntity {{", service.Name); writer.WriteLine(@""); writer.WriteLine(@" /**"); writer.WriteLine(@" * "); writer.WriteLine(@" */"); writer.WriteLine(@" private static final long serialVersionUID = 1L;"); writer.WriteLine(@""); foreach (var field in service.OutDTO.FieldArray) { writer.WriteLine(@""); writer.WriteLine(@" public {0} {1}; // {2}", getFieldTypeInString(field.FieldType, field.FieldTypeString), field.name.ToPrivateDefinition(), field.caption); } writer.WriteLine(@"}"); } }
private void createModel(DirectoryInfo newFolder, HcServiceInfo service) { var fileName = service.Name.Remove(0, Constants.ServiceFirstName.Length); createModelH(newFolder, service, fileName); createModelM(newFolder, service, fileName); }
private void createRequester(string path, HcServiceInfo service, string info) { var file = new FileStream(string.Format(@"{0}\{1}Requester.java", path, service.Name), FileMode.Create, FileAccess.Write); using (StreamWriter writer = new StreamWriter(file, System.Text.Encoding.UTF8)) { writer.WriteLine(@"package com.xl.frame.requester.{0};", info); writer.WriteLine(@""); if (service.InDTO.FieldArray.FindAll(d => d.FieldType == EmFieldType.DTOArray).Count > 0) { writer.WriteLine(@"import java.util.ArrayList;"); } writer.WriteLine(@"import java.util.HashMap;"); if (service.InDTO.FieldArray.FindAll(d => d.FieldType == EmFieldType.DTOArray).Count > 0) { writer.WriteLine(@"import java.util.List;"); } writer.WriteLine(@"import java.util.Map;"); writer.WriteLine(@""); writer.WriteLine(@"import com.xl.frame.core.lib.gson.reflect.TypeToken;"); writer.WriteLine(@"import com.xl.frame.core.lib.volley.AuthFailureError;"); writer.WriteLine(@"import com.xl.frame.core.lib.volley.Response;"); writer.WriteLine(@"import com.xl.frame.core.lib.volley.VolleyError;"); writer.WriteLine(@"import com.xl.frame.core.net.GsonRequest;"); writer.WriteLine(@"import com.xl.frame.entity.RetEntity;"); writer.WriteLine(@"import com.xl.frame.entity.{0}Entity;", service.Name); service.InDTO.FieldArray.FindAll(d => d.FieldType == EmFieldType.DTO).ForEach(item => { writer.WriteLine(@"import com.xl.frame.entity.{0};", item.FieldTypeString); }); writer.WriteLine(@"import com.xl.frame.requester.BaseRequester;"); writer.WriteLine(@""); writer.WriteLine(@"public class {0}Requester extends BaseRequester<{0}Entity> {{", service.Name); writer.WriteLine(@""); foreach (var field in service.InDTO.FieldArray) { writer.WriteLine(@" private {0} {1} = null; //{2}", getFieldTypeInString(field.FieldType, field.FieldTypeString), field.name.ToPrivateDefinition(), field.caption); } writer.WriteLine(@""); writer.WriteLine(@" // {0}", service.Caption); var inputParam = new StringBuilder(); service.InDTO.FieldArray.ForEach(item => { if (inputParam.Length > 0) inputParam.Append(", "); inputParam.Append(string.Format("final {0} {1}", getFieldTypeInString(item.FieldType, item.FieldTypeString), item.name.ToPrivateDefinition())); }); writer.WriteLine(@" public void postData({0}) {{", inputParam.ToString()); service.InDTO.FieldArray.ForEach(item => { writer.WriteLine(@" this.{0} = {0};", item.name.ToPrivateDefinition()); }); writer.WriteLine(@""); writer.WriteLine(@" if (this.checkInputData()) {"); writer.WriteLine(@" final Map<String, Object> params = buildVerificationData();"); writer.WriteLine(@" GsonRequest<RetEntity<{0}Entity>> req = new GsonRequest<RetEntity<{0}Entity>>(", service.Name); writer.WriteLine(@" getUrl(""{0}""),", service.Name); writer.WriteLine(@" new Response.Listener<RetEntity<{0}Entity>>() {{", service.Name); writer.WriteLine(@" "); writer.WriteLine(@" @Override"); writer.WriteLine(@" public void onResponse(RetEntity<{0}Entity> response) {{", service.Name); writer.WriteLine(@" if (response.success) {"); writer.WriteLine(@" if (callback != null) {"); writer.WriteLine(@" callback.onCallback(response.result);"); writer.WriteLine(@" }"); writer.WriteLine(@" } else {"); writer.WriteLine(@" if (callback != null) {"); writer.WriteLine(@" callback.onErrorCallback(response.getErrorMsg());"); writer.WriteLine(@" }"); writer.WriteLine(@" }"); writer.WriteLine(@" }"); writer.WriteLine(@""); writer.WriteLine(@" }, new Response.ErrorListener() {"); writer.WriteLine(@" @Override"); writer.WriteLine(@" public void onErrorResponse(VolleyError error) {"); writer.WriteLine(@" if (callback != null) {"); writer.WriteLine(@" callback.onErrorCallback(error.getMessage());"); writer.WriteLine(@" }"); writer.WriteLine(@" }"); writer.WriteLine(@" }) {"); writer.WriteLine(@""); writer.WriteLine(@" @Override"); writer.WriteLine(@" public Map<String, Object> getParams() throws AuthFailureError {"); writer.WriteLine(@" return params;"); writer.WriteLine(@" }"); writer.WriteLine(@" };"); writer.WriteLine(@" "); writer.WriteLine(@" req.setTypeOfT(new TypeToken<RetEntity<{0}Entity>>() {{}}.getType());", service.Name); writer.WriteLine(@" mNetManager.addToRequestQueue(req, ""{0}Requester"");", service.Name); writer.WriteLine(@" } else {"); writer.WriteLine(@" if (callback != null) {"); writer.WriteLine(@" callback.onErrorCallback(this.errorMsg);"); writer.WriteLine(@" }"); writer.WriteLine(@" }"); writer.WriteLine(@" }"); writer.WriteLine(@""); writer.WriteLine(@" @Override"); writer.WriteLine(@" public HashMap<String, Object> buildRequestData() {"); writer.WriteLine(@" HashMap<String, Object> params = new HashMap<String, Object>({0});", service.InDTO.FieldArray.Count); var lstField = service.InDTO.FieldArray.FindAll(d => isBaseType(d.FieldType)); if (lstField != null) { foreach (var item in lstField) { writer.WriteLine(@" params.put(""{0}"", this.{1});", item.name, item.name.ToPrivateDefinition()); } } lstField = service.InDTO.FieldArray.FindAll(d => isArrayType(d.FieldType)); if (lstField != null) { if (lstField.Count > 0) { foreach (var item in lstField) { if (item.FieldType == EmFieldType.DTOArray) { writer.WriteLine(@" List<HashMap<String, Object>> array{0} = new ArrayList<HashMap<String, Object>>();", item.name); writer.WriteLine(@" for (IBaseEntity entity : this.{0}) {{", item.name.ToPrivateDefinition()); writer.WriteLine(@" array{0}.add(entity.buildRequestData());", item.name.ToPrivateDefinition()); writer.WriteLine(@" }"); writer.WriteLine(@" if (array{0}.size()>0) {{", item.name.ToPrivateDefinition()); writer.WriteLine(@" params.put(""{0}"",array{1});", item.name, item.name.ToPrivateDefinition()); writer.WriteLine(@" }"); } else { writer.WriteLine(@" if (this.{0}.length>0) {{", item.name.ToPrivateDefinition()); writer.WriteLine(@" params.put(""{0}"", this.{1});", item.name, item.name.ToPrivateDefinition()); writer.WriteLine(@" }"); } } } } lstField = service.InDTO.FieldArray.FindAll(d => d.FieldType == EmFieldType.DTO); if (lstField != null) { if (lstField.Count > 0) { foreach (var item in lstField) { writer.WriteLine(@" HashMap<String, Object> map{0} = this.{1}.buildRequestData();", item.name, item.name.ToPrivateDefinition()); writer.WriteLine(@" if (map{0} != null) {{", item.name); writer.WriteLine(@" params.put(""{0}"", map{0});", item.name.ToPrivateDefinition()); writer.WriteLine(@" }"); } } } writer.WriteLine(@" return params;"); writer.WriteLine(@" }"); writer.WriteLine(@""); writer.WriteLine(@" @Override"); writer.WriteLine(@" public Boolean checkInputData() {"); foreach (var item in service.InDTO.FieldArray) { if (item.FieldCheckType != null && item.FieldCheckType.Count > 0) { foreach (var chk in item.FieldCheckType) { switch (chk) { case EmCheckType.MustEnter: getMustInput(writer, item); break; default: getMustInput(writer, item); break; } } } } writer.WriteLine(@" return true;"); writer.WriteLine(@" }"); writer.WriteLine(@"}"); } }
private void setSubInfo(Worksheet sheet, HcSubInfo subInfo) { var name = sheet.Name; if (name.Length > Constants.ServiceFirstName.Length && name.Substring(0, Constants.ServiceFirstName.Length).Equals(Constants.ServiceFirstName)) { if (subInfo.ServiceArray == null) { subInfo.ServiceArray = new List<HcServiceInfo>(); } var serviceInfo = new HcServiceInfo(); Range range = null; if (string.IsNullOrEmpty(subInfo.Name)) { range = (Range)sheet.Cells[3, 9]; subInfo.Name = range.Value.ToString(); } serviceInfo.ModelID = subInfo.Name; range = (Range)sheet.Cells[4, 9]; serviceInfo.Caption = range.Value.ToString(); range = (Range)sheet.Cells[5, 9]; serviceInfo.Name = range.Value.ToString(); range = (Range)sheet.Cells[9, 2]; serviceInfo.Summary = range.Value.ToString(); range = (Range)sheet.Cells[3, 40]; string type = range.Value.ToString(); switch (type) { case "Read": serviceInfo.ServiceType = Type.EmServiceType.Read; break; case "Update": serviceInfo.ServiceType = Type.EmServiceType.Update; break; default: break; } var irow = 20; setInDTO(sheet, serviceInfo, ref irow); setOutDTO(sheet, serviceInfo, ref irow); setInDTOCheck(sheet, serviceInfo, irow); subInfo.ServiceArray.Add(serviceInfo); } }
private void setInDTOCheck(Worksheet sheet, HcServiceInfo serviceInfo, int starRow) { Range range = null; for (int i = 1; i < 100; i++) { starRow += 1; range = (Range)sheet.Cells[starRow, 2]; var val = range.Value; if (val != null && !string.IsNullOrEmpty(val.ToString()) && val.Equals("输入验证")) { break; } } starRow += 2; range = (Range)sheet.Cells[starRow, 3]; var dicCheck = new Dictionary<string, List<EmCheckType>>(); var cellValue = range.Value; while (cellValue != null && !string.IsNullOrEmpty(cellValue.ToString())) { List<EmCheckType> lstCheck = null; if (dicCheck.ContainsKey(cellValue.ToString())) { lstCheck = dicCheck[cellValue.ToString()]; } else { lstCheck = new List<EmCheckType>(); } range = (Range)sheet.Cells[starRow, 15]; lstCheck.Add(convertToCheckType(range.Value.ToString())); if (dicCheck.ContainsKey(cellValue.ToString())) { dicCheck[cellValue.ToString()] = lstCheck; } else { dicCheck.Add(cellValue.ToString(), lstCheck); } starRow += 1; range = (Range)sheet.Cells[starRow, 3]; cellValue = range.Value; } foreach (var item in serviceInfo.InDTO.FieldArray) { if (dicCheck.ContainsKey(item.caption)) { item.FieldCheckType = dicCheck[item.caption]; } } }
private void createModelH(DirectoryInfo newFolder, HcServiceInfo service, string fileName) { var file = new FileStream(string.Format(@"{0}\{1}.h", newFolder.FullName, fileName), FileMode.Create, FileAccess.Write); using (StreamWriter writer = new StreamWriter(file, System.Text.Encoding.UTF8)) { writer.WriteLine(@"//"); writer.WriteLine(@"// {0}.h", fileName); writer.WriteLine(@"// {0}", Constants.ProjectName); writer.WriteLine(@"//"); writer.WriteLine(@"// Created by xiao huama on {0}.", DateTime.Now.ToString("yy/MM/dd")); writer.WriteLine(@"// {0}", Constants.CompanyName); writer.WriteLine(@"//"); writer.WriteLine(@"#import ""ServiceBaseModel.h"""); service.InDTO.FieldArray.FindAll(d => d.FieldType == EmFieldType.DTO || d.FieldType == EmFieldType.DTOArray).ForEach(item => { if (item.FieldType == EmFieldType.DTO) { writer.WriteLine(@"#import ""{0}.h""", item.FieldTypeString); } else { writer.WriteLine(@"#import ""{0}.h""", item.FieldTypeString.Replace("[]", String.Empty)); } }); service.OutDTO.FieldArray.FindAll(d => d.FieldType == EmFieldType.DTO || d.FieldType == EmFieldType.DTOArray).ForEach(item => { if (item.FieldType == EmFieldType.DTO) { writer.WriteLine(@"#import ""{0}.h""", item.FieldTypeString); } else { writer.WriteLine(@"#import ""{0}.h""", item.FieldTypeString.Replace("[]", String.Empty)); } }); writer.WriteLine(@""); writer.WriteLine(@"@interface {0} : ServiceBaseModel", fileName); writer.WriteLine(@""); service.OutDTO.FieldArray.ForEach(item => { writer.WriteLine(@"@property(nonatomic,strong){0} *{1}; /**< {2}*/", getFieldTypeOutString(item.FieldType, item.FieldTypeString), item.name.ToPrivateDefinition(), item.caption); }); writer.WriteLine(@""); var inputParam = new StringBuilder(); service.InDTO.FieldArray.ForEach(item => { if (inputParam.Length > 0) inputParam.Append(string.Format(" {0}:", item.name.ToPrivateDefinition())); inputParam.Append(string.Format("({0} *){1}", getFieldTypeInString(item.FieldType, item.FieldTypeString), item.name.ToPrivateDefinition())); }); if (inputParam.Length > 0) { inputParam.Insert(0, ":"); } writer.WriteLine(@"- (void)postData{0};", inputParam.ToString()); writer.WriteLine(@""); writer.WriteLine(@"@end"); } }
private void createModelM(DirectoryInfo newFolder, HcServiceInfo service, string fileName) { var file = new FileStream(string.Format(@"{0}\{1}.m", newFolder.FullName, fileName), FileMode.Create, FileAccess.Write); using (StreamWriter writer = new StreamWriter(file, System.Text.Encoding.UTF8)) { writer.WriteLine(@"//"); writer.WriteLine(@"// {0}.m", fileName); writer.WriteLine(@"// {0}", Constants.ProjectName); writer.WriteLine(@"//"); writer.WriteLine(@"// Created by xiao huama on {0}.", DateTime.Now.ToString("yy/MM/dd")); writer.WriteLine(@"// {0}", Constants.CompanyName); writer.WriteLine(@"//"); writer.WriteLine(@""); writer.WriteLine(@"#import ""{0}.h""", fileName); writer.WriteLine(@""); writer.WriteLine(@"@interface {0}()", fileName); foreach (var field in service.InDTO.FieldArray) { writer.WriteLine(@"@property(nonatomic,strong){0} *{1}; /**< {2}*/", getFieldTypeInString(field.FieldType, field.FieldTypeString), field.name.ToPrivateDefinition(), field.caption); } writer.WriteLine(@"@end"); writer.WriteLine(@"@implementation {0}", fileName); writer.WriteLine(@""); writer.WriteLine(@"- (instancetype)init"); writer.WriteLine(@"{"); writer.WriteLine(@" self = [super init];"); writer.WriteLine(@" if (self) {"); writer.WriteLine(@" serviceMethod = @""{0}"";", service.Name); writer.WriteLine(@" self.className = @""{0}"";", fileName); writer.WriteLine(@" }"); writer.WriteLine(@" return self;"); writer.WriteLine(@"}"); writer.WriteLine(@""); var inputParam = new StringBuilder(); service.InDTO.FieldArray.ForEach(item => { if (inputParam.Length > 0) inputParam.Append(string.Format(" {0}:", item.name.ToPrivateDefinition())); inputParam.Append(string.Format("({0} *){1}", getFieldTypeInString(item.FieldType, item.FieldTypeString), item.name.ToPrivateDefinition())); }); if (inputParam.Length > 0) { inputParam.Insert(0, ":"); } writer.WriteLine(@"- (void)postData{0}{{", inputParam.ToString()); service.InDTO.FieldArray.ForEach(item => { writer.WriteLine(@" self.{0} = {0};", item.name.ToPrivateDefinition()); }); writer.WriteLine(@" [self requestWebService:^{"); writer.WriteLine(@" if (delegate) {"); writer.WriteLine(@" [delegate successMethd:self];"); writer.WriteLine(@" }"); writer.WriteLine(@" } faild:^{"); writer.WriteLine(@" if (delegate) {"); writer.WriteLine(@" [delegate errorMethd];"); writer.WriteLine(@" }"); writer.WriteLine(@" }];"); writer.WriteLine(@"}"); writer.WriteLine(@""); writer.WriteLine(@"-(NSMutableDictionary *)buildRequestData"); writer.WriteLine(@"{"); var lstField = service.InDTO.FieldArray.FindAll(d => isBaseType(d.FieldType)); writer.WriteLine(@" NSMutableDictionary *dic = [NSMutableDictionary dictionary];"); if (lstField != null) { foreach (var item in lstField) { writer.WriteLine(@" if (self.{0}) {{", item.name.ToPrivateDefinition()); writer.WriteLine(@" dic[@""{0}""] = self.{0};", item.name.ToPrivateDefinition()); writer.WriteLine(@" }"); } } lstField = service.InDTO.FieldArray.FindAll(d => isArrayType(d.FieldType)); if (lstField != null) { if (lstField.Count > 0) { foreach (var item in lstField) { if (item.FieldType == EmFieldType.DTOArray) { writer.WriteLine(@" NSMutableArray *array{0} =[NSMutableArray array];", item.name.ToPrivateDefinition()); writer.WriteLine(@" for (BaseModel *model in self.{0}) {{", item.name.ToPrivateDefinition()); writer.WriteLine(@" [array{0} addObject:[model buildRequestData]];", item.name.ToPrivateDefinition()); writer.WriteLine(@" }"); writer.WriteLine(@" if (array{0}.count>0) {{", item.name.ToPrivateDefinition()); writer.WriteLine(@" dic[@""{0}""] = array{0};", item.name.ToPrivateDefinition()); writer.WriteLine(@" }"); } else { writer.WriteLine(@" if (self.{0}.count>0) {{", item.name.ToPrivateDefinition()); writer.WriteLine(@" dic[@""{0}""] = self.{0};", item.name.ToPrivateDefinition()); writer.WriteLine(@" }"); } } } } lstField = service.InDTO.FieldArray.FindAll(d => d.FieldType == EmFieldType.DTO); if (lstField != null) { if (lstField.Count > 0) { foreach (var item in lstField) { writer.WriteLine(@" NSDictionary *{0}Dic = [self.{0} buildRequestData];", item.name.ToPrivateDefinition()); writer.WriteLine(@" if ({0}Dic) {{", item.name.ToPrivateDefinition()); writer.WriteLine(@" dic[@""{0}""] = {0}Dic;", item.name.ToPrivateDefinition()); writer.WriteLine(@" }"); } } } writer.WriteLine(@" return dic;"); writer.WriteLine(@"}"); writer.WriteLine(@""); writer.WriteLine(@"- (void)loadDataWithJsonData:(id)jsonData"); writer.WriteLine(@"{"); writer.WriteLine(@" if (![jsonData isKindOfClass:[NSDictionary class]]) {"); writer.WriteLine(@" return;"); writer.WriteLine(@" }"); writer.WriteLine(@" if (!jsonData) {"); writer.WriteLine(@" return;"); writer.WriteLine(@" }"); foreach (var field in service.OutDTO.FieldArray) { if (isNumberType(field.FieldType)) { writer.WriteLine(@" if (![jsonData[@""{0}""] isKindOfClass:[NSNull class]]) {{", field.name.ToPrivateDefinition()); writer.WriteLine(@" self.{0} = jsonData[@""{0}""];", field.name.ToPrivateDefinition()); writer.WriteLine(@" }"); } else if (field.FieldType == EmFieldType.DTO) { writer.WriteLine(@" if ([jsonData[@""{0}""] isKindOfClass:[NSDictionary class]]) {{", field.name.ToPrivateDefinition()); writer.WriteLine(@" self.{0} = [[{1} alloc] init];", field.name.ToPrivateDefinition(), field.FieldTypeString); writer.WriteLine(@" [self.{0} loadDataWithJsonData:jsonData[@""{0}""]];", field.name.ToPrivateDefinition()); writer.WriteLine(@" }"); } else { writer.WriteLine(@" if ([jsonData[@""{0}""] isKindOfClass:[NSArray class]]) {{", field.name.ToPrivateDefinition()); writer.WriteLine(@" if ([jsonData[@""{0}""] count]>0) {{", field.name.ToPrivateDefinition()); writer.WriteLine(@" NSMutableArray *tempArray = [NSMutableArray array];"); writer.WriteLine(@" for (id data in jsonData[@""{0}""]) {{", field.name.ToPrivateDefinition()); if (isStringArray(field.FieldTypeString.Replace("[]", ""))) { writer.WriteLine(@" [tempArray addObject:data];"); } else { writer.WriteLine(@" [tempArray addObject:[[{0} alloc]initWithJsonData:data]];", field.FieldTypeString.Replace("[]", "")); } writer.WriteLine(@" }"); writer.WriteLine(@" self.{0} = tempArray;", field.name.ToPrivateDefinition()); writer.WriteLine(@" }"); writer.WriteLine(@" }"); } } writer.WriteLine(@"}"); writer.WriteLine(@""); writer.WriteLine(@"-(BOOL)checkRequired"); writer.WriteLine(@"{"); writer.WriteLine(@" NSMutableArray *muArray = [[NSMutableArray alloc] init];"); writer.WriteLine(@" BOOL rest = YES;"); foreach (var item in service.InDTO.FieldArray) { if (item.FieldCheckType != null && item.FieldCheckType.Count > 0) { foreach (var chk in item.FieldCheckType) { switch (chk) { case EmCheckType.MustEnter: getMustInput(writer, item); break; default: getMustInput(writer, item); break; } } } } writer.WriteLine(@" "); writer.WriteLine(@" if (!rest){"); writer.WriteLine(@" self.exceptions = muArray;"); writer.WriteLine(@" }"); writer.WriteLine(@" return rest;"); writer.WriteLine(@"}"); writer.WriteLine(@""); writer.WriteLine(@"@end"); } }
private void createOutDTO(DirectoryInfo newFolder, HcServiceInfo service, String infoName) { var file = new FileStream(string.Format(@"{0}\{1}OutDTO.java", newFolder.FullName, service.Name), FileMode.Create, FileAccess.Write); using (StreamWriter writer = new StreamWriter(file, System.Text.Encoding.UTF8)) { writer.WriteLine(@"/* {0}", Constants.ProjectName); writer.WriteLine(@"* {0}", Constants.CompanyName); writer.WriteLine(@"*/"); writer.WriteLine(@"package " + Constants.Package + @".main.service.{0}.dto;", service.ModelID.ToLower()); writer.WriteLine(@""); if (service.OutDTO.FieldArray != null && service.OutDTO.FieldArray.Count > 0) { writer.WriteLine(@"import " + Constants.Package + @".fw.core.type.Alias;"); } foreach (var item in service.OutDTO.FieldArray.FindAll(d => d.FieldType == EmFieldType.DTO || d.FieldType == EmFieldType.DTOArray)) { writer.WriteLine(@"import " + Constants.Package + @".main.biz.{0}.dto.{1};", infoName, item.FieldTypeString.Replace("[]", String.Empty)); } writer.WriteLine(@""); writer.WriteLine(@"/**"); writer.WriteLine(@" * {0}的OutDTO", service.Caption); writer.WriteLine(@" *"); writer.WriteLine(@" * 变更履历"); writer.WriteLine(@" * REV. 变更日期 变更者 变更内容"); writer.WriteLine(@" * ------- --------------- ---------------- ------------------"); writer.WriteLine(@" * 1.0 {0} TOOL 初次作成", DateTime.Now.ToString("yyyy/MM/dd")); writer.WriteLine(@" *"); writer.WriteLine(@" */"); writer.WriteLine(@"@" + Constants.Package + @".fw.core.type.AliasKanJi(""{0}"")", service.Caption); writer.WriteLine(@"public class {0} implements java.io.Serializable, Comparable<{0}> {{", service.OutDTO.Name); writer.WriteLine(@" /**"); writer.WriteLine(@" * Serial ID"); writer.WriteLine(@" */"); writer.WriteLine(@" private static final long serialVersionUID = 1L;"); writer.WriteLine(@""); foreach (var field in service.OutDTO.FieldArray) { writer.WriteLine(@" /**"); writer.WriteLine(@" * {0} ", field.caption); writer.WriteLine(@" */"); writer.WriteLine(@" @Alias(""{0}"")", field.caption); writeFieldCheck(writer, field); writer.WriteLine(@" private {0} {1} = null;", getFieldTypeString(field.FieldType, field.FieldTypeString), field.name.ToPrivateDefinition()); writer.WriteLine(@""); } foreach (var field in service.OutDTO.FieldArray) { writer.WriteLine(@" /**"); writer.WriteLine(@" * <code>{0}</code>返回", field.caption); writer.WriteLine(@" * @return <code>{0}</code>", field.caption); writer.WriteLine(@" */"); writer.WriteLine(@" public {0} get{1}() {{", getFieldTypeString(field.FieldType, field.FieldTypeString), field.name.ToTitleCase()); writer.WriteLine(@" return this.{0};", field.name.ToPrivateDefinition()); writer.WriteLine(@" }"); writer.WriteLine(@""); writer.WriteLine(@" /**"); writer.WriteLine(@" * <code>{0}</code>设定", field.name.ToPrivateDefinition()); writer.WriteLine(@" * @param {0} <code>{0}</code>设定值", field.name.ToPrivateDefinition()); writer.WriteLine(@" */"); writer.WriteLine(@" public void set{0}(", field.name.ToTitleCase()); writer.WriteLine(@" {0} {1}) {{", getFieldTypeString(field.FieldType, field.FieldTypeString), field.name.ToPrivateDefinition()); writer.WriteLine(@" this.{0} = {0};", field.name.ToPrivateDefinition()); writer.WriteLine(@" }"); writer.WriteLine(@""); } writer.WriteLine(@" /* (non-Javadoc)"); writer.WriteLine(@" * @see java.lang.Comparable#compareTo(java.lang.Object)"); writer.WriteLine(@" */"); writer.WriteLine(@" @Override"); writer.WriteLine(@" public int compareTo({0} compareToDTO) {{", service.OutDTO.Name); writer.WriteLine(@" return this.equals(compareToDTO) ? 0 : -1;"); writer.WriteLine(@" }"); writer.WriteLine(@"}"); } }
private void createServiceInteface(DirectoryInfo directoryInfo, HcServiceInfo service, String sub) { var file = new FileStream(string.Format(@"{0}\{1}.java", directoryInfo.FullName, service.Name), FileMode.Create, FileAccess.Write); using (StreamWriter writer = new StreamWriter(file, System.Text.Encoding.UTF8)) { writer.WriteLine(@"/*"); writer.WriteLine(@" * {0}", Constants.ProjectName); writer.WriteLine(@" * {0}", Constants.CompanyName); writer.WriteLine(@" */"); writer.WriteLine(@"package " + Constants.Package + @".main.service.{0};", sub); writer.WriteLine(@""); writer.WriteLine(@"import " + Constants.Package + @".fw.core.service.AbstractService;"); if (service.ServiceType == EmServiceType.Update) { writer.WriteLine(@"import " + Constants.Package + @".fw.core.type.Transactional;"); } writer.WriteLine(@"import " + Constants.Package + @".main.service.{0}.dto.{1}InDTO;", sub, service.Name); writer.WriteLine(@"import " + Constants.Package + @".main.service.{0}.dto.{1}OutDTO;", sub, service.Name); writer.WriteLine(@""); writer.WriteLine(@"public class {0} extends AbstractService<{0}OutDTO, {0}InDTO> {{", service.Name); writer.WriteLine(@""); writer.WriteLine(@" /*"); writer.WriteLine(@" * (non-Javadoc)"); writer.WriteLine(@" *"); writer.WriteLine(@" * @see"); writer.WriteLine(@" * " + Constants.Package + @".fw.core.service.AbstractService#execute(java.lang.Object)"); writer.WriteLine(@" */"); writer.WriteLine(@" @Override"); if (service.ServiceType == EmServiceType.Update) { writer.WriteLine(@" @Transactional"); } writer.WriteLine(@" public {0}OutDTO execute(", service.Name); writer.WriteLine(@" {0}InDTO {1}InDTO) {{", service.Name, service.Name.ToPrivateDefinition()); writer.WriteLine(@" {0}OutDTO {1}OutDTO = new {0}OutDTO();", service.Name, service.Name.ToPrivateDefinition()); writer.WriteLine(@" return {0}OutDTO;", service.Name.ToPrivateDefinition()); writer.WriteLine(@" }"); writer.WriteLine(@"}"); } }