使用@WebService註解開發介面
@WebService
public class CrmForDWOrderService{
private String ACCOUNT = "test";
private String PASSWORD = "test1234";
//設定表頭驗證,只有驗證通過才能夠呼叫介面的方法
private boolean autoUser(String userAccount, String password) {
if (ACCOUNT.equals(userAccount) && PASSWORD.equals(password)) {
return true;
} else {
return false;
}
}
//寫介面方法,以JSON格式獲取資料存入資料庫中
public AjaxJson addOrder(@WebParam(name = "userName", header = true) String userName,
@WebParam(name = "password", header = true) String password,
@WebParam(name = "crmAccount") String crmAccount, @WebParam(name = "clientId") Integer clientId,
@WebParam(name = "erpCode") String erpCode, @WebParam(name = "orderNum") String orderNum,
@WebParam(name = "contractPrice") Double contractPrice, @WebParam(name = "orderSort") String orderSort,
@WebParam(name = "orderType") String orderType) {
AjaxJson ajaxJson = new AjaxJson();
try {
if (this.autoUser(userName, password)) {
CrmUser crmUser = crmUserService.findCrmUserByAccount(crmAccount);
CrmClient crmClient = crmClientService.findCrmClientById(clientId);
CrmDivision crmDivision = crmDivisionService.findCrmDivisionByCode("C");
CrmShop crmShop = crmShopService.findCrmShopById(crmClient.getCrmShop().getId());
Integer orderSortTemp = null;
Integer orderTypeTemp = null;
if (CrmOrderConstants.DW_ORDER_SORT.D.getValue().equals(orderSort)) {
orderSortTemp = CrmOrderConstants.DW_ORDER_SORT.D.getKey();
}
if (CrmOrderConstants.DW_ORDER_TYPE.D.getValue().equals(orderSort)) {
orderTypeTemp = CrmOrderConstants.DW_ORDER_TYPE.D.getKey();
}
if (crmUser != null && crmShop != null) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
CrmDWOrder crmDWOrder = new CrmDWOrder();
crmDWOrder.setClientId(clientId);
crmDWOrder.setShopId(crmShop.getId());
crmDWOrder.setOrderNumber(orderNum);
crmDWOrder.setMergeNumber(orderNum);
crmDWOrder.setContractPrice(contractPrice);
crmDWOrder.setCreateUserId(crmUser.getId());
crmDWOrder.setCreateDate(sdf.parse(sdf.format(new Date())));
crmDWOrder.setModifyDate(new Date());
crmDWOrder.setDivisionId(crmDivision.getId());
crmDWOrder.setOrderSort(orderSortTemp);
crmDWOrder.setOrderType(orderTypeTemp);
crmDWOrder.setOrderStatus(1);
CrmShopDivision csd = getCrmShopDivisionByOrderType(crmDWOrder.getShopId(),
crmDWOrder.getOrderType());
System.out.println("addOrder-csd="+csd.getRegionId()+","+csd.getTerritoryId());
if (csd != null) {
crmDWOrder.setRegionId(csd.getRegionId());
crmDWOrder.setTerritoryId(csd.getTerritoryId());
}
crmDWOrderService.insertCrmDWOrder(crmDWOrder);
} else {
ajaxJson.setSuccess(false);
ajaxJson.setMessage("使用者或門店不存在");
}
} else {
ajaxJson.setSuccess(false);
ajaxJson.setMessage("身份驗證錯誤");
}
} catch (Exception e) {
log.error("呼叫新增訂單接口出錯!", e);
ajaxJson.setSuccess(false);
ajaxJson.setMessage("引數錯誤");
}
return ajaxJson;
}
//通過EndPoint(端點服務)釋出一個WebService
public static void main(String[] args) {
/*引數:1,本地的服務地址; 2,提供服務的類; */
System.out.println("釋出成功!");
}
}