|
|
@@ -0,0 +1,206 @@
|
|
|
+package com.zhongzheng.modules.top.mall.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.lang.Validator;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.zhongzheng.common.exception.CustomException;
|
|
|
+import com.zhongzheng.common.utils.DateUtils;
|
|
|
+import com.zhongzheng.common.utils.SecurityUtils;
|
|
|
+import com.zhongzheng.common.utils.SnowflakeIdUtils;
|
|
|
+import com.zhongzheng.modules.top.mall.bo.TopMerchantAddBo;
|
|
|
+import com.zhongzheng.modules.top.mall.bo.TopMerchantEditBo;
|
|
|
+import com.zhongzheng.modules.top.mall.bo.TopMerchantQueryBo;
|
|
|
+import com.zhongzheng.modules.top.mall.domain.TopMerchant;
|
|
|
+import com.zhongzheng.modules.top.mall.domain.TopStore;
|
|
|
+import com.zhongzheng.modules.top.mall.mapper.TopMerchantMapper;
|
|
|
+import com.zhongzheng.modules.top.mall.service.ITopMerchantService;
|
|
|
+import com.zhongzheng.modules.top.mall.vo.TopMerchantExportVo;
|
|
|
+import com.zhongzheng.modules.top.mall.vo.TopMerchantVo;
|
|
|
+import com.zhongzheng.modules.top.mall.vo.TopStoreExportVo;
|
|
|
+import com.zhongzheng.modules.top.mall.vo.TopStoreVo;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 商户管理Service业务层处理
|
|
|
+ *
|
|
|
+ * @author ruoyi
|
|
|
+ * @date 2023-05-25
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class TopMerchantServiceImpl extends ServiceImpl<TopMerchantMapper, TopMerchant> implements ITopMerchantService {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TopMerchantVo queryById(Long merId){
|
|
|
+ TopMerchant db = this.baseMapper.selectById(merId);
|
|
|
+ return BeanUtil.toBean(db, TopMerchantVo.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<TopMerchantVo> queryList(TopMerchantQueryBo bo) {
|
|
|
+ LambdaQueryWrapper<TopMerchant> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.like(StrUtil.isNotBlank(bo.getMerName()), TopMerchant::getMerName, bo.getMerName());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getTelphone()), TopMerchant::getTelphone, bo.getTelphone());
|
|
|
+ lqw.like(StrUtil.isNotBlank(bo.getUserName()), TopMerchant::getUserName, bo.getUserName());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getPassword()), TopMerchant::getPassword, bo.getPassword());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getContacts()), TopMerchant::getContacts, bo.getContacts());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getInitPwd()), TopMerchant::getInitPwd, bo.getInitPwd());
|
|
|
+ lqw.in(bo.getStatus() != null, TopMerchant::getStatus, bo.getStatus());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getMerAccount()), TopMerchant::getMerAccount, bo.getMerAccount());
|
|
|
+ return entity2Vo(this.list(lqw));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 实体类转化成视图对象
|
|
|
+ *
|
|
|
+ * @param collection 实体类集合
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<TopMerchantVo> entity2Vo(Collection<TopMerchant> collection) {
|
|
|
+ List<TopMerchantVo> voList = collection.stream()
|
|
|
+ .map(any -> BeanUtil.toBean(any, TopMerchantVo.class))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (collection instanceof Page) {
|
|
|
+ Page<TopMerchant> page = (Page<TopMerchant>)collection;
|
|
|
+ Page<TopMerchantVo> pageVo = new Page<>();
|
|
|
+ BeanUtil.copyProperties(page,pageVo);
|
|
|
+ pageVo.addAll(voList);
|
|
|
+ voList = pageVo;
|
|
|
+ }
|
|
|
+ return voList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean insertByAddBo(TopMerchantAddBo bo) {
|
|
|
+ if (getOne(new LambdaQueryWrapper<TopMerchant>().eq(TopMerchant::getMerName, bo.getMerName()).last("limit 1")) != null) {
|
|
|
+ throw new CustomException("该商户名已被注册");
|
|
|
+ }
|
|
|
+ if (getOne(new LambdaQueryWrapper<TopMerchant>().eq(TopMerchant::getTelphone, bo.getTelphone()).last("limit 1")) != null) {
|
|
|
+ throw new CustomException("该手机号已被注册");
|
|
|
+ }
|
|
|
+ TopMerchant add = BeanUtil.toBean(bo, TopMerchant.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ add.setCreateTime(DateUtils.getNowTime());
|
|
|
+ add.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ String pwd = add.getTelphone().substring(add.getTelphone().length() - 6);
|
|
|
+ add.setUserName("manager");
|
|
|
+ add.setPassword(pwd);
|
|
|
+ add.setInitPwd(add.getPassword());
|
|
|
+ add.setPassword(SecurityUtils.encryptPassword(add.getPassword()));
|
|
|
+ add.setTenantId("867735392558919680");//初始按祥粤创建
|
|
|
+ SnowflakeIdUtils idWorker = new SnowflakeIdUtils(3, 1);
|
|
|
+ add.setMerAccount(String.valueOf(idWorker.nextId()));
|
|
|
+ return this.save(add);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updateByEditBo(TopMerchantEditBo bo) {
|
|
|
+ if(Validator.isEmpty(bo.getMerId())){
|
|
|
+ throw new CustomException("参数错误");
|
|
|
+ }
|
|
|
+ if(Validator.isNotEmpty(bo.getMerName())){
|
|
|
+ if (getOne(new LambdaQueryWrapper<TopMerchant>().ne(TopMerchant::getMerId, bo.getMerId()).eq(TopMerchant::getMerName, bo.getMerName()).last("limit 1")) != null) {
|
|
|
+ throw new CustomException("该商户名称已被注册");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(Validator.isNotEmpty(bo.getTelphone())){
|
|
|
+ TopMerchant topStore = getOne(new LambdaQueryWrapper<TopMerchant>().eq(TopMerchant::getMerId, bo.getMerId()));
|
|
|
+ if(!topStore.getTelphone().equals(bo.getTelphone())){
|
|
|
+ if (getOne(new LambdaQueryWrapper<TopMerchant>().ne(TopMerchant::getMerId, bo.getMerId()).eq(TopMerchant::getTelphone, bo.getTelphone()).last("limit 1")) != null) {
|
|
|
+ throw new CustomException("该手机号码已被注册");
|
|
|
+ }
|
|
|
+ String pwd = bo.getTelphone().substring(bo.getTelphone().length() - 6);
|
|
|
+ bo.setInitPwd(pwd);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ TopMerchant update = BeanUtil.toBean(bo, TopMerchant.class);
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ update.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ return this.updateById(update);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ *
|
|
|
+ * @param entity 实体类数据
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(TopMerchant entity){
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if(isValid){
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return this.removeByIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean restorePwd(TopMerchantEditBo bo) {
|
|
|
+ if(Validator.isEmpty(bo.getMerId())){
|
|
|
+ throw new CustomException("参数错误");
|
|
|
+ }
|
|
|
+ TopMerchant store = getOne(new LambdaQueryWrapper<TopMerchant>().eq(TopMerchant::getMerId, bo.getMerId()).last("limit 1"));
|
|
|
+ LambdaUpdateWrapper<TopMerchant> objectLambdaUpdateWrapper = Wrappers.lambdaUpdate();
|
|
|
+ objectLambdaUpdateWrapper.eq(TopMerchant::getMerId, bo.getMerId());
|
|
|
+ objectLambdaUpdateWrapper.set(TopMerchant::getPassword, SecurityUtils.encryptPassword(store.getInitPwd()));
|
|
|
+ objectLambdaUpdateWrapper.set(TopMerchant::getUpdateTime, DateUtils.getNowTime());
|
|
|
+ return this.update(null, objectLambdaUpdateWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updatePwd(TopMerchantEditBo bo) {
|
|
|
+ if(Validator.isEmpty(bo.getMerId())||Validator.isEmpty(bo.getPassword())){
|
|
|
+ throw new CustomException("参数错误");
|
|
|
+ }
|
|
|
+ TopMerchantVo storeVo = queryById(bo.getMerId());
|
|
|
+ LambdaUpdateWrapper<TopMerchant> objectLambdaUpdateWrapper = Wrappers.lambdaUpdate();
|
|
|
+ objectLambdaUpdateWrapper.eq(TopMerchant::getMerId, bo.getMerId());
|
|
|
+ objectLambdaUpdateWrapper.set(TopMerchant::getPassword, SecurityUtils.encryptPassword(bo.getPassword()));
|
|
|
+ objectLambdaUpdateWrapper.set(TopMerchant::getUpdateTime, DateUtils.getNowTime());
|
|
|
+ return this.update(null, objectLambdaUpdateWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean batchRemove(TopMerchantEditBo bo) {
|
|
|
+ if(Validator.isNotEmpty(bo.getMerIds())){
|
|
|
+ for(Long id : bo.getMerIds()){
|
|
|
+ LambdaUpdateWrapper<TopMerchant> objectLambdaUpdateWrapper = Wrappers.lambdaUpdate();
|
|
|
+ objectLambdaUpdateWrapper.eq(TopMerchant::getMerId, id);
|
|
|
+ objectLambdaUpdateWrapper.set(TopMerchant::getStatus, -1);
|
|
|
+ objectLambdaUpdateWrapper.set(TopMerchant::getUpdateTime, DateUtils.getNowTime());
|
|
|
+ this.update(null, objectLambdaUpdateWrapper);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<TopMerchantExportVo> listExport(TopMerchantQueryBo bo) {
|
|
|
+ List<TopMerchantExportVo> exportVoList = new ArrayList<>();
|
|
|
+ List<TopMerchantVo> list = queryList(bo);
|
|
|
+ for(TopMerchantVo vo : list){
|
|
|
+ TopMerchantExportVo exportVo = BeanUtil.toBean(vo, TopMerchantExportVo.class);
|
|
|
+ exportVo.setCreateTime(DateUtils.timestampToDate(vo.getCreateTime()));
|
|
|
+ if(vo.getStatus()==1){
|
|
|
+ exportVo.setStatus("启用");
|
|
|
+ }
|
|
|
+ if(vo.getStatus()==0){
|
|
|
+ exportVo.setStatus("禁用");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return exportVoList;
|
|
|
+ }
|
|
|
+}
|