CustomerController.java 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package net.chenlin.dp.modules.api.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.fasterxml.jackson.databind.ObjectMapper;
  4. import net.chenlin.dp.common.openapi4j.exception.OpenAPIException;
  5. import net.chenlin.dp.common.support.orm.db.DynamicDataSource;
  6. import net.chenlin.dp.common.utils.SpringContextUtils;
  7. import net.chenlin.dp.modules.api.dao.CustomerMapper;
  8. import net.chenlin.dp.modules.api.service.CustomerService;
  9. import net.chenlin.dp.modules.api.vo.ICustomer;
  10. import net.chenlin.dp.modules.api.vo.ICustomerEdit;
  11. import net.chenlin.dp.modules.api.vo.YonyouSaleOrder;
  12. import java.util.HashMap;
  13. import java.util.List;
  14. import java.util.Map;
  15. public class CustomerController {
  16. private CustomerService customerService=new CustomerService();
  17. private CustomerMapper customerMapper= SpringContextUtils.getBean("customerMapper",CustomerMapper.class);
  18. /**
  19. * u8客户档案新增接口
  20. * @throws OpenAPIException
  21. */
  22. public void addCustomer() throws OpenAPIException {
  23. customerService.getToaccount();
  24. try {
  25. List<Map<String,Object>> iCustomers = customerService.CrmCustomer();
  26. if (iCustomers!=null &&iCustomers.size()>0){
  27. for (Map<String,Object> i:iCustomers){
  28. String s = customerService.addCustomer(i);
  29. Object customer = i.get("customer");
  30. ObjectMapper objectMapper = new ObjectMapper();
  31. ICustomer zfsp = objectMapper.convertValue(customer, ICustomer.class);
  32. if (s.equals("0")){
  33. DynamicDataSource.setDataSource("last-data-source");
  34. customerMapper.UpdateCustomer(zfsp.getCode(),"ok","1");
  35. DynamicDataSource.setDataSource("");
  36. }else {
  37. DynamicDataSource.setDataSource("last-data-source");
  38. customerMapper.UpdateCustomer(zfsp.getCode(),s,"1");
  39. DynamicDataSource.setDataSource("");
  40. }
  41. }
  42. }
  43. }catch (Exception e){
  44. e.printStackTrace();
  45. }
  46. }
  47. /**
  48. * 客户档案修改接口
  49. * @throws OpenAPIException
  50. */
  51. public void ICustomerEdit() throws OpenAPIException {
  52. customerService.getToaccount();
  53. DynamicDataSource.setDataSource("last-data-source");
  54. List<ICustomerEdit> iCustomerEdits = customerMapper.ICustomerEditList();
  55. DynamicDataSource.setDataSource("");
  56. if (iCustomerEdits!=null&&iCustomerEdits.size()>0){
  57. for (ICustomerEdit i:iCustomerEdits){
  58. HashMap customer = customerService.getCustomer(i.getCode());
  59. if (customer!=null&&customer.size()>0) {
  60. String s = customerService.editCustomer(i);
  61. if (s.equals("0")) {
  62. DynamicDataSource.setDataSource("last-data-source");
  63. // customerMapper.UpdateCustomer(i.getCode());
  64. DynamicDataSource.setDataSource("");
  65. }
  66. }
  67. }
  68. }
  69. }
  70. }