/* * Copyright 2019-2020 Zheng Jie * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package me.zhengjie.modules.contract.repository; import me.zhengjie.modules.contract.domain.Contract; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Query; import java.math.BigDecimal; import java.util.List; import java.util.Set; /** * @website https://eladmin.vip * @author 赵士淞 * @date 2023-02-02 **/ public interface ContractRepository extends JpaRepository, JpaSpecificationExecutor { /** * 查询当天合同数据 * @return */ @Query(value = "SELECT * FROM contract WHERE contract_number LIKE CONCAT('%',?1,'%')",nativeQuery = true) List findLikeContractNumber(String contractNumber); /** * 查询合同款总金额 * @return */ @Query(value = "SELECT SUM(contract_amount) FROM contract WHERE " + "CASE WHEN ?1 IS NOT NULL THEN contract_number LIKE CONCAT('%',?1,'%') ELSE 1 = 1 END AND " + "CASE WHEN ?2 IS NOT NULL THEN contract_name LIKE CONCAT('%',?2,'%') ELSE 1 = 1 END AND " + "CASE WHEN ?3 IS NOT NULL THEN first_id = ?3 ELSE 1 = 1 END AND " + "CASE WHEN ?4 IS NOT NULL THEN second_id = ?4 ELSE 1 = 1 END AND " + "CASE WHEN ?5 IS NOT NULL THEN sign_date BETWEEN ?5 AND ?6 ELSE 1 = 1 END AND " + "CASE WHEN ?7 IS NOT NULL THEN contract_type = ?7 ELSE 1 = 1 END AND " + "CASE WHEN ?8 IS NOT NULL THEN contract_payment_state = ?8 ELSE 1 = 1 END AND " + "CASE WHEN ?9 IS NOT NULL THEN service_payment_state = ?9 ELSE 1 = 1 END AND " + "CASE WHEN ?10 IS NOT NULL THEN contract_status = ?10 ELSE 1 = 1 END AND " + "CASE WHEN ?11 IS NOT NULL THEN contract_area_code LIKE concat(?11,'%') ELSE 1 = 1 END AND " + "company_id IN ?12",nativeQuery = true) BigDecimal contractTotalMoney( String contractNumber, String contractName, Long firstId, Long secondId, String signStartDate, String signEndDate, String contractType, String contractPaymentState, String servicePaymentState, String contractStatus, String contractAreaCode, Set companyIdSet ); /** * 查询有合同款的合同数据 * @return */ @Query(value = "SELECT * FROM contract WHERE " + "CASE WHEN ?1 IS NOT NULL THEN contract_number LIKE CONCAT('%',?1,'%') ELSE 1 = 1 END AND " + "CASE WHEN ?2 IS NOT NULL THEN contract_name LIKE CONCAT('%',?2,'%') ELSE 1 = 1 END AND " + "CASE WHEN ?3 IS NOT NULL THEN first_id = ?3 ELSE 1 = 1 END AND " + "CASE WHEN ?4 IS NOT NULL THEN second_id = ?4 ELSE 1 = 1 END AND " + "CASE WHEN ?5 IS NOT NULL THEN sign_date BETWEEN ?5 AND ?6 ELSE 1 = 1 END AND " + "CASE WHEN ?7 IS NOT NULL THEN contract_type = ?7 ELSE 1 = 1 END AND " + "CASE WHEN ?8 IS NOT NULL THEN contract_payment_state = ?8 ELSE 1 = 1 END AND " + "CASE WHEN ?9 IS NOT NULL THEN service_payment_state = ?9 ELSE 1 = 1 END AND " + "CASE WHEN ?10 IS NOT NULL THEN contract_status = ?10 ELSE 1 = 1 END AND " + "CASE WHEN ?11 IS NOT NULL THEN contract_area_code LIKE concat(?11,'%') ELSE 1 = 1 END AND " + "contract_amount IS NOT NULL AND contract_amount != '' AND company_id IN ?12",nativeQuery = true) List findContractAmountNotNull( String contractNumber, String contractName, Long firstId, Long secondId, String signStartDate, String signEndDate, String contractType, String contractPaymentState, String servicePaymentState, String contractStatus, String contractAreaCode, Set companyIdSet ); /** * 查询运维服务总金额 * @return */ @Query(value = "SELECT SUM(service_amount) FROM contract WHERE " + "CASE WHEN ?1 IS NOT NULL THEN contract_number LIKE CONCAT('%',?1,'%') ELSE 1 = 1 END AND " + "CASE WHEN ?2 IS NOT NULL THEN contract_name LIKE CONCAT('%',?2,'%') ELSE 1 = 1 END AND " + "CASE WHEN ?3 IS NOT NULL THEN first_id = ?3 ELSE 1 = 1 END AND " + "CASE WHEN ?4 IS NOT NULL THEN second_id = ?4 ELSE 1 = 1 END AND " + "CASE WHEN ?5 IS NOT NULL THEN sign_date BETWEEN ?5 AND ?6 ELSE 1 = 1 END AND " + "CASE WHEN ?7 IS NOT NULL THEN contract_type = ?7 ELSE 1 = 1 END AND " + "CASE WHEN ?8 IS NOT NULL THEN contract_payment_state = ?8 ELSE 1 = 1 END AND " + "CASE WHEN ?9 IS NOT NULL THEN service_payment_state = ?9 ELSE 1 = 1 END AND " + "CASE WHEN ?10 IS NOT NULL THEN contract_status = ?10 ELSE 1 = 1 END AND " + "CASE WHEN ?11 IS NOT NULL THEN contract_area_code LIKE concat(?11,'%') ELSE 1 = 1 END AND " + "company_id IN ?12",nativeQuery = true) BigDecimal serviceTotalMoney( String contractNumber, String contractName, Long firstId, Long secondId, String signStartDate, String signEndDate, String contractType, String contractPaymentState, String servicePaymentState, String contractStatus, String contractAreaCode, Set companyIdSet ); /** * 查询有运维服务的合同数据 * @return */ @Query(value = "SELECT * FROM contract WHERE " + "CASE WHEN ?1 IS NOT NULL THEN contract_number LIKE CONCAT('%',?1,'%') ELSE 1 = 1 END AND " + "CASE WHEN ?2 IS NOT NULL THEN contract_name LIKE CONCAT('%',?2,'%') ELSE 1 = 1 END AND " + "CASE WHEN ?3 IS NOT NULL THEN first_id = ?3 ELSE 1 = 1 END AND " + "CASE WHEN ?4 IS NOT NULL THEN second_id = ?4 ELSE 1 = 1 END AND " + "CASE WHEN ?5 IS NOT NULL THEN sign_date BETWEEN ?5 AND ?6 ELSE 1 = 1 END AND " + "CASE WHEN ?7 IS NOT NULL THEN contract_type = ?7 ELSE 1 = 1 END AND " + "CASE WHEN ?8 IS NOT NULL THEN contract_payment_state = ?8 ELSE 1 = 1 END AND " + "CASE WHEN ?9 IS NOT NULL THEN service_payment_state = ?9 ELSE 1 = 1 END AND " + "CASE WHEN ?10 IS NOT NULL THEN contract_status = ?10 ELSE 1 = 1 END AND " + "CASE WHEN ?11 IS NOT NULL THEN contract_area_code LIKE concat(?11,'%') ELSE 1 = 1 END AND " + "service_amount IS NOT NULL AND service_amount != '' AND company_id IN ?12",nativeQuery = true) List findServiceAmountNotNull( String contractNumber, String contractName, Long firstId, Long secondId, String signStartDate, String signEndDate, String contractType, String contractPaymentState, String servicePaymentState, String contractStatus, String contractAreaCode, Set companyIdSet ); /** * 查询本公司合同年内最大排序 * @return */ @Query(value = "SELECT CAST(SUBSTRING(contract_number, 12, 3) AS UNSIGNED) AS val FROM contract \n" + "WHERE SUBSTRING(contract_number, 5, 2) = SUBSTRING(?1, 3, 2) AND contract_number LIKE CONCAT(?2, '%') AND contract_id != ?3 \n" + "ORDER BY CAST(SUBSTRING(contract_number, 12, 3) AS UNSIGNED) DESC LIMIT 1", nativeQuery = true) Long countContractSort(String year, String companyCode, Long id); /** * 查询全部公司合同年内最大排序 * @return */ @Query(value = "SELECT CAST(SUBSTRING(contract_number, 16, 4) AS UNSIGNED) AS val FROM contract \n" + "WHERE SUBSTRING(contract_number, 5, 2) = SUBSTRING(?1, 3, 2) AND contract_id != ?2 \n" + "ORDER BY CAST(SUBSTRING(contract_number, 16, 4) AS UNSIGNED) DESC LIMIT 1", nativeQuery = true) Long countAllContractSort(String year, Long id); }