From f9b40885618932786646184a45a70874ff7860dd Mon Sep 17 00:00:00 2001 From: luoyang Date: Mon, 11 Mar 2019 15:19:51 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E7=99=BB=E5=87=BA=E3=80=81=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=AF=86=E7=A0=81=E3=80=81=E5=95=86=E6=88=B7=E8=BF=9B?= =?UTF-8?q?=E4=BB=B6=E3=80=81=E5=95=86=E6=88=B7=E5=88=97=E8=A1=A8=E3=80=81?= =?UTF-8?q?=E5=95=86=E6=88=B7=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../appclient/core/ManageAppService.java | 17 ++++ .../core/impls/ManageAppServiceImp.java | 80 +++++++++++++++++++ .../appclient/web/ManageAppController.java | 53 +++++++++++- .../system/ManageDeviceTokenMapper.java | 25 ++++++ .../system/ManageDeviceTokenMapper.xml | 9 +++ 5 files changed, 182 insertions(+), 2 deletions(-) create mode 100644 src/main/java/au/com/royalpay/payment/manage/mappers/system/ManageDeviceTokenMapper.java create mode 100644 src/main/resources/au/com/royalpay/payment/manage/mappers/system/ManageDeviceTokenMapper.xml diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/core/ManageAppService.java b/src/main/java/au/com/royalpay/payment/manage/appclient/core/ManageAppService.java index c8b001d75..8a32cb867 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/core/ManageAppService.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/core/ManageAppService.java @@ -1,5 +1,8 @@ package au.com.royalpay.payment.manage.appclient.core; +import au.com.royalpay.payment.manage.merchants.beans.ClientRegisterInfo; +import au.com.royalpay.payment.manage.merchants.beans.PartnerQuery; +import au.com.royalpay.payment.manage.signin.beans.ChangePwdBean; import com.alibaba.fastjson.JSONObject; import java.util.List; @@ -8,6 +11,20 @@ public interface ManageAppService { void updateDevToken(JSONObject device, String devToken); + void updateDevTokenStatus(String devId, int status); + + JSONObject getDevTokenByDevId(String dev_id); + + void sign_out(JSONObject device); + + void changeAccountPassword(JSONObject device, ChangePwdBean change, String manager_id); + List getReferrerList(JSONObject device); + JSONObject registerClient(JSONObject device, ClientRegisterInfo registery); + + List listPartners(JSONObject device, PartnerQuery query); + + JSONObject clientDetail(JSONObject device, String clientMoniker); + } diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/ManageAppServiceImp.java b/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/ManageAppServiceImp.java index 7a1cd2098..db2c72541 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/ManageAppServiceImp.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/ManageAppServiceImp.java @@ -1,11 +1,22 @@ package au.com.royalpay.payment.manage.appclient.core.impls; import au.com.royalpay.payment.manage.appclient.core.ManageAppService; +import au.com.royalpay.payment.manage.mappers.system.ManageDeviceTokenMapper; +import au.com.royalpay.payment.manage.mappers.system.ManagerMapper; import au.com.royalpay.payment.manage.mappers.system.OrgMapper; +import au.com.royalpay.payment.manage.merchants.beans.ClientRegisterInfo; +import au.com.royalpay.payment.manage.merchants.beans.PartnerQuery; +import au.com.royalpay.payment.manage.merchants.core.ClientManager; +import au.com.royalpay.payment.manage.signin.beans.ChangePwdBean; +import au.com.royalpay.payment.manage.signin.core.ManagerAccountsService; +import au.com.royalpay.payment.manage.signin.core.SignInAccountService; import au.com.royalpay.payment.tools.device.DeviceSupport; import au.com.royalpay.payment.tools.device.ManageDeviceSupport; +import au.com.royalpay.payment.tools.device.support.DeviceRegister; +import au.com.royalpay.payment.tools.exceptions.ForbiddenException; import com.alibaba.fastjson.JSONObject; import com.github.miemiedev.mybatis.paginator.domain.PageBounds; +import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -18,16 +29,85 @@ public class ManageAppServiceImp implements ManageAppService { private ManageDeviceSupport manageDeviceSupport; @Resource private OrgMapper orgMapper; + @Resource + private ManagerMapper managerMapper; + @Resource + private ClientManager clientManager; + @Resource + private SignInAccountService signInAccountService; + @Resource + private ManageDeviceTokenMapper manageDeviceTokenMapper; + @Override public void updateDevToken(JSONObject device, String devToken) { manageDeviceSupport.updateDeviceMessageToken(device, devToken); } + @Override + public void sign_out(JSONObject device) { + String clientType = device.getString("client_type"); + DeviceRegister register = manageDeviceSupport.findRegister(clientType); + register.manageSignout(device); + } + + @Override + public void changeAccountPassword(JSONObject device, ChangePwdBean change, String manager_id) { + String clientType = device.getString("client_type"); + manageDeviceSupport.findRegister(clientType); + // JSONObject client = signInAccountService.getClient(account_id); + if (!manager_id.equals(device.getString("manager_id"))) { + throw new ForbiddenException("You have no permission"); + } + signInAccountService.changeManagerPassword(device, change); + updateDevTokenStatus(device.getString("dev_id"), 0); + } + @Override public List getReferrerList(JSONObject device) { String clientType = device.getString("client_type"); manageDeviceSupport.findRegister(clientType); return orgMapper.listOrgs(1,new PageBounds()); } + + @Override + public JSONObject registerClient(JSONObject device, ClientRegisterInfo registery) { + String clientType = device.getString("client_type"); + manageDeviceSupport.findRegister(clientType); + JSONObject manager = managerMapper.findById(device.getString("manager_id")); + return clientManager.registerClient(null, registery, manager); + } + + @Override + public List listPartners(JSONObject device, PartnerQuery query) { + String clientType = device.getString("client_type"); + manageDeviceSupport.findRegister(clientType); + JSONObject manager = managerMapper.findById(device.getString("manager_id")); + return clientManager.listPartners( manager, query); + } + + @Override + public JSONObject clientDetail(JSONObject device, String clientMoniker) { + String clientType = device.getString("client_type"); + manageDeviceSupport.findRegister(clientType); + JSONObject manager = managerMapper.findById(device.getString("manager_id")); + return clientManager.clientDetail(manager, clientMoniker); + } + + @Override + public void updateDevTokenStatus(String devId, int status) { + JSONObject devTokenObj = getDevTokenByDevId(devId); + if (devTokenObj != null) { + devTokenObj.put("is_valid", status); + manageDeviceTokenMapper.update(devTokenObj); + } + } + + @Override + @Cacheable(value = ":dev_message_token:", key = "#dev_id") + public JSONObject getDevTokenByDevId(String dev_id) { + return manageDeviceTokenMapper.findByDevId(dev_id); + } + + } diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/web/ManageAppController.java b/src/main/java/au/com/royalpay/payment/manage/appclient/web/ManageAppController.java index f4606143d..350644e4a 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/web/ManageAppController.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/web/ManageAppController.java @@ -1,16 +1,26 @@ package au.com.royalpay.payment.manage.appclient.web; import au.com.royalpay.payment.manage.appclient.core.ManageAppService; +import au.com.royalpay.payment.manage.merchants.beans.ClientRegisterInfo; +import au.com.royalpay.payment.manage.merchants.beans.PartnerQuery; +import au.com.royalpay.payment.manage.permission.manager.ManagerMapping; +import au.com.royalpay.payment.manage.signin.beans.ChangePwdBean; import au.com.royalpay.payment.tools.CommonConsts; -import au.com.royalpay.payment.tools.device.ManageDeviceSupport; +import au.com.royalpay.payment.tools.connections.attachment.core.AttachmentClient; +import au.com.royalpay.payment.tools.http.HttpUtils; +import au.com.royalpay.payment.tools.permission.enums.ManagerRole; import com.alibaba.fastjson.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.validation.Errors; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import javax.validation.Valid; import java.util.List; + @RestController @RequestMapping("/api/v1.0/manage/app") public class ManageAppController { @@ -18,14 +28,53 @@ public class ManageAppController { @Resource private ManageAppService manageAppService; + @Resource + private AttachmentClient attachmentClient; @RequestMapping(value = "/token", method = RequestMethod.PUT) public void updateDevToken(@ModelAttribute(CommonConsts.MANAGER_DEVICE) JSONObject device, @RequestBody JSONObject token) { manageAppService.updateDevToken(device, token.getString("devToken")); } + @RequestMapping(value = "/sign_out", method = RequestMethod.PUT) + public void signOut(@ModelAttribute(CommonConsts.MANAGER_DEVICE) JSONObject device) { + manageAppService.sign_out(device); + } + + @RequestMapping(value = "/manager_password/{manager_id}", method = RequestMethod.PUT) + public void changePassword(@ModelAttribute(CommonConsts.MANAGER_DEVICE) JSONObject device, @PathVariable String manager_id, + @RequestBody @Valid ChangePwdBean change, Errors errors) { + HttpUtils.handleValidErrors(errors); + manageAppService.changeAccountPassword(device, change, manager_id); + } + @RequestMapping(value = "/referrer", method = RequestMethod.GET) public List getReferrerList(@ModelAttribute(CommonConsts.MANAGER_DEVICE) JSONObject device, @RequestBody JSONObject token) { - return manageAppService.getReferrerList(device); + return manageAppService.getReferrerList(device); + } + + @RequestMapping(value = "/attachment/files", method = RequestMethod.POST) + public JSONObject uploadImage(@ModelAttribute(CommonConsts.MANAGER_DEVICE) JSONObject device, @RequestParam MultipartFile file) throws Exception { + return attachmentClient.uploadFile(file, false); } + + @RequestMapping(value = "/merchant/register", method = RequestMethod.POST) + public JSONObject registerPartner(@ModelAttribute(CommonConsts.MANAGER_DEVICE) JSONObject device, @RequestBody @Valid ClientRegisterInfo registery, + Errors errors){ + HttpUtils.handleValidErrors(errors); + return manageAppService.registerClient(device, registery); + } + + @RequestMapping(value = "/merchants", method = RequestMethod.GET) + public List listPartners(@ModelAttribute(CommonConsts.MANAGER_DEVICE) JSONObject device, PartnerQuery query) { + return manageAppService.listPartners(device, query); + } + + @RequestMapping(value = "/merchant/{clientMoniker}/detail", method = RequestMethod.GET) + public JSONObject getClientByMoniker(@PathVariable String clientMoniker, @ModelAttribute(CommonConsts.MANAGER_DEVICE) JSONObject device) { + return manageAppService.clientDetail(device, clientMoniker); + } + + + } diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/system/ManageDeviceTokenMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/system/ManageDeviceTokenMapper.java new file mode 100644 index 000000000..7a758ad85 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/system/ManageDeviceTokenMapper.java @@ -0,0 +1,25 @@ +package au.com.royalpay.payment.manage.mappers.system; + +import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper; +import cn.yixblog.support.mybatis.autosql.annotations.AutoSql; +import cn.yixblog.support.mybatis.autosql.annotations.SqlType; +import com.alibaba.fastjson.JSONObject; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * Created by yixian on 2016-09-12. + */ +@AutoMapper(tablename = "sys_manage_devices_token", pkName = "dev_token_id") +public interface ManageDeviceTokenMapper { + + JSONObject findByDevId(@Param("dev_id") String devDevId); + + @AutoSql(type = SqlType.UPDATE) + void update(JSONObject devInfo); + + @AutoSql(type = SqlType.INSERT) + void save(JSONObject devTokenInfo); + +} diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/system/ManageDeviceTokenMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/system/ManageDeviceTokenMapper.xml new file mode 100644 index 000000000..df785f3e7 --- /dev/null +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/system/ManageDeviceTokenMapper.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file