if (item.tmsdType != null) { return item.tmsdType == "1" ? _iDerCardsG(item) : item.tmsdType == "2" ? _iDerCardsQ(item) : const Center(); } else if (item.tdrWorkType != null) { return _iDerCards(item); } else if (item.tmdiMemberId != null) { return _itemBuilderD(item); } else if (item.tmdMemberId != null) { return _itemBuilder(item); }该判断能给我优化一下吗?

时间: 2024-02-14 15:08:51 浏览: 28
这段代码中的判断逻辑看起来比较繁琐,可以考虑使用 switch case 语句来进行优化。具体实现方式如下: ``` switch (true) { case item.tmsdType == "1": return _iDerCardsG(item); case item.tmsdType == "2": return _iDerCardsQ(item); case item.tdrWorkType != null: return _iDerCards(item); case item.tmdiMemberId != null: return _itemBuilderD(item); case item.tmdMemberId != null: return _itemBuilder(item); default: return const Center(); } ``` 使用 switch case 语句可以减少代码行数,使代码更加清晰易懂。同时,通过将表达式放在 case 语句后面,可以避免使用多个 if else 语句的情况。
相关问题

优化这段代码 res.data.availablePlayItemVoList.forEach((item: any) => { this.playDateProductInfoList.forEach((v: any) => { v.playScreeningList.forEach((items: any) => { if (items.playItemCode == item.playItemCode) { this.$set( items, "availableTotal", item.availableTotal != null ? item.availableTotal : null ); } if (item.screeningList.length > 0) { item.screeningList.forEach((itemA: any) => { if (items.sysTimeQuantumList != null) { items.sysTimeQuantumList.forEach((itemB: any) => { if (itemA.screeningCode == itemB.screeningCode) { this.$set( itemB, "surplusTotal", itemA.surplusTotal != null ? itemA.surplusTotal : null ); } }); } }); } }); }); }); });

这段代码也可以使用ES6的数组方法进行优化,如下所示: ```javascript res.data.availablePlayItemVoList.forEach(item => { this.playDateProductInfoList.forEach(v => { v.playScreeningList.filter(items => items.playItemCode === item.playItemCode) .forEach(items => { this.$set( items, "availableTotal", item.availableTotal != null ? item.availableTotal : null ); item.screeningList.forEach(itemA => { if (items.sysTimeQuantumList != null) { items.sysTimeQuantumList.filter(itemB => itemA.screeningCode === itemB.screeningCode) .forEach(itemB => { this.$set( itemB, "surplusTotal", itemA.surplusTotal != null ? itemA.surplusTotal : null ); }); } }); }); }); }); ``` 同样地,使用`filter`方法可以减少循环嵌套,使代码更加清晰易读。另外,可以使用ES6的箭头函数来简化代码。

<select id="selectAll" resultMap="tblTicketCardDistributionMap"> select * from TBL_TICKET_CARD_DISTRIBUTION <where> <choose> <when test="query.orderType != null and query.orderType != '' and query.orderType =='03'"> and ORDER_TYPE = #{query.orderType} and ( <if test="query.inStationId != null and query.inStationId != '' "> IN_STATION_ID = #{query.inStationId} </if> <if test="query.outStationId != null and query.outStationId != '' "> or OUT_STATION_ID = #{query.outStationId} </if> ) </when> <otherwise> <if test="query.orderType != null and query.orderType != '' "> and ORDER_TYPE = #{query.orderType} </if> <if test="query.inStationId != null and query.inStationId != '' "> and IN_STATION_ID = #{query.inStationId} </if> <if test="query.outStationId != null and query.outStationId != '' "> or OUT_STATION_ID = #{query.outStationId} </if> </otherwise> </choose> <if test="query.lineId != null and query.lineId != '' "> and LINE_ID = #{query.lineId} </if> <if test="query.stationId != null and query.stationId != '' "> and STATION_ID = #{query.stationId} </if> <if test="query.operatorId != null and query.operatorId != '' "> and OPERATOR_ID = #{query.operatorId} </if> <if test="query.curDay != null and query.curDay != '' "> and CUR_DAY = #{query.curDay} </if> <if test="query.beginTime != null and query.beginTime != '' "> and OPERATE_TIME between #{query.beginTime} and #{query.endTime} </if> </where> </select>报错语法有问题,修改正确的

根据报错信息,需要看一下具体是哪个语法有问题。不过根据代码,有一个语法问题: 在`<when>`标签中,使用了`<if>`标签,应该改为`${}`,例如: ``` <when test="query.orderType != null and query.orderType != '' and query.orderType =='03'"> and ORDER_TYPE = #{query.orderType} and ( ${query.inStationId != null and query.inStationId != '' ? 'IN_STATION_ID = #{query.inStationId}' : ''} ${query.outStationId != null and query.outStationId != '' ? ' or OUT_STATION_ID = #{query.outStationId}' : ''} ) </when> ``` 这样应该就能解决语法问题了。

相关推荐

请帮我解释下面这段代码 <select id="listByUser" resultType="com.yj.model.vo.EnrollByUserItemVO"> select cc.*, cc.course_start_time AS courseStartTimeMd, ub.id ubid, info.payment_status as payment_status, info.total_money as totalMoney, ccc.category_name, CASE WHEN cc.course_video is not null and cc.course_video != '' THEN 2 WHEN (SELECT count(1) FROM crs_course_class ccc2 WHERE cc.id = ccc2.course_id AND ccc2.data_flag = 1 AND ccc2.class_video IS NOT NULL and ccc2.class_video != '') > 0 THEN 2 ELSE 1 END AS courseType from user_course_enroll ub INNER JOIN crs_course cc ON ub.course_id = cc.id INNER JOIN crs_course_category ccc ON cc.course_category_id = ccc.id LEFT JOIN order_item item ON item.project_relevancy_id = ub.id LEFT JOIN order_info info ON item.info_id = info.id LEFT JOIN user_browse uu ON uu.user_id = ub.user_id and uu.course_id = ub.course_id and uu.data_flag = 1 where 1 = 1 <if test="(publicId != null and publicId != '' ) or ( userIds != null and userIds.size() != 0)"> and ( <if test="publicId != null and publicId != '' "> ub.public_id = #{publicId} </if> <if test="publicId != null and publicId != '' and userIds != null and userIds.size() != 0"> or ub.user_id IN <foreach collection="userIds" item="item" open="(" separator="," close=")" index="index"> #{item} </foreach> </if> <if test="(publicId == null or publicId == '') and userIds != null and userIds.size() != 0"> ub.user_id IN <foreach collection="userIds" item="item" open="(" separator="," close=")" index="index"> #{item} </foreach> </if> ) </if> <choose> <when test="query.paymentStateList != null and query.paymentStateList.size() != 0"> and ccc.data_flag = 1 </when> <otherwise> and ub.apply_type = 1 and ccc.data_flag = 1 and ub.data_flag = 1 and ub.verify_state = 1 and cc.data_flag = 1 </otherwise> </choose> <if test="query.shelfStatus !=null"> and cc.shelf_status = #{query.shelfStatus} </if> <if test="query.categoryId !=null and query.categoryId != ''"> and ccc.id = #{query.categoryId} </if> <if test="query.learnState !=null"> and uu.learn_state = #{query.learnState} and ccc.prelect_way = 1 </if> <if test="query.paymentStateList != null and query.paymentStateList.size() != 0"> AND ( info.payment_status IN <foreach collection="query.paymentStateList" item="item" open="(" separator="," close=")" index="index"> #{item} </foreach> ) </if> </select>

// 获取表单值 const form = getFieldsValue(); // 条件值的component类型会随着字段的变化发生变化 // 条件值发生变化时获取当前字段列详细数据 const currentFieldData = columnOptions.value.find( (item: Recordable) => item.value === form.field, ) as unknown as Recordable; // 根据字段label const fieldLabel = columnOptions.value.find((item) => item.value === form?.field)?.label; // 判断条件 const conditionType = ARITHMETIC_OPERATOR_BACK.find( (item) => item.value === form?.op, )?.operate; if (form.op === ConditionTypeEnum.IS_NULL || form.op === ConditionTypeEnum.IS_NOT_NULL) { // 判断条件为空、非空时,清空条件值 conditionName = ${fieldLabel ?? ''}${conditionType ?? ''}; } else { // 字段值和判断条件发生变化 let labelText; // 字段变化 if (key === 'field') { if (currentFieldData?.component !== FormElementEnum.SWITCH) { // 清空条件值 await setFieldsValue({ value: undefined }); labelText = ''; } else { await setFieldsValue({ value: 0 }); labelText = '否'; } } else { // 判断条件和条件值变化 // 当前字段有值集时,component类型为ApiSelect if (currentFieldData?.component === FormElementEnum.API_SELECT) { const fieldVsList = await getVsList(currentFieldData.vsId); labelText = fieldVsList?.find( (item: Recordable) => item.itemValue === form.value, )?.itemText; } else if (currentFieldData?.component === FormElementEnum.SWITCH) { // 当前字段类型为boolean时,component类型为Switch,条件值为开关 labelText = form.value === 1 ? '是' : '否'; } else { // 其他 labelText = form.value; } } conditionName = ${fieldLabel ?? ''}${conditionType ?? ''}${labelText ?? ''}; }简化if语句

优化代码 参考 if (cstemp.combos != null && cstemp.combos.Count > 0) { List<BCD_COMBO_ITEMEntity> _ITEMEntities_Yes = new BCD_COMBO_ITEM().GetItemList( String.Format("COMBOGUID IN ({0})", String.Join(",", cstemp.combos.Select(x => "'" + x.GUID + "'").Distinct()))); if (_ITEMEntities_Yes != null && _ITEMEntities_Yes.Count > 0) { List<BCD_COMBO_ITEMEntity> _ITEMEntities_No = (cstemp.Nocombos != null && cstemp.Nocombos.Count > 0) ? new BCD_COMBO_ITEM().GetItemList( String.Format("COMBOGUID IN ({0})", String.Join(",", cstemp.combos.Select(x => "'" + x.GUID + "'").Distinct()))) : null; string _ITEMEntities_YesString = String.Join(",", _ITEMEntities_Yes.Select(x => x.ITEMGUID ).Distinct()); string _ITEMEntities_NoString = (_ITEMEntities_No != null && _ITEMEntities_No.Count > 0)? String.Join(",", _ITEMEntities_No.Select(x => x.ITEMGUID).Distinct()):""; List<BCB_CHECKSUBEntity> subTempsno = !string.IsNullOrWhiteSpace(_ITEMEntities_NoString) ? _CHECKSUBEntities.Where(x => _ITEMEntities_NoString.Contains(x.ITEMGUID)).ToList() : null; string subTempsnoString = (subTempsno != null && subTempsno.Count > 0) ? String.Join(",", subTempsno.Select(x => x.MAINGUID).Distinct()):""; List < BCB_CHECKMAINEntity > mainsTemps = _CHECKMAINEntitys.ToList().Where(r => ((cstemp.ageb > 0 || cstemp.agee > 0) ? (r.AGE >= cstemp.ageb && r.AGE <= cstemp.agee) : true) && (!string.IsNullOrWhiteSpace(subTempsnoString) ? (cstemp.bothagree == "True" ? subTempsnoString.Contains(r.GUID): !subTempsnoString.Contains(r.GUID)) : true)).ToList(); string mainguidstring = (mainsTemps != null && mainsTemps.Count > 0) ? String.Join(",", mainsTemps.Select(x => x.GUID).Distinct()) : ""; List <BCB_CHECKSUBEntity> subTemps = _CHECKSUBEntities.Where(x => !string.IsNullOrWhiteSpace(x.RESULT) && _ITEMEntities_YesString.Contains(x.ITEMGUID) && mainguidstring.Contains(x.MAINGUID)).ToList(); if (subTemps != null ) { drAuto[cstemp.CSName] = subTemps.Select(x => x.MAINGUID).Distinct().Count(); } } }

<select id="findList" resultType="ZdrgkBkyj" > SELECT <include refid="zdrgkBkyjColumns"/> FROM zdrgk_zdrgj a left join zdryk_bkgl b on a.zdrgj_xm = b.bkgl_zdrxm and b.del_flag = #{DEL_FLAG_NORMAL} <where> a.del_flag = #{DEL_FLAG_NORMAL} ${dataScope} <if test="zdrgjXm != null and zdrgjXm != ''"> AND a.zdrgj_xm = #{zdrgjXm} </if> <if test="zdrgjSfzhm != null and zdrgjSfzhm != ''"> AND a.zdrgj_sfzhm = #{zdrgjSfzhm} </if> <if test="zdrgjXsd != null and zdrgjXsd != ''"> AND a.zdrgj_xsd = #{zdrgjXsd} </if> <if test="bkglZdrxm != null and bkglZdrxm != ''"> AND b.bkgl_zdrxm = #{bkglZdrxm} </if> </where> <choose> <when test="page !=null and page.orderBy != null and page.orderBy != ''"> ORDER BY ${page.orderBy} </when> <otherwise> ORDER BY a.update_date DESC </otherwise> </choose> </select>为zdrgkbkyj的xml文件 bkglZdrxm只作为查询没有显示在列表数据中如何在jeeplus中 queryParams : function(params) { var searchParam = $("#searchForm").serializeJSON(); searchParam.zdrgjXm = $("#zdrgjXm").val(); searchParam.bkglZdrxm = $("#bkglZdrxm").val(); if (searchParam.zdrgjXm && searchParam.bkglZdrxm && searchParam.zdrgjXm === searchParam.bkglZdrxm) { searchParam.matchedValue = searchParam.zdrgjXm; } else { searchParam.matchedValue = null; } searchParam.pageNo = params.limit === undefined? "1" :params.offset/params.limit+1; searchParam.pageSize = params.limit === undefined? -1 : params.limit; if(params.sort && params.order){ searchParam.orderBy = params.sort+ " "+ params.order; } return searchParam; }中添加一个查询条件 当前的zdrgjXm字段要和bkglZdrxm字段有一样的值才能显示

最新推荐

recommend-type

还在用if(obj!=null)做非空判断,带你快速上手Optional

Optional 是 Java 8 中引入的新特性,旨在解决空指针异常(Null Pointer Exception,NPE)这个长期困扰开发者的问题。下面我们将对 Optional 的基本概念、使用方法、优点等进行详细的介绍。 Optional 的基本概念 ...
recommend-type

浅谈JS中的!=、== 、!==、===的用法和区别

例如,`'1' == 1`会返回`true`,因为在比较前,字符串`'1'`被转换成了数值`1`。相反,`!=`则是`==`的否定形式,它会在类型转换后比较值的不等性。 接着是`===`和`!==`,它们被称为“严格相等”和“严格不等”。`===...
recommend-type

利用迪杰斯特拉算法的全国交通咨询系统设计与实现

全国交通咨询模拟系统是一个基于互联网的应用程序,旨在提供实时的交通咨询服务,帮助用户找到花费最少时间和金钱的交通路线。系统主要功能包括需求分析、个人工作管理、概要设计以及源程序实现。 首先,在需求分析阶段,系统明确了解用户的需求,可能是针对长途旅行、通勤或日常出行,用户可能关心的是时间效率和成本效益。这个阶段对系统的功能、性能指标以及用户界面有明确的定义。 概要设计部分详细地阐述了系统的流程。主程序流程图展示了程序的基本结构,从开始到结束的整体运行流程,包括用户输入起始和终止城市名称,系统查找路径并显示结果等步骤。创建图算法流程图则关注于核心算法——迪杰斯特拉算法的应用,该算法用于计算从一个节点到所有其他节点的最短路径,对于求解交通咨询问题至关重要。 具体到源程序,设计者实现了输入城市名称的功能,通过 LocateVex 函数查找图中的城市节点,如果城市不存在,则给出提示。咨询钱最少模块图是针对用户查询花费最少的交通方式,通过 LeastMoneyPath 和 print_Money 函数来计算并输出路径及其费用。这些函数的设计体现了算法的核心逻辑,如初始化每条路径的距离为最大值,然后通过循环更新路径直到找到最短路径。 在设计和调试分析阶段,开发者对源代码进行了严谨的测试,确保算法的正确性和性能。程序的执行过程中,会进行错误处理和异常检测,以保证用户获得准确的信息。 程序设计体会部分,可能包含了作者在开发过程中的心得,比如对迪杰斯特拉算法的理解,如何优化代码以提高运行效率,以及如何平衡用户体验与性能的关系。此外,可能还讨论了在实际应用中遇到的问题以及解决策略。 全国交通咨询模拟系统是一个结合了数据结构(如图和路径)以及优化算法(迪杰斯特拉)的实用工具,旨在通过互联网为用户提供便捷、高效的交通咨询服务。它的设计不仅体现了技术实现,也充分考虑了用户需求和实际应用场景中的复杂性。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

【实战演练】基于TensorFlow的卷积神经网络图像识别项目

![【实战演练】基于TensorFlow的卷积神经网络图像识别项目](https://img-blog.csdnimg.cn/20200419235252200.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM3MTQ4OTQw,size_16,color_FFFFFF,t_70) # 1. TensorFlow简介** TensorFlow是一个开源的机器学习库,用于构建和训练机器学习模型。它由谷歌开发,广泛应用于自然语言
recommend-type

CD40110工作原理

CD40110是一种双四线双向译码器,它的工作原理基于逻辑编码和译码技术。它将输入的二进制代码(一般为4位)转换成对应的输出信号,可以控制多达16个输出线中的任意一条。以下是CD40110的主要工作步骤: 1. **输入与编码**: CD40110的输入端有A3-A0四个引脚,每个引脚对应一个二进制位。当你给这些引脚提供不同的逻辑电平(高或低),就形成一个四位的输入编码。 2. **内部逻辑处理**: 内部有一个编码逻辑电路,根据输入的四位二进制代码决定哪个输出线应该导通(高电平)或保持低电平(断开)。 3. **输出**: 输出端Y7-Y0有16个,它们分别与输入的编码相对应。当特定的
recommend-type

全国交通咨询系统C++实现源码解析

"全国交通咨询系统C++代码.pdf是一个C++编程实现的交通咨询系统,主要功能是查询全国范围内的交通线路信息。该系统由JUNE于2011年6月11日编写,使用了C++标准库,包括iostream、stdio.h、windows.h和string.h等头文件。代码中定义了多个数据结构,如CityType、TrafficNode和VNode,用于存储城市、交通班次和线路信息。系统中包含城市节点、交通节点和路径节点的定义,以及相关的数据成员,如城市名称、班次、起止时间和票价。" 在这份C++代码中,核心的知识点包括: 1. **数据结构设计**: - 定义了`CityType`为short int类型,用于表示城市节点。 - `TrafficNodeDat`结构体用于存储交通班次信息,包括班次名称(`name`)、起止时间(原本注释掉了`StartTime`和`StopTime`)、运行时间(`Time`)、目的地城市编号(`EndCity`)和票价(`Cost`)。 - `VNodeDat`结构体代表城市节点,包含了城市编号(`city`)、火车班次数(`TrainNum`)、航班班次数(`FlightNum`)以及两个`TrafficNodeDat`数组,分别用于存储火车和航班信息。 - `PNodeDat`结构体则用于表示路径中的一个节点,包含城市编号(`City`)和交通班次号(`TraNo`)。 2. **数组和变量声明**: - `CityName`数组用于存储每个城市的名称,按城市编号进行索引。 - `CityNum`用于记录城市的数量。 - `AdjList`数组存储各个城市的线路信息,下标对应城市编号。 3. **算法与功能**: - 系统可能实现了Dijkstra算法或类似算法来寻找最短路径,因为有`MinTime`和`StartTime`变量,这些通常与路径规划算法有关。 - `curPath`可能用于存储当前路径的信息。 - `SeekCity`函数可能是用来查找特定城市的函数,其参数是一个城市名称。 4. **编程语言特性**: - 使用了`#define`预处理器指令来设置常量,如城市节点的最大数量(`MAX_VERTEX_NUM`)、字符串的最大长度(`MAX_STRING_NUM`)和交通班次的最大数量(`MAX_TRAFFIC_NUM`)。 - `using namespace std`导入标准命名空间,方便使用iostream库中的输入输出操作。 5. **编程实践**: - 代码的日期和作者注释显示了良好的编程习惯,这对于代码维护和团队合作非常重要。 - 结构体的设计使得数据组织有序,方便查询和操作。 这个C++代码实现了全国交通咨询系统的核心功能,涉及城市节点管理、交通班次存储和查询,以及可能的路径规划算法。通过这些数据结构和算法,用户可以查询不同城市间的交通信息,并获取最优路径建议。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

【实战演练】使用Seaborn和Plotly进行数据可视化项目

![【实战演练】使用Seaborn和Plotly进行数据可视化项目](https://ask.qcloudimg.com/http-save/yehe-5669851/lifus0nfda.jpeg) # 1. 数据可视化的基础** 数据可视化是指将数据转换为图形或图表,以帮助人们理解和解释数据。它是一种强大的工具,可以揭示数据中的模式、趋势和异常情况,从而帮助人们做出更好的决策。 数据可视化有许多不同的类型,包括条形图、折线图、散点图和饼图。每种类型都有其独特的优点和缺点,具体选择哪种类型取决于数据类型和要传达的信息。 在创建数据可视化时,重要的是要考虑以下因素: * **受众:**
recommend-type

Python的六种数据类型

Python是一种动态类型的高级编程语言,它的六种基本数据类型包括: 1. **数字类型(Numeric Types)**:主要有整型(int)、浮点型(float)、复数型(complex)。整型用于表示整数值,浮点型用于存储小数,复数型用于处理复数。 2. **字符串类型(String Type)**:用单引号('')或双引号("")包围的文本序列,用来存储文本数据。 3. **布尔类型(Boolean Type)**:只有两个值,True和False,表示逻辑判断的结果。 4. **列表类型(List Type)**:有序的可变序列,可以包含不同类型的元素。 5. **元组类型