package com.doumee.service.business.impl; import com.doumee.biz.system.SystemDictDataBiz; import com.doumee.core.constants.ResponseStatus; import com.doumee.core.exception.BusinessException; import com.doumee.core.model.LoginUserInfo; import com.doumee.core.model.PageData; import com.doumee.core.model.PageWrap; import com.doumee.core.utils.Constants; import com.doumee.core.utils.Utils; import com.doumee.dao.business.MultifileMapper; import com.doumee.dao.business.ShopApplyMapper; import com.doumee.dao.business.ShopMapper; import com.doumee.dao.business.join.ShopApplyJoinMapper; import com.doumee.dao.business.model.*; import com.doumee.dao.web.dto.ShopApplyDTO; import com.doumee.service.business.ShopApplyService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.github.yulichang.wrapper.MPJLambdaWrapper; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.SecurityUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import java.util.Date; import java.util.List; import java.util.Objects; /** * 店铺申请信息表Service实现 * @author 江蹄蹄 * @date 2023/03/21 15:48 */ @Service public class ShopApplyServiceImpl implements ShopApplyService { @Autowired private ShopApplyMapper shopApplyMapper; @Autowired private ShopApplyJoinMapper shopApplyJoinMapper; @Autowired private MultifileMapper multifileMapper; @Autowired private SystemDictDataBiz systemDictDataBiz; @Autowired private ShopMapper shopMapper; @Transactional(rollbackFor = {Exception.class,BusinessException.class}) @Override public Integer create(ShopApplyDTO shopApplyDTO) { LoginUserInfo loginUserInfo = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal(); ShopApply shopApply = new ShopApply(); shopApply.setCreator(loginUserInfo.getId()); shopApply.setEditor(loginUserInfo.getId()); shopApply.setRemark(shopApplyDTO.getRemark()); shopApply.setImgurl(shopApplyDTO.getImgurl()); shopApply.setName(shopApplyDTO.getName()); shopApply.setRealname(shopApplyDTO.getRealname()); shopApply.setSex(shopApplyDTO.getSex() != null ? shopApplyDTO.getSex() : 2); shopApply.setPhone(shopApplyDTO.getPhone()); shopApply.setIdcard(shopApplyDTO.getIdcard()); shopApply.setIdcardImg(shopApplyDTO.getIdcardImg()); shopApply.setIdcardImgBack(shopApplyDTO.getIdcardImgBack()); shopApply.setBusinessImg(shopApplyDTO.getBusinessImg()); shopApply.setStatus(Constants.ZERO); shopApply.setAreaId(shopApplyDTO.getAreaId()); shopApply.setLongitude(shopApplyDTO.getLongitude()); shopApply.setLatitude(shopApplyDTO.getLatitude()); shopApply.setAddr(shopApplyDTO.getAddr()); shopApply.setInfo(shopApplyDTO.getInfo()); shopApply.setOrigin(shopApplyDTO.getOrigin()); shopApply.setMemberId(shopApplyDTO.getMemberId()); // shopApply.setCheckInfo(shopApplyDTO.getCheckInfo()); // shopApply.setCheckDate(); shopApplyMapper.insert(shopApply); return shopApply.getId(); } @Override public void deleteById(Integer id) { shopApplyMapper.deleteById(id); } @Override public void delete(ShopApply shopApply) { UpdateWrapper deleteWrapper = new UpdateWrapper<>(shopApply); shopApplyMapper.delete(deleteWrapper); } @Override public void deleteByIdInBatch(List ids) { if (CollectionUtils.isEmpty(ids)) { return; } shopApplyMapper.deleteBatchIds(ids); } @Override @Transactional(rollbackFor = {BusinessException.class,Exception.class}) public void updateById(ShopApply shopApply) { LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); shopApply.setEditor(user.getId()); shopApply.setEditDate(new Date()); ShopApply result=shopApplyMapper.selectById(shopApply.getId()); if(result!=null&&Constants.equalsInteger(result.getStatus(),Constants.ONE)){ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "审核已通过,禁止操作"); } if(Constants.equalsInteger(shopApply.getStatus(),Constants.ONE)){ //审核通过 approved(shopApply,user); } shopApplyMapper.updateById(shopApply); } public void approved(ShopApply shopApply,LoginUserInfo user){ Shop query=new Shop(); query.setIsdeleted(Constants.ZERO); query.setApplyId(shopApply.getId()); Shop result=shopMapper.selectOne(new QueryWrapper<>(query)); Shop shop=new Shop(); BeanUtils.copyProperties(shop, shopApply); if(Objects.nonNull(result)){ /* shop.setId(result.getId()); shop.setStatus(Constants.ZERO); shop.setEditDate(new Date()); shop.setEditor(user.getId()); shopMapper.updateById(shop);*/ }else{ shop.setId(null); shop.setStatus(Constants.ZERO); shop.setCreateDate(new Date()); shop.setCreator(user.getId()); shopMapper.insert(shop); } } @Override public void updateByIdInBatch(List shopApplys) { if (CollectionUtils.isEmpty(shopApplys)) { return; } for (ShopApply shopApply: shopApplys) { this.updateById(shopApply); } } @Override public ShopApply findById(Integer id) { ShopApply shopApply= shopApplyMapper.selectById(id); String path = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() + systemDictDataBiz.queryByCode(Constants.OSS, Constants.ACTIVITY_FILE).getCode(); Multifile queryfile = new Multifile(); queryfile.setObjId(shopApply.getId()); queryfile.setObjType(Constants.MultiFile.SHOP_PICTURE.getKey()); List filelist = multifileMapper.selectList(new QueryWrapper<>(queryfile)); shopApply.setResourcePath(path); shopApply.setFileList(filelist); return shopApply; } @Override public ShopApply findOne(ShopApply shopApply) { QueryWrapper wrapper = new QueryWrapper<>(shopApply); return shopApplyMapper.selectOne(wrapper); } @Override public ShopApply findLastOne(Integer memberId) { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.lambda().eq(ShopApply::getMemberId,memberId) .orderByDesc(ShopApply::getCheckDate).last("limit 1"); return shopApplyMapper.selectOne(wrapper); } @Override public List findList(ShopApply shopApply) { QueryWrapper wrapper = new QueryWrapper<>(shopApply); return shopApplyMapper.selectList(wrapper); } @Override public PageData findPage(PageWrap pageWrap) { IPage page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); MPJLambdaWrapper queryWrapper = new MPJLambdaWrapper<>(); Utils.MP.blankToNull(pageWrap.getModel()); queryWrapper.selectAll(ShopApply.class); queryWrapper.selectAs(Member::getNickname,ShopApply::getNikeName); queryWrapper.leftJoin(Member.class,Member::getId,ShopApply::getMemberId); queryWrapper.eq(pageWrap.getModel().getStatus()!=null,ShopApply::getStatus, pageWrap.getModel().getStatus()); queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getName()),ShopApply::getName,pageWrap.getModel().getName()); queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getRealname()),ShopApply::getRealname,pageWrap.getModel().getRealname()); queryWrapper.eq(ShopApply::getIsdeleted, Constants.ZERO); queryWrapper.orderByDesc(ShopApply::getCreateDate); IPage result = shopApplyJoinMapper.selectJoinPage(page, ShopApply.class, queryWrapper); return PageData.from(result); } @Override public long count(ShopApply shopApply) { QueryWrapper wrapper = new QueryWrapper<>(shopApply); return shopApplyMapper.selectCount(wrapper); } }