PositionBiz.java 4.44 KB
package com.cjs.site.biz.user.pick;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cjs.site.dao.user.pick.InventoryDao;
import com.cjs.site.dao.user.pick.PickPackDao;
import com.cjs.site.model.user.account.UserInfo;
import com.cjs.site.model.user.pick.InventoryInfo;
import com.cjs.site.model.user.pick.PickPackInfo;
import com.cjs.site.util.t2.T2Result;
import com.cjs.site.util.t2.T2Util;

/**
 * 持仓列表
 * 
 * @author tongyufu
 *
 */
@Service
public class PositionBiz {

    @Autowired
    private PickPackDao  pickPackDao;
    @Autowired
    private InventoryDao inventoryDao;

    /**用户持仓*/
    public T2Result position(UserInfo userInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("identity_type", "");//身份类别
        params.put("op_branch_no", "");//操作分支机构
        params.put("op_entrust_way", "7");//委托方式
        params.put("op_station", "");//站点地址
        params.put("branch_no", "11");//分支机构
        params.put("client_id", userInfo.getClient_id());//客户编号
        params.put("fund_account", userInfo.getClient_id());//资产账户
        params.put("password", userInfo.getPassword());//密码
        params.put("password_type", "2");//密码类别
        params.put("user_token", " ");//用户口令
        params.put("otcexch_type", " ");//股权市场
        params.put("otc_account", " ");//股权账号
        params.put("otc_code", " ");//股权代码
        params.put("query_mode", "0");//查询模式
        params.put("position_str", " ");//定位串
        params.put("request_num", "100");//请求行数
        return T2Util.request(params, "619008");
    }

    public T2Result positionSelf(UserInfo userInfo){
        List<PickPackInfo> list = pickPackDao.queryUserPosition(userInfo.getClient_id());
        List<Map<String, Object>> t2 = new ArrayList<Map<String, Object>>();
        for(PickPackInfo info :list){
            Map<String, Object> map =  new HashMap<String, Object>();
            map.put("otc_code",info.getOtcCode());
            map.put("otc_name",info.getOtcName());
            map.put("enable_amount",info.getCurrentAmount());
            t2.add(map);
        }
        T2Result t =  new T2Result();
        t.setData(t2);
        return t;
    }

    /**持仓列表(封装)*/
    public List<Map<String, Object>> packPosition(UserInfo userInfo) {
        List<Map<String, Object>> positions = this.position(userInfo).getData();
        List<PickPackInfo> packs = pickPackDao.queryAll();
        List<Map<String, Object>> positionList = new ArrayList<Map<String, Object>>();

        if (packs.isEmpty() || positions.isEmpty()) {
            return positionList;
        }
        for (Map<String, Object> position : positions) {
            for (PickPackInfo pack : packs) {
                if (StringUtils.equals(pack.getOtcCode(), position.get("otc_code").toString())) {
                    position.put("pack_fee", pack.getPackFee());
                    positionList.add(position);
                    break;
                }
            }
        }
        return positionList;
    }

    /**持仓列表(网点自提)*/
    public List<InventoryInfo> warehousePosition(UserInfo userInfo, String warehouseCode) {
        List<Map<String, Object>> positions = this.position(userInfo).getData();
        List<InventoryInfo> inventories = inventoryDao.queryByWarehouseCode(warehouseCode);

        for (InventoryInfo inventory : inventories) {
            for (Map<String, Object> position : positions) {
                if (StringUtils.equals(position.get("otc_code").toString(),
                    inventory.getOtcCode())) {
                    Integer enableAmount = Double.valueOf(position.get("enable_amount").toString())
                        .intValue();
                    inventory.setEnableAmount(enableAmount);
                    break;
                }
            }
        }
        Collections.sort(inventories, new Comparator<InventoryInfo>() {
            @Override
            public int compare(InventoryInfo o1, InventoryInfo o2) {
                return o2.getEnableAmount().compareTo(o1.getEnableAmount());
            }
        });
        return inventories;
    }
}