SET @batch_date = '20230222'; set @partition_name=concat('p',@batch_date); set @stat=concat('alter table tb_bond_price_comparision_reuslt truncate partition ',@partition_name); prepare stmt from @stat; execute stmt; insert into tb_bond_price_comparision_reuslt select distinct org.ISIN, mul.Broker_Yield, mul.Broker_Price, org.MARKET_PRICE, case when org.MARKET_PRICE > mul.Broker_Price then 'Broker Price' else 'BVAL' end as MARKET_PRICE_MIN, org.TRADE_REF, case when org.MARKET_PRICE > mul.Broker_Price then mul.Broker_Price else org.MARKET_PRICE end as MARKET_PRICE_MIN, case when org.MARKET_PRICE > mul.Broker_Price then mul.Broker_Price * org.NOMINAL_AMT else org.MARKET_PRICE * org.NOMINAL_AMT end as MARKET_VALUE_MIN, org.dt from tb_trade_blotter_op_sec org left join tb_bond_price_comparision_trade_blotter_op_sec_mul mul on org.TRADE_REF = mul.TRADE_REF and org.ISIN = mul.ISIN and org.dt = mul.dt where org.dt = @batch_date转换为mybatis执行语句以及生成service层代码
时间: 2024-01-29 08:05:02 浏览: 85
首先,将SQL语句转换为MyBatis执行语句:
```sql
<insert id="insertBondPriceComparisonResult" parameterType="string">
SET @batch_date = #{batchDate};
SET @partition_name = CONCAT('p', @batch_date);
SET @stat = CONCAT('ALTER TABLE tb_bond_price_comparision_reuslt TRUNCATE PARTITION ', @partition_name);
PREPARE stmt FROM @stat;
EXECUTE stmt;
INSERT INTO tb_bond_price_comparision_reuslt
SELECT DISTINCT
org.ISIN,
mul.Broker_Yield,
mul.Broker_Price,
org.MARKET_PRICE,
CASE
WHEN org.MARKET_PRICE > mul.Broker_Price THEN 'Broker Price'
ELSE 'BVAL'
END AS MARKET_PRICE_MIN,
org.TRADE_REF,
CASE
WHEN org.MARKET_PRICE > mul.Broker_Price THEN mul.Broker_Price
ELSE org.MARKET_PRICE
END AS MARKET_PRICE_MIN,
CASE
WHEN org.MARKET_PRICE > mul.Broker_Price THEN mul.Broker_Price * org.NOMINAL_AMT
ELSE org.MARKET_PRICE * org.NOMINAL_AMT
END AS MARKET_VALUE_MIN,
org.dt
FROM tb_trade_blotter_op_sec org
LEFT JOIN tb_bond_price_comparision_trade_blotter_op_sec_mul mul
ON org.TRADE_REF = mul.TRADE_REF AND org.ISIN = mul.ISIN AND org.dt = mul.dt
WHERE org.dt = @batch_date;
</insert>
```
然后,生成对应的Service层代码:
```java
@Service
public class BondPriceComparisonResultServiceImpl implements BondPriceComparisonResultService {
@Autowired
private BondPriceComparisonResultMapper bondPriceComparisonResultMapper;
@Override
public void insertBondPriceComparisonResult(String batchDate) {
bondPriceComparisonResultMapper.insertBondPriceComparisonResult(batchDate);
}
}
```
阅读全文