| | |
| | | package com.panzhihua.service_community.service.impl; |
| | | |
| | | import static java.util.Objects.isNull; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.panzhihua.common.utlis.DateUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.panzhihua.common.exceptions.ServiceException; |
| | | import com.panzhihua.common.model.dtos.community.convenient.DisableOrEnableConvenientMerchantDTO; |
| | | import com.panzhihua.common.model.dtos.community.microCommercialStreet.DisableOrEnableMcsMerchantDTO; |
| | | import com.panzhihua.common.model.dtos.community.microCommercialStreet.McsMerchantDTO; |
| | | import com.panzhihua.common.model.dtos.community.microCommercialStreet.PageMcsMerchantDTO; |
| | | import com.panzhihua.common.model.vos.R; |
| | | import com.panzhihua.common.model.vos.community.microCommercialStreet.McsMerchantVO; |
| | | import com.panzhihua.common.service.user.UserService; |
| | | import com.panzhihua.common.utlis.DateUtils; |
| | | import com.panzhihua.service_community.dao.McsMerchantDAO; |
| | | import com.panzhihua.service_community.entity.McsMerchant; |
| | | import com.panzhihua.service_community.service.McsMerchantService; |
| | | |
| | | import static java.util.Objects.isNull; |
| | | |
| | | /** |
| | | * (McsMerchant)表服务实现类 |
| | |
| | | } |
| | | return R.fail("添加失败"); |
| | | } |
| | | |
| | | /** |
| | | * 编辑数字商业街商家 |
| | | * @param mcsMerchantDTO |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R putMcsMerchant(McsMerchantDTO mcsMerchantDTO) { |
| | | McsMerchant mcsMerchant = this.baseMapper.selectById(mcsMerchantDTO.getId()); |
| | | if (isNull(mcsMerchant)) { |
| | | return R.fail("商家不存在"); |
| | | } |
| | | if (mcsMerchantDTO.getLevel().equals(1)) { |
| | | Integer litDays = mcsMerchantDTO.getLitDays(); |
| | | if (isNull(litDays)) { |
| | | return R.fail("临时商家未设置点亮天数"); |
| | | } |
| | | mcsMerchant.setExpireAt(DateUtils.addDay(new Date(), litDays)); |
| | | } |
| | | BeanUtils.copyProperties(mcsMerchantDTO, mcsMerchant); |
| | | int result = this.baseMapper.updateById(mcsMerchant); |
| | | if (result > 0) { |
| | | //修改商家绑定账户号 |
| | | mcsMerchantDTO.setUserId(mcsMerchant.getUserId()); |
| | | R putResult = userService.putMcsMerchantUser(mcsMerchantDTO); |
| | | if (!R.isOk(putResult)) { |
| | | throw new ServiceException("406", putResult.getMsg()); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | return R.fail("修改失败,请重新尝试"); |
| | | } |
| | | |
| | | /** |
| | | * 查询数字商业街商家详情 |
| | | * @param merchantId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R getMcsMerchant(Long merchantId) { |
| | | return R.ok(this.baseMapper.getMcsMerchantById(merchantId)); |
| | | } |
| | | |
| | | /** |
| | | * 删除数字商业街商家 |
| | | * @param merchantId |
| | | * @param userId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R deleteMcsMerchant(Long merchantId, Long userId) { |
| | | McsMerchant mcsMerchant = this.baseMapper.selectById(merchantId); |
| | | if (isNull(mcsMerchant)) { |
| | | return R.fail("商家不存在"); |
| | | } |
| | | mcsMerchant.setIsDel(true); |
| | | this.baseMapper.updateById(mcsMerchant); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 分页查询数字商业街商家 |
| | | * @param pageMcsMerchantDTO |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R pageMcsMerchant(PageMcsMerchantDTO pageMcsMerchantDTO) { |
| | | Page page = new Page<>(); |
| | | page.setSize(pageMcsMerchantDTO.getPageSize()); |
| | | page.setCurrent(pageMcsMerchantDTO.getPageNum()); |
| | | IPage<McsMerchantVO> mcsMerchants = this.baseMapper.pageMcsMerchant(page, pageMcsMerchantDTO); |
| | | return R.ok(mcsMerchants); |
| | | } |
| | | |
| | | /** |
| | | * 禁用/启用数字商业街商家 |
| | | * @param disableOrEnableMcsMerchantDTO |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R disableOrEnableMcsMerchant(DisableOrEnableMcsMerchantDTO disableOrEnableMcsMerchantDTO) { |
| | | McsMerchant mcsMerchant = this.baseMapper.selectById(disableOrEnableMcsMerchantDTO.getMerchantId()); |
| | | if (isNull(mcsMerchant)) { |
| | | return R.fail("商家不存在"); |
| | | } |
| | | Integer type = disableOrEnableMcsMerchantDTO.getType(); |
| | | if (type.equals(1) || type.equals(2)) { |
| | | //启用 or 禁用 |
| | | DisableOrEnableConvenientMerchantDTO dto = new DisableOrEnableConvenientMerchantDTO(); |
| | | dto.setType(type); |
| | | dto.setUserIds(Arrays.asList(mcsMerchant.getUserId())); |
| | | R r = userService.disableOrEnableMerchantUsers(dto); |
| | | return r; |
| | | } else { |
| | | return R.fail("未知错误"); |
| | | } |
| | | } |
| | | } |