package com.deloitte.sbg.controller import com.alibaba.fastjson.JSON import com.alibaba.fastjson.JSONArray import com.alibaba.fastjson.JSONObject import com.alibaba.fastjson.serializer.SerializerFeature import com.common.core.domain.DesensitiveType import com.common.core.enums.ResultCodeEnum import com.common.core.service.SFService import com.common.core.utils.DesensitiveUtils import com.common.core.utils.IdUtils import com.common.core.utils.RestUtil import com.common.core.utils.StringUtils import com.deloitte.system.model.Contact import com.deloitte.system.request.SFTokenDto import groovy.util.logging.Log import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Value import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RequestMethod import org.springframework.web.bind.annotation.RestController import org.springframework.web.client.HttpServerErrorException import org.springframework.web.context.request.RequestContextHolder import org.springframework.web.context.request.ServletRequestAttributes import org.springframework.http.HttpHeaders import javax.servlet.http.HttpServletResponse import java.util.logging.Level import static com.jfinal.plugin.activerecord.Db.tx /** * @Author: Ben Pi * @Date: 22/02/2022 14:14 */ @RestController @RequestMapping("/sbg") @Log("log") class SfSBGRest { @Autowired private SFService sfService; @Autowired private IdUtils idUtils; @Value("\${salesforce.sbgurl}") private String uri; @RequestMapping(value = "/203", method = RequestMethod.POST) def sbg203(@RequestBody def body) { log.info("203接口请求=====================body:"+body) HttpServletResponse resp = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse() def result; tx({ -> SFTokenDto tokenDto = sfService.getToken() String accessToken = tokenDto.getAccessToken() HttpHeaders header = new HttpHeaders() header.add("Authorization", "Bearer " + accessToken) try { for (int i = 0; i < body.Partners.size(); i++) { body.Partners[i].other1 = body.Partners[i].RegisterAddress if(null == body.Partners[i].Consignee_Info){ continue; } String registerAddress = body.Partners[i].RegisterAddress String englishAddress = body.Partners[i].STR_SUPPL1 String bpType = body.Partners[i].BPType //置空字段 body.Partners[i].Invoice_phone = "" body.Partners[i].Incorporator = "" for (int k = 0; k < body.Partners[i].Consignee_Info.size(); k++) { if (StringUtils.isNotBlank(body.Partners[i].Consignee_Info[k].ContactName)) { //置空字段 body.Partners[i].Consignee_Info[k].ContactMobilePhone = "" if(null != body.Partners[i].License_Info){ for(int j = 0 ; j < body.Partners[i].License_Info.size(); j++){ body.Partners[i].License_Info[j].Principal = "" body.Partners[i].License_Info[j].BusinessAddress = "" } } if ("23" == bpType){ //bpType 为23时不加密 continue } def contactDataId = idUtils.nextId() Contact contact = new Contact() String name = body.Partners[i].Consignee_Info[k].ContactName String contactPhone = body.Partners[i].Consignee_Info[k].ContactPhone String contactAddress = body.Partners[i].Consignee_Info[k].ContactAddress String contactEnglishName = body.Partners[i].Consignee_Info[k].ContactEnglishName // 邮政编码 String postalCode = body.Partners[i].Consignee_Info[k].PostalCode contact.setDataId(Long.parseLong(contactDataId)) contact.setMobilePhone(contactPhone) contact.setMobilePhoneD(contactPhone) if (StringUtils.isNotBlank(contactEnglishName) && "22".equals(bpType)) { contact.setLastName(name + '(' + contactEnglishName + ')') contact.setContactEnglishName(contactEnglishName) contact.setFirstName(null) } else { contact.setLastName(name) contact.setFirstName(null) } contact.setAddress1("22".equals(bpType) ? registerAddress : contactAddress) contact.setAddress1D("22".equals(bpType) ? registerAddress : contactAddress) contact.setEnglishAddress("22".equals(bpType) ? englishAddress : null) body.Partners[i].RegisterAddress = StringUtils.isNotBlank(registerAddress) ? DesensitiveUtils.getFieldDesensitive(DesensitiveType.ADDRESS) : "" body.Partners[i].Consignee_Info[k].ContactName = StringUtils.isNotBlank(name) ? DesensitiveUtils.getFieldDesensitive(DesensitiveType.CHINESE_NAME) : "" body.Partners[i].Consignee_Info[k].ContactPhone = StringUtils.isNotBlank(contactPhone) ? DesensitiveUtils.getFieldDesensitive(DesensitiveType.MOBILE_PHONE) : "" body.Partners[i].Consignee_Info[k].ContactEnglishName = StringUtils.isNotBlank(contactEnglishName) ? DesensitiveUtils.getFieldDesensitive(DesensitiveType.CHINESE_NAME) : "" //body.Partners[i].Consignee_Info[k].EnglishAddress = null//StringUtils.isNotBlank(contact.getEnglishAddress()) ? DesensitiveUtils.getFieldDesensitive(DesensitiveType.ADDRESS) : "" body.Partners[i].Consignee_Info[k].remove("EnglishAddress") body.Partners[i].Consignee_Info[k].ContactAddress = StringUtils.isNotBlank(contactAddress) ? DesensitiveUtils.getFieldDesensitive(DesensitiveType.ADDRESS) : "" body.Partners[i].Consignee_Info[k].PostalCode = StringUtils.isNotBlank(postalCode) ? DesensitiveUtils.getFieldDesensitive(DesensitiveType.ZIP_CODE) : "" body.Partners[i].RegisterAddressEncrypted = com.common.core.utils.SM4Utils.encryptStr(registerAddress) body.Partners[i].Consignee_Info[k].ContactNameEncrypted = com.common.core.utils.SM4Utils.encryptStr(name) body.Partners[i].Consignee_Info[k].ContactPhoneEncrypted = com.common.core.utils.SM4Utils.encryptStr(contactPhone) body.Partners[i].Consignee_Info[k].ContactAddressEncrypted = com.common.core.utils.SM4Utils.encryptStr(contactAddress) body.Partners[i].Consignee_Info[k].ContactEnglishNameEncrypted = StringUtils.isNotBlank(contactEnglishName) ? com.common.core.utils.SM4Utils.encryptStr(contactEnglishName) : "" //body.Partners[i].Consignee_Info[k].EnglishAddressEncrypted = null//StringUtils.isNotBlank(contact.getEnglishAddress()) ? com.common.core.utils.SM4Utils.encryptStr(englishAddress) : "" body.Partners[i].Consignee_Info[k].remove("EnglishAddressEncrypted") body.Partners[i].Consignee_Info[k].PostalCodeEncrypted = com.common.core.utils.SM4Utils.encryptStr(postalCode) body.Partners[i].Consignee_Info[k].DataId = contactDataId contact.save() } } } ResponseEntity sfRes = RestUtil.postNative(uri + "SBG203/execute", header, null, JSONObject.toJSONString(body,SerializerFeature.WriteMapNullValue)) resp.setStatus(sfRes.getStatusCodeValue()) result = sfRes.getBody().getJSONObject("staticResponse") Boolean sfStatus = sfRes.getBody().get("SFStatus") if (!sfStatus) { return false } return true } catch(HttpServerErrorException e){ log.log(new Level("ERROR", Integer.MAX_VALUE, "ch.qos.logback.classic.Logger"), "203请求异常", e) resp.setStatus(e.getRawStatusCode()) result = JSON.parse(e.getResponseBodyAsString()) return false } catch (Exception e) { log.log(new Level("ERROR",Integer.MAX_VALUE, "ch.qos.logback.classic.Logger"), "203请求异常", e) resp.setStatus(Integer.valueOf(ResultCodeEnum.AWS_RT_ERROR.getCode())) result = [[errorCode: 500, message: e.getMessage()]] as JSONArray return false } }) return result } @RequestMapping(value = "/comparaEncrypt", method = RequestMethod.POST) def comparaEncrypt(@RequestBody encryptBody){ def root = new ArrayList() for(int i = 0 ; i < encryptBody.size() ; i++){ def node = [:] def encrypt = encryptBody[i]; node.encryptStr = encrypt.encryptStr node.unencryptStr = encrypt.unencryptStr boolean flag = false; try{ flag = com.common.core.utils.SM4Utils.decryptStr(encrypt.encryptStr.toString()).equals(encrypt.unencryptStr.toString()) }catch(Exception e){ flag = false; } if(flag){ node.ismatch = "true" }else{ node.ismatch = "false" } root.add(node) } return root } }