WorldBoxController.java 20.3 KB
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
package com.lhcredit.project.webbusiness.controller;

import cn.hutool.core.codec.Base64;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.lhcredit.common.utils.DateUtils;
import com.lhcredit.common.utils.FileSysUtils;
import com.lhcredit.common.utils.HolidayOrWork;
import com.lhcredit.common.utils.mail.SendMailUtil;
import com.lhcredit.common.utils.security.ShiroUtils;
import com.lhcredit.framework.aspectj.lang.annotation.CheckToken;
import com.lhcredit.framework.aspectj.lang.annotation.OrderCountCheck;
import com.lhcredit.framework.web.controller.BaseController;
import com.lhcredit.framework.web.domain.AjaxResult;
import com.lhcredit.framework.web.page.TableDataInfo;
import com.lhcredit.project.business.HolidayWorkday.domain.HolidayWorkday;
import com.lhcredit.project.business.HolidayWorkday.mapper.HolidayWorkdayMapper;
import com.lhcredit.project.business.bCreditReport.domain.BCreditReport;
import com.lhcredit.project.business.bCreditReport.domain.ReportStatus;
import com.lhcredit.project.business.bCreditReport.mapper.BCreditReportMapper;
import com.lhcredit.project.business.bCreditReport.service.BCreditReportServiceImpl;
import com.lhcredit.project.business.contractBusinessType.domain.ContractBusinessType;
import com.lhcredit.project.business.contractBusinessType.mapper.ContractBusinessTypeMapper;
import com.lhcredit.project.business.contractReportBusinessType.domain.ContractReportBusinessType;
import com.lhcredit.project.business.contractReportBusinessType.service.IContractReportBusinessTypeService;
import com.lhcredit.project.business.country.domain.CountryName;
import com.lhcredit.project.business.country.service.ICountryNameService;
import com.lhcredit.project.business.frontDept.domain.FrontDept;
import com.lhcredit.project.business.frontDept.mapper.FrontDeptMapper;
import com.lhcredit.project.business.frontDept.service.FrontDeptServiceImpl;
import com.lhcredit.project.business.frontUser.domain.FrontUserMon;
import com.lhcredit.project.business.overseaCompanyInfoVerify.domain.OverseaCompanyInfoVerify;
import com.lhcredit.project.business.overseaCompanyInfoVerify.service.OverseaCompanyInfoVerifyServiceImpl;
import com.lhcredit.project.business.overseasreportedprices.domain.Overseasreportedprices;
import com.lhcredit.project.business.overseasreportedprices.mapper.OverseasreportedpricesMapper;
import com.lhcredit.project.business.overseasreportedprices.service.OverseasreportedpricesServiceImpl;
import com.lhcredit.project.business.search.service.SearchHistoryServiceImpl;
import com.lhcredit.project.business.worldboxlog.domain.Worldboxlog;
import com.lhcredit.project.business.worldboxlog.service.WorldboxlogServiceImpl;
import com.lhcredit.project.system.dict.domain.DictData;
import com.lhcredit.project.system.dict.service.DictDataServiceImpl;
import com.lhcredit.project.worldbox.WorldBoxAPI;
import io.swagger.models.auth.In;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

import static com.lhcredit.framework.web.domain.AjaxResult.success;

@Controller()
@RequestMapping("web/worldBox")
public class WorldBoxController extends BaseController {


    @Autowired
    private ContractBusinessTypeMapper contractBusinessTypeMapper;

    @Autowired
    private BCreditReportServiceImpl bCreditReportService;

    @Autowired
    OverseasreportedpricesMapper overseasreportedpricesMapper;

    @Autowired
    HolidayWorkdayMapper holidayWorkdayMapper;

    @Autowired
    private BCreditReportMapper bCreditReportMapper;

    @Autowired
    private OverseaCompanyInfoVerifyServiceImpl overseaCompanyInfoVerifyService;

    @Autowired
    private ICountryNameService countryService;

    @Autowired
    private FrontDeptServiceImpl frontDeptService;

    @Autowired
    private IContractReportBusinessTypeService contractReportBusinessTypeService;

    @Autowired
    private FrontDeptMapper frontDeptMapper;

    @Autowired
    private DictDataServiceImpl dictDataService;

    @Autowired
    private WorldboxlogServiceImpl worldboxlogService;

    @Autowired
    WorldBoxAPI WorldBoxAPI;




    private static Logger logger = LoggerFactory.getLogger(WorldBoxController.class);

//    private static final  String ORDER_EMAIL = "group-report@lhcis.com";
//    private static final  String ADD_EMAIL = "madanni_nxzx@lhcis.com";

    private static final  String ORDER_EMAIL = "kouxinyu_bjzx@lhcis.com";
    private static final  String ADD_EMAIL = "kouxinyu_bjzx@lhcis.com";


    /**
     * 搜索 海外公司
     * @param name
     * @param countrycode
     * @return
     */
     @GetMapping("/search")
     @CheckToken
     @ResponseBody
     public AjaxResult search(@RequestParam String name,@RequestParam String countrycode){

         FrontUserMon userInfo = getUserInfo();

         return worldboxlogService.getSearChResult(name, countrycode,userInfo);
     }









    /**
     * 查询详情
     * @param win
     * @return
     */
    /*@RequestMapping("/getCompaniesInfo")
    public AjaxResult getCompaniesInfo(String win,String name){
        Worldboxlog worldboxlog=new Worldboxlog();
        worldboxlog.setName(name);
        worldboxlog.setCreateTime(new Date());
        worldboxlog.setCreateBy(getUserInfo().getLoginName());

        String res=WorldBoxAPI.getCompaniesInfo(win,worldboxlog);
        if(StringUtils.isNotEmpty(res)){
            JSONObject object=JSONObject.parseObject(res);
            return success(object.getJSONObject("company"));
        }
        return AjaxResult.error();
    }*/

    /**
     * 订单下单
     * @param report
     * @return
     */
    @OrderCountCheck(reportType = "overSeaOrder")
    @PostMapping("/commitOrder")
    @CheckToken
    @ResponseBody
//    public AjaxResult commitOrder(String win,String enterpriseName,String entrustType,String country,String translateType, String createImmediate, Long templateParamId,String reportType){
    public AjaxResult commitOrder(@RequestBody BCreditReport report){

        //获取登录用户信息
        FrontUserMon userInfo = getUserInfo();
//        report.setOrgId(86l);
//        report.setCountry("CHE");
//        report.setEnterpriseName("Worldbox AG");
        //判断用户是否可以下单
        if (!bCreditReportService.isOrder(report,userInfo.getOrgId()))
            return AjaxResult.error("用户有未完成订单");
//        FrontUserMon userInfo = new FrontUserMon();
//        userInfo.setLoginName("test");
        //日志记录对象
        Worldboxlog worldboxlog=new Worldboxlog();
        worldboxlog.setName(report.getEnterpriseName());
        worldboxlog.setCreateTime(new Date());
        worldboxlog.setCreateBy(userInfo.getLoginName());

        //调用接口 下单
        Long comontStartDate = System.currentTimeMillis();
        logger.info("海外订单提交时间: {}{}{}  "+comontStartDate);
        String resOrder=WorldBoxAPI.commitOrder("REO125", report.getWin(), "",report.getRemark(),worldboxlog);
        logger.info("订单结果返回时间 : {}{}{}  "+(comontStartDate-System.currentTimeMillis()));
        if(StringUtils.isNotEmpty(resOrder)){

            if (resOrder.contains("Validation Failed")){
                return AjaxResult.error("下单失败");
            }
            //解析返回结果 获取订单编号
            JSONObject object=JSONObject.parseObject(resOrder);
            String ordernumber=object.getString("ordernumber");
            //无 返回的订单编号,则下单失败
            if(StringUtils.isEmpty(ordernumber)){
                return AjaxResult.error("下单失败,请联系管理员");
            }
            //数据插入数据库
            BCreditReport bCreditReport = new BCreditReport();
            //设置订单编号
            bCreditReport.setReferenceNo(ordernumber);
            bCreditReport.setId("XYGJHW-"+ UUID.randomUUID().toString().replace("-",""));
            //设置 bCreditReport 属性
            bCreditReportService.initBCreditReoportInfo(report, bCreditReport, userInfo);
            //来源 : 前端用户
            bCreditReport.setSource("2");
            bCreditReport.setCreateBy(userInfo.getUserName());
            //客服发送邮件
            StringBuffer content = new StringBuffer();
            content.append("下单渠道: 信用管家前台下单。" ).append("</br>");
            content.append("下单用户名: " ).append(userInfo.getUserName()).append("。").append("</br>");
            //查询 用户的组织机构
            String allDeptNameForAdmin = frontDeptService.getAllDeptNameForAdmin(userInfo.getOrgId());
            content.append("所属分公司和机构: "  ).append(allDeptNameForAdmin).append("。").append("</br>");
            content.append("报告类型: 海外信用报告。" ).append("</br>");
            content.append("报告目标公司: ").append(report.getEnterpriseName()).append("。").append("</br>");
            content.append("下单时间: " ).append(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,new Date())).append("。").append("</br>");
            //发送邮件
            SendMailUtil.send("前台海外订单", content.toString(), ORDER_EMAIL,"");
            //插入 报告表
            int flag = bCreditReportService.insertBCreditReport(bCreditReport);
            //将 翻译类型,是否立即制作报告 。存入contract_report_business_type 表
//            List<DictData> sysYesNo = dictDataService.selectDictDataByType("sys_yes_no");
//            Map<String, DictData> noYesMap = sysYesNo.stream().collect(Collectors.toMap(DictData::getDictValue, Function.identity()));
//            saveContractReportBusinessType(report, userInfo);
            if(flag > 0){
                return success();
            }
        }
        return AjaxResult.error("下单失败!");
    }

    /**
     * 保存 存入contract_report_business_type
     */
    /*private void saveContractReportBusinessType(BCreditReport report, FrontUserMon userInfo) {
        ContractReportBusinessType businessType = new ContractReportBusinessType();
        businessType.setContractId(userInfo.getContractId());
        //报告类型: -10为海外报告
        businessType.setTypeId(-10l);
        //翻译类型
        businessType.setReportTranslationType(report.getTranslateType());
        //是否立即生成
        businessType.setCreateImmediate(report.getCreateImmediate());
        businessType.setCreateTime(new Date());
        contractReportBusinessTypeService.insertContractReportBusinessType(businessType);
    }*/






    /**
     * 订单查询
     * @param ordernumber
     * @return
     */
   /* @RequestMapping("/queryOrder")
    public AjaxResult queryOrder(String ordernumber,String name){
        Worldboxlog worldboxlog=new Worldboxlog();
        worldboxlog.setName(name);
        worldboxlog.setCreateTime(new Date());
        worldboxlog.setCreateBy(getUserInfo().getLoginName());

        String res=WorldBoxAPI.getOrder(ordernumber,worldboxlog);
        if(StringUtils.isNotEmpty(res)){
            JSONObject json=JSONObject.parseObject(res);
            JSONArray array=json.getJSONArray("orderitems");
            String base64Str=array.getJSONObject(0).getString("binary");
            // 解码Base64字符串
            byte[] decodedBytes = Base64.decode(base64Str);
            //上传文件

            //文件路径写入数据库


            return success("订单获取成功!");
        }


        return AjaxResult.error("暂无数据,请稍后重试");
    }*/


    /**
     * 根据企业名称查询历史订单 (父公司看所有,子公司看自己)
     * @param enterPriseName
     * @return
     */
    @GetMapping("/getHistoryReport")
    @CheckToken
    @ResponseBody
    public AjaxResult getHistoryReport(@RequestParam String enterPriseName){

        if(StringUtils.isEmpty(enterPriseName)){
//            TableDataInfo dataInfo = new TableDataInfo();
//            dataInfo.setCode(5000);
            logger.info("接口: /getHistoryReport --- 参数未传");
            return AjaxResult.error("参数未传");
        }
        //获取登录用于的 组织机构id
        Long orgId = getUserInfo().getOrgId();
        BCreditReport bCreditReport = new BCreditReport();
//        bCreditReport.setOrgId(96l);
        bCreditReport.setOrgId(orgId);
        bCreditReport.setEnterpriseName(enterPriseName);
        //父公司看所有,子公司看自己
        startPage();
        List<BCreditReport> overseaHistoryOrderList = bCreditReportMapper.getOverseaHistoryOrder(bCreditReport);
//        return getDataTable(overseaHistoryOrderList);
        //第一个条数据 不参与于分页
        /*for(BCreditReport order:overseaHistoryOrderList){
            //拼接报告附件名称  海外报告 + 企业名称
            order.setAnnex(order.getEnterpriseName() + "海外报告");
            //解析 url,并 设置下载地址
            String url = order.getUrl();
            JSONArray urlArr = JSONArray.parseArray(url);
            if(urlArr != null){
                for(int i=0;i<urlArr.size();i++){
                    JSONObject u = (JSONObject)urlArr.get(i);
                    String extension = u.getString("fileExtension");
                    String attachments = u.getString("fileAttachments");
                    //xml下载地址
                    if ("xml".equals(extension)){
                        order.setXmlUrl(attachments);
                        //pdf下载地址
                    }else if ("pdf".equals(extension)){
                        order.setPdfUrl(attachments);
                    }
                }
            }
        }*/

        return AjaxResult.success(getDataTable(overseaHistoryOrderList));

    }

    /**
     * 获取全部 国家信息
     * @return
     */
    @GetMapping("/getAllCountry")
    @ResponseBody
    public AjaxResult getAllCountry() {
        List<CountryName> countries = countryService.selectCountryList(null);
        return AjaxResult.success(countries);
    }


    /**
     * 海外企业信息核实 存储接口
     * @param companyInfoVerify
     * @return
     */
    @PostMapping("/addOverseaCompanyInfoVerifyInfo")
    @CheckToken
    @ResponseBody
    public AjaxResult addOverseaCompanyInfoVerifyInfo(@RequestBody OverseaCompanyInfoVerify companyInfoVerify){
        // 判断必传参数
        if(StringUtils.isEmpty(companyInfoVerify.getCountryName()) ||
                StringUtils.isEmpty(companyInfoVerify.getCountryCodeRb()) ||
                StringUtils.isEmpty(companyInfoVerify.getCountryCodeWb()) ||
                StringUtils.isEmpty(companyInfoVerify.getAddress()) ||
                StringUtils.isEmpty(companyInfoVerify.getCity())){

            return AjaxResult.error("请填写正确的参数信息");
        }
        // 是否已处理(0:未处理。1:已经下单处理过),默认未处理
        companyInfoVerify.setHandStatus(0);
        companyInfoVerify.setCreateTime(new Date());
        int flag = overseaCompanyInfoVerifyService.insertOverseaCompanyInfoVerify(companyInfoVerify);
        //向客服发送 邮件
        if(flag > 0){
            //查询 用户公司信息
            FrontUserMon userInfo = getUserInfo();
            FrontDept frontDept = frontDeptService.getParentOrgInfoByOrgId(userInfo.getOrgId());
            String title = "前台海外报告未查询到企业";
            StringBuffer content = new StringBuffer();

            content.append("您好:").append(" </br>");
            String parentName = frontDept.getParentName();
            if(StringUtils.isNotEmpty(parentName)){
                content.append(parentName).append(frontDept.getDeptName()).append(userInfo.getUserName());
            }else {
                content.append(frontDept.getDeptName()).append(userInfo.getUserName());
            }
            content.append("于");
            String timeStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, new Date());
            content.append(timeStr).append("交了海外企业信用报告下单需求,请您尽快与客户联系。").append("</br>");
            content.append("海外企业信息如下:").append("</br>");
            content.append("所属国家/地区:  ").append(companyInfoVerify.getCountryName()).append("。    ").append("企业名称: ").append(companyInfoVerify.getEnterpriseName()).append("。 </br>");
            content.append("城市: ").append(companyInfoVerify.getCity()).append("。     ").append("企业地址:  ").append(companyInfoVerify.getAddress()).append("。 </br>");
            if (StringUtils.isNotEmpty(companyInfoVerify.getPostCode()))
                content.append("邮政编码: ").append(companyInfoVerify.getPostCode()).append("。    ");
            else
                content.append("邮政编码: ").append("暂无").append("。    ");

            if (StringUtils.isNotEmpty(companyInfoVerify.getEmail()))
                content.append("电子邮箱: ").append(companyInfoVerify.getEmail()).append("。 </br>");
            else
                content.append("电子邮箱: ").append("暂无").append("。 </br>");

            if (StringUtils.isNotEmpty(companyInfoVerify.getPhone()))
                content.append("联系电话: ").append(companyInfoVerify.getPhone()).append("。     ");
            else
                content.append("联系电话: ").append("暂无").append("。     ");

            if (StringUtils.isNotEmpty(companyInfoVerify.getRegNo()))
                content.append("公司注册号码: ").append(companyInfoVerify.getRegNo()).append("。 </br>");
            else
                content.append("公司注册号码: ").append("暂无").append("。 </br>");




            content.append("客户联系方式如下:").append(" </br>");
            content.append("联系电话: ").append(userInfo.getPhone()).append("。  </br>");
            content.append("邮箱: ").append(userInfo.getMail()).append("。  </br>");
            SendMailUtil.send(title,content.toString(),ADD_EMAIL,"");

            return AjaxResult.success();
        }
        return AjaxResult.error();

    }


    /**
     * 获取 公司详情
     * @param win
     * @param companyName
     * @return
     */
    @GetMapping("/getCompanyInfo/{win}/{companyName}")
    @CheckToken
    @ResponseBody
    public AjaxResult getCompanyInfo(@PathVariable("win") String win,@PathVariable("companyName") String companyName) {

        Worldboxlog worldboxlog=new Worldboxlog();
        worldboxlog.setName(companyName);
        worldboxlog.setCreateTime(new Date());
        worldboxlog.setCreateBy(getUserInfo().getLoginName());
        //根据 win查询公司详细信息
        String infoResult = WorldBoxAPI.getCompaniesInfo(win, worldboxlog);
        if(StringUtils.isNotEmpty(infoResult)){
            JSONObject companyInfoObj = JSONObject.parseObject(infoResult);
            JSONObject company = companyInfoObj.getJSONObject("company");
            return AjaxResult.success(company);
        }
        return AjaxResult.error();

    }

    /**
     * 下载报告
     * @param cardScoreInfo
     * @return
     **/
    @PostMapping(value = "/downloadScoreCard")
    @ResponseBody
    public ResponseEntity<Resource> downloadScoreCard(@RequestBody String cardScoreInfo){
        return bCreditReportService.downloadScoreCard(cardScoreInfo);
    }

    @RequestMapping("/test")
    public void test(HttpServletResponse response) {
        String url="http://filestorage.lhdna.com/creditManager/1908022041487208448.xml";
        try {
            byte[] xmlByte = new byte[4089];
            xmlByte = FileSysUtils.downloadFile(url, response);
            //读取数据
            String xmlStr = new String(xmlByte, "utf-8");
            Map<String, Object> xmlMap = bCreditReportService.readXml(xmlStr);
            System.out.println(JSON.toJSONString(xmlMap));
        }catch (Exception e){
            e.printStackTrace();
        }

    }

}