//package com.yizhi.application.rangeImport;
//
//import com.yizhi.application.context.RequestContext;
//import com.yizhi.application.context.TaskContext;
//import com.yizhi.application.domain.TrVoteParticipant;
//import com.yizhi.application.feign.VoteClient;
//import com.yizhi.application.file.task.AbstractDefaultTask;
//import com.yizhi.application.model.AccountRangeImportModel;
//import com.yizhi.application.model.AccountRangeImportParam;
//import com.yizhi.application.system.remote.AccountRangeClient;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//import org.springframework.util.CollectionUtils;
//
//import java.sql.Timestamp;
//import java.text.SimpleDateFormat;
//import java.util.ArrayList;
//import java.util.Date;
//import java.util.List;
//import java.util.Map;
//
///**
// * @Auther: dingxiaowei
// * @Date: 2018/9/17 16:43
// * @Description:投票可见范围异步导入
// */
//@Component
//public class VoteRangeImport extends AbstractDefaultTask<String, Map<String, Object>> {
//
//    private static final Logger LOGGER = LoggerFactory.getLogger(VoteRangeImport.class);
//
//    @Autowired
//    private AccountRangeClient accountRangeClient;
//
//    @Autowired
//    private VoteClient voteClient;
//
//    @Autowired
//    private RangeUtil importUtil;
//
//    @Override
//    protected String execute(Map<String, Object> map) {
//
//        //从map中取值
//        String ossUrl = (String) map.get("ossUrl");
//        RequestContext res = (RequestContext) map.get("requestContext");
//        Long voteId = (Long) map.get("voteId");
//        Long accountId = res.getAccountId();
//        String accountFullName = res.getAccountFullName();
//        Long siteId = res.getSiteId();
//        Long companyId = res.getCompanyId();
//        Date submitTime = new Date();
//        Long taskId = (Long) map.get("taskId");
//        String serialNo = (String) map.get("serialNo");
//        String taskName = (String) map.get("taskName");
//        TaskContext taskContext = new TaskContext(taskId, serialNo, taskName, accountId, submitTime, siteId, companyId);
//        working(taskContext);
//        //将请求值装入param
//        AccountRangeImportParam param = new AccountRangeImportParam();
//        param.setType(AccountRangeImportParam.Type.VOTE);
//        param.setOssUrl(ossUrl);
//        param.setRequestContext(res);
//        List<AccountRangeImportModel.SuccessAccount> successList = null;
//        List<AccountRangeImportModel.ErrorAccount> errorList = null;
//        List<Integer> integerList = null;
//        //进行入库
//        try {
//            AccountRangeImportModel accountRangeImportModel = accountRangeClient.doImport(param);
//            if (null != accountRangeImportModel) {
//                successList = accountRangeImportModel.getSuccessList();
//                errorList = accountRangeImportModel.getErrorList();
//            }
//
//            errorList = (errorList == null ? new ArrayList<>() : errorList);
//            successList = (successList == null ? new ArrayList<>() : successList);
//            List<TrVoteParticipant> trVoteParticipants = new ArrayList<>();
//            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//            Timestamp createTime = Timestamp.valueOf(sdf.format(new Date()));
//
//            TrVoteParticipant trVoteParticipant = null;
//            if (!CollectionUtils.isEmpty(successList)) {
//                for (AccountRangeImportModel.SuccessAccount rangeImportModel : successList) {
//                    trVoteParticipant = new TrVoteParticipant();
//                    trVoteParticipant.setState(1);
//                    trVoteParticipant.setType(1);
//                    trVoteParticipant.setAccountId(rangeImportModel.getId());
//                    trVoteParticipant.setName(rangeImportModel.getName());
//                    trVoteParticipant.setVoteId(voteId);
//                    trVoteParticipant.setCreateById(accountId);
//                    trVoteParticipant.setCreateByName(accountFullName);
//                    trVoteParticipant.setCreateTime(createTime);
//                    trVoteParticipants.add(trVoteParticipant);
//                }
//                voteClient.insertParticipant(trVoteParticipants);
//            }
//
//            importUtil.returnResults(taskContext, successList, errorList, ossUrl);
//
//        } catch (Exception e) {
//            e.printStackTrace();
//            fail(taskContext, "投票可见范围异步导入过程中出现错误");
//            LOGGER.error("投票可见范围异步导入过程中出现错误", e);
//        }
//
//        return "ok";
//    }
//}
