Search in sources :

Example 46 with ApiRest

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);
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) ApiRest(build.dream.common.api.ApiRest) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 47 with 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);
}
Also used : ApiRest(build.dream.common.api.ApiRest) OfflinePosModel(build.dream.catering.models.pos.OfflinePosModel) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 48 with 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);
}
Also used : ObtainVipInfoModel(build.dream.catering.models.vip.ObtainVipInfoModel) ApiRest(build.dream.common.api.ApiRest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 49 with 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, "获取订单配送记录成功!");
}
Also used : SearchModel(build.dream.common.utils.SearchModel) BigInteger(java.math.BigInteger) ApiRest(build.dream.common.api.ApiRest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 50 with ApiRest

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;
}
Also used : JSONObject(net.sf.json.JSONObject) SearchModel(build.dream.common.utils.SearchModel) BigInteger(java.math.BigInteger) ApiRest(build.dream.common.api.ApiRest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ApiRest (build.dream.common.api.ApiRest)187 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)101 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)101 BigInteger (java.math.BigInteger)78 HashMap (java.util.HashMap)68 IOException (java.io.IOException)59 JSONObject (net.sf.json.JSONObject)56 Transactional (org.springframework.transaction.annotation.Transactional)36 SearchModel (build.dream.common.utils.SearchModel)19 Branch (build.dream.common.erp.catering.domains.Branch)14 ArrayList (java.util.ArrayList)8 SimpleDateFormat (java.text.SimpleDateFormat)6 Map (java.util.Map)6 GoodsCategory (build.dream.common.erp.catering.domains.GoodsCategory)5 SaveBuyGiveActivityModel (build.dream.catering.models.activity.SaveBuyGiveActivityModel)2 SaveSpecialGoodsActivityModel (build.dream.catering.models.activity.SaveSpecialGoodsActivityModel)2 SaveDietOrderModel (build.dream.catering.models.dietorder.SaveDietOrderModel)2 Pos (build.dream.common.erp.catering.domains.Pos)2 Vip (build.dream.common.erp.catering.domains.Vip)2 UpdateModel (build.dream.common.utils.UpdateModel)2