CustomerInterLowerServiceImpl.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. package com.jkcredit.invoice.credit.custInterface;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.jkcredit.invoice.common.DataResult;
  4. import com.jkcredit.invoice.mapper.customer.CustomerMapper;
  5. import com.jkcredit.invoice.mapper.customer.CustomerRecMapper;
  6. import com.jkcredit.invoice.model.entity.customer.Customer;
  7. import com.jkcredit.invoice.model.entity.customer.CustomerRec;
  8. import com.jkcredit.invoice.service.customer.CustomerService;
  9. import com.jkcredit.invoice.service.lowerService.CustomeLowerService;
  10. import com.jkcredit.invoice.util.*;
  11. import lombok.extern.slf4j.Slf4j;
  12. import org.apache.commons.lang3.StringUtils;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Service;
  15. import java.util.ArrayList;
  16. import java.util.List;
  17. @Service("customerInterLowerService")
  18. @Slf4j
  19. public class CustomerInterLowerServiceImpl implements CustomerInterLowerService {
  20. @Autowired
  21. CustomeLowerService lowerService;
  22. @Autowired
  23. CustomerService customerService;
  24. @Autowired
  25. CustomerMapper customerMapper;
  26. @Autowired
  27. CustomerRecMapper customerRecMapper;
  28. /**
  29. * 无车 自有车 企业注册
  30. * @param appKey
  31. * @param api
  32. * @param data
  33. * @return
  34. */
  35. @Override
  36. public DataResult customeInterRec(String appKey, String api, String data,String requestid) {
  37. long costtimestart = System.currentTimeMillis();
  38. DataResult result = new DataResult();
  39. result.setData(3);
  40. result.setCode(200);
  41. result.setRequestid(requestid);
  42. result.setMsg("无法认证");
  43. try {
  44. log.info("[-CustomerInterLowerServiceImpl.customeInterRec-] request appKey=" + appKey + " ,api=" + api + " ,data=" +data+ " ,requestid=" +requestid);
  45. JSONObject jsonObject = JSONObject.parseObject(data);
  46. Integer interType = 0;//0-接口 1-平台 3.手工录入
  47. String name = jsonObject.getString("name");//公司名称 companyName
  48. String taxpayerCode = jsonObject.getString("taxplayerCode");//企业税号 companyReferencenum
  49. String customerName = appKey;//客户名称
  50. Customer cust = customerMapper.selectByCustomerName(customerName);
  51. /**
  52. * 所属类型:
  53. *1-行业用户 2-自营平台 3-合作商户
  54. */
  55. Integer companyType = jsonObject.getInteger("companyType");
  56. /**
  57. * 运用类型:
  58. * 1-快递
  59. 2-速运
  60. 3-货运代理
  61. 4-普通货运
  62. 5-专线运输
  63. 6-其他
  64. * 运营范围
  65. */
  66. Integer operatingRangeType = jsonObject.getInteger("operatingRangeType");
  67. String contact = jsonObject.getString("contact");//联系人
  68. String tel = jsonObject.getString("tel");//联系人电话
  69. String emergencyContact = jsonObject.getString("emergencyContact");//紧急联系人 companyLeader
  70. String emergencyTel = jsonObject.getString("emergencyTel");//紧急联系人电话 companyLeaderPhone
  71. String buyerName = jsonObject.getString("buyerName");//购方客户名称
  72. String buyerTaxpayerCode = jsonObject.getString("buyerTaxpayerCode");//购方税号
  73. String buyerAddr = jsonObject.getString("buyerAddr");//购方单位地址
  74. String buyerTel = jsonObject.getString("buyerTel");//购方电话
  75. String buyerBank = jsonObject.getString("buyerBank");//购方开户行
  76. String buyerBankAccount = jsonObject.getString("buyerBankAccount");//购方银行账号
  77. if(StringUtils.isEmpty(data)|| null == jsonObject
  78. || StringUtils.isEmpty(name)
  79. || StringUtils.isEmpty(taxpayerCode)
  80. || StringUtils.isEmpty(customerName)
  81. || null == companyType
  82. || null == operatingRangeType
  83. || StringUtils.isEmpty(emergencyContact)
  84. || StringUtils.isEmpty(emergencyTel)
  85. || StringUtils.isEmpty(contact)
  86. || StringUtils.isEmpty(tel)
  87. || StringUtils.isEmpty(buyerName)
  88. || StringUtils.isEmpty(buyerTaxpayerCode)
  89. || StringUtils.isEmpty(buyerAddr)
  90. || StringUtils.isEmpty(buyerTel)
  91. || StringUtils.isEmpty(buyerBank)
  92. || StringUtils.isEmpty(buyerBankAccount)
  93. ){
  94. return result;
  95. }
  96. CustomerRec customerRec = new CustomerRec();
  97. customerRec.setCustomerName(customerName);//客户名称
  98. customerRec.setCompanyLeader(contact);//紧急联系人
  99. customerRec.setCompanyLeaderPhone(tel);//紧急联系人电话
  100. customerRec.setCompanyName(name);//企业名称
  101. customerRec.setCompanyReferencenum(taxpayerCode);//企业税号
  102. customerRec.setCompanyOpenbank(buyerBank);//公司开户行
  103. customerRec.setCompanyOpenbankAcc(buyerBankAccount);//公司开户行电话
  104. customerRec.setCompanyAdress(buyerAddr);//公司地址
  105. customerRec.setCompanyPhone(buyerTel);//公司电话
  106. customerRec.setInterType(interType);////0-接口 1-平台
  107. customerRec.setBussinessType(String.valueOf(cust.getBussinessType()));//业务类型 0 -自有车 1-外协车 2-无车
  108. customerRec.setOperatingRangeType(operatingRangeType);//运用类型
  109. customerRec.setCompanyType(companyType);//所属类型
  110. // customerRec.setServiceStartTime(serviceStartTime);//服务开始时间
  111. // customerRec.setServiceEndTime(serviceEndTime);//服务结束时间
  112. // customerRec.setServiceType(serviceType);//协议类型
  113. // customerRec.setContractFileName(contractFileName);//协议名称
  114. // customerRec.setBase64Str(base64Str);//协议base64编码
  115. List<CustomerRec> customerRecs = new ArrayList<CustomerRec>();
  116. customerRecs.add(customerRec);
  117. RespR rs = lowerService.customeRec(customerRecs);
  118. long costtimeend = System.currentTimeMillis();
  119. log.info("[-CustomerInterLowerServiceImpl.customeInterRec-] result is "
  120. + rs.toString() + ", request is " + data + " ,costtime="
  121. + (costtimeend - costtimestart));
  122. //返回成功
  123. if(null != rs && rs.getCode() == 0){
  124. RespR rs1 = customerService.customeRec(customerRec);
  125. log.info("[-CustomerInterLowerServiceImpl.customeInterRecRc1-] result is "
  126. + rs1.toString() + ", request is " + data + " ,costtime="
  127. + (System.currentTimeMillis() - costtimestart));
  128. if(null != rs1 && rs1.getCode() == 0){
  129. result.setData(1);
  130. result.setCode(200);
  131. result.setMsg(rs1.getMsg());
  132. return result;
  133. }else {
  134. result.setData(3);
  135. result.setCode(200);
  136. result.setMsg(rs1.getMsg());
  137. return result;
  138. }
  139. } else {
  140. result.setData(3);
  141. result.setCode(200);
  142. result.setMsg("无法认证");
  143. return result;
  144. }
  145. } catch (Exception e) {
  146. log.error("[-CustomerInterLowerServiceImpl.customeInterRec-] get httpclient exception is "
  147. + e + ", request is " + data);
  148. }
  149. return result;
  150. }
  151. /**
  152. * 无车 自有车企业查询
  153. * @param appKey
  154. * @param api
  155. * @param data
  156. * @return
  157. */
  158. @Override
  159. public DataResult customeInterRecQuery(String appKey, String api, String data,String requestid) {
  160. long costtimestart = System.currentTimeMillis();
  161. DataResult result = new DataResult();
  162. result.setData(3);
  163. result.setCode(200);
  164. result.setRequestid(requestid);
  165. result.setMsg("无法认证");
  166. try {
  167. log.info("[-CustomerInterLowerServiceImpl.customeInterRecQuery-] request appKey=" + appKey + " ,api=" + api + " ,data=" +data+ " ,requestid=" +requestid);
  168. JSONObject jsonObject = JSONObject.parseObject(data);
  169. String companyName = jsonObject.getString("companyName");//企业名称
  170. String taxpayerCode = jsonObject.getString("taxplayerCode");//企业税号
  171. if(StringUtils.isEmpty(data)|| null == jsonObject){
  172. return result;
  173. }
  174. if( StringUtils.isEmpty(companyName) && StringUtils.isEmpty(taxpayerCode)){
  175. result.setMsg("查询错误");
  176. result.setCode(9998);
  177. return result;
  178. }
  179. CustomerRec customerRec = new CustomerRec();
  180. customerRec.setCompanyName(companyName);
  181. customerRec.setCompanyReferencenum(taxpayerCode);
  182. RespR rs = customerService.customerRecQuery(customerRec);
  183. long costtimeend = System.currentTimeMillis();
  184. log.info("[-CustomerInterLowerServiceImpl.customeInterRecQuery-] result is "
  185. + rs.toString() + ", request is " + data + " ,costtime="
  186. + (costtimeend - costtimestart));
  187. if(null != rs && rs.getCode() == 0){
  188. result.setData(1);
  189. result.setCode(200);
  190. result.setMsg(rs.getData().toString());
  191. return result;
  192. } else {
  193. result.setData(3);
  194. result.setCode(200);
  195. result.setMsg(rs.getMsg());
  196. return result;
  197. }
  198. } catch (Exception e) {
  199. log.error("[-CustomerInterLowerServiceImpl.customeInterRecQuery-] get httpclient exception is "
  200. + e + ", request is " + data);
  201. }
  202. return result;
  203. }
  204. @Override
  205. public DataResult customeProtocolUpLoad(String appKey, String api, String data, String requestid) {
  206. long costtimestart = System.currentTimeMillis();
  207. DataResult result = new DataResult();
  208. result.setData(3);
  209. result.setCode(200);
  210. result.setRequestid(requestid);
  211. result.setMsg("无法认证");
  212. try {
  213. log.info("[-CustomerInterLowerServiceImpl.customeProtocolUpLoad-] request appKey=" + appKey + " ,api=" + api + " ,data=" +data+ " ,requestid=" +requestid);
  214. JSONObject jsonObject = JSONObject.parseObject(data);
  215. String companyNum = jsonObject.getString("companyNum");//公司编号
  216. String serviceStartTime = jsonObject.getString("serviceStartTime");//服务开始时间
  217. String serviceEndTime = jsonObject.getString("serviceEndTime");//服务结束时间
  218. String contractFileName = jsonObject.getString("contractFileName");//协议文件名
  219. String base64Str = jsonObject.getString("base64Str");//上传文件转换的base64
  220. Integer serviceType = jsonObject.getInteger("serviceType");//协议类型
  221. if(StringUtils.isEmpty(data)|| null == jsonObject){
  222. return result;
  223. }
  224. if( StringUtils.isEmpty(companyNum) || StringUtils.isEmpty(serviceStartTime)
  225. || StringUtils.isEmpty(serviceEndTime)
  226. || StringUtils.isEmpty(contractFileName)
  227. || StringUtils.isEmpty(base64Str)
  228. || null == serviceType){
  229. return result;
  230. }
  231. CustomerRec customerRec2 = new CustomerRec();
  232. customerRec2.setCustomerName(appKey);
  233. customerRec2.setCompanyNum(companyNum);
  234. CustomerRec customerRec1 = customerRecMapper.selectByCustomerNameAndCompanyNum(customerRec2);
  235. if (null == customerRec1 || customerRec1.getRecStatus() != 1){
  236. result.setMsg("企业还未备案成功!");
  237. return result;
  238. }
  239. /* if((Base64Util.base64FileSize(base64Str)/1024)> 10){
  240. result.setMsg("pdf不可超过10M!");
  241. return result;
  242. }*/
  243. String fileType = contractFileName.substring(contractFileName.lastIndexOf(".") + 1, contractFileName.length()).toLowerCase();
  244. if(!fileType.equals("pdf")){
  245. result.setMsg("必须是pdf文件!");
  246. return result;
  247. }
  248. CustomerRec customerRec = new CustomerRec();
  249. customerRec.setServiceStartTime(DateUtil.getDistanceHoursFormat(serviceStartTime));//服务开始时间
  250. customerRec.setServiceEndTime(DateUtil.getDistanceHoursFormat(serviceEndTime));//服务结束时间
  251. customerRec.setServiceType(serviceType);//协议类型
  252. customerRec.setLowerFileName(contractFileName);//协议名称
  253. customerRec.setLowerBase64Str(base64Str.replaceAll(" ","+"));//协议base64编码
  254. customerRec.setCustomerName(appKey);//客户名称
  255. customerRec.setCompanyNum(companyNum);
  256. customerRec.setInterType(0);//接口
  257. List<CustomerRec> customerRecs = new ArrayList<CustomerRec>();
  258. customerRecs.add(customerRec);
  259. RespR rs = lowerService.customeRecUpload(customerRecs);
  260. long costtimeend = System.currentTimeMillis();
  261. log.info("[-CustomerInterLowerServiceImpl.customeProtocolUpLoad-] result is "
  262. + rs.toString() + ", request is " + data + " ,costtime="
  263. + (costtimeend - costtimestart));
  264. if(null != rs && rs.getCode() == 0){
  265. result.setData(1);
  266. result.setCode(200);
  267. result.setMsg(rs.getMsg());
  268. return result;
  269. } else {
  270. result.setData(3);
  271. result.setCode(200);
  272. result.setMsg(rs.getMsg());
  273. return result;
  274. }
  275. } catch (Exception e) {
  276. log.error("[-CustomerInterLowerServiceImpl.customeProtocolUpLoad-] get httpclient exception is "
  277. + e + ", request is " + data);
  278. }
  279. return result;
  280. }
  281. }