ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/mapper/PartnerMapper.java
@@ -27,4 +27,9 @@ * Query built-in role by partner type role name. */ Integer getDefaultPartnerRoleId(@Param("roleName") String roleName); /** * Validate that a non-administrator role can be assigned to a partner account. */ Integer getAssignablePartnerRoleId(@Param("roleId") Integer roleId); } ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/PartnerServiceImpl.java
@@ -93,7 +93,7 @@ if(ajaxResult.isError()){ return ajaxResult; } assignDefaultRole(partner); assignPartnerRole(partner); Partner one = this.getOne(new LambdaQueryWrapper<Partner>() .eq(Partner::getCode, partner.getCode()) .eq(Partner::getDelFlag, 0) @@ -200,7 +200,11 @@ if(ajaxResult.isError()){ return ajaxResult; } assignDefaultRole(partner); Partner oldPartner = this.getById(partner.getId()); if (partner.getRoleId() == null && oldPartner != null) { partner.setRoleId(oldPartner.getRoleId()); } assignPartnerRole(partner); Partner one = this.getOne(new LambdaQueryWrapper<Partner>() .eq(Partner::getCode, partner.getCode()) .eq(Partner::getDelFlag, 0) @@ -215,7 +219,6 @@ if(null != one && !one.getId().equals(partner.getId())){ return AjaxResult.error("登录账号不能重复"); } Partner oldPartner = this.getById(partner.getId()); SysUser user = sysUserClient.queryUserByUserName(oldPartner.getAccount()).getData(); if(StringUtils.isEmpty(partner.getPassword())){ partner.setPassword(oldPartner.getPassword()); @@ -272,8 +275,15 @@ } private void assignDefaultRole(Partner partner) { Integer roleId = resolveDefaultRoleId(partner.getPartnerType()); void assignPartnerRole(Partner partner) { if (partner.getRoleId() == null) { partner.setRoleId(resolveDefaultRoleId(partner.getPartnerType())); return; } Integer roleId = this.baseMapper.getAssignablePartnerRoleId(partner.getRoleId()); if (roleId == null) { throw new RuntimeException("所选合作商角色不存在或不可用"); } partner.setRoleId(roleId); } ruoyi-service/ruoyi-chargingPile/src/main/resources/mapper/chargingPile/PartnerMapper.xml
@@ -69,4 +69,14 @@ order by role_id asc limit 1 </select> <select id="getAssignablePartnerRoleId" resultType="java.lang.Integer"> select role_id from charging_pile_other.sys_role where role_id = #{roleId} and role_id != 1 and del_flag = '0' and status = '0' limit 1 </select> </mapper> ruoyi-service/ruoyi-chargingPile/src/test/java/com/ruoyi/chargingPile/service/impl/PartnerServiceImplTest.java
@@ -108,6 +108,38 @@ } @Test void selectedPartnerRoleIsNotOverwrittenByDefaultRole() { PartnerServiceImpl service = new PartnerServiceImpl(); PartnerMapper mapper = mock(PartnerMapper.class); ReflectionTestUtils.setField(service, "baseMapper", mapper); Partner partner = new Partner(); partner.setPartnerType(1); partner.setRoleId(25); when(mapper.getAssignablePartnerRoleId(25)).thenReturn(25); service.assignPartnerRole(partner); assertEquals(Integer.valueOf(25), partner.getRoleId()); verify(mapper).getAssignablePartnerRoleId(25); verify(mapper, never()).getDefaultPartnerRoleId(any()); } @Test void missingPartnerRoleStillUsesTypeDefault() { PartnerServiceImpl service = new PartnerServiceImpl(); PartnerMapper mapper = mock(PartnerMapper.class); ReflectionTestUtils.setField(service, "baseMapper", mapper); Partner partner = new Partner(); partner.setPartnerType(1); when(mapper.getDefaultPartnerRoleId("独立合作商")).thenReturn(11); service.assignPartnerRole(partner); assertEquals(Integer.valueOf(11), partner.getRoleId()); verify(mapper, never()).getAssignablePartnerRoleId(any()); } @Test void clearingShareRatiosStillProducesExplicitDatabaseUpdate() { PartnerServiceImpl service = new PartnerServiceImpl(); PartnerMapper mapper = mock(PartnerMapper.class); ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/dto/EnterpriseChargingAnalysisVO.java
@@ -24,10 +24,7 @@ @ApiModelProperty("Company phone") private String companyPhone; @ApiModelProperty("Charging count") private Long chargingCount; @ApiModelProperty("Invoice count") @ApiModelProperty("Invoice application count") private Long invoiceCount; @ApiModelProperty("Invoice amount") @@ -42,4 +39,4 @@ @ApiModelProperty("Average charging interval hours") private BigDecimal averageChargingInterval; } } ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TOrderInvoiceServiceImpl.java
@@ -196,6 +196,8 @@ TOrderInvoice invoice = new TOrderInvoice(); BeanUtils.copyProperties(source, invoice); invoice.setId(null); invoice.setName(trimInvoiceIdentity(source.getName())); invoice.setTaxIdentificationNumber(trimInvoiceIdentity(source.getTaxIdentificationNumber())); invoice.setCode(generateInvoiceCode()); invoice.setAppUserId(userId); invoice.setInvoicingCompany(invoiceType.getInvoicingCompany()); @@ -219,6 +221,10 @@ return invoice; } private String trimInvoiceIdentity(String value) { return value == null ? null : value.trim(); } private void saveInvoiceDetails(TOrderInvoice invoice, TInvoiceType invoiceType, List<Long> orderIds, Map<Long, BigDecimal> amountMap) { for (Long orderId : orderIds) { BigDecimal electrovalence = BigDecimal.ZERO; ruoyi-service/ruoyi-order/src/main/resources/mapper/order/TChargingOrderMapper.xml
@@ -2744,13 +2744,13 @@ AND toi.status IN (2, 3) AND tod.order_type = 1 <if test="data.exactCompanyName != null and data.exactCompanyName != ''"> AND toi.name = #{data.exactCompanyName} AND TRIM(toi.name) = TRIM(#{data.exactCompanyName}) </if> <if test="(data.exactCompanyName == null or data.exactCompanyName == '') and data.companyName != null and data.companyName != ''"> AND toi.name LIKE CONCAT('%', #{data.companyName}, '%') AND TRIM(toi.name) LIKE CONCAT('%', TRIM(#{data.companyName}), '%') </if> <if test="data.socialCreditCode != null and data.socialCreditCode != ''"> AND IFNULL(toi.tax_identification_number, '') = #{data.socialCreditCode} AND IFNULL(TRIM(toi.tax_identification_number), '') = TRIM(#{data.socialCreditCode}) </if> <if test="data.siteType != null"> AND s.site_type = #{data.siteType} @@ -2775,20 +2775,18 @@ b.socialCreditCode, MAX(b.companyAddress) AS companyAddress, MAX(b.companyPhone) AS companyPhone, SUM(b.orderCount) AS chargingCount, COUNT(1) AS invoiceCount, SUM(CASE WHEN b.detailInvoiceAmount > 0 THEN b.detailInvoiceAmount ELSE b.totalAmount END) AS invoiceAmount, MAX(b.latestChargingTime) AS latestChargingTime FROM ( SELECT toi.id AS invoiceId, toi.name AS companyName, IFNULL(toi.tax_identification_number, '') AS socialCreditCode, TRIM(toi.name) AS companyName, IFNULL(TRIM(toi.tax_identification_number), '') AS socialCreditCode, MAX(toi.company_address) AS companyAddress, MAX(toi.company_phone) AS companyPhone, MAX(IFNULL(toi.total_amount, 0)) AS totalAmount, SUM(IFNULL(tod.invoice_amount, 0)) AS detailInvoiceAmount, COUNT(DISTINCT co.id) AS orderCount, MAX(co.start_time) AS latestChargingTime FROM t_order_invoice toi INNER JOIN t_order_invoice_detail tod ON tod.order_invoice_id = toi.id @@ -2797,10 +2795,10 @@ <where> <include refid="enterpriseChargingBaseWhere" /> </where> GROUP BY toi.id, toi.name, toi.tax_identification_number GROUP BY toi.id, TRIM(toi.name), TRIM(toi.tax_identification_number) ) b GROUP BY b.companyName, b.socialCreditCode ORDER BY chargingCount DESC ORDER BY invoiceCount DESC </select> <select id="enterpriseTopSites" resultType="map"> @@ -2822,8 +2820,8 @@ <select id="enterpriseTopSitesByCompanies" resultType="map"> SELECT toi.name AS companyName, IFNULL(toi.tax_identification_number, '') AS socialCreditCode, TRIM(toi.name) AS companyName, IFNULL(TRIM(toi.tax_identification_number), '') AS socialCreditCode, s.name AS siteName, COUNT(DISTINCT co.id) AS counts FROM t_order_invoice toi @@ -2833,12 +2831,12 @@ <where> <include refid="enterpriseChargingBaseWhere" /> AND s.name IS NOT NULL AND toi.name IN AND TRIM(toi.name) IN <foreach collection="companyNames" item="companyName" open="(" separator="," close=")"> #{companyName} </foreach> </where> GROUP BY toi.name, toi.tax_identification_number, s.id, s.name GROUP BY TRIM(toi.name), TRIM(toi.tax_identification_number), s.id, s.name </select> <select id="enterpriseChargingTimes" resultType="java.time.LocalDateTime"> @@ -2856,8 +2854,8 @@ <select id="enterpriseChargingTimesByCompanies" resultType="map"> SELECT DISTINCT toi.name AS companyName, IFNULL(toi.tax_identification_number, '') AS socialCreditCode, TRIM(toi.name) AS companyName, IFNULL(TRIM(toi.tax_identification_number), '') AS socialCreditCode, co.start_time AS startTime FROM t_order_invoice toi INNER JOIN t_order_invoice_detail tod ON tod.order_invoice_id = toi.id @@ -2866,12 +2864,12 @@ <where> <include refid="enterpriseChargingBaseWhere" /> AND co.start_time IS NOT NULL AND toi.name IN AND TRIM(toi.name) IN <foreach collection="companyNames" item="companyName" open="(" separator="," close=")"> #{companyName} </foreach> </where> ORDER BY toi.name, co.start_time ORDER BY TRIM(toi.name), co.start_time </select> <select id="enterpriseInvoiceIds" resultType="long"> @@ -2881,13 +2879,13 @@ invoicing_object_type = 2 AND status IN (2, 3) <if test="data.exactCompanyName != null and data.exactCompanyName != ''"> AND name = #{data.exactCompanyName} AND TRIM(name) = TRIM(#{data.exactCompanyName}) </if> <if test="(data.exactCompanyName == null or data.exactCompanyName == '') and data.companyName != null and data.companyName != ''"> AND name LIKE CONCAT('%', #{data.companyName}, '%') AND TRIM(name) LIKE CONCAT('%', TRIM(#{data.companyName}), '%') </if> <if test="data.socialCreditCode != null and data.socialCreditCode != ''"> AND IFNULL(tax_identification_number, '') = #{data.socialCreditCode} AND IFNULL(TRIM(tax_identification_number), '') = TRIM(#{data.socialCreditCode}) </if> </where> </select> ruoyi-service/ruoyi-order/src/test/java/com/ruoyi/order/mapper/EnterpriseChargingAnalysisMapperTest.java
@@ -39,6 +39,10 @@ assertFalse(baseWhere.contains("AND toi.status IN (1, 2, 3)")); assertTrue(analysis.contains("LEFT JOIN t_charging_order co ON co.id = tod.order_id")); assertTrue(analysis.contains("COUNT(1) AS invoiceCount")); assertTrue(analysis.contains("ORDER BY invoiceCount DESC")); assertFalse(analysis.contains("chargingCount")); assertTrue(analysis.contains("TRIM(toi.name) AS companyName")); assertTrue(analysis.contains("IFNULL(TRIM(toi.tax_identification_number), '') AS socialCreditCode")); assertTrue(analysis.contains("detailInvoiceAmount")); } } ruoyi-service/ruoyi-order/src/test/java/com/ruoyi/order/service/impl/TOrderInvoiceServiceImplTest.java
New file @@ -0,0 +1,38 @@ package com.ruoyi.order.service.impl; import com.ruoyi.order.api.model.TOrderInvoice; import com.ruoyi.order.dto.AddOrderInvoice; import com.ruoyi.other.api.domain.TInvoiceType; import org.junit.jupiter.api.Test; import org.springframework.test.util.ReflectionTestUtils; import java.math.BigDecimal; import java.util.Collections; import static org.junit.jupiter.api.Assertions.assertEquals; class TOrderInvoiceServiceImplTest { @Test void trimsCompanyNameAndTaxIdentificationNumberBeforeSaving() { AddOrderInvoice source = new AddOrderInvoice(); source.setOrderType(2); source.setName(" Test Company "); source.setTaxIdentificationNumber(" 91510000TEST "); TInvoiceType invoiceType = new TInvoiceType(); invoiceType.setName("Electronic invoice"); TOrderInvoice invoice = ReflectionTestUtils.invokeMethod( new TOrderInvoiceServiceImpl(), "buildOrderInvoice", source, 1L, invoiceType, Collections.singletonList(10L), Collections.singletonMap(10L, BigDecimal.ONE)); assertEquals("Test Company", invoice.getName()); assertEquals("91510000TEST", invoice.getTaxIdentificationNumber()); } }