use of build.dream.common.api.ApiRest in project erp-catering by liuyandong33.
the class PosController method uploadFile.
@RequestMapping(value = "/uploadFile")
@ResponseBody
public String uploadFile(HttpServletRequest httpServletRequest) {
ApiRest apiRest = null;
Map<String, String> requestParameters = ApplicationHandler.getRequestParameters();
try {
Validate.isTrue(httpServletRequest instanceof MultipartHttpServletRequest, "请上传文件!");
MultipartHttpServletRequest multipartHttpServletRequest = (MultipartHttpServletRequest) httpServletRequest;
MultipartFile multipartFile = multipartHttpServletRequest.getFile("file");
Validate.notNull(multipartFile, "请上传文件!");
String tenantId = requestParameters.get("tenantId");
ApplicationHandler.notBlank(tenantId, "tenantId");
String branchId = requestParameters.get("branchId");
ApplicationHandler.notBlank(branchId, "branchId");
String userId = requestParameters.get("userId");
ApplicationHandler.notBlank(userId, "userId");
String type = requestParameters.get("type");
ApplicationHandler.notBlank(type, "type");
String originalFilename = multipartFile.getOriginalFilename();
String posDataPath = ConfigurationUtils.getConfiguration(Constants.POS_DATA_PATH);
String directoryPath = null;
if ("database".equals(type)) {
directoryPath = posDataPath + File.separator + tenantId + File.separator + branchId + File.separator + userId + File.separator + "databases";
} else if ("log".equals(type)) {
directoryPath = posDataPath + File.separator + tenantId + File.separator + branchId + File.separator + userId + File.separator + "logs";
}
File directory = new File(directoryPath);
if (!directory.exists()) {
directory.mkdirs();
}
File file = new File(directoryPath + File.separator + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + originalFilename);
multipartFile.transferTo(file);
apiRest = new ApiRest();
apiRest.setMessage("上传文件成功!");
} catch (Exception e) {
LogUtils.error("上传文件失败", controllerSimpleName, "uploadFile", e, requestParameters);
apiRest = new ApiRest(e);
}
return GsonUtils.toJson(apiRest);
}
use of build.dream.common.api.ApiRest in project erp-catering by liuyandong33.
the class PosController method offlinePos.
/**
* 下线POS
*
* @return
*/
@RequestMapping(value = "/offlinePos")
@ResponseBody
public String offlinePos() {
ApiRest apiRest = null;
Map<String, String> requestParameters = ApplicationHandler.getRequestParameters();
try {
OfflinePosModel offlinePosModel = ApplicationHandler.instantiateObject(OfflinePosModel.class, requestParameters);
offlinePosModel.validateAndThrow();
apiRest = posService.offlinePos(offlinePosModel);
} catch (Exception e) {
LogUtils.error("下线POS", controllerSimpleName, "offlinePos", e, requestParameters);
apiRest = new ApiRest(e);
}
return GsonUtils.toJson(apiRest);
}
use of build.dream.common.api.ApiRest in project erp-catering by liuyandong33.
the class VipController method obtainVipInfo.
/**
* 获取会员信息
*
* @return
*/
@RequestMapping(value = "/obtainVipInfo")
@ResponseBody
public String obtainVipInfo() {
ApiRest apiRest = null;
Map<String, String> requestParameters = ApplicationHandler.getRequestParameters();
try {
ObtainVipInfoModel obtainVipInfoModel = ApplicationHandler.instantiateObject(ObtainVipInfoModel.class, requestParameters);
obtainVipInfoModel.validateAndThrow();
apiRest = vipService.obtainVipInfo(obtainVipInfoModel);
} catch (Exception e) {
LogUtils.error("获取会员信息失败", controllerSimpleName, "obtainVipInfo", e, requestParameters);
apiRest = new ApiRest(e);
}
return GsonUtils.toJson(apiRest);
}
use of build.dream.common.api.ApiRest in project erp-catering by liuyandong33.
the class AnubisService method obtainDeliveryStates.
/**
* 获取订单配送记录
*
* @param obtainDeliveryStatesModel
* @return
*/
@Transactional(readOnly = true)
public ApiRest obtainDeliveryStates(ObtainDeliveryStatesModel obtainDeliveryStatesModel) {
BigInteger tenantId = obtainDeliveryStatesModel.getTenantId();
BigInteger branchId = obtainDeliveryStatesModel.getBranchId();
BigInteger dietOrderId = obtainDeliveryStatesModel.getDietOrderId();
SearchModel searchModel = new SearchModel(true);
searchModel.addSearchCondition("tenant_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, tenantId);
searchModel.addSearchCondition("branch_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, branchId);
searchModel.addSearchCondition("diet_order_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, dietOrderId);
List<DietOrderDeliveryState> dietOrderDeliveryStates = dietOrderDeliveryStateMapper.findAll(searchModel);
return new ApiRest(dietOrderDeliveryStates, "获取订单配送记录成功!");
}
use of build.dream.common.api.ApiRest in project erp-catering by liuyandong33.
the class AnubisService method handleAnubisCallback.
/**
* 处理蜂鸟配送系统回调
*
* @param callbackRequestBody
* @return
* @throws UnsupportedEncodingException
*/
@Transactional(rollbackFor = Exception.class)
public ApiRest handleAnubisCallback(String callbackRequestBody) throws IOException {
JSONObject callbackRequestBodyJsonObject = JSONObject.fromObject(callbackRequestBody);
String data = URLDecoder.decode(callbackRequestBodyJsonObject.getString("data"), Constants.CHARSET_NAME_UTF_8);
String appId = ConfigurationUtils.getConfiguration(Constants.ANUBIS_APP_ID);
String signature = callbackRequestBodyJsonObject.getString("signature");
int salt = callbackRequestBodyJsonObject.getInt("salt");
Validate.isTrue(AnubisUtils.verifySignature(appId, data, salt, signature), "签名验证未通过!");
JSONObject dataJsonObject = JSONObject.fromObject(data);
String orderNumber = dataJsonObject.getString("partner_order_code");
SearchModel searchModel = new SearchModel(true);
searchModel.addSearchCondition("order_number", Constants.SQL_OPERATION_SYMBOL_EQUALS, orderNumber);
DietOrder dietOrder = dietOrderMapper.find(searchModel);
Validate.notNull(dietOrder, "订单不存在!");
DietOrderDeliveryState dietOrderDeliveryState = new DietOrderDeliveryState();
dietOrderDeliveryState.setTenantId(dietOrder.getTenantId());
dietOrderDeliveryState.setTenantCode(dietOrder.getTenantCode());
dietOrderDeliveryState.setBranchId(dietOrder.getBranchId());
dietOrderDeliveryState.setDietOrderId(dietOrder.getId());
dietOrderDeliveryState.setDietOrderNumber(orderNumber);
dietOrderDeliveryState.setStatus(dataJsonObject.getInt("order_status"));
dietOrderDeliveryState.setCarrierDriverName(dataJsonObject.optString("carrier_driver_name", null));
dietOrderDeliveryState.setCarrierDriverPhone(dataJsonObject.optString("carrier_driver_phone", null));
dietOrderDeliveryState.setDescription(dataJsonObject.optString("description", null));
dietOrderDeliveryState.setStationName(dataJsonObject.optString("station_name", null));
dietOrderDeliveryState.setStationTel(dataJsonObject.optString("station_tel", null));
int cancelReason = dataJsonObject.optInt("cancel_reason", -1);
dietOrderDeliveryState.setCancelReason(cancelReason == -1 ? null : cancelReason);
dietOrderDeliveryState.setErrorCode(dataJsonObject.optString("error_code", null));
dietOrderDeliveryState.setAddress(dataJsonObject.optString("address", null));
dietOrderDeliveryState.setLongitude(dataJsonObject.optString("longitude", null));
dietOrderDeliveryState.setLatitude(dataJsonObject.optString("latitude", null));
BigInteger userId = BigInteger.ZERO;
dietOrderDeliveryState.setCreateUserId(userId);
dietOrderDeliveryState.setLastUpdateUserId(userId);
long pushTime = dataJsonObject.getLong("push_time");
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(pushTime);
dietOrderDeliveryState.setPushTime(calendar.getTime());
dietOrderDeliveryStateMapper.insert(dietOrderDeliveryState);
ApiRest apiRest = new ApiRest();
apiRest.setMessage("处理成功!");
apiRest.setSuccessful(true);
return apiRest;
}
Aggregations