js //异步发送优惠券
    sendcoupon:function(){
    var txt;
    if($(“#coupontype”).val()==”1”){
    txt=”优惠券”
    }else{
    txt=”积客活动”
    }
    if($(“#selectcouponno”).val()==””){

    layer.msg(“请选择”+txt);
    return;
    }

    var selectsharecount = 0;
    if($(“#selectsharecount”).val()==”无限制”){
    selectsharecount = 0;
    }else{
    selectsharecount = $(“#selectsharecount”).val();
    }
    if (!$(“#formsendcoupon”).validate().form()) return;
    var issendall = 0;
    var sendallcouponinfo = {}
    var data = window.params;
    if (data && Object.prototype.toString.call(data) == ‘[object Array]’) {
    if (data && data.length > 0) {
    } else {
    layer.msg(“请选择用户”);
    return;
    }
    }else if (data && data.content && data.content == “all”) {
    data = [];
    issendall = 1;
    sendallcouponinfo = {“selectcouponno”:$(“#selectcouponno”).val(),
    “agent”:top.log_name,
    “grantnum”:$(“#selectgrantnum”).val(),
    “sharecount”:selectsharecount
    }
    }
    var nicknames = “”;
    var arrData = [];
    console.log(data);
    $.each(data,function(index,item){
    arrData.push({“selectcouponno”:$(“#selectcouponno”).val(),
    “openid”:item.openid,
    “nickname”:item.nickname,
    “custname”:item.custname,
    “custtel”:item.custtel,
    “compno”:top.log_compno,
    “agent”:top.log_name,
    “grantnum”:$(“#selectgrantnum”).val(),
    “sharecount”:selectsharecount
    });
    //nicknames += item.nickname+”
    “;
    });

    var tipmsg = “”;
    if(issendall){
    tipmsg = “所有粉丝将将收到”+($(“#coupontype”).val()==”1”?”优惠券”: “积客活动”);
    }else{
    tipmsg = “选中粉丝将收到”+($(“#coupontype”).val()==”1”?”优惠券”: “积客活动”);
    }
    tipmsg += “,确认发送吗?”
    layer.confirm(tipmsg, function(index) {
    layer.close(index);
    /var loadIndex = parent.layer.load(1,{ // 此处1没有意义,随便写个东西
    icon: 1, // 0~2 ,
    shade: [0.5,’black’] // 黑色透明度0.5背景
    });
    /
    $.ajax({
    type : “POST”,
    url : “admin/weixin/sendWeiXinMpCoupon/“+$(“#coupontype”).val()+”.do”,
    data : {
    “data”:JSON.stringify(arrData),
    “content”:$(“#msgcontent”).val(),
    “issendall”:issendall,
    “sendallcouponinfo”:JSON.stringify(sendallcouponinfo),
    “compno”: top.log_compno,
    “operator”: top.log_name,
    “toyorno”: top.ToyorNo
    },
    success : function(data, status) {
    if (data.success) {
    $(“#selectcouponno”).val(“”);
    $(“#selectcouponname”).val(“”);
    $(“#selectmoney”).val(“”);
    $(“#selectgrantnum”).val(“”);
    $(“#selectsharecount”).val(“”);
    $(“#selectperiod”).val(“”);//
    parent.layer.open({
    type: 1,
    title: false,
    closeBtn: 0,
    anim: -1,
    content: ‘

    正在发送,请耐心等待…
    总计:0,成功:0,失败:0

    });
    var params = {compno: top.log_compno, keyno: data.root.keyno};
    if(!top.sendCouponIntervalHandle){
    top.sendCouponIntervalHandle = setInterval(function(){
    crud.onSearchSendCouponAsynResultNode(params);
    },10000);
    } else {
    clearInterval(top.sendCouponIntervalHandle);
    top.sendCouponIntervalHandle = setInterval(function(){
    crud.onSearchSendCouponAsynResultNode(params);
    },10000);
    }



    }
    else {
    parent.layer.closeAll(‘loading’);
    layer.msg(data.errors);
    }
    },
    error : function(data) {
    layer.msg(data.errors?data.errors:”发送失败!”);
    }
    });
    });


    },
    //查询发送优惠券结果

    onSearchSendCouponAsynResultNode: function(params){
    if(!params) return;

    $.ajax({
    type : “POST”,
    url : “BaseList/searchAsynResultNode.do”,
    data : {compno: params.compno, keyno: params.keyno},
    success : function(data) {
    if(!data.success){
    parent.layer.msg(data.errors?data.errors:”查询发送异步结果失败!”);
    return;
    }
    var r = data.root;
    if (r) {
    var tips = “总计: “+r.exectotal + “,成功:”+r.execcountok+”,失败:” + r.execcountfail ;
    parent.$(“.sendcount”).text(tips);
    //异步过程尚未执行完毕,继续循环查询
    if (r.resultcode == 0) {


    }
    //异步过程已经执行完毕,停止循环查询
    else {
    if(top.sendCouponIntervalHandle){
    clearInterval(top.sendCouponIntervalHandle);
    }

    //确认后台执行完毕后删除记录
    parent.$.ajax({
    type: ‘POST’,
    url: ‘BaseList/deleteAsynResultNode.do’,//发送请求
    data: {compno: params.compno, keyno: params.keyno},
    success:function(r){

    },
    error : function(data) {
    parent.layer.msg(data.errors?data.errors:”删除异步处理失败!”);
    }
    });

    // 异步执行成功
    if (r.resultcode == 1) {
    parent.layer.closeAll();
    parent.layer.msg(“发送成功!”,{
    offset: ‘t’,
    anim: 6
    });
    }
    else if (r.resultcode == 2) {


    if (r.resulturl) {
    parent.layer.confirm(‘存在发送失败的记录,您需要下载失败反馈的Csv文件吗?’, function (index) {
    //console.table(r);
    parent.layer.close(index);

    var save_link = top.document.createElementNS(‘http://www.w3.org/1999/xhtml’, ‘a’);
    save_link.href = r.resulturl;
    save_link.download = r.resultfilename;
    var event = top.document.createEvent(‘MouseEvents’);
    event.initMouseEvent(‘click’, true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
    save_link.dispatchEvent(event);
    parent.layer.closeAll();


    },function () {
    $.ajax({
    type: ‘POST’,
    url: ‘BaseList/delDownloadExcelFile.do’,
    data: {
    fileKey: r.resultfilekey,
    fileName: r.resultfilename
    },
    success: function (data) {
    if (data.success) {
    parent.layer.closeAll();
    }else{
    parent.layer.closeAll();
    parent.layer.msg(data.errors, {
    icon: 1,
    time: 2000
    });
    }
    },
    error: function (data) {
    //console.log(data.msg);
    parent.layer.closeAll();
    parent.layer.msg(data.errors?data.errors:”出错了”);
    }
    });
    });

    } else {
    parent.layer.closeAll();
    parent.layer.msg(‘存在发送失败的记录,但是在生成失败反馈的Csv文件时出错!’);

    }
    } else if (r.resultcode == 3) {


    parent.layer.closeAll();
    parent.layer.msg(‘存在导入失败的记录,但是在生成失败反馈的Excel文件时出错!’);

    }
    }
    } else {
    if(top.sendCouponIntervalHandle){
    clearInterval(top.sendCouponIntervalHandle);
    }
    }
    },
    error : function(data) {
    parent.layer.closeAll();
    parent.layer.msg(data.errors?data.errors:”发送失败!”);
    }
    });
    },



    控制器
    //发送优惠券asyn
    @RequestMapping(“/sendWeiXinMpCoupon/{coupontype}”)
    public void sendWeiXinMpCoupon(@PathVariable(“coupontype”) int coupontype,String data,
    String issendall,String sendallcouponinfo,String compno,
    String operator,String toyorno, HttpServletRequest request, HttpServletResponse response) {
    try {
    List list = new ArrayList();
    CouponInfo couponInfo = null;
    if(StringUtils.isEmpty(issendall)) issendall = “0”;
    if(issendall.equals(“0”)) {
    ArrayList arrOpenid = new ArrayList();

    JSONArray jsonData = JSONArray.fromObject(data);
    for (int i = 0; i < jsonData.size(); i++) {
    String openid = jsonData.getJSONObject(i).getString(“openid”);
    if (arrOpenid.contains(openid)) continue;//去重
    arrOpenid.add(openid);
    WxOnLineCustomer wxOnLineCustomer = weiXinService.getByOpenIdWxOnLineCustomer(openid);
    String couponno = jsonData.getJSONObject(i).getString(“selectcouponno”);
    if (couponInfo == null) {
    couponInfo = weiXinService.getByKeyCouponInfo(couponno);
    }
    String grantnum = jsonData.getJSONObject(i).getString(“grantnum”);
    String agent = jsonData.getJSONObject(i).getString(“agent”);
    couponInfo.setGrantnum(Integer.valueOf(grantnum));
    if (coupontype == 2) {
    String sharecount = “0”;
    sharecount = jsonData.getJSONObject(i).getString(“sharecount”);
    couponInfo.setSharecount(Integer.valueOf(sharecount));
    }
    wxOnLineCustomer.setCustname(jsonData.getJSONObject(i).getString(“custname”));
    wxOnLineCustomer.setCusttel(jsonData.getJSONObject(i).getString(“custtel”));
    list.add(wxOnLineCustomer);
    }

    }else{
    if(StringUtils.isEmpty(sendallcouponinfo)) {
    outError(response,”发送信息为空”);
    return;
    }
    JSONObject jsonObject = JSONObject.fromObject(sendallcouponinfo);
    String grantnum = jsonObject.getString(“grantnum”);
    String agent = jsonObject.getString(“agent”);
    String couponno = jsonObject.getString(“selectcouponno”);
    if (couponInfo == null) {
    couponInfo = weiXinService.getByKeyCouponInfo(couponno);
    }
    couponInfo.setGrantnum(Integer.valueOf(grantnum));
    if (coupontype == 2) {
    String sharecount = “0”;
    sharecount = jsonObject.getString(“sharecount”);
    couponInfo.setSharecount(Integer.valueOf(sharecount));
    }
    WxOnLineCustomer wxOnLineCustomerTmp = new WxOnLineCustomer();
    wxOnLineCustomerTmp.setLimit(900000);
    wxOnLineCustomerTmp.setStart(0);
    wxOnLineCustomerTmp.setConditions(“ and isnull(w.openid,’’) != ‘’ “);
    list = weiXinService.getAllWxOnLineCustomer(wxOnLineCustomerTmp);
    }
    if(list.size() <= 0){
    outError(response,”可发送粉丝为空!”);
    return;
    }
    String keyno = UUID.randomUUID().toString().replaceAll(“-“, “”).substring(0, 32);
    AsynResult asynResult = new AsynResult();
    asynResult.setCompno(compno);
    asynResult.setUsername(operator);
    asynResult.setKeyno(keyno);
    asynResult.setExecdesc(“正在初始化数据!”);
    baseService.createAsynResultNode(asynResult);

    asynResult.setToyorno(toyorno);
    SendCouponParam sendCouponParam = new SendCouponParam();
    sendCouponParam.setList(list);
    sendCouponParam.setToyorno(toyorno);
    sendCouponParam.setAgent(operator);
    sendCouponParam.setUsername(operator);
    sendCouponParam.setKeyno(keyno);
    sendCouponParam.setCompno(compno);
    sendCouponParam.setCouponInfo(couponInfo);
    sendCouponParam.setRequest(request);
    SendCouponRunnable sendCouponRunnable = new SendCouponRunnable(sendCouponParam);
    Thread sendCouponThread = new Thread(sendCouponRunnable);
    sendCouponThread.start();

    outObjectString(asynResult, response);
    } catch (Exception e) {
    e.printStackTrace();
    outError(response);
    }
    }




    //查询异步执行结果
    @RequestMapping(“/searchAsynResultNode”)
    public void searchAsynResultNode(AsynResult searchAsynResult, HttpServletRequest request, HttpServletResponse response) {
    try {
    if (StringUtils.isEmpty(searchAsynResult.getCompno())) {
    this.outError(response, “公司编码不能为空!”);
    return;
    }
    if (StringUtils.isEmpty(searchAsynResult.getKeyno())) {
    this.outError(response, “结果回执编码不能为空!”);
    return;
    }
    AsynResult asynResult = baseService.searchAsynResultNode(searchAsynResult);
    if(asynResult != null){
    this.outObjectString(asynResult, response);
    } else {
    this.outError(response, “未查询到异步执行结果!”);
    }

    } catch (Exception e) {
    e.printStackTrace();
    this.outError(response, “查询异步执行结果出错!”);
    }
    }

    //删除异步执行结果
    @RequestMapping(“/deleteAsynResultNode”)
    public void deleteAsynResultNode(AsynResult searchAsynResult, HttpServletRequest request, HttpServletResponse response) {
    try {
    if (StringUtils.isEmpty(searchAsynResult.getCompno())) {
    this.outError(response, “公司编码不能为空!”);
    return;
    }
    if (StringUtils.isEmpty(searchAsynResult.getKeyno())) {
    this.outError(response, “结果回执编码不能为空!”);
    return;
    }
    Map mapResult = baseService.deleteAsynResultNode(searchAsynResult);
    if(mapResult.get(“result”).toString().equals(“0”)){
    this.outObjectString(null, response);
    } else {
    this.outError(response, mapResult.get(“msg”).toString());
    }

    } catch (Exception e) {
    e.printStackTrace();
    this.outError(response, “删除异步执行结果出错!”);
    }
    }
    //删除Excel导入时的错误反馈文件
    @RequestMapping(“/delDownloadExcelFile”)
    public void delDownloadExcelFile(String fileKey, String fileName, HttpServletResponse response, HttpServletRequest request) {
    try {
    if (StringUtils.isNotEmpty(fileKey) && StringUtils.isNotEmpty(fileName)) {
    String vistBasePath = SystemConfigUtil.getProperty(“urlMsimsService”);
    if (StringUtils.isNotEmpty(vistBasePath)) {
    vistBasePath = vistBasePath + “/BaseList/delDownloadExcelFile.do”;
    Map params = new HashMap();
    params.put(“fileKey”, fileKey);
    params.put(“fileName”, fileName);

    PlatUtil.post(vistBasePath, params);
    outObjectString(null, response);
    }
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    }


    线程处理执行




    public class SendCouponRunnable implements Runnable {
    private BaseService baseService;
    private SendCouponParam params;

    public SendCouponRunnable(SendCouponParam sendCouponParam) {
    this.params = sendCouponParam;
    PlatUtil.setDbInfo(params.getToyorno(),””,null,null);
    baseService = SpringContextUtil.getBean(“baseServiceImpl”);
    }

    @Override
    public void run() {
    PlatUtil.setDbInfo(params.getToyorno(),””,null,null);
    AsynResult asynResult = null;
    asynResult = sendCoupon();
    asynResult.setCompno(params.getCompno());
    asynResult.setKeyno(params.getKeyno());
    baseService.updateAsynResultNode(asynResult);


    }

    /
    /
    private AsynResult sendCoupon() {
    AsynResult asynResult = new AsynResult();
    LinkedHashMap fieldsMap = new LinkedHashMap() {{
    put(“发送状态”, “sendstate”);
    put(“昵称”, “nickname”);
    put(“关联客户”, “custname”);
    put(“关联客户编码”, “custno”);
    put(“省”, “province”);
    put(“市”, “city”);
    put(“手机”, “userphone”);
    put(“用户名”, “username”);
    put(“OpenId”, “openid”);
    }};
    long startInitData = System.currentTimeMillis();

    /try {

    } catch (Exception e) {
    e.printStackTrace();
    asynResult.setResultcode(-1);
    asynResult.setResultmsg(“出错!”);
    return asynResult;
    }
    /
    long endInitData = System.currentTimeMillis();

    try {
    List list = params.getList();
    List resultList = new ArrayList();
    long startImportData = System.currentTimeMillis();

    AsynResult updateAsynResult = new AsynResult();
    updateAsynResult.setCompno(params.getCompno());
    updateAsynResult.setUsername(params.getUsername());
    updateAsynResult.setKeyno(params.getKeyno());

    updateAsynResult.setExectotal(list.size());
    updateAsynResult.setExecdesc(“正在发送优惠券!”);
    baseService.updateAsynResultNode(updateAsynResult);


    // 开始 将任务分给多个线程去处理
    List>> futureTasks = new ArrayList<>();
    int size = list.size();
    int num = 100;
    int div = size / num;
    int mod = size % num;
    for(int i = 0;i < div; i++){
    List newList = list.subList(inum,inum + num);
    SendCouponSubCallable task = new SendCouponSubCallable(newList, params);
    FutureTask> futureTask = new FutureTask>(task);
    futureTasks.add(futureTask);

    Thread subThread = new Thread(futureTask);
    subThread.start();
    }

    if (mod > 0){
    List newList = list.subList(size - mod,size);
    SendCouponSubCallable task = new SendCouponSubCallable(newList, params);
    FutureTask> futureTask = new FutureTask>(task);
    futureTasks.add(futureTask);

    Thread subThread = new Thread(futureTask);
    subThread.start();
    }

    for (int i = 0; i < futureTasks.size(); i++) {
    //获取子线程执行结果,阻塞的
    Map map = futureTasks.get(i).get();
    if(!map.get(“result”).toString().equals(“0”)){
    List tempResultList = (List) map.get(“resultList”);
    resultList.addAll(tempResultList);
    }
    }
    // 结束 将任务分给多个线程去处理
    if (resultList != null && resultList.size() > 0) {
    //导出csv
    Map map = (new CsvUtil()).saveCsvToPath(DateTime.getNowDateString() + “发送失败记录”, resultList, fieldsMap);
    if (!map.get(“result”).toString().equals(“0”)) {
    asynResult.setResultcode(3);
    asynResult.setResultmsg(“存在发送失败记录,但是生成Csv错误回馈文件失败!”);
    } else {
    asynResult.setResultcode(2);
    asynResult.setResultmsg(“存在发送失败记录!”);
    asynResult.setResulturl(map.get(“url”).toString());
    asynResult.setResultfilekey(map.get(“filekey”).toString());
    asynResult.setResultfilename(map.get(“filename”).toString());
    }
    } else {
    asynResult.setResultcode(1);
    asynResult.setResultmsg(“发送成功!”);
    }

    long endImportData = System.currentTimeMillis();

    System.out.println(“初始化数据时长: “ + (endInitData - startInitData) + “ 毫秒”);
    System.out.println(“数据发送时长: “ + (endImportData - startImportData) + “ 毫秒”);

    } catch (Exception e) {
    asynResult.setResultcode(-1);
    asynResult.setResultmsg(“发送数据出错!”+e.getMessage());
    e.printStackTrace();
    return asynResult;
    }
    return asynResult;
    }

    }


    //多个子线程,通过get阻塞
    public class SendCouponSubCallable implements Callable> {
    private BaseService baseService;
    private WeiXinService weiXinService;
    private SendCouponParam sendCouponParam;
    private List list;
    private String toyorno;
    private String keyno;
    private String compno;
    private String agent;
    private CouponInfo couponInfo;
    private HttpServletRequest request;


    public SendCouponSubCallable(List list,SendCouponParam sendCouponParam) {
    this.list = list;
    this.toyorno = sendCouponParam.getToyorno();
    this.keyno = sendCouponParam.getKeyno();
    this.compno = sendCouponParam.getCompno();
    this.agent = sendCouponParam.getAgent();
    this.couponInfo = sendCouponParam.getCouponInfo();
    this.request = sendCouponParam.getRequest();


    baseService = SpringContextUtil.getBean(“baseServiceImpl”);
    weiXinService = SpringContextUtil.getBean(“weiXinServiceImpl”);
    }

    @Override
    public Map call() throws Exception {
    Map mapResult = new HashMap<>();
    List resultListSuccess = new ArrayList();
    List resultListFail = new ArrayList();
    try {
    PlatUtil.setDbInfo(toyorno, “”, null, null);



    CouponGrant couponGrant = null;
    String urlBasePath = SystemConfigUtil.getProperty(“urlMsimsMarket”);
    for (WxOnLineCustomer item : list) {

    if (StringUtils.isEmpty(item.getOpenid())) continue;
    String custname = StringUtils.isEmpty(item.getCustname()) ? StringUtils.trimToEmpty(item.getNickname()) : item.getCustname();
    String custtel = item.getCusttel();
    couponGrant = weiXinService.createCouponGrant(1, agent, item.getOpenid(), null, couponInfo);
    String msg = weiXinService.SendCouponMsg(couponGrant, couponInfo, item.getOpenid(), custname, custtel, null, urlBasePath, toyorno);
    if (StringUtils.isNotEmpty(msg)) {
    //outError(response, msg);
    //MyLogUtil.error(“fail:”+StringUtils.trimToEmpty(item.getNickname())+”:”+item.getOpenid()+”:”+msg);
    item.setSendstate(“发送失败:” + msg.replaceAll(“,”, “,”));
    resultListFail.add(item);
    //weiXinService.deleteCouponGrantByKey(couponGrant.getGrantno());
    if (msg.contains(“not in whitelist”)) {
    break;
    }
    } else {
    try {
    weiXinService.insertOrUpdateCouponGrant(couponGrant);
    resultListSuccess.add(item);
    }catch(Exception e){
    e.printStackTrace();
    item.setSendstate(“发送失败:” + StringUtils.trimToEmpty(e.getMessage()).replaceAll(“,”, “,”));
    }

    }

    }
    AsynResult updateAsynResult = new AsynResult();
    updateAsynResult.setCompno(compno);
    updateAsynResult.setKeyno(keyno);

    updateAsynResult.setExectotal(0);
    updateAsynResult.setExeccountok(resultListSuccess.size());
    updateAsynResult.setExeccountfail(resultListFail.size());
    baseService.updateAsynResultNode(updateAsynResult);

    if (resultListFail.size() > 0) {
    mapResult.put(“result”, “1”);
    } else {
    mapResult.put(“result”, “0”);
    }
    mapResult.put(“resultList”, resultListFail);
    return mapResult;
    }
    catch(Exception e){
    e.printStackTrace();
    MyLogUtil.error(“子线程出错”+e.getMessage());
    WxOnLineCustomer wxOnLineCustomerTmp = new WxOnLineCustomer();
    wxOnLineCustomerTmp.setSendstate(“发送失败:线程出错”);
    resultListFail.add(wxOnLineCustomerTmp);
    mapResult.put(“result”, “1”);
    mapResult.put(“resultList”, resultListFail);
    return mapResult;
    }
    }
    }

    public class AsynResult extends BaseClass {
    private int rid;
    private String compno;
    private String keyno;
    private String username;
    private String createdate;
    private int resultcode;
    private String resultmsg;
    private String resulturl;
    private String resultfilekey;
    private String resultfilename;
    private int exectotal;
    private int execcountok;
    private int execcountfail;
    private String execdesc;
    }



    public class CsvUtil {
    public Map saveCsvToPath(String fileName, List list, LinkedHashMap map){
    Map mapResult = new HashMap();
    try {

    if(StringUtils.isEmpty(fileName)){
    mapResult.put(“result”,”-1”);
    mapResult.put(“msg”,”要保存的文件名不能为空!”);
    return mapResult;
    }

    fileName = fileName + “.csv”;

    String basePath = SystemConfigUtil.getProperty(“urlMsimsServiceReportPath”);
    String vistBasePath = SystemConfigUtil.getProperty(“urlMsimsService”);
    if(StringUtils.isEmpty(basePath)){
    mapResult.put(“result”,”-1”);
    mapResult.put(“msg”,”您尚未在后台配置urlMsimsServiceReportPath参数!”);
    return mapResult;
    }

    if(StringUtils.isEmpty(vistBasePath)){
    mapResult.put(“result”,”-1”);
    mapResult.put(“msg”,”您尚未在后台配置urlMsimsService参数!”);
    return mapResult;
    }

    String fileKey = UUID.randomUUID().toString().replaceAll(“-“, “”).substring(0, 32);
    String filePath = “DownloadExcel/“+fileKey+”/“;

    File fp = new File(basePath+filePath);
    // 目录已存在创建文件夹
    if (!fp.exists()) {
    // 目录不存在的情况下,会抛出异常
    fp.mkdirs();
    }

    FileOutputStream out = new FileOutputStream(basePath+filePath+fileName);
    StringBuilder stringBuilder = new StringBuilder();
    //设置表头
    for (Map.Entry entry : map.entrySet()) {
    stringBuilder.append(entry.getKey().toString());
    stringBuilder.append(“,”);
    }
    stringBuilder.append(“\n\t”);
    // 拼装excel内容
    T t = null;
    for (int i = 0; i < list.size(); i++) {
    t = (T)list.get(i);
    // 创建单元格,并设置值
    int j=0;
    for (Map.Entry entry : map.entrySet()) {
    int pos = j++;
    try {
    if (!entry.getValue().toString().contains(“.”)) {
    if(t.getClass().getName().equals(“java.util.HashMap”)){
    Object obj = ((Map)t).get(entry.getValue().toString());
    if(obj.toString().equals(“0E-10”)) {
    stringBuilder.append(“0”);
    stringBuilder.append(“,”);
    }
    else {
    stringBuilder.append(obj == null ? “” :obj);
    stringBuilder.append(“,”);
    }
    } else {
    Field field = t.getClass().getDeclaredField(entry.getValue().toString());
    //设置对象的访问权限,保证对private的属性的访问
    field.setAccessible(true);
    stringBuilder.append(field.get(t) == null ? “” : field.get(t));
    stringBuilder.append(“,”);
    }
    } else {
    String[] arr = entry.getValue().toString().split(“\.”);
    Object tmpObject = t;

    for (int k = 0; k < arr.length; k++) {
    if(t.getClass().getName().equals(“java.util.HashMap”)){
    if (k == arr.length - 1) {
    Object obj = ((Map)t).get(arr[k]);
    if(obj.toString().equals(“0E-10”)) {
    stringBuilder.append(“0”);
    stringBuilder.append(“,”);
    }
    else {
    stringBuilder.append(obj == null ? “” :obj);
    stringBuilder.append(“,”);
    }
    break;
    }
    } else {
    if (k == arr.length - 1) {
    Field tmpField = tmpObject.getClass().getDeclaredField(arr[k]);
    //设置对象的访问权限,保证对private的属性的访问
    tmpField.setAccessible(true);
    stringBuilder.append(tmpField.get(tmpObject) == null? “” : tmpField.get(tmpObject));
    stringBuilder.append(“,”);
    break;
    }

    Field field = tmpObject.getClass().getDeclaredField(arr[k]);
    //设置对象的访问权限,保证对private的属性的访问
    field.setAccessible(true);
    tmpObject = field.get(tmpObject);
    }
    }
    }
    }catch (Exception ex){
    ex.printStackTrace();
    }
    }
    stringBuilder.append(“\n\t”);
    }
    out.write(stringBuilder.toString().getBytes());
    out.close();
    mapResult.put(“result”,”0”);
    mapResult.put(“msg”,”保存Csv成功!”);
    mapResult.put(“url”,vistBasePath + filePath + fileName);
    mapResult.put(“filekey”,fileKey);
    mapResult.put(“filename”,fileName);
    return mapResult;

    }
    catch (Exception e){
    e.printStackTrace();
    mapResult.put(“result”,”-1”);
    mapResult.put(“msg”,”保存Csv出错!”);
    mapResult.put(“url”,””);
    mapResult.put(“filekey”,””);
    mapResult.put(“filename”,””);
    return mapResult;
    }
    }
    }