|
@@ -0,0 +1,142 @@
|
|
|
|
+package com.citu.module.menduner.system.dal.mysql.enterprise;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.lang.Assert;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
|
+import com.citu.framework.common.pojo.PageResult;
|
|
|
|
+import com.citu.framework.mybatis.core.mapper.BaseMapperX;
|
|
|
|
+import com.citu.framework.mybatis.core.query.LambdaQueryWrapperX;
|
|
|
|
+import com.citu.framework.mybatis.core.query.MPJLambdaWrapperX;
|
|
|
|
+import com.citu.module.menduner.system.controller.admin.enterprise.vo.EnterpriseAccountPageRespVO;
|
|
|
|
+import com.citu.module.menduner.system.controller.admin.user.vo.UserAccountPageRespVO;
|
|
|
|
+import com.citu.module.menduner.system.controller.base.enterprise.account.EnterpriseAccountPageReqVO;
|
|
|
|
+import com.citu.module.menduner.system.dal.dataobject.enterprise.EnterpriseAccountDO;
|
|
|
|
+import com.citu.module.menduner.system.dal.dataobject.enterprise.EnterpriseDO;
|
|
|
|
+import com.citu.module.menduner.system.dal.dataobject.enterprise.EnterpriseUserBindDO;
|
|
|
|
+import com.citu.module.menduner.system.dal.dataobject.person.PersonInfoDO;
|
|
|
|
+import org.apache.ibatis.annotations.Mapper;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 企业账户 Mapper
|
|
|
|
+ *
|
|
|
|
+ * @author Rayson
|
|
|
|
+ */
|
|
|
|
+@Mapper
|
|
|
|
+public interface EnterpriseAccountMapper extends BaseMapperX<EnterpriseAccountDO> {
|
|
|
|
+
|
|
|
|
+ default PageResult<EnterpriseAccountDO> selectPage(EnterpriseAccountPageReqVO reqVO) {
|
|
|
|
+ return selectPage(reqVO, new LambdaQueryWrapperX<EnterpriseAccountDO>()
|
|
|
|
+ .eqIfPresent(EnterpriseAccountDO::getEnterpriseId, reqVO.getEnterpriseId())
|
|
|
|
+ .eqIfPresent(EnterpriseAccountDO::getUserId, reqVO.getUserId())
|
|
|
|
+ .betweenIfPresent(EnterpriseAccountDO::getCreateTime, reqVO.getCreateTime())
|
|
|
|
+ .orderByDesc(EnterpriseAccountDO::getId));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ default PageResult<EnterpriseAccountPageRespVO> page(EnterpriseAccountPageReqVO reqVO) {
|
|
|
|
+ MPJLambdaWrapperX<EnterpriseAccountDO> query = new MPJLambdaWrapperX<>();
|
|
|
|
+ query.selectAll(EnterpriseAccountDO.class);
|
|
|
|
+ query.selectAs(EnterpriseDO::getName, EnterpriseAccountPageRespVO::getEnterpriseName);
|
|
|
|
+ query.selectAs(EnterpriseDO::getAnotherName, EnterpriseAccountPageRespVO::getAnotherName);
|
|
|
|
+ query.selectAs(EnterpriseDO::getLogoUrl, EnterpriseAccountPageRespVO::getLogoUrl);
|
|
|
|
+
|
|
|
|
+ query.selectAs(EnterpriseUserBindDO::getName, EnterpriseAccountPageRespVO::getUserName);
|
|
|
|
+ query.selectAs(EnterpriseUserBindDO::getSex, EnterpriseAccountPageRespVO::getSex);
|
|
|
|
+ query.selectAs(EnterpriseUserBindDO::getAvatar, EnterpriseAccountPageRespVO::getAvatar);
|
|
|
|
+ query.selectAs(EnterpriseUserBindDO::getPhone, UserAccountPageRespVO::getPhone);
|
|
|
|
+ query.selectAs(EnterpriseUserBindDO::getEmail, UserAccountPageRespVO::getEmail);
|
|
|
|
+
|
|
|
|
+ query.innerJoin(EnterpriseDO.class, EnterpriseDO::getId, EnterpriseAccountDO::getEnterpriseId);
|
|
|
|
+ query.innerJoin(EnterpriseUserBindDO.class, on ->
|
|
|
|
+ on.eq(EnterpriseUserBindDO::getEnterpriseId, EnterpriseAccountDO::getEnterpriseId)
|
|
|
|
+ .eq(EnterpriseUserBindDO::getUserId, EnterpriseAccountDO::getUserId)
|
|
|
|
+ );
|
|
|
|
+ query.eqIfPresent(EnterpriseAccountDO::getEnterpriseId, reqVO.getEnterpriseId())
|
|
|
|
+ .eqIfPresent(EnterpriseAccountDO::getUserId, reqVO.getUserId())
|
|
|
|
+ .likeIfExists(EnterpriseUserBindDO::getName, reqVO.getUserName())
|
|
|
|
+ .eqIfExists(EnterpriseUserBindDO::getSex, reqVO.getSex())
|
|
|
|
+ .likeIfExists(EnterpriseUserBindDO::getPhone, reqVO.getPhone())
|
|
|
|
+ .likeIfExists(EnterpriseUserBindDO::getEmail, reqVO.getEmail());
|
|
|
|
+
|
|
|
|
+ query.betweenIfPresent(EnterpriseAccountDO::getCreateTime, reqVO.getCreateTime())
|
|
|
|
+ .orderByDesc(EnterpriseAccountDO::getUpdateTime);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return selectJoinPage(reqVO, EnterpriseAccountPageRespVO.class, query);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ default EnterpriseAccountDO selectByEnterpriseId(Long enterpriseId, Long userId) {
|
|
|
|
+ return selectOne(new LambdaQueryWrapperX<EnterpriseAccountDO>()
|
|
|
|
+ .eqIfPresent(EnterpriseAccountDO::getEnterpriseId, enterpriseId)
|
|
|
|
+ .eq(EnterpriseAccountDO::getEnterpriseId, userId)
|
|
|
|
+
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 更新用户积分(增加)
|
|
|
|
+ *
|
|
|
|
+ * @param enterpriseId 企业编号
|
|
|
|
+ * @param userId 用户编号
|
|
|
|
+ * @param incrCount 增加积分(正数)
|
|
|
|
+ */
|
|
|
|
+ default void updatePointIncr(Long enterpriseId, Long userId, Integer incrCount) {
|
|
|
|
+ Assert.isTrue(incrCount > 0);
|
|
|
|
+ LambdaUpdateWrapper<EnterpriseAccountDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<EnterpriseAccountDO>()
|
|
|
|
+ .setSql(" point = point + " + incrCount)
|
|
|
|
+ .eq(EnterpriseAccountDO::getEnterpriseId, enterpriseId)
|
|
|
|
+ .eq(EnterpriseAccountDO::getUserId, userId);
|
|
|
|
+ update(null, lambdaUpdateWrapper);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 更新用户积分(减少)
|
|
|
|
+ *
|
|
|
|
+ * @param enterpriseId 企业编号
|
|
|
|
+ * @param userId 用户编号
|
|
|
|
+ * @param incrCount 增加积分(负数)
|
|
|
|
+ * @return 更新行数
|
|
|
|
+ */
|
|
|
|
+ default int updatePointDecr(Long enterpriseId, Long userId, Integer incrCount) {
|
|
|
|
+ Assert.isTrue(incrCount < 0);
|
|
|
|
+ LambdaUpdateWrapper<EnterpriseAccountDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<EnterpriseAccountDO>()
|
|
|
|
+ .setSql(" point = point + " + incrCount) // 负数,所以使用 + 号
|
|
|
|
+ .eq(EnterpriseAccountDO::getEnterpriseId, enterpriseId)
|
|
|
|
+ .eq(EnterpriseAccountDO::getUserId, userId);
|
|
|
|
+ return update(null, lambdaUpdateWrapper);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 更新用户余额(增加)
|
|
|
|
+ *
|
|
|
|
+ * @param enterpriseId 企业编号
|
|
|
|
+ * @param userId 用户编号
|
|
|
|
+ * @param incrCount 增加余额(正数)
|
|
|
|
+ */
|
|
|
|
+ default void updateBalanceIncr(Long enterpriseId, Long userId, Integer incrCount) {
|
|
|
|
+ Assert.isTrue(incrCount > 0);
|
|
|
|
+ LambdaUpdateWrapper<EnterpriseAccountDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<EnterpriseAccountDO>()
|
|
|
|
+ .setSql(" balance = balance + " + incrCount)
|
|
|
|
+ .eq(EnterpriseAccountDO::getEnterpriseId, enterpriseId)
|
|
|
|
+ .eq(EnterpriseAccountDO::getUserId, userId);
|
|
|
|
+ update(null, lambdaUpdateWrapper);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 更新用户余额(减少)
|
|
|
|
+ *
|
|
|
|
+ * @param enterpriseId 企业编号
|
|
|
|
+ * @param userId 用户编号
|
|
|
|
+ * @param incrCount 增加余额(负数)
|
|
|
|
+ * @return 更新行数
|
|
|
|
+ */
|
|
|
|
+ default int updateBalanceDecr(Long enterpriseId, Long userId, Integer incrCount) {
|
|
|
|
+ Assert.isTrue(incrCount < 0);
|
|
|
|
+ LambdaUpdateWrapper<EnterpriseAccountDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<EnterpriseAccountDO>()
|
|
|
|
+ .setSql(" balance = balance + " + incrCount) // 负数,所以使用 + 号
|
|
|
|
+ .eq(EnterpriseAccountDO::getEnterpriseId, enterpriseId)
|
|
|
|
+ .eq(EnterpriseAccountDO::getUserId, userId);
|
|
|
|
+ return update(null, lambdaUpdateWrapper);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|