UserFundCountServiceImpl.java 1.94 KB
Newer Older
zp's avatar
zp committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
package com.tanpu.fund.service.impl;

import com.tanpu.common.enums.Constant;
import com.tanpu.fund.entity.generator.UserFundInfo;
import com.tanpu.fund.entity.generator.UserFundInfoExample;
import com.tanpu.fund.service.UserFundCountService;
import com.tanpu.fund.utils.FormulaToUserUtil;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

public class UserFundCountServiceImpl implements UserFundCountService {

    @Autowired
    UserFundInfoMapper userFundInfoMapper;
    @Autowired
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    @Override
    public void share(String pFundId, String userId) {
        //查询用户所持有当前组合基金的单只基金集合
        UserFundInfoExample example = new UserFundInfoExample();
        example.createCriteria().andPFundIdEqualTo(pFundId).andUserIdEqualTo(userId).andDeleteTagEqualTo(Constant.ZERO_NUM);
        List<UserFundInfo> userFundInfos = userFundInfoMapper.selectByExample(example);

        for (UserFundInfo userFundInfo : userFundInfos) {
            BigDecimal matchRatio = FormulaToUserUtil.positionShare(userFundInfo.getConfirmAmount(), userFundInfo.getBuyFeeRatio(), userFundInfo.getFundNav());
            userFundInfo.setMatchRatio(matchRatio);
            userFundInfo.setUpdateTime(new Date());
        }

        SQL sql = new SQL().UPDATE(UserFundInfo.TABLE_NAME).SET(
                UserFundInfo.Column.matchRatio.getEscapedColumnName() + "= :"+UserFundInfo.Column.matchRatio.getJavaProperty()
        );

        namedParameterJdbcTemplate.batchUpdate(sql.toString(), SqlParameterSourceUtils.createBatch(userFundInfos));
    }

    @Override
    public void matchRatio(String fundId, String userId) {

    }

}