Search in sources :

Example 91 with ApiRest

use of build.dream.common.api.ApiRest in project erp-catering by liuyandong33.

the class PosService method initPos.

/**
 * 上线POS
 *
 * @param onlinePosModel
 * @return
 */
public ApiRest initPos(OnlinePosModel onlinePosModel) {
    BigInteger tenantId = onlinePosModel.getTenantId();
    BigInteger branchId = onlinePosModel.getBranchId();
    BigInteger userId = onlinePosModel.getUserId();
    String registrationId = onlinePosModel.getRegistrationId();
    String type = onlinePosModel.getType();
    String version = onlinePosModel.getVersion();
    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("user_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, userId);
    Pos pos = posMapper.find(searchModel);
    if (pos == null) {
        pos = new Pos();
        pos.setTenantId(tenantId);
        pos.setTenantCode(onlinePosModel.getTenantCode());
        pos.setBranchId(branchId);
        pos.setBranchCode(onlinePosModel.getBranchCode());
        pos.setUserId(userId);
        pos.setRegistrationId(registrationId);
        pos.setType(type);
        pos.setVersion(version);
        pos.setOnline(true);
        pos.setCreateUserId(userId);
        pos.setLastUpdateUserId(userId);
        pos.setLastUpdateRemark("POS不存在,新增POS并且设置为在线状态!");
        posMapper.insert(pos);
    } else {
        pos.setUserId(userId);
        pos.setRegistrationId(registrationId);
        pos.setType(type);
        pos.setVersion(version);
        pos.setOnline(true);
        pos.setLastUpdateUserId(userId);
        pos.setLastUpdateRemark("POS存在,设置为在线状态!");
        posMapper.update(pos);
    }
    return new ApiRest(pos, "上线POS成功!");
}
Also used : SearchModel(build.dream.common.utils.SearchModel) Pos(build.dream.common.erp.catering.domains.Pos) BigInteger(java.math.BigInteger) ApiRest(build.dream.common.api.ApiRest)

Example 92 with ApiRest

use of build.dream.common.api.ApiRest in project erp-catering by liuyandong33.

the class UserService method listUsers.

@Transactional(readOnly = true)
public ApiRest listUsers(Map<String, String> parameters) throws IOException {
    String tenantId = parameters.get("tenantId");
    Validate.notNull(tenantId, "参数(tenantId)不能为空!");
    String branchId = parameters.get("branchId");
    Validate.notNull(branchId, "参数(branchId)不能为空!");
    PagedSearchModel pagedSearchModel = new PagedSearchModel();
    pagedSearchModel.addSearchCondition("tenant_id", "=", BigInteger.valueOf(Long.valueOf(tenantId)));
    pagedSearchModel.addSearchCondition("branch_id", "=", BigInteger.valueOf(Long.valueOf(branchId)));
    String page = parameters.get("page");
    if (StringUtils.isBlank(page)) {
        page = "1";
    }
    String rows = parameters.get("rows");
    if (StringUtils.isBlank(rows)) {
        rows = "20";
    }
    pagedSearchModel.setPage(Integer.valueOf(page));
    pagedSearchModel.setRows(Integer.valueOf(rows));
    List<BigInteger> userIds = branchMapper.findAllUserIds(pagedSearchModel);
    Map<String, String> findAllUsersRequestParameters = new HashMap<String, String>();
    findAllUsersRequestParameters.put("userIds", StringUtils.join(userIds, ","));
    String findAllUsersResult = ProxyUtils.doGetOriginalWithRequestParameters(Constants.SERVICE_NAME_PLATFORM, "user", "findAllUsers", findAllUsersRequestParameters);
    ApiRest findAllUsersApiRest = ApiRest.fromJson(findAllUsersResult);
    Validate.isTrue(findAllUsersApiRest.isSuccessful(), findAllUsersApiRest.getError());
    Map<String, Object> data = new HashMap<String, Object>();
    long total = branchMapper.countUsers(pagedSearchModel);
    data.put("total", total);
    data.put("rows", findAllUsersApiRest.getData());
    ApiRest apiRest = new ApiRest(data, "查询员工列表成功!");
    return apiRest;
}
Also used : HashMap(java.util.HashMap) BigInteger(java.math.BigInteger) PagedSearchModel(build.dream.common.utils.PagedSearchModel) ApiRest(build.dream.common.api.ApiRest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 93 with ApiRest

use of build.dream.common.api.ApiRest in project erp-catering by liuyandong33.

the class VipService method obtainVipInfo.

/**
 * 获取会员信息
 *
 * @param obtainVipInfoModel
 * @return
 */
@Transactional(readOnly = true)
public ApiRest obtainVipInfo(ObtainVipInfoModel obtainVipInfoModel) {
    SearchModel searchModel = new SearchModel(true);
    searchModel.addSearchCondition("tenant_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, obtainVipInfoModel.getTenantId());
    searchModel.addSearchCondition("branch_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, obtainVipInfoModel.getBranchId());
    if (obtainVipInfoModel.getVipId() != null) {
        searchModel.addSearchCondition("id", Constants.SQL_OPERATION_SYMBOL_EQUALS, obtainVipInfoModel.getVipId());
    }
    if (StringUtils.isNotBlank(obtainVipInfoModel.getVipCode())) {
        searchModel.addSearchCondition("vip_code", Constants.SQL_OPERATION_SYMBOL_EQUALS, obtainVipInfoModel.getVipCode());
    }
    if (StringUtils.isNotBlank(obtainVipInfoModel.getPhoneNumber())) {
        searchModel.addSearchCondition("phone_number", Constants.SQL_OPERATION_SYMBOL_EQUALS, obtainVipInfoModel.getPhoneNumber());
    }
    if (StringUtils.isNotBlank(obtainVipInfoModel.getOpenId())) {
        searchModel.addSearchCondition("open_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, obtainVipInfoModel.getOpenId());
    }
    if (StringUtils.isNotBlank(obtainVipInfoModel.getAlipayUserId())) {
        searchModel.addSearchCondition("alipay_user_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, obtainVipInfoModel.getAlipayUserId());
    }
    Vip vip = vipMapper.find(searchModel);
    return new ApiRest(vip, "获取会员信息成功!");
}
Also used : SearchModel(build.dream.common.utils.SearchModel) Vip(build.dream.common.erp.catering.domains.Vip) ApiRest(build.dream.common.api.ApiRest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 94 with ApiRest

use of build.dream.common.api.ApiRest in project erp-catering by liuyandong33.

the class AnubisUtils method callAnubisSystem.

public static ApiRest callAnubisSystem(String url, String appId, Map<String, Object> data) throws IOException {
    String accessToken = getAccessToken();
    int salt = RandomUtils.nextInt(1000, 9999);
    String signature = generateSignature(appId, GsonUtils.toJson(data), salt, accessToken);
    Map<String, Object> requestBody = new HashMap<String, Object>();
    requestBody.put("app_id", appId);
    requestBody.put("data", data);
    requestBody.put("salt", salt);
    requestBody.put("signature", signature);
    Map<String, String> callAnubisSystemRequestParameters = new HashMap<String, String>();
    callAnubisSystemRequestParameters.put("url", url);
    callAnubisSystemRequestParameters.put("requestBody", GsonUtils.toJson(requestBody));
    ApiRest apiRest = ProxyUtils.doPostWithRequestParameters(Constants.SERVICE_NAME_OUT, "anubis", "callAnubisSystem", callAnubisSystemRequestParameters);
    return apiRest;
}
Also used : HashMap(java.util.HashMap) JSONObject(net.sf.json.JSONObject) ApiRest(build.dream.common.api.ApiRest)

Example 95 with ApiRest

use of build.dream.common.api.ApiRest in project erp-catering by liuyandong33.

the class AnubisUtils method obtainAccessToken.

public static Map<String, Object> obtainAccessToken(String url, String appId, String appSecret) throws IOException {
    int salt = RandomUtils.nextInt(1000, 9999);
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append("app_id=" + appId);
    stringBuilder.append("&salt=" + salt);
    stringBuilder.append("&secret_key=" + appSecret);
    String signature = DigestUtils.md5Hex(URLEncoder.encode(stringBuilder.toString(), Constants.CHARSET_NAME_UTF_8));
    Map<String, String> obtainAccessTokenRequestParameters = new HashMap<String, String>();
    obtainAccessTokenRequestParameters.put("url", url);
    obtainAccessTokenRequestParameters.put("appId", appId);
    obtainAccessTokenRequestParameters.put("salt", String.valueOf(salt));
    obtainAccessTokenRequestParameters.put("signature", signature);
    ApiRest obtainAccessTokenApiRest = ProxyUtils.doGetWithRequestParameters(Constants.SERVICE_NAME_OUT, "anubis", "obtainAccessToken", obtainAccessTokenRequestParameters);
    Validate.isTrue(obtainAccessTokenApiRest.isSuccessful(), obtainAccessTokenApiRest.getError());
    return (Map<String, Object>) obtainAccessTokenApiRest.getData();
}
Also used : HashMap(java.util.HashMap) ApiRest(build.dream.common.api.ApiRest) HashMap(java.util.HashMap) Map(java.util.Map)

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