diff --git a/epmet-auth/pom.xml b/epmet-auth/pom.xml index d96a621883..838cf9a1bd 100644 --- a/epmet-auth/pom.xml +++ b/epmet-auth/pom.xml @@ -122,6 +122,12 @@ 2.0.0 compile + + com.epmet + oper-crm-client + 2.0.0 + compile + diff --git a/epmet-auth/src/main/java/com/epmet/dto/form/GovWxmpFormDTO.java b/epmet-auth/src/main/java/com/epmet/dto/form/GovWxmpFormDTO.java index 8bab423dec..55abfd3bce 100644 --- a/epmet-auth/src/main/java/com/epmet/dto/form/GovWxmpFormDTO.java +++ b/epmet-auth/src/main/java/com/epmet/dto/form/GovWxmpFormDTO.java @@ -19,5 +19,9 @@ public class GovWxmpFormDTO extends LoginCommonFormDTO implements Serializable { */ @NotBlank(message = "wxCode不能为空",groups = {AddUserInternalGroup.class}) private String wxCode; + /** + * appId + */ + private String appId; } diff --git a/epmet-auth/src/main/java/com/epmet/dto/form/LoginByWxCodeFormDTO.java b/epmet-auth/src/main/java/com/epmet/dto/form/LoginByWxCodeFormDTO.java index 8ddfe9edff..3f59baf4d7 100644 --- a/epmet-auth/src/main/java/com/epmet/dto/form/LoginByWxCodeFormDTO.java +++ b/epmet-auth/src/main/java/com/epmet/dto/form/LoginByWxCodeFormDTO.java @@ -29,4 +29,6 @@ public class LoginByWxCodeFormDTO extends LoginCommonFormDTO implements Serializ * 加密算法的初始向量 */ private String iv; + + private String appId; } diff --git a/epmet-auth/src/main/java/com/epmet/dto/form/ResiWxPhoneFormDTO.java b/epmet-auth/src/main/java/com/epmet/dto/form/ResiWxPhoneFormDTO.java index f0148b3c14..f710be379e 100644 --- a/epmet-auth/src/main/java/com/epmet/dto/form/ResiWxPhoneFormDTO.java +++ b/epmet-auth/src/main/java/com/epmet/dto/form/ResiWxPhoneFormDTO.java @@ -32,4 +32,6 @@ public class ResiWxPhoneFormDTO implements Serializable { */ @NotBlank(message = "iv不能为空",groups = {AddUserInternalGroup.class}) private String iv; + + private String appId; } diff --git a/epmet-auth/src/main/java/com/epmet/redis/CustomerAppWxServiceUtil.java b/epmet-auth/src/main/java/com/epmet/redis/CustomerAppWxServiceUtil.java new file mode 100644 index 0000000000..a9f5f4901a --- /dev/null +++ b/epmet-auth/src/main/java/com/epmet/redis/CustomerAppWxServiceUtil.java @@ -0,0 +1,98 @@ +/** + * Copyright (c) 2018 人人开源 All rights reserved. + *

+ * https://www.renren.io + *

+ * 版权所有,侵权必究! + */ + +package com.epmet.redis; + +import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; +import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl; +import com.alibaba.fastjson.JSON; +import com.epmet.commons.tools.redis.RedisKeys; +import com.epmet.commons.tools.redis.RedisUtils; +import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.CustomerAppDTO; +import com.epmet.dto.form.CustomerAppSecretFormDTO; +import com.epmet.feign.OperCrmOpenFeignClient; +import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; + +import javax.annotation.PostConstruct; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * 客户app Redis + * + * @author Mark sunlightcs@gmail.com + * @since 1.0.0 + */ +@Component +public class CustomerAppWxServiceUtil { + private Logger logger = LogManager.getLogger(CustomerAppWxServiceUtil.class); + + /** + * 过期时长为30分钟,单位:秒 + */ + private final static long MINUTE_THIRTY_EXPIRE = 60 * 60 * 24 * 7L; + private final static String JSON_STR = "JSON"; + + @Autowired + private RedisUtils redisUtils; + @Autowired + private OperCrmOpenFeignClient operCrmOpenFeignClient; + + private static Map maServices = Maps.newHashMap(); + @PostConstruct + private void initWxMa() { + Result> configAllAppResult = operCrmOpenFeignClient.getConfigAllApp(); + if (configAllAppResult != null && configAllAppResult.success() && CollectionUtils.isEmpty(configAllAppResult.getData())) { + maServices = configAllAppResult.getData().stream() + .map(a -> { + WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl(); + config.setAppid(a.getAppId()); + config.setSecret(a.getSecret()); + config.setMsgDataFormat(JSON_STR); + + WxMaService service = new WxMaServiceImpl(); + service.setWxMaConfig(config); + return service; + }).collect(Collectors.toMap(s -> s.getWxMaConfig().getAppid(), a -> a)); + } + logger.info("initWxMa success:{}", JSON.toJSONString(maServices)); + } + public WxMaService getWxMaService(String appId) { + WxMaService wxMaService = maServices.get(appId); + if (wxMaService == null){ + logger.error("getMaService appId:{} is not config from customer_app",appId); + } + return wxMaService; + } + public String get(String appId) { + String key = RedisKeys.getAppSecretKey(appId); + String secret = (String) redisUtils.get(key); + if (StringUtils.isBlank(secret)) { + CustomerAppSecretFormDTO param = new CustomerAppSecretFormDTO(); + param.setAppId(appId); + Result result = operCrmOpenFeignClient.getSecretByAppId(param); + if (result.success()) { + secret = result.getData(); + if (StringUtils.isNotBlank(secret)) { + redisUtils.set(key, secret, MINUTE_THIRTY_EXPIRE); + } + } + } + return secret; + } + +} diff --git a/epmet-auth/src/main/java/com/epmet/service/LoginService.java b/epmet-auth/src/main/java/com/epmet/service/LoginService.java index 248e7c4d97..a0e429eff9 100644 --- a/epmet-auth/src/main/java/com/epmet/service/LoginService.java +++ b/epmet-auth/src/main/java/com/epmet/service/LoginService.java @@ -45,11 +45,12 @@ public interface LoginService { * @return cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult * @param app * @param wxCode + * @param appId 非必填 * @Author yinzuomei * @Description 解析wxCode * @Date 2020/4/19 0:24 **/ - WxMaJscode2SessionResult getWxMaUser(String app, String wxCode); + WxMaJscode2SessionResult getWxMaUser(String app, String wxCode, String appId); /** * @return java.lang.String diff --git a/epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java b/epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java index 406ae0fe6f..6e6c16f6bb 100644 --- a/epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java +++ b/epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java @@ -141,7 +141,7 @@ public class GovLoginServiceImpl implements GovLoginService { @Override public UserTokenResultDTO loginByWxCode(GovWxmpFormDTO formDTO) { //1、解析微信用户 - WxMaJscode2SessionResult wxMaJscode2SessionResult = loginService.getWxMaUser(formDTO.getApp(), formDTO.getWxCode()); + WxMaJscode2SessionResult wxMaJscode2SessionResult = loginService.getWxMaUser(formDTO.getApp(), formDTO.getWxCode(), formDTO.getAppId()); if(null!=wxMaJscode2SessionResult){ logger.info(String.format("app=%s,wxCode=%s,openId=%s",formDTO.getApp(),formDTO.getWxCode(),wxMaJscode2SessionResult.getOpenid())); } diff --git a/epmet-auth/src/main/java/com/epmet/service/impl/LoginServiceImpl.java b/epmet-auth/src/main/java/com/epmet/service/impl/LoginServiceImpl.java index 695c187105..89fbdbebb0 100644 --- a/epmet-auth/src/main/java/com/epmet/service/impl/LoginServiceImpl.java +++ b/epmet-auth/src/main/java/com/epmet/service/impl/LoginServiceImpl.java @@ -22,6 +22,7 @@ import com.epmet.feign.EpmetUserFeignClient; import com.epmet.feign.OperAccessOpenFeignClient; import com.epmet.jwt.JwtTokenProperties; import com.epmet.jwt.JwtTokenUtils; +import com.epmet.redis.CustomerAppWxServiceUtil; import com.epmet.service.CaptchaService; import com.epmet.service.LoginService; import com.epmet.utils.WxMaServiceUtils; @@ -66,6 +67,8 @@ public class LoginServiceImpl implements LoginService { @Autowired private OperAccessOpenFeignClient operAccessOpenFeignClient; + @Autowired + private CustomerAppWxServiceUtil customerAppWxServiceUtil; /** * 居民端微信小程序登录 @@ -82,7 +85,7 @@ public class LoginServiceImpl implements LoginService { throw new RenException("参数错误"); } //1、根据wxCode获取微信信息 - WxMaJscode2SessionResult wxMaJscode2SessionResult = this.getWxMaUser(formDTO.getApp(),formDTO.getWxCode()); + WxMaJscode2SessionResult wxMaJscode2SessionResult = this.getWxMaUser(formDTO.getApp(),formDTO.getWxCode(),formDTO.getAppId()); logger.info("openId=[" + wxMaJscode2SessionResult.getOpenid() + "]unionId=[" + wxMaJscode2SessionResult.getUnionid() + "]"); //2、根据openId查询数据库,没有则直接插入一条记录 String userId = this.getUserId(formDTO, wxMaJscode2SessionResult); @@ -109,15 +112,19 @@ public class LoginServiceImpl implements LoginService { * @date 2020/3/14 20:16 */ @Override - public WxMaJscode2SessionResult getWxMaUser(String app,String wxCode) { + public WxMaJscode2SessionResult getWxMaUser(String app,String wxCode,String appId) { WxMaJscode2SessionResult wxMaJscode2SessionResult = null; try { - if (LoginConstant.APP_GOV.equals(app)) { - wxMaJscode2SessionResult = wxMaServiceUtils.govWxMaService().jsCode2SessionInfo(wxCode); - } else if (LoginConstant.APP_OPER.equals(app)) { - wxMaJscode2SessionResult = wxMaServiceUtils.operWxMaService().jsCode2SessionInfo(wxCode); - } else if (LoginConstant.APP_RESI.equals(app)) { - wxMaJscode2SessionResult = wxMaServiceUtils.resiWxMaService().jsCode2SessionInfo(wxCode); + if (StringUtils.isNotBlank(appId)){ + wxMaJscode2SessionResult = customerAppWxServiceUtil.getWxMaService(appId).jsCode2SessionInfo(wxCode); + }else{ + if (LoginConstant.APP_GOV.equals(app)) { + wxMaJscode2SessionResult = wxMaServiceUtils.govWxMaService().jsCode2SessionInfo(wxCode); + } else if (LoginConstant.APP_OPER.equals(app)) { + wxMaJscode2SessionResult = wxMaServiceUtils.operWxMaService().jsCode2SessionInfo(wxCode); + } else if (LoginConstant.APP_RESI.equals(app)) { + wxMaJscode2SessionResult = wxMaServiceUtils.resiWxMaService().jsCode2SessionInfo(wxCode); + } } } catch (WxErrorException e) { log.error("->[getMaOpenId]::error[{}]", "解析微信code失败"); @@ -137,7 +144,12 @@ public class LoginServiceImpl implements LoginService { String phone=""; try { ValidatorUtils.validateEntity(formDTO, ResiWxPhoneFormDTO.AddUserInternalGroup.class); - WxMaService wxMaService = wxMaServiceUtils.resiWxMaService(); + WxMaService wxMaService = null; + if (StringUtils.isNotBlank(formDTO.getAppId())){ + wxMaService = customerAppWxServiceUtil.getWxMaService(formDTO.getAppId()); + }else{ + wxMaService = wxMaServiceUtils.resiWxMaService(); + } WxMaJscode2SessionResult wxMaJscode2SessionResult = wxMaService.jsCode2SessionInfo(formDTO.getWxCode()); WxMaPhoneNumberInfo phoneNoInfo = wxMaService.getUserService().getPhoneNoInfo(wxMaJscode2SessionResult.getSessionKey(), formDTO.getEncryptedData(), diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java index dcf93d3a24..fc0dc2fe49 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java @@ -254,4 +254,13 @@ public class RedisKeys { return rootPrefix.concat("tags:grid:relationTag:").concat(gridId).concat(StrConstant.COLON).concat(tagId); } + /** + * appId secret 缓存Key + * @param appId + * @return + */ + public static String getAppSecretKey(String appId) { + return rootPrefix.concat("oper:crm:appid:secret").concat(appId); + } + } diff --git a/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/dto/CustomerAppDTO.java b/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/dto/CustomerAppDTO.java new file mode 100644 index 0000000000..5a58975a7d --- /dev/null +++ b/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/dto/CustomerAppDTO.java @@ -0,0 +1,97 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dto; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + + +/** + * 客户表 appId表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-07-27 + */ +@Data +public class CustomerAppDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + private String id; + + /** + * 客户Id + */ + private String customerId; + + /** + * 小程序的appId + */ + private String appId; + + /** + * resi,work + */ + private String client; + + /** + * app的secret + */ + private String secret; + + /** + * 0:停用,1:启用 + */ + private Integer enableFlag; + + /** + * 删除标识:0.未删除 1.已删除 + */ + private Integer delFlag; + + /** + * 乐观锁 + */ + private Integer revision; + + /** + * 创建人 + */ + private String createdBy; + + /** + * 创建时间 + */ + private Date createdTime; + + /** + * 更新人 + */ + private String updatedBy; + + /** + * 更新时间 + */ + private Date updatedTime; + +} \ No newline at end of file diff --git a/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/dto/form/CustomerAppSecretFormDTO.java b/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/dto/form/CustomerAppSecretFormDTO.java new file mode 100644 index 0000000000..bed538b63b --- /dev/null +++ b/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/dto/form/CustomerAppSecretFormDTO.java @@ -0,0 +1,42 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dto.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + + +/** + * 客户表 appId表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-07-27 + */ +@Data +public class CustomerAppSecretFormDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 小程序的appId + */ + @NotBlank(message = "小程序Id不能为空") + private String appId; +} \ No newline at end of file diff --git a/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/feign/OperCrmOpenFeignClient.java b/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/feign/OperCrmOpenFeignClient.java index 5b220aa698..71cc77831d 100644 --- a/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/feign/OperCrmOpenFeignClient.java +++ b/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/feign/OperCrmOpenFeignClient.java @@ -1,13 +1,16 @@ package com.epmet.feign; +import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.CustomerAppDTO; import com.epmet.dto.CustomerDTO; -import org.springframework.cloud.openfeign.FeignClient; - -import com.epmet.commons.tools.constant.ServiceConstant; +import com.epmet.dto.form.CustomerAppSecretFormDTO; import com.epmet.feign.fallback.OperCrmOpenFeignClientFallback; +import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.PostMapping; +import java.util.List; + /** * 本服务对外开放的API,其他服务通过引用此client调用该服务 * @@ -23,4 +26,19 @@ public interface OperCrmOpenFeignClient { */ @PostMapping("/oper/crm/customer/getcostomerInfo") Result getCustomerInfo(CustomerDTO dto); + + /** + * 获取客户appId信息 + * @param dto + * @return + */ + @PostMapping("/oper/crm/customerapp/getsecretbyappid") + Result getSecretByAppId(CustomerAppSecretFormDTO dto); + + /** + * 获取所有已配置的app信息 + * @return + */ + @PostMapping("/oper/crm/customerapp/getconfigallapp") + Result getConfigAllApp(); } diff --git a/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/feign/fallback/OperCrmOpenFeignClientFallback.java b/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/feign/fallback/OperCrmOpenFeignClientFallback.java index 39594aa4fe..81b74a4f7c 100644 --- a/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/feign/fallback/OperCrmOpenFeignClientFallback.java +++ b/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/feign/fallback/OperCrmOpenFeignClientFallback.java @@ -3,10 +3,14 @@ package com.epmet.feign.fallback; import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.utils.ModuleUtils; import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.CustomerAppDTO; import com.epmet.dto.CustomerDTO; +import com.epmet.dto.form.CustomerAppSecretFormDTO; import com.epmet.feign.OperCrmOpenFeignClient; import org.springframework.stereotype.Component; +import java.util.List; + /** * 本服务对外开放的API,其他服务通过引用此client调用该服务 * @@ -19,4 +23,20 @@ public class OperCrmOpenFeignClientFallback implements OperCrmOpenFeignClient { public Result getCustomerInfo(CustomerDTO dto) { return ModuleUtils.feignConError(ServiceConstant.OPER_CRM_SERVER, "getCustomerInfo", dto); } + + /** + * 获取客户appId信息 + * + * @param dto + * @return + */ + @Override + public Result getSecretByAppId(CustomerAppSecretFormDTO dto) { + return ModuleUtils.feignConError(ServiceConstant.OPER_CRM_SERVER, "getSecretByAppId", dto); + } + + @Override + public Result> getConfigAllApp() { + return ModuleUtils.feignConError(ServiceConstant.OPER_CRM_SERVER, "getConfigAllApp", null); + } } diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/controller/CustomerAppController.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/controller/CustomerAppController.java new file mode 100644 index 0000000000..90bdfd56c4 --- /dev/null +++ b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/controller/CustomerAppController.java @@ -0,0 +1,88 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.controller; + +import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.validator.ValidatorUtils; +import com.epmet.commons.tools.validator.group.AddGroup; +import com.epmet.commons.tools.validator.group.DefaultGroup; +import com.epmet.commons.tools.validator.group.UpdateGroup; +import com.epmet.dto.CustomerAppDTO; +import com.epmet.dto.form.CustomerAppSecretFormDTO; +import com.epmet.service.CustomerAppIdService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.Map; + + +/** + * 客户表 app表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-07-27 + */ +@RestController +@RequestMapping("customerapp") +public class CustomerAppController { + + @Autowired + private CustomerAppIdService customerAppIdService; + + @GetMapping("page") + public Result> page(@RequestParam Map params){ + PageData page = customerAppIdService.page(params); + return new Result>().ok(page); + } + + @GetMapping("{id}") + public Result get(@PathVariable("id") String id){ + CustomerAppDTO data = customerAppIdService.get(id); + return new Result().ok(data); + } + + @PostMapping + public Result save(@RequestBody CustomerAppDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); + customerAppIdService.save(dto); + return new Result(); + } + + @PutMapping + public Result update(@RequestBody CustomerAppDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); + customerAppIdService.update(dto); + return new Result(); + } + @PostMapping("getsecretbyappid") + public Result getSecretByAppId(@RequestBody CustomerAppSecretFormDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, DefaultGroup.class); + return new Result().ok(customerAppIdService.selectSecretByAppId(dto.getAppId())); + } + @PostMapping("getconfigallapp") + public Result> getConfigAllApp(){ + return new Result>().ok(customerAppIdService.list(null)); + } + + +} \ No newline at end of file diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/dao/CustomerAppDao.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/dao/CustomerAppDao.java new file mode 100644 index 0000000000..b69ea9fe11 --- /dev/null +++ b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/dao/CustomerAppDao.java @@ -0,0 +1,35 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dao; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.entity.CustomerAppEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + * 客户表 appId表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-07-27 + */ +@Mapper +public interface CustomerAppDao extends BaseDao { + + String selectSecretByAppId(@Param("appId") String appId); +} \ No newline at end of file diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/entity/CustomerAppEntity.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/entity/CustomerAppEntity.java new file mode 100644 index 0000000000..89d62c233d --- /dev/null +++ b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/entity/CustomerAppEntity.java @@ -0,0 +1,63 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 客户表 appId表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-07-27 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("customer_app") +public class CustomerAppEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 客户Id + */ + private String customerId; + + /** + * 小程序的appId + */ + private String appId; + + /** + * resi,work + */ + private String client; + + /** + * app的secret + */ + private String secret; + + /** + * 0:停用,1:启用 + */ + private Integer enableFlag; + +} diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/CustomerAppIdService.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/CustomerAppIdService.java new file mode 100644 index 0000000000..3da3da447d --- /dev/null +++ b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/CustomerAppIdService.java @@ -0,0 +1,92 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.service; + +import com.epmet.commons.mybatis.service.BaseService; +import com.epmet.commons.tools.page.PageData; +import com.epmet.dto.CustomerAppDTO; +import com.epmet.entity.CustomerAppEntity; + +import java.util.List; +import java.util.Map; + +/** + * 客户表 appId表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-07-27 + */ +public interface CustomerAppIdService extends BaseService { + + /** + * 默认分页 + * + * @param params + * @return PageData + * @author generator + * @date 2020-07-27 + */ + PageData page(Map params); + + /** + * 默认查询 + * + * @param params + * @return java.util.List + * @author generator + * @date 2020-07-27 + */ + List list(Map params); + + /** + * 单条查询 + * + * @param id + * @return CustomerAppIdDTO + * @author generator + * @date 2020-07-27 + */ + CustomerAppDTO get(String id); + + /** + * 默认保存 + * + * @param dto + * @return void + * @author generator + * @date 2020-07-27 + */ + void save(CustomerAppDTO dto); + + /** + * 默认更新 + * + * @param dto + * @return void + * @author generator + * @date 2020-07-27 + */ + void update(CustomerAppDTO dto); + + /** + * desc:获取客户app secret + * @param appId + * @return + */ + String selectSecretByAppId(String appId); +} \ No newline at end of file diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerAppIdServiceImpl.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerAppIdServiceImpl.java new file mode 100644 index 0000000000..44dfa97eb9 --- /dev/null +++ b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerAppIdServiceImpl.java @@ -0,0 +1,96 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.commons.tools.constant.FieldConstant; +import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.dao.CustomerAppDao; +import com.epmet.dto.CustomerAppDTO; +import com.epmet.entity.CustomerAppEntity; +import com.epmet.service.CustomerAppIdService; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Map; + +/** + * 客户表 appId表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-07-27 + */ +@Service +public class CustomerAppIdServiceImpl extends BaseServiceImpl implements CustomerAppIdService { + + @Override + public PageData page(Map params) { + IPage page = baseDao.selectPage( + getPage(params, FieldConstant.CREATED_TIME, false), + getWrapper(params) + ); + return getPageData(page, CustomerAppDTO.class); + } + + @Override + public List list(Map params) { + List entityList = baseDao.selectList(getWrapper(params)); + + return ConvertUtils.sourceToTarget(entityList, CustomerAppDTO.class); + } + + private QueryWrapper getWrapper(Map params){ + String id = (String)params.get(FieldConstant.ID_HUMP); + + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); + + return wrapper; + } + + @Override + public CustomerAppDTO get(String id) { + CustomerAppEntity entity = baseDao.selectById(id); + return ConvertUtils.sourceToTarget(entity, CustomerAppDTO.class); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(CustomerAppDTO dto) { + CustomerAppEntity entity = ConvertUtils.sourceToTarget(dto, CustomerAppEntity.class); + insert(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(CustomerAppDTO dto) { + CustomerAppEntity entity = ConvertUtils.sourceToTarget(dto, CustomerAppEntity.class); + updateById(entity); + } + + @Override + public String selectSecretByAppId(String appId) { + return baseDao.selectSecretByAppId(appId); + } + +} \ No newline at end of file diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/resources/CustomerAppDao.xml b/epmet-module/oper-crm/oper-crm-server/src/main/resources/CustomerAppDao.xml new file mode 100644 index 0000000000..599ef18c59 --- /dev/null +++ b/epmet-module/oper-crm/oper-crm-server/src/main/resources/CustomerAppDao.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file