欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

对接小程序接口

程序员文章站 2022-03-04 13:33:33
...
@Api(name = "wholesale.customer.lists")
	public Object getList(WholeSaleCustomerRequest request) throws Exception {
		String tips = "批发客户列表";
		PagerResult<Map<String, Object>> result = new PagerResult<>();
		try{
			String tenantId = getTenantId();
			
			Pager pager = new Pager();
			pager.setPageSize(request.getPageSize());
			pager.setPageNumber(request.getPageNumber());
			
			String url  = ossconfig.getAccessDomain()+"/";
			String sql = "SELECT CONCAT(c.`id`, '''') AS         id,c.`tenantId`,c.workerId,c.code,c.`name`,c.contact,c.mobile,c.`storageAddress`,cl.`name` AS levelName,c.`address`,c.`totalAmount`,c.`unpaidAmount`  FROM ls_customer c"
					+ "	LEFT JOIN ls_customer_level cl ON c.levelId = cl.id "
					+ "WHERE c.`tenantId` = ''{0}'' ";
			
			if (StringUtils.isNotBlank(request.getKeyWord())) {
				sql += " and (  c.code like ''%" + request.getKeyWord() + "%'' " + " or c.rem like ''%" + request.getKeyWord()
						+ "%'' or c.name like ''%" + request.getKeyWord() + "%'' ) ";
			}
			
			sql = MessageFormat.format(sql, tenantId);
		
			pager = customerService.selectPager(tenantId, sql, pager);
			List<Map<String, Object>> data = (List<Map<String, Object>>)pager.getList();
			
			Set<String> workerIds=new HashSet<String>();
			for(int i=0;i<data.size();i++) {
				Object workerIdObj = data.get(i).get("workerId");
				if(workerIdObj != null && StringUtils.isNotBlank(workerIdObj.toString()){
					workerIds.add(workerIdObj.toString());
				}
				data.get(i).put("storageAddress", url+data.get(i).get("storageAddress"));
			}
			
			Criteria criteria=new Criteria();
			criteria.add(Restrictions.in("id", workerIds));
			List<Worker> workerList=workerService.getList(tenantId, criteria);
			
			for(Worker worker:workerList) {
				for(Map<String,Object> customerMap:data) {
					Object workerIdObj = customerMap.get("workerId");
					if(workerIdObj != null && 
                              StringUtils.isNotBlank(workerIdObj.toString()) &&                     
                               workerIdObj.toString().equals(worker.getId())) {
						      customerMap.put("worker", worker);
					}
				}
			}
			
			
			result.setPageCount(pager.getPageCount());
			result.setPageNumber(pager.getPageNumber());
			result.setPageSize(pager.getPageSize());
			result.setTotalCount(pager.getTotalCount());
			result.setList(data);
		}catch(Exception ex){
			logger.error(tips + "发生异常", ex);
			throw new ApiException("{open.error_9}");
		}
		return result;
	}

 

相关标签: 接口