From ca60e849b76fa20a898d6a68fbff14d9ac0872be Mon Sep 17 00:00:00 2001 From: DB <2502523450@qq.com> Date: Fri, 10 Nov 2023 18:35:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=95=86=E5=9F=8E=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=91=98;=E6=B7=BB=E5=8A=A0=E7=A7=AF=E5=88=86?= =?UTF-8?q?=E5=87=8F=E6=89=A3;=E6=B7=BB=E5=8A=A0=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E5=88=9B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cpop-Api/pom.xml | 5 - Cpop-Core/pom.xml | 5 + .../cpop/core/base/enums/InitRoleEnum.java | 53 +++++++ .../com/cpop/core/service/CoreService.java | 11 ++ .../core/service/impl/CoreServiceImpl.java | 27 ++++ .../strategy/login/MallLoginStrategy.java | 8 +- .../strategy/login/MiniLoginStrategy.java | 15 +- .../jambox/business/entity/BrandExtend.java | 5 - .../business/task/CardTemplateAsyncTask.java | 99 +++++++++++++ .../framework/constant/JamboxCloudUrl.java | 17 +++ .../cpop/mall/business/dto/UserPointDto.java | 27 ++++ .../cpop/mall/business/entity/Product.java | 5 + .../service/impl/OrderServiceImpl.java | 98 +++++++++++-- .../service/impl/StaffServiceImpl.java | 5 +- .../business/task/OrderDetailAsyncTask.java | 71 ++++++++++ .../buyRestrict/MemberRestrictStrategy.java | 33 +++-- .../com/cpop/oam/business/bo/MallStaffBo.java | 13 -- .../controller/OamMallController.java | 74 +++++++++- .../oam/business/service/OamMallService.java | 19 +++ .../service/impl/OamMallServiceImpl.java | 131 +++++++++++++++++- .../com/cpop/oam/business/vo/BrandListVo.java | 31 +++++ .../cpop/oam/framework/config/InitConfig.java | 42 ++++++ .../com/cpop/system/business/bo/BrandBo.java | 14 +- .../cpop/system/business/bo/BrandPageBo.java | 28 ---- .../business/controller/BrandController.java | 38 +++-- .../business/controller/MenuController.java | 3 - .../controller/SysCommonController.java | 5 +- .../system/business/service/BrandService.java | 3 +- .../service/impl/BrandServiceImpl.java | 12 +- .../service/impl/MenuServiceImpl.java | 37 +++-- 30 files changed, 799 insertions(+), 135 deletions(-) create mode 100644 Cpop-Core/src/main/java/com/cpop/core/base/enums/InitRoleEnum.java create mode 100644 Cpop-Jambox/src/main/java/com/cpop/jambox/business/task/CardTemplateAsyncTask.java create mode 100644 Cpop-Jambox/src/main/java/com/cpop/jambox/framework/constant/JamboxCloudUrl.java create mode 100644 Cpop-Mall/src/main/java/com/cpop/mall/business/dto/UserPointDto.java create mode 100644 Cpop-Mall/src/main/java/com/cpop/mall/business/task/OrderDetailAsyncTask.java create mode 100644 Cpop-Oam/src/main/java/com/cpop/oam/business/vo/BrandListVo.java create mode 100644 Cpop-Oam/src/main/java/com/cpop/oam/framework/config/InitConfig.java delete mode 100644 Cpop-System/src/main/java/com/cpop/system/business/bo/BrandPageBo.java diff --git a/Cpop-Api/pom.xml b/Cpop-Api/pom.xml index e901ef2..6695113 100644 --- a/Cpop-Api/pom.xml +++ b/Cpop-Api/pom.xml @@ -18,11 +18,6 @@ com.cpop Cpop-Core - - - com.squareup.okhttp3 - okhttp - diff --git a/Cpop-Core/pom.xml b/Cpop-Core/pom.xml index 1b56efb..85b663c 100644 --- a/Cpop-Core/pom.xml +++ b/Cpop-Core/pom.xml @@ -107,6 +107,11 @@ org.bouncycastle bcprov-jdk15on + + + com.squareup.okhttp3 + okhttp + diff --git a/Cpop-Core/src/main/java/com/cpop/core/base/enums/InitRoleEnum.java b/Cpop-Core/src/main/java/com/cpop/core/base/enums/InitRoleEnum.java new file mode 100644 index 0000000..df7aaea --- /dev/null +++ b/Cpop-Core/src/main/java/com/cpop/core/base/enums/InitRoleEnum.java @@ -0,0 +1,53 @@ +package com.cpop.core.base.enums; + +import lombok.Getter; + +/** + * 初始化角色枚举 + * @author Administrator + */ +@Getter +public enum InitRoleEnum { + /** + * OAM超级管理员角色 + */ + SUPER_OAM_ROLE("1", "SuperOamAdmin", "SuperOamAdmin", -1, UserType.OAM_USER), + /** + * MALL超级管理员角色 + */ + SUPER_MALL_ROLE("2", "SuperMallAdmin", "SuperMallAdmin", -1, UserType.MALL_USER), + ; + + /** + * 主键 + */ + private final String id; + + /** + * 角色名称 + */ + private final String roleName; + + /** + * 角色值 + */ + private final String roleValue; + + /** + * 排序 + */ + private final Integer orderNo; + + /** + * 用户类型 + */ + private final UserType userType; + + InitRoleEnum(String id, String roleName, String roleValue, Integer orderNo, UserType userType) { + this.id = id; + this.roleName = roleName; + this.roleValue = roleValue; + this.orderNo = orderNo; + this.userType = userType; + } +} diff --git a/Cpop-Core/src/main/java/com/cpop/core/service/CoreService.java b/Cpop-Core/src/main/java/com/cpop/core/service/CoreService.java index f58bc20..329edd6 100644 --- a/Cpop-Core/src/main/java/com/cpop/core/service/CoreService.java +++ b/Cpop-Core/src/main/java/com/cpop/core/service/CoreService.java @@ -140,4 +140,15 @@ public interface CoreService { * @Date: 2023/8/27 23:37 */ SysUser getSysUserByPhone(String phoneNumber, UserType userType); + + /** + * @descriptions 检查用户是否存在 + * @author DB + * @date 2023/11/10 11:57 + * @param username 用户名 + * @param id 主键 + * @param userType 用户类型 + * @return: void + */ + void isAccountExist(String username, String id, String userType); } diff --git a/Cpop-Core/src/main/java/com/cpop/core/service/impl/CoreServiceImpl.java b/Cpop-Core/src/main/java/com/cpop/core/service/impl/CoreServiceImpl.java index 191db85..cb94780 100644 --- a/Cpop-Core/src/main/java/com/cpop/core/service/impl/CoreServiceImpl.java +++ b/Cpop-Core/src/main/java/com/cpop/core/service/impl/CoreServiceImpl.java @@ -1,5 +1,6 @@ package com.cpop.core.service.impl; +import com.cpop.common.utils.StringUtils; import com.cpop.core.base.entity.LoginUser; import com.cpop.core.base.enums.OperationLogEnum; import com.cpop.core.base.enums.UserType; @@ -12,6 +13,9 @@ import com.cpop.core.service.CoreService; import com.cpop.core.utils.MessageUtils; import com.cpop.core.utils.SecurityUtils; import com.cpop.core.utils.uuid.IdUtils; +import com.mybatisflex.core.query.QueryWrapper; +import com.mybatisflex.core.row.Db; +import com.mybatisflex.core.row.DbChain; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; @@ -21,6 +25,8 @@ import java.util.Arrays; import java.util.List; import java.util.Map; +import static com.cpop.core.base.table.table.SysUserTableDef.SYS_USER; + /** * @author DB * @Description: @@ -258,4 +264,25 @@ public class CoreServiceImpl implements CoreService { public SysUser getSysUserByPhone(String phoneNumber, UserType userType) { return coreMapper.getSysUserByPhone(phoneNumber, userType.toString()); } + + /** + * @descriptions 检查用户是否存在 + * @author DB + * @date 2023/11/10 11:57 + * @param username 用户名 + * @param id 主键 + * @param userType 用户类型 + * @return: void + */ + @Override + public void isAccountExist(String username, String id, String userType) { + if (StringUtils.isBlank(username)) { + return; + } + if (DbChain.table(SYS_USER).where(SYS_USER.USER_NAME.eq(username)) + .and(SYS_USER.USER_TYPE.eq(userType)) + .and(SYS_USER.ID.ne(id)).count() > 0) { + throw new ServiceException(MessageUtils.message("i18n_alert_userIsExist")); + } + } } diff --git a/Cpop-Core/src/main/java/com/cpop/core/strategy/login/MallLoginStrategy.java b/Cpop-Core/src/main/java/com/cpop/core/strategy/login/MallLoginStrategy.java index b665ec4..da79f39 100644 --- a/Cpop-Core/src/main/java/com/cpop/core/strategy/login/MallLoginStrategy.java +++ b/Cpop-Core/src/main/java/com/cpop/core/strategy/login/MallLoginStrategy.java @@ -3,6 +3,7 @@ package com.cpop.core.strategy.login; import com.cpop.common.constant.Constants; import com.cpop.common.utils.bean.BeanUtils; import com.cpop.core.base.entity.LoginUser; +import com.cpop.core.base.entity.Permission; import com.cpop.core.base.entity.loginInfo.MallStaffLoginInfo; import com.cpop.core.base.enums.SourceType; import com.cpop.core.base.enums.UserType; @@ -10,11 +11,14 @@ import com.cpop.core.base.exception.CpopAuthenticationException; import com.cpop.core.base.table.SysUser; import com.mybatisflex.core.row.DbChain; import com.mybatisflex.core.row.Row; +import com.mybatisflex.core.row.RowUtil; import org.springframework.stereotype.Component; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; /** * @author DB @@ -85,7 +89,7 @@ public class MallLoginStrategy implements LoginStrategy{ else { permissionSet.add(Constants.ALL_PERMISSION); //TODO:测试中所有新建用户都是超级管理员 - /*//查询员工信息 + //查询员工信息 List list = DbChain.table("cp_sys_menu") .select("pom.permission") .from("cp_sys_menu").as("pom") @@ -99,7 +103,7 @@ public class MallLoginStrategy implements LoginStrategy{ } else { List permissions = RowUtil.toEntityList(list, Permission.class); permissionSet = permissions.stream().map(Permission::getPermission).collect(Collectors.toSet()); - }*/ + } } return permissionSet; } diff --git a/Cpop-Core/src/main/java/com/cpop/core/strategy/login/MiniLoginStrategy.java b/Cpop-Core/src/main/java/com/cpop/core/strategy/login/MiniLoginStrategy.java index f2a98d6..3f88ca1 100644 --- a/Cpop-Core/src/main/java/com/cpop/core/strategy/login/MiniLoginStrategy.java +++ b/Cpop-Core/src/main/java/com/cpop/core/strategy/login/MiniLoginStrategy.java @@ -7,6 +7,7 @@ import com.cpop.core.base.enums.SourceType; import com.cpop.core.base.enums.UserType; import com.cpop.core.base.exception.ServiceException; import com.cpop.core.base.table.SysUser; +import com.mybatisflex.core.row.Db; import com.mybatisflex.core.row.DbChain; import com.mybatisflex.core.row.Row; import com.mybatisflex.core.row.RowKey; @@ -112,10 +113,8 @@ public class MiniLoginStrategy implements LoginStrategy { } //保存小程序用户信息 LocalDateTime now = LocalDateTime.now(); - RowKey snowFlakeId = RowKey.SNOW_FLAKE_ID; - boolean save = DbChain.table("cp_mini_user") - .setId(snowFlakeId) - .set("user_id", loginInfo.getUserId()) + Row miniUser = Row.ofKey(RowKey.SNOW_FLAKE_ID); + miniUser.set("user_id", loginInfo.getUserId()) .set("open_id", credentials.get("openId")) .set("app_id", credentials.get("appId")) .set("brand_id", brand.getString("id")) @@ -125,16 +124,16 @@ public class MiniLoginStrategy implements LoginStrategy { .set("create_time", now) .set("update_time", now) .set("create_user_id", 1) - .set("update_user_id", 1) - .save(); - if (save){ + .set("update_user_id", 1); + int save = Db.insert("cp_mini_user", miniUser); + if (save > 0) { loginInfo.setOpenId((String) credentials.get("openId")) .setAppId((String) credentials.get("appId")) .setUserId(loginInfo.getUserId()) .setBrandId(brand.getString("id")) .setNickName((String) credentials.get("nickName")) .setAvatar((String) credentials.get("avatar")) - .setId(snowFlakeId.getValue()) + .setId(miniUser.getString("id")) .setSourceType(sourceType); } } else { diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/entity/BrandExtend.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/entity/BrandExtend.java index 32d1dfb..5308caf 100644 --- a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/entity/BrandExtend.java +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/entity/BrandExtend.java @@ -44,11 +44,6 @@ public class BrandExtend extends BaseEntity implements Serializable { */ private String brandCloudId; - /** - * 背景地址 - */ - private String backgroundUrl; - /** * 是否删除(0否1是) */ diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/task/CardTemplateAsyncTask.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/task/CardTemplateAsyncTask.java new file mode 100644 index 0000000..8592e86 --- /dev/null +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/task/CardTemplateAsyncTask.java @@ -0,0 +1,99 @@ +package com.cpop.jambox.business.task; + +import com.alibaba.fastjson.JSONObject; +import com.cpop.common.utils.DateUtils; +import com.cpop.common.utils.StringUtils; +import com.cpop.core.base.exception.ServiceException; +import com.cpop.core.utils.SpringUtils; +import com.cpop.jambox.business.entity.CardTemplate; +import com.cpop.jambox.business.service.CardTemplateService; +import com.cpop.jambox.framework.constant.JamboxCloudUrl; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import org.springframework.scheduling.annotation.Async; +import org.springframework.security.core.parameters.P; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.util.Date; + +/** + * @author DB + * @createTime 2023/11/10 17:52 + * @description 课卡模板异步任务 + */ +@Component +public class CardTemplateAsyncTask { + + /** + * 生成课卡 + */ + @Async("customAsyncThreadPool") + public void cloudCreateCard(JSONObject jsonBody,String cardTemplateId) { + try { + //查询课卡信息 + CardTemplate cardTemplate = SpringUtils.getBean(CardTemplateService.class).getById(cardTemplateId); + //课卡名称 + jsonBody.put("periodName", cardTemplate.getName()); + //时限卡 + if (cardTemplate.getTemplateType().equals(1)) { + jsonBody.put("moneyCard", true); + jsonBody.put("amount", cardTemplate.getPrice()); + } else if (cardTemplate.getTemplateType().equals(2)) { + jsonBody.put("timeLimit", true); + jsonBody.put("periodNumber", cardTemplate.getValidDay()); + jsonBody.put("periodType", cardTemplate.getTemplateType()); + } else { + // 课卡类型课时卡 + jsonBody.put("periodType", cardTemplate.getTemplateType()); + // 课卡计费类型 true false 课时卡 + jsonBody.put("timeLimit", false); + // 课时卡课时数 + jsonBody.put("periodNumber", cardTemplate.getClassNumber()); + // 课卡到期时间 + if (null != cardTemplate.getDayAppointment()){ + // 日最大约课次数 + jsonBody.put("maxFrequency", cardTemplate.getDayAppointment()); + } + if (StringUtils.isNotBlank(cardTemplate.getName())){ + // 课卡名称 + jsonBody.put("periodName", cardTemplate.getName()); + } + if (null != cardTemplate.getWeekAppointment()){ + // 周最大约课次数 + jsonBody.put("maxWeekFrequency", cardTemplate.getWeekAppointment()); + } + // 首次上课开始计有效期 + if (null != cardTemplate.getBufferDay()){ + // 最大停卡次数 + jsonBody.put("maxStopTime", cardTemplate.getBufferDay()); + } + } + //课卡有效期 + String periodExpire; + if (null != cardTemplate.getValidDay() && cardTemplate.getValidDay() > 0) { + //减一天 + Date date = DateUtils.addDateDays(new Date(), cardTemplate.getValidDay() - 1); + periodExpire = DateUtils.dateTime(date); + } else { + //TODO:可能需要调整 + periodExpire = DateUtils.parseDateToStr("yyyy-MM-dd", cardTemplate.getEndDate()); + } + jsonBody.put("periodExpire", periodExpire); + //获取课卡信息 + OkHttpClient client = new OkHttpClient().newBuilder().build(); + MediaType mediaType = MediaType.parse("application/json"); + RequestBody body = RequestBody.create(mediaType, jsonBody.toJSONString()); + Request request = new Request.Builder() + .url(JamboxCloudUrl.COMMON_CARD_URL) + .method("POST", body) + .addHeader("Content-Type", "application/json") + .build(); + client.newCall(request).execute(); + } catch (IOException e) { + throw new ServiceException(e.getMessage()); + } + } +} diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/framework/constant/JamboxCloudUrl.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/framework/constant/JamboxCloudUrl.java new file mode 100644 index 0000000..ce98eea --- /dev/null +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/framework/constant/JamboxCloudUrl.java @@ -0,0 +1,17 @@ +package com.cpop.jambox.framework.constant; + +/** + * 果酱云地址 + */ +public interface JamboxCloudUrl { + + /** + * 基础地址 + */ + String BASE_URL = "https://beibeike-qy-b33k4-1302318474.ap-shanghai.app.tcloudbase.com"; + + /** + * 课卡相关云函数 + */ + String COMMON_CARD_URL = BASE_URL + "/merchant_cloud"; +} diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/dto/UserPointDto.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/dto/UserPointDto.java new file mode 100644 index 0000000..966158d --- /dev/null +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/dto/UserPointDto.java @@ -0,0 +1,27 @@ +package com.cpop.mall.business.dto; + +import lombok.Data; + +/** + * @author DB + * @createTime 2023/11/10 16:33 + * @description + */ +@Data +public class UserPointDto { + + /** + * 总积分 + */ + private Integer totalPoint; + + /** + * 云品牌id + */ + private String brandCloudId; + + /** + * 旧用户id + */ + private String oldUserId; +} diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/entity/Product.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/entity/Product.java index 91d12c4..3215f36 100644 --- a/Cpop-Mall/src/main/java/com/cpop/mall/business/entity/Product.java +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/entity/Product.java @@ -105,6 +105,11 @@ public class Product extends BaseEntity implements Serializable { */ private BigDecimal minPrice; + /** + * 课卡模板id + */ + private String cardTemplateId; + /** * 逻辑删除(0否1是) */ diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/OrderServiceImpl.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/OrderServiceImpl.java index 0d1c75c..a914958 100644 --- a/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/OrderServiceImpl.java +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/OrderServiceImpl.java @@ -13,11 +13,15 @@ import com.cpop.core.utils.QuartzUtils; import com.cpop.core.utils.SecurityUtils; import com.cpop.core.utils.SpringUtils; import com.cpop.core.utils.sql.SqlUtils; +import com.cpop.jambox.business.entity.BrandExtend; +import com.cpop.jambox.business.service.BrandExtendService; import com.cpop.mall.business.bo.*; +import com.cpop.mall.business.dto.UserPointDto; import com.cpop.mall.business.dto.WxPayGoodsDetailDto; import com.cpop.mall.business.entity.*; import com.cpop.mall.business.mapper.OrderMapper; import com.cpop.mall.business.service.*; +import com.cpop.mall.business.task.OrderDetailAsyncTask; import com.cpop.mall.business.task.OrderOverTimeUnPayTask; import com.cpop.mall.business.task.ProductRecordSyncStockTask; import com.cpop.mall.business.task.WxPayAsyncTask; @@ -36,29 +40,34 @@ import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.WxPayService; +import com.mybatisflex.annotation.KeyType; +import com.mybatisflex.core.datasource.DataSourceKey; import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.query.QueryWrapper; +import com.mybatisflex.core.row.DbChain; +import com.mybatisflex.core.row.Row; +import com.mybatisflex.core.row.RowKey; import com.mybatisflex.spring.service.impl.ServiceImpl; import org.quartz.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDateTime; import java.util.*; import java.util.concurrent.locks.Lock; import java.util.stream.Collectors; import static com.cpop.core.base.table.table.SysUserTableDef.SYS_USER; +import static com.cpop.jambox.business.entity.table.BrandExtendTableDef.BRAND_EXTEND; import static com.cpop.mall.business.entity.table.OrderDetailTableDef.ORDER_DETAIL; import static com.cpop.mall.business.entity.table.OrderRefundTableDef.ORDER_REFUND; import static com.cpop.mall.business.entity.table.OrderTableDef.ORDER; import static com.cpop.mall.business.entity.table.ProductRecordTableDef.PRODUCT_RECORD; import static com.cpop.mall.business.entity.table.ProductTableDef.PRODUCT; -import static com.cpop.mall.business.entity.table.ShoppingCartTableDef.SHOPPING_CART; import static com.cpop.system.business.entity.table.ProfitSharingTableDef.PROFIT_SHARING; import static com.cpop.system.business.entity.table.StoreTableDef.STORE; -import static com.mybatisflex.core.query.QueryMethods.field; -import static com.mybatisflex.core.query.QueryMethods.select; +import static com.mybatisflex.core.query.QueryMethods.*; /** @@ -156,6 +165,13 @@ public class OrderServiceImpl extends ServiceImpl implements //检查库存 Map recordNumIsEnough = null; try { + //如果是积分商品,先检查积分 + if (bo.getPayType() == 1) { + UserPointDto userPoint = getUserPoint(loginUserInfo); + if (userPoint.getTotalPoint() < bo.getTotalPoint()) { + throw new ServiceException("您的积分不足!"); + } + } Order order = BeanUtils.mapToClass(bo, Order.class); List orderDetails = BeanUtils.mapToList(bo.getOrderDetailList(), OrderDetail.class); //规格记录ids @@ -303,7 +319,7 @@ public class OrderServiceImpl extends ServiceImpl implements } else { //统计支付商品情况 Map recordNumIsEnough = orderDetails.stream().collect(Collectors.toMap(OrderDetail::getProductRecordId, OrderDetail::getNumber)); - result = pointPay(recordNumIsEnough, order.getId()); + result = pointPay(recordNumIsEnough, order, loginUserInfo); //删除定时器任务 QuartzUtils quartzUtils = SpringUtils.getBean(QuartzUtils.class); quartzUtils.deleteJob(QuartzEnums.ORDER_OVERTIME_UN_PAY_TASK.getName() + order.getId(), @@ -315,6 +331,8 @@ public class OrderServiceImpl extends ServiceImpl implements .set(ORDER.RECEIVE_NAME,bo.getReceiveName()) .where(ORDER.ID.eq(bo.getId())) .update(); + //异步处理订单详情 + SpringUtils.getBean(OrderDetailAsyncTask.class).asyncProcessingOrderDetails(order, loginUserInfo, orderDetails, productList); return result; } catch (Exception e) { throw new ServiceException(e.getMessage()); @@ -330,22 +348,82 @@ public class OrderServiceImpl extends ServiceImpl implements /** * @Description: 积分支付 - * @param recordNumIsEnough - * @return * @Author DB * @Date: 2023/10/28 9:33 */ - private Object pointPay(Map recordNumIsEnough,String orderId){ + private Object pointPay(Map recordNumIsEnough, Order order, JSONObject loginUserInfo) { + UserPointDto userPoint = getUserPoint(loginUserInfo); + if (userPoint.getTotalPoint() < order.getTotalPoint()) { + throw new ServiceException("您的积分不足!"); + } + //扣除积分 + try { + LocalDateTime now = LocalDateTime.now(); + DataSourceKey.use("jambox"); + DbChain.table("t_point_record") + .setId(RowKey.of("record_id", KeyType.Auto)) + .set("user_id", userPoint.getOldUserId()) + .set("brand_id", userPoint.getBrandCloudId()) + .set("point_behaviour", 9) + .set("behaviour_record", "商城购买商品") + .set("point_change", order.getTotalPoint()) + .set("point_time", now) + .set("cumulative", userPoint.getTotalPoint() - order.getTotalPoint()) + .set("creation_by", userPoint.getOldUserId()) + .set("last_modified", userPoint.getOldUserId()) + .set("creation_time", now) + .save(); + } finally { + DataSourceKey.clear(); + } ProductRecordService productRecordService = SpringUtils.getBean(ProductRecordService.class); List productRecords = productRecordService.listByIds(recordNumIsEnough.keySet()); productRecords.forEach(item -> { item.setRecordNum(item.getRecordNum() - recordNumIsEnough.get(item.getId())); }); productRecordService.updateBatch(productRecords); - //TODO: 通知到云? //修改订单状态 - return this.updateChain().set(ORDER.ORDER_STATUS, 1).where(ORDER.ID.eq(orderId)).update(); + return this.updateChain().set(ORDER.ORDER_STATUS, 1).where(ORDER.ID.eq(order.getId())).update(); + } + /** + * @descriptions 获取当前用户积分 + * @author DB + * @date 2023/11/10 16:10 + * @param loginUserInfo 用户信息 + * @return: java.lang.Integer + */ + private UserPointDto getUserPoint(JSONObject loginUserInfo){ + //获取云品牌id + BrandExtend brandExtend = SpringUtils.getBean(BrandExtendService.class) + .getOne(QueryWrapper.create() + .where(BRAND_EXTEND.BRAND_ID.eq(loginUserInfo.getString("brandId")))); + //修改用户积分 + try { + DataSourceKey.use("jambox"); + //获取旧用户信息 + List rows = DbChain.table("t_user_info") + .select("user_id") + .where("open_id = ?", loginUserInfo.getString("openId")) + .list(); + List userIds = rows.stream().map(item -> item.getString("userId")).collect(Collectors.toList()); + Row pointChange = DbChain.table("t_point_record") + .select(sum("point_change").as("pointChange")) + .in("user_id", userIds) + .and("brand_id = ?", brandExtend.getBrandCloudId()) + .one(); + if (null == pointChange.getInt("pointChange")) { + throw new ServiceException("您的积分不足!"); + }else { + UserPointDto userPointDto = new UserPointDto(); + userPointDto.setTotalPoint(pointChange.getInt("pointChange")); + userPointDto.setBrandCloudId(brandExtend.getBrandCloudId()); + userPointDto.setOldUserId(userIds.get(0)); + return userPointDto; + } + } finally { + DataSourceKey.clear(); + } } /** @@ -568,7 +646,7 @@ public class OrderServiceImpl extends ServiceImpl implements return wxPayService.createOrder(orderRequest); } else { - return pointPay(recordNumIsEnough, order.getId()); + return pointPay(recordNumIsEnough, order, loginUserInfo); } } catch (Exception e){ //回滚库存 diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/StaffServiceImpl.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/StaffServiceImpl.java index 8fd92f5..a82937b 100644 --- a/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/StaffServiceImpl.java +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/StaffServiceImpl.java @@ -8,6 +8,7 @@ import com.cpop.core.base.entity.LoginUser; import com.cpop.core.base.entity.PageDomain; import com.cpop.core.base.entity.loginInfo.MallStaffLoginInfo; import com.cpop.core.base.entity.loginInfo.OamStaffLoginInfo; +import com.cpop.core.base.enums.InitRoleEnum; import com.cpop.core.base.enums.SourceType; import com.cpop.core.base.enums.UserType; import com.cpop.core.base.exception.ServiceException; @@ -70,7 +71,7 @@ public class StaffServiceImpl extends ServiceImpl implements , QueryWrapper.create() //去重 .select(distinct(STAFF.ALL_COLUMNS)) - .select(SYS_USER.USER_NAME,SYS_USER.NICK_NAME, SYS_USER.EMAIL, SYS_USER.PHONE_NUMBER, SYS_USER.SEX, SYS_USER.AVATAR, SYS_USER.STATUS, SYS_USER.PASSWORD) + .select(SYS_USER.USER_NAME, SYS_USER.NICK_NAME, SYS_USER.EMAIL, SYS_USER.PHONE_NUMBER, SYS_USER.SEX, SYS_USER.AVATAR, SYS_USER.STATUS, SYS_USER.PASSWORD) .select(ROLE.ROLE_NAME) .select(ROLE_BRAND.BRAND_ID) .select(BRAND.BRAND_NAME) @@ -83,6 +84,8 @@ public class StaffServiceImpl extends ServiceImpl implements //姓名 .and(STAFF.NAME.like(bo.getName())) .and(SYS_USER.USER_NAME.ne(Constants.SUPER_ADMIN).or(SYS_USER.USER_NAME.isNull())) + //不查询超级管理员 + .and(ROLE.ID.ne(InitRoleEnum.SUPER_MALL_ROLE.getId()).or(ROLE.ID.isNull())) .groupBy(STAFF.ID) , StaffPageVo.class); } diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/task/OrderDetailAsyncTask.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/task/OrderDetailAsyncTask.java new file mode 100644 index 0000000..171cba0 --- /dev/null +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/task/OrderDetailAsyncTask.java @@ -0,0 +1,71 @@ +package com.cpop.mall.business.task; + +import com.alibaba.fastjson.JSONObject; +import com.cpop.common.utils.DateUtils; +import com.cpop.core.utils.SpringUtils; +import com.cpop.jambox.business.entity.StoreExtend; +import com.cpop.jambox.business.service.CardTemplateService; +import com.cpop.jambox.business.service.StoreExtendService; +import com.cpop.jambox.business.task.CardTemplateAsyncTask; +import com.cpop.jambox.framework.constant.JamboxCloudUrl; +import com.cpop.mall.business.entity.Order; +import com.cpop.mall.business.entity.OrderDetail; +import com.cpop.mall.business.entity.Product; +import com.cpop.mall.business.entity.ProductRecord; +import com.cpop.mall.business.service.ProductRecordService; +import okhttp3.*; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static com.cpop.jambox.business.entity.table.StoreExtendTableDef.STORE_EXTEND; + +/** + * @author DB + * @createTime 2023/11/10 17:11 + * @description 订单详情异步任务 + */ +@Component +public class OrderDetailAsyncTask { + @Async("customAsyncThreadPool") + public void asyncProcessingOrderDetails(Order order, JSONObject loginUserInfo, List orderDetails, List productList) { + Map productMap = productList.stream().collect(Collectors.toMap(Product::getId, item -> item)); + List productRecords = SpringUtils.getBean(ProductRecordService.class).listByIds(orderDetails.stream().map(OrderDetail::getProductRecordId).collect(Collectors.toSet())); + Map productRecordMap = productRecords.stream().collect(Collectors.toMap(ProductRecord::getId, item -> item)); + //获取云校区id + List storeExtendList = SpringUtils.getBean(StoreExtendService.class).queryChain() + .where(STORE_EXTEND.STORE_ID.in(orderDetails.stream().map(OrderDetail::getStoreId).collect(Collectors.toSet()))) + .list(); + Map storeCloudMap = storeExtendList.stream().collect(Collectors.toMap(StoreExtend::getStoreId, StoreExtend::getStoreCloudId)); + orderDetails.forEach(item -> { + //获取当前订单记录的商品信息 + ProductRecord productRecord = productRecordMap.get(item.getProductRecordId()); + Product product = productMap.get(productRecord.getId()); + //课卡 + if (product.getProductType() == 0) { + //课卡信息 + JSONObject jsonBody = new JSONObject(); + jsonBody.put("_type", "addPeriod"); + //订单id + jsonBody.put("classCardId", order.getId()); + //办卡实收金额 + jsonBody.put("money", order.getTotalAmount()); + //店铺/校区 + jsonBody.put("storeId", storeCloudMap.get(item.getStoreId())); + //手机号 + jsonBody.put("phone", loginUserInfo.getString("phoneNumber")); + //客户名称 + jsonBody.put("customerName", loginUserInfo.getString("nickName")); + //客户性别 + jsonBody.put("customerSex", loginUserInfo.getBoolean("sex") ? "女" : "男"); + //客户地址 + jsonBody.put("customerAddress", order.getReceiveAddress()); + SpringUtils.getBean(CardTemplateAsyncTask.class).cloudCreateCard(jsonBody, product.getCardTemplateId()); + } + }); + } +} diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/framework/strategy/buyRestrict/MemberRestrictStrategy.java b/Cpop-Mall/src/main/java/com/cpop/mall/framework/strategy/buyRestrict/MemberRestrictStrategy.java index 9bac773..9af49b0 100644 --- a/Cpop-Mall/src/main/java/com/cpop/mall/framework/strategy/buyRestrict/MemberRestrictStrategy.java +++ b/Cpop-Mall/src/main/java/com/cpop/mall/framework/strategy/buyRestrict/MemberRestrictStrategy.java @@ -41,21 +41,24 @@ public class MemberRestrictStrategy implements BuyRestrictStrategy{ .where(BRAND_EXTEND.BRAND_ID.eq(loginUserInfo.getString("brandId"))) .one(); //查询当前用户是否是会员 - DataSourceKey.use("jambox"); - long count = Db.selectCountByQuery("j_membership", QueryWrapper.create() - .select() - .leftJoin("t_brand_info").on("t_brand_info.brand_id = j_membership.brand_id") - //手机号 - .where("j_membership.phone = ?", loginUserInfo.getString("phoneNumber")) - //品牌id - .and("t_brand_info.brand_id = ?", brandExtend.getBrandCloudId()) - //会员时间未过期 - .and("j_membership.end_time >= ?", LocalDate.now()) - .and("j_membership.deleted = 1")); - DataSourceKey.clear(); - //没有会员 - if (count == 0) { - throw new ServiceException("你尚未成为会员,无法购买商品:" + product.getProductName()); + try { + DataSourceKey.use("jambox"); + long count = Db.selectCountByQuery("j_membership", QueryWrapper.create() + .select() + .leftJoin("t_brand_info").on("t_brand_info.brand_id = j_membership.brand_id") + //手机号 + .where("j_membership.phone = ?", loginUserInfo.getString("phoneNumber")) + //品牌id + .and("t_brand_info.brand_id = ?", brandExtend.getBrandCloudId()) + //会员时间未过期 + .and("j_membership.end_time >= ?", LocalDate.now()) + .and("j_membership.deleted = 1")); + //没有会员 + if (count == 0) { + throw new ServiceException("你尚未成为会员,无法购买商品:" + product.getProductName()); + } + } finally { + DataSourceKey.clear(); } } } diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/bo/MallStaffBo.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/bo/MallStaffBo.java index 2ebb3bf..f01e9e8 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/business/bo/MallStaffBo.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/bo/MallStaffBo.java @@ -40,12 +40,6 @@ public class MallStaffBo implements Serializable { @ApiModelProperty(value = "品牌id") private String brandId; - /** - * 角色品牌id - */ - @ApiModelProperty("角色品牌id") - private String roleBrandId; - /** * 用户id */ @@ -106,11 +100,4 @@ public class MallStaffBo implements Serializable { @ApiModelProperty(value = "状态(0:停用;1:启用)",required = true) private Boolean status; - /** - * 角色id - */ - @NotBlank(message = "角色id不能为空") - @ApiModelProperty(value = "角色id",required = true) - private String roleId; - } diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/OamMallController.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/OamMallController.java index a3d47ff..29fac32 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/OamMallController.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/OamMallController.java @@ -1,21 +1,21 @@ package com.cpop.oam.business.controller; import com.cpop.core.base.R; +import com.cpop.core.service.CoreService; +import com.cpop.core.utils.SpringUtils; import com.cpop.oam.business.bo.MallStaffBo; -import com.cpop.oam.business.bo.MallStaffPageBo; -import com.cpop.oam.business.bo.StaffPageBo; import com.cpop.oam.business.service.OamMallService; +import com.cpop.oam.business.vo.BrandListVo; import com.cpop.oam.business.vo.MallStaffPageVo; -import com.cpop.oam.business.vo.StaffPageVo; +import com.cpop.system.business.service.BrandService; import com.mybatisflex.core.paginate.Page; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -40,10 +40,70 @@ public class OamMallController { * @param name 姓名 * @return: com.cpop.core.base.R> */ + @PreAuthorize("@aps.hasPermission('mall:admin:list')") @ApiOperation("查询商城管理员分页列表") @GetMapping("/getMallStaffPage") public R> getMallStaffPage(String brandIds, String name) { Page page = oamMallService.getMallStaffPage(brandIds, name); return R.ok(page); } + + /** + * @descriptions 查询品牌列表 + * @author DB + * @date 2023/11/10 11:45 + * @return: com.cpop.core.base.R> + */ + @ApiOperation("查询品牌列表") + @GetMapping("/getBrandList") + public R> getBrandList() { + List list = SpringUtils.getBean(BrandService.class).queryChain().listAs(BrandListVo.class); + return R.ok(list); + } + + /** + * @descriptions 用户名是否存在 + * @author DB + * @date 2023/11/10 12:03 + * @param username 用户名 + * @param id id + * @param userType 用户类型 + * @return: com.cpop.core.base.R + */ + @ApiOperation("用户名是否存在") + @GetMapping("/isAccountExist") + public R isAccountExist(@ApiParam("用户名") String username, @ApiParam("userId") String id, @ApiParam("用户类型") String userType) { + SpringUtils.getBean(CoreService.class).isAccountExist(username, id, userType); + return R.ok(); + } + + /** + * @descriptions 新增管理员 + * @author DB + * @date 2023/09/08 14:04 + * @param bo 请求参数 + * @return com.jambox.core.base.R + */ + @PreAuthorize("@aps.hasPermission('mall:admin:insert')") + @ApiOperation("新增管理员") + @PostMapping("/insertAdmin") + public R insertAdmin(@RequestBody @Validated MallStaffBo bo) { + oamMallService.insertAdmin(bo); + return R.ok(); + } + + /** + * @descriptions 删除管理员 + * @author DB + * @date 2023/11/10 14:33 + * @param id 主键 + * @return: com.cpop.core.base.R + */ + @PreAuthorize("@aps.hasPermission('mall:admin:remove')") + @ApiOperation("删除管理员") + @DeleteMapping("/removeAdmin/{id}") + public R removeAdmin(@PathVariable String id) { + oamMallService.removeAdmin(id); + return R.ok(); + } } diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/service/OamMallService.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/service/OamMallService.java index c89c7d2..0fbf8c0 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/business/service/OamMallService.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/service/OamMallService.java @@ -1,5 +1,6 @@ package com.cpop.oam.business.service; +import com.cpop.oam.business.bo.MallStaffBo; import com.cpop.oam.business.vo.MallStaffPageVo; import com.mybatisflex.core.paginate.Page; @@ -17,4 +18,22 @@ public interface OamMallService { * @return: com.mybatisflex.core.paginate.Page */ Page getMallStaffPage(String brandIds, String name); + + /** + * @descriptions 新增管理员 + * @author DB + * @date 2023/11/10 12:14 + * @param bo 请求参数 + * @return: void + */ + void insertAdmin(MallStaffBo bo); + + /** + * @descriptions 删除管理员 + * @author DB + * @date 2023/11/10 14:34 + * @param id 主键 + * @return: void + */ + void removeAdmin(String id); } diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/service/impl/OamMallServiceImpl.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/service/impl/OamMallServiceImpl.java index 09842c9..b4a2c4b 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/business/service/impl/OamMallServiceImpl.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/service/impl/OamMallServiceImpl.java @@ -1,20 +1,34 @@ package com.cpop.oam.business.service.impl; +import com.alibaba.fastjson.JSONObject; import com.cpop.common.utils.StringUtils; import com.cpop.common.utils.bean.BeanUtils; +import com.cpop.core.base.entity.LoginUser; import com.cpop.core.base.entity.PageDomain; +import com.cpop.core.base.entity.loginInfo.OamStaffLoginInfo; +import com.cpop.core.base.enums.InitRoleEnum; +import com.cpop.core.base.enums.SourceType; import com.cpop.core.base.enums.UserType; +import com.cpop.core.base.exception.ServiceException; +import com.cpop.core.base.table.SysUser; +import com.cpop.core.service.CoreService; +import com.cpop.core.service.RedisService; +import com.cpop.core.utils.*; import com.cpop.core.utils.sql.SqlUtils; +import com.cpop.core.utils.uuid.IdUtils; +import com.cpop.oam.business.bo.MallStaffBo; import com.cpop.oam.business.bo.MallStaffPageBo; +import com.cpop.oam.business.bo.StaffBo; +import com.cpop.oam.business.entity.Staff; import com.cpop.oam.business.service.OamMallService; import com.cpop.oam.business.vo.MallStaffPageVo; import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.query.QueryWrapper; -import com.mybatisflex.core.row.Db; -import com.mybatisflex.core.row.Row; -import com.mybatisflex.core.row.RowUtil; +import com.mybatisflex.core.row.*; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDateTime; import java.util.Arrays; import java.util.List; @@ -57,7 +71,116 @@ public class OamMallServiceImpl implements OamMallService { .leftJoin("cp_mall_role_brand").on("cp_mall_role_brand.id = cp_mall_staff.role_brand_id") .leftJoin("cp_sys_role").on("cp_sys_role.id = cp_mall_role_brand.role_id") .leftJoin("cp_sys_brand").on("cp_sys_brand.id = cp_mall_role_brand.brand_id") - .where(SYS_USER.USER_TYPE.eq(UserType.MALL_USER))); + .where(SYS_USER.USER_TYPE.eq(UserType.MALL_USER)) + .and("cp_mall_staff.is_delete = 0")); return rowPage.map(item -> RowUtil.toEntity(item, MallStaffPageVo.class)); } + + /** + * @descriptions 新增管理员 + * @author DB + * @date 2023/11/10 12:14 + * @param bo 请求参数 + * @return: void + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void insertAdmin(MallStaffBo bo) { + //先添加用户信息 + SysUser sysUser; + if (validatedUserInfo(bo)) { + throw new ServiceException(MessageUtils.message("i18n_alert_userOrPhoneOrEmailIsExist")); + } else { + //用户名-手机-邮箱都需要做唯一校验 + sysUser = BeanUtils.mapToClass(bo, SysUser.class); + //解密与重设密码 + decryptAndResetPasswords(sysUser); + sysUser.setId(IdUtils.fastSimpleUUID()); + //获取当前创建人员信息 + LoginUser loginUser = SecurityUtils.getInstance().getLoginUser(); + sysUser.setCreateUserId(loginUser.getUserId()); + sysUser.setUpdateUserId(loginUser.getUserId()); + sysUser.setUserType(UserType.MALL_USER.toString()); + SpringUtils.getBean(CoreService.class).insertSysUser(sysUser); + } + LocalDateTime now = LocalDateTime.now(); + //创建中间表 + Row roleBrand = Row.ofKey(RowKey.SNOW_FLAKE_ID); + roleBrand.set("brand_id", bo.getBrandId()) + .set("role_id", InitRoleEnum.SUPER_MALL_ROLE.getId()) + .set("source_type", SourceType.JAMBOX.toString()) + .set("create_time", now) + .set("update_time", now) + .set("create_user_id", 1) + .set("update_user_id", 1); + Db.insert("cp_mall_role_brand",roleBrand); + DbChain.table("cp_mall_staff") + .setId(RowKey.SNOW_FLAKE_ID) + .set("name", bo.getName()) + .set("role_brand_id", roleBrand.getString("id")) + .set("user_id", sysUser.getId()) + .set("create_time", now) + .set("update_time", now) + .set("create_user_id", 1) + .set("update_user_id", 1) + .save(); + } + + /** + * @descriptions 删除管理员 + * @author DB + * @date 2023/11/10 14:34 + * @param id 主键 + * @return: void + */ + @Override + public void removeAdmin(String id) { + //查询员工信息 + Row staff = DbChain.table("cp_mall_staff").where("id = ?", id).one(); + if (null != staff) { + DbChain.table("cp_mall_staff") + .set("is_delete", 1) + .where("id = ?", id) + .update(); + DbChain.table("cp_mall_role_brand") + .where("id = ?", staff.getString("roleBrandId")) + .remove(); + //删除系统用户 + SpringUtils.getBean(CoreService.class).removeSysUserById(staff.getString("userId")); + } + } + + /** + * @Description: 用户名-手机-邮箱都需要做唯一校验 + * @param bo 请求参数 + * @return Boolean 通过/未通过 + * @Author DB + * @Date: 2023/5/11 11:02 + **/ + private Boolean validatedUserInfo(MallStaffBo bo) { + long count = DbChain.table(SYS_USER) + //用户名 + .where(SYS_USER.USER_NAME.eq(bo.getUserName())) + //手机号 + .or(SYS_USER.PHONE_NUMBER.eq(bo.getPhoneNumber())) + .count(); + if (StringUtils.isNotBlank(bo.getUserId())) { + return count > 1; + } else { + return count > 0; + } + } + + /** + * @Description: 解密与重设密码 + * @param sysUser 系统用户 + * @Author: DB + * @Date: 2023/5/11 11:03 + **/ + private void decryptAndResetPasswords(SysUser sysUser) { + //先用rsa解密 + String password = SpringUtils.getBean(RsaUtils.class).decrypt(sysUser.getPassword()); + //再加密 + sysUser.setPassword(SpringUtils.getBean(PasswordEncoder.class).encode(password)); + } } diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/vo/BrandListVo.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/vo/BrandListVo.java new file mode 100644 index 0000000..a440f16 --- /dev/null +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/vo/BrandListVo.java @@ -0,0 +1,31 @@ +package com.cpop.oam.business.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +/** + * @author DB + * @createTime 2023/11/10 11:39 + * @description + */ +@Data +@Accessors(chain = true) +@ApiModel(value = "Brand列表返回对象") +public class BrandListVo implements Serializable { + + /** + * 主键 + */ + @ApiModelProperty("主键") + private String id; + + /** + * 云函数id + */ + @ApiModelProperty("品牌名") + private String brandName; +} diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/framework/config/InitConfig.java b/Cpop-Oam/src/main/java/com/cpop/oam/framework/config/InitConfig.java new file mode 100644 index 0000000..2f56a98 --- /dev/null +++ b/Cpop-Oam/src/main/java/com/cpop/oam/framework/config/InitConfig.java @@ -0,0 +1,42 @@ +package com.cpop.oam.framework.config; + +import com.cpop.core.base.enums.InitRoleEnum; +import com.cpop.core.utils.SpringUtils; +import com.cpop.system.business.entity.Role; +import com.cpop.system.business.service.RoleService; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; + +import static org.springframework.integration.config.xml.IntegrationNamespaceUtils.ROLE; + + +/** + * @author DB + * @createTime 2023/11/10 12:25 + * @description 初始化配置 + */ +@Component +public class InitConfig { + + /** + * 初始化 + */ + @PostConstruct + public void init(){ + //检查角色初始化 + RoleService roleService = SpringUtils.getBean(RoleService.class); + for (InitRoleEnum value : InitRoleEnum.values()) { + Role role = roleService.queryChain().where("id = ?", value.getId()).one(); + if (role == null){ + Role newRole = new Role(); + newRole.setId(value.getId()) + .setRoleName(value.getRoleName()) + .setRoleValue(value.getRoleValue()) + .setOrderNo(value.getOrderNo()) + .setUserType(value.getUserType()); + roleService.save(newRole); + } + } + } +} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/bo/BrandBo.java b/Cpop-System/src/main/java/com/cpop/system/business/bo/BrandBo.java index 8b2d3af..af0973b 100644 --- a/Cpop-System/src/main/java/com/cpop/system/business/bo/BrandBo.java +++ b/Cpop-System/src/main/java/com/cpop/system/business/bo/BrandBo.java @@ -1,10 +1,13 @@ package com.cpop.system.business.bo; +import com.cpop.core.annontation.StringArrayConvert; import com.mybatisflex.annotation.Id; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import javax.validation.constraints.NotBlank; + /** * @author DB * @createTime 2023/10/25 16:43 @@ -23,13 +26,15 @@ public class BrandBo { /** * 品牌名 */ + @NotBlank(message = "品牌不能为空") @ApiModelProperty(value = "品牌名", required = true) private String brandName; /** * 微信商户号 */ - @ApiModelProperty("微信商户号") + @NotBlank(message = "商户号不能为空") + @ApiModelProperty(value = "微信商户号",required = true) private String wxMchId; /** @@ -49,4 +54,11 @@ public class BrandBo { */ @ApiModelProperty("微信支付keypath") private String wxKeyPath; + + /** + * 背景图 + */ + @StringArrayConvert + @ApiModelProperty("背景图") + private String backgroundUrl; } diff --git a/Cpop-System/src/main/java/com/cpop/system/business/bo/BrandPageBo.java b/Cpop-System/src/main/java/com/cpop/system/business/bo/BrandPageBo.java deleted file mode 100644 index e9732ae..0000000 --- a/Cpop-System/src/main/java/com/cpop/system/business/bo/BrandPageBo.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.cpop.system.business.bo; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.io.Serializable; - -/** - * Description: - * date: 2023/6/1 18:07 - * @Author DB - */ -@Data -@Accessors(chain = true) -@ApiModel(value = "Brand分页对象", description = "Brand分页对象") -public class BrandPageBo implements Serializable { - - private static final long serialVersionUID = 1L; - - /** - * 品牌名 - */ - @ApiModelProperty("品牌名") - private String name; - -} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/controller/BrandController.java b/Cpop-System/src/main/java/com/cpop/system/business/controller/BrandController.java index d6266eb..8af81d4 100644 --- a/Cpop-System/src/main/java/com/cpop/system/business/controller/BrandController.java +++ b/Cpop-System/src/main/java/com/cpop/system/business/controller/BrandController.java @@ -1,15 +1,13 @@ package com.cpop.system.business.controller; import com.cpop.common.utils.bean.BeanUtils; -import com.cpop.core.annontation.OperationLog; import com.cpop.core.base.R; -import com.cpop.core.base.enums.OperationLogEnum; import com.cpop.core.base.enums.SourceType; import com.cpop.system.business.bo.BrandBo; -import com.cpop.system.business.bo.BrandPageBo; import com.cpop.system.business.vo.BrandPageVo; import com.mybatisflex.core.paginate.Page; import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -24,8 +22,6 @@ import org.springframework.web.bind.annotation.RestController; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import java.io.Serializable; -import java.util.List; /** * 系统-品牌表 控制层。 @@ -45,18 +41,35 @@ public class BrandController { * @descriptions 新增系统品牌 * @author DB * @date 2023/10/25 16:53 - * @param brand 品牌参数 + * @param bo 品牌参数 * @return: com.cpop.core.base.R */ + @PreAuthorize("@aps.hasPermission('brandStore:brand:insert')") @PostMapping("/insertSysBrand") @ApiOperation("新增系统品牌") - public R insertSysBrand(@RequestBody @ApiParam("系统-品牌") BrandBo brand) { - Brand entity = BeanUtils.mapToClass(brand, Brand.class); + public R insertSysBrand(@RequestBody @ApiParam("系统-品牌") @Validated BrandBo bo) { + Brand entity = BeanUtils.mapToClass(bo, Brand.class); entity.setSourceType(SourceType.COMMON.toString()); brandService.save(entity); return R.ok(); } + /** + * @descriptions 修改系统品牌 + * @author DB + * @date 2023/11/10 9:21 + * @param bo 品牌参数 + * @return: com.cpop.core.base.R + */ + @PreAuthorize("@aps.hasPermission('brandStore:brand:update')") + @ApiOperation("修改系统品牌") + @PutMapping("/updateSysBrand") + public R updateSysBrand(@RequestBody @ApiParam("系统-品牌") @Validated BrandBo bo) { + Brand entity = BeanUtils.mapToClass(bo, Brand.class); + brandService.updateById(entity); + return R.ok(); + } + /** * @descriptions 导入果酱品牌 * @author DB @@ -64,6 +77,7 @@ public class BrandController { * @param brandId 果酱品牌信息 * @return: boolean */ + @PreAuthorize("@aps.hasPermission('brandStore:brand:insert')") @PostMapping("/importJamboxBrand/{brandId}") @ApiOperation("导入果酱品牌") public R importJamboxBrand(@PathVariable String brandId) { @@ -75,13 +89,14 @@ public class BrandController { * @descriptions 查询品牌分页列表 * @author DB * @date 2023/09/13 17:55 - * @param bo 请求参数 + * @param brandName 请求参数 * @return com.cpop.core.base.R> */ @ApiOperation("查询品牌分页列表") @GetMapping("/getBrandPage") - public R> getBrandPageList(BrandPageBo bo) { - Page pageVo = brandService.getBrandPage(bo); + @PreAuthorize("@aps.hasPermission('brandStore:brand:list')") + public R> getBrandPageList(String brandName) { + Page pageVo = brandService.getBrandPage(brandName); return R.ok(pageVo); } @@ -92,6 +107,7 @@ public class BrandController { * @param id 主键 * @return: com.cpop.core.base.R */ + @PreAuthorize("@aps.hasPermission('brandStore:brand:remove')") @ApiOperation("根据品牌id删除品牌") @DeleteMapping("/removeBrandById/{id}") public R removeBrandById(@PathVariable String id) { diff --git a/Cpop-System/src/main/java/com/cpop/system/business/controller/MenuController.java b/Cpop-System/src/main/java/com/cpop/system/business/controller/MenuController.java index beae5ad..67c162e 100644 --- a/Cpop-System/src/main/java/com/cpop/system/business/controller/MenuController.java +++ b/Cpop-System/src/main/java/com/cpop/system/business/controller/MenuController.java @@ -66,7 +66,6 @@ public class MenuController { * @return com.jambox.core.base.R */ @PreAuthorize("@aps.hasPermission('system:menu:insert')") - @OperationLog(operationLogEnumType = OperationLogEnum.INSERT_OAM_MENU) @ApiOperation("新增系统菜单") @PostMapping("/insertSysMenu") public R insertSysMenu(@RequestBody @Validated MenuBo bo) { @@ -81,7 +80,6 @@ public class MenuController { * @Date: 2023/5/10 16:01 **/ @PreAuthorize("@aps.hasPermission('system:menu:update')") - @OperationLog(operationLogEnumType = OperationLogEnum.UPDATE_OAM_MENU) @ApiOperation("修改系统菜单") @PutMapping("/updateSysMenu") public R updateSysMenu(@RequestBody @Validated MenuBo bo) { @@ -96,7 +94,6 @@ public class MenuController { * @Date: 2023/5/10 16:01 **/ @PreAuthorize("@aps.hasPermission('system:menu:remove')") - @OperationLog(operationLogEnumType = OperationLogEnum.REMOVE_OAM_MENU) @ApiOperation("删除系统菜单") @DeleteMapping("/removeSysMenu/{id}") public R removeSysMenu(@PathVariable String id) { diff --git a/Cpop-System/src/main/java/com/cpop/system/business/controller/SysCommonController.java b/Cpop-System/src/main/java/com/cpop/system/business/controller/SysCommonController.java index c1e3a48..a3da6d4 100644 --- a/Cpop-System/src/main/java/com/cpop/system/business/controller/SysCommonController.java +++ b/Cpop-System/src/main/java/com/cpop/system/business/controller/SysCommonController.java @@ -49,8 +49,9 @@ public class SysCommonController { // 上传并返回新文件名称 String fileName = FileUploadUtils.getInstance().upload(filePath, file); //强制将http变成https - String https = serverConfig.getUrl().replace("http:", "https:"); - String url = https + fileName; + //String https = serverConfig.getUrl().replace("http:", "https:"); + //String url = https + fileName; + String url = serverConfig.getUrl() + fileName; SysFileVo sysFileVo = new SysFileVo(); sysFileVo.setUrl(url) .setFileName(fileName) diff --git a/Cpop-System/src/main/java/com/cpop/system/business/service/BrandService.java b/Cpop-System/src/main/java/com/cpop/system/business/service/BrandService.java index 266cf06..1eb4a0a 100644 --- a/Cpop-System/src/main/java/com/cpop/system/business/service/BrandService.java +++ b/Cpop-System/src/main/java/com/cpop/system/business/service/BrandService.java @@ -1,6 +1,5 @@ package com.cpop.system.business.service; -import com.cpop.system.business.bo.BrandPageBo; import com.cpop.system.business.vo.BrandPageVo; import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.service.IService; @@ -30,7 +29,7 @@ public interface BrandService extends IService { * @param bo 请求参数 * @return: com.mybatisflex.core.paginate.Page */ - Page getBrandPage(BrandPageBo bo); + Page getBrandPage(String brandName); /** * @descriptions 根据品牌id删除品牌 diff --git a/Cpop-System/src/main/java/com/cpop/system/business/service/impl/BrandServiceImpl.java b/Cpop-System/src/main/java/com/cpop/system/business/service/impl/BrandServiceImpl.java index 6ea4aed..eaffe89 100644 --- a/Cpop-System/src/main/java/com/cpop/system/business/service/impl/BrandServiceImpl.java +++ b/Cpop-System/src/main/java/com/cpop/system/business/service/impl/BrandServiceImpl.java @@ -9,7 +9,6 @@ import com.cpop.core.base.exception.ServiceException; import com.cpop.core.utils.SecurityUtils; import com.cpop.core.utils.SpringUtils; import com.cpop.core.utils.sql.SqlUtils; -import com.cpop.system.business.bo.BrandPageBo; import com.cpop.system.business.entity.Store; import com.cpop.system.business.service.StoreService; import com.cpop.system.business.vo.BrandPageVo; @@ -152,16 +151,16 @@ public class BrandServiceImpl extends ServiceImpl implements * @descriptions 查询品牌分页列表 * @author DB * @date 2023/10/25 17:32 - * @param bo 请求参数 + * @param brandName 品牌名 * @return: com.mybatisflex.core.paginate.Page */ @Override - public Page getBrandPage(BrandPageBo bo) { + public Page getBrandPage(String brandName) { PageDomain pageDomain = SqlUtils.getInstance().getPageDomain(); return this.mapper.paginateAs(pageDomain.getPageNum(), pageDomain.getPageSize(), QueryWrapper.create() .select(BRAND.ID, BRAND.BRAND_NAME, BRAND.WX_MCH_ID, BRAND.CREATE_TIME, BRAND.BACKGROUND_URL, BRAND.WX_APP_ID, BRAND.WX_MCH_KEY, BRAND.WX_KEY_PATH) - .and(BRAND.BRAND_NAME.like(bo.getName())), + .and(BRAND.BRAND_NAME.like(brandName)), BrandPageVo.class); } @@ -173,6 +172,7 @@ public class BrandServiceImpl extends ServiceImpl implements * @return: void */ @Override + @Transactional(rollbackFor = Exception.class) public void removeBrandById(String id) { Brand brand = this.getById(id); StoreService storeService = SpringUtils.getBean(StoreService.class); @@ -181,7 +181,7 @@ public class BrandServiceImpl extends ServiceImpl implements List storeList = storeService.queryChain().where(STORE.BRAND_ID.eq(id)).list(); if (!storeList.isEmpty()){ DbChain.table("cp_j_store_extend") - .set("is_delete = ?", 1) + .set("is_delete", 1) .where("store_id in ?", storeList.stream().map(Store::getId).collect(Collectors.toSet())) .update(); } @@ -190,7 +190,7 @@ public class BrandServiceImpl extends ServiceImpl implements storeService.updateChain().where(STORE.BRAND_ID.eq(brand.getId())).remove(); //逻辑删除品牌拓展 DbChain.table("cp_j_brand_extend") - .set("is_delete = ?", 1) + .set("is_delete", 1) .where("brand_id = ?", id) .update(); //删除品牌 diff --git a/Cpop-System/src/main/java/com/cpop/system/business/service/impl/MenuServiceImpl.java b/Cpop-System/src/main/java/com/cpop/system/business/service/impl/MenuServiceImpl.java index 7fea0d3..624cf98 100644 --- a/Cpop-System/src/main/java/com/cpop/system/business/service/impl/MenuServiceImpl.java +++ b/Cpop-System/src/main/java/com/cpop/system/business/service/impl/MenuServiceImpl.java @@ -5,6 +5,7 @@ import com.cpop.common.constant.Constants; import com.cpop.common.utils.StringUtils; import com.cpop.common.utils.bean.BeanUtils; import com.cpop.core.base.entity.LoginUser; +import com.cpop.core.base.enums.InitRoleEnum; import com.cpop.core.utils.SecurityUtils; import com.cpop.system.business.bo.MenuBo; import com.cpop.system.business.bo.MenuListBo; @@ -57,18 +58,30 @@ public class MenuServiceImpl extends ServiceImpl implements Me MenuRouteVo.class); return buildMenuRouteTree(list); } else { - return buildMenuRouteTree(this.listAs(QueryWrapper.create() - .select(MENU.ALL_COLUMNS) - .leftJoin(ROLE_MENU).on(ROLE_MENU.MENU_ID.eq(MENU.ID)) - .leftJoin(ROLE).on(ROLE.ID.eq(ROLE_MENU.ROLE_ID)) - .where(MENU.STATUS.eq(1)) - .and(MENU.TYPE.in(0, 1)) - .and(MENU.NAME.notIn(Constants.HIDE_MENU.split(","))) - .and(ROLE_MENU.ROLE_ID.eq(loginStaffInfo.getString("roleId"))) - //构建公共菜单与特有菜单 - .and(MENU.USER_TYPE.eq(user.getUserType())) - .orderBy(MENU.ORDER_NO.asc()), - MenuRouteVo.class)); + //一般管理员 + if (StringUtils.equals(loginStaffInfo.getString("roleId"), InitRoleEnum.SUPER_MALL_ROLE.getId())) { + return buildMenuRouteTree(this.listAs(QueryWrapper.create() + .where(MENU.TYPE.in(0, 1)) + //构建公共菜单与特有菜单 + .and(MENU.USER_TYPE.eq(user.getUserType())) + .where(MENU.STATUS.eq(1)) + .and(MENU.NAME.notIn(Constants.HIDE_MENU.split(","))) + .orderBy(MENU.ORDER_NO.asc()), + MenuRouteVo.class)); + }else { + return buildMenuRouteTree(this.listAs(QueryWrapper.create() + .select(MENU.ALL_COLUMNS) + .leftJoin(ROLE_MENU).on(ROLE_MENU.MENU_ID.eq(MENU.ID)) + .leftJoin(ROLE).on(ROLE.ID.eq(ROLE_MENU.ROLE_ID)) + .where(MENU.STATUS.eq(1)) + .and(MENU.TYPE.in(0, 1)) + .and(MENU.NAME.notIn(Constants.HIDE_MENU.split(","))) + .and(ROLE_MENU.ROLE_ID.eq(loginStaffInfo.getString("roleId"))) + //构建公共菜单与特有菜单 + .and(MENU.USER_TYPE.eq(user.getUserType())) + .orderBy(MENU.ORDER_NO.asc()), + MenuRouteVo.class)); + } } }