| | |
| | | package com.hrt.system.service.impl; |
| | | |
| | | import com.hrt.system.pojo.Shop; |
| | | import com.hrt.system.mapper.ShopMapper; |
| | | import com.hrt.system.service.ShopService; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.hrt.common.core.utils.StringUtils; |
| | | import com.hrt.system.api.domain.SysUser; |
| | | import com.hrt.system.domain.dto.MgtChangeCoopDto; |
| | | import com.hrt.system.domain.dto.MgtEditShopDto; |
| | | import com.hrt.system.domain.dto.MgtEditShopTagDto; |
| | | import com.hrt.system.domain.dto.MgtShopPageDto; |
| | | import com.hrt.system.domain.poji.shop.*; |
| | | import com.hrt.system.domain.poji.sys.SysTag; |
| | | import com.hrt.system.domain.vo.AppShopInfoVo; |
| | | import com.hrt.system.domain.vo.MgtShopInfoVo; |
| | | import com.hrt.system.domain.vo.MgtShopPageVo; |
| | | import com.hrt.system.mapper.shop.ShopMapper; |
| | | import com.hrt.system.service.shop.*; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.hrt.system.service.sys.SysTagService; |
| | | import com.hrt.system.service.user.ISysUserService; |
| | | import com.hrt.system.util.CodeFactoryUtil; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.StringJoiner; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class ShopServiceImpl extends ServiceImpl<ShopMapper, Shop> implements ShopService { |
| | | |
| | | @Resource |
| | | private ShopMapper shopMapper; |
| | | |
| | | @Resource |
| | | private ShopFileService shopFileService; |
| | | |
| | | @Resource |
| | | private ShopCertificateService shopCertificateService; |
| | | |
| | | @Resource |
| | | private SysTagService sysTagService; |
| | | |
| | | @Resource |
| | | private ShopRelTagService shopRelTagService; |
| | | |
| | | @Resource |
| | | private ShopRelUserService shopRelUserService; |
| | | |
| | | @Resource |
| | | private ISysUserService sysUserService; |
| | | |
| | | /** |
| | | * 获取商户详情 |
| | | * @param shopId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public AppShopInfoVo getAppShopInfo(Long shopId){ |
| | | AppShopInfoVo appShopInfoVo = new AppShopInfoVo(); |
| | | Shop shop = this.getById(shopId); |
| | | BeanUtils.copyProperties(shop,appShopInfoVo); |
| | | //商户地址 |
| | | appShopInfoVo.setShopAddress(shop.getShopAreaName()+shop.getShopAddress()); |
| | | //商品图片 |
| | | List<ShopFile> shopFileList = shopFileService.listShopFileByShopId(shopId); |
| | | String shopPicture = null; |
| | | StringJoiner shopBanners = new StringJoiner(","); |
| | | if(shopFileList!=null&&!shopFileList.isEmpty()){ |
| | | for(ShopFile shopFile : shopFileList){ |
| | | if(shopFile.getFileType()==1){ |
| | | shopPicture = shopFile.getFileUrl(); |
| | | }else{ |
| | | shopBanners.add(shopFile.getFileUrl()); |
| | | } |
| | | } |
| | | } |
| | | appShopInfoVo.setShopPicture(shopPicture); |
| | | appShopInfoVo.setShopBanners(shopBanners.toString()); |
| | | //商户证书 |
| | | List<ShopCertificate> shopCertificateList = shopCertificateService.listShopCertificateByShopId(shopId); |
| | | if(shopCertificateList!=null&&!shopCertificateList.isEmpty()){ |
| | | appShopInfoVo.setShopCertificateList(shopCertificateList); |
| | | } |
| | | return appShopInfoVo; |
| | | } |
| | | |
| | | /** |
| | | * 创建商户 |
| | | * @param MGTEditShopDto |
| | | */ |
| | | @Override |
| | | public void createShop(MgtEditShopDto MGTEditShopDto){ |
| | | Shop shop = new Shop(); |
| | | if(MGTEditShopDto.getShopId()!=null){ |
| | | shop = this.getById(MGTEditShopDto.getShopId()); |
| | | shop.setUpdateTime(new Date()); |
| | | shop.setUpdateUserId(MGTEditShopDto.getUserId()); |
| | | shop.setShopTags(null); |
| | | //清空关联记录 |
| | | shopFileService.deleteByShopId(shop.getShopId()); |
| | | shopRelTagService.deleteByShopId(shop.getShopId()); |
| | | shopRelUserService.deleteByShopId(shop.getShopId()); |
| | | }else{ |
| | | shop.setShopStatus(2); |
| | | shop.setCreateTime(new Date()); |
| | | shop.setCreateUserId(MGTEditShopDto.getUserId()); |
| | | } |
| | | BeanUtils.copyProperties(MGTEditShopDto,shop); |
| | | this.saveOrUpdate(shop); |
| | | //商户编号 |
| | | if(MGTEditShopDto.getShopId()==null){ |
| | | String shopNo = CodeFactoryUtil.getShopNo(shop.getShopId()); |
| | | shop.setShopNumber(shopNo); |
| | | } |
| | | //商户标签 |
| | | String shopTagIds = MGTEditShopDto.getShopTagIds(); |
| | | if(StringUtils.isNotBlank(shopTagIds)){ |
| | | String[] shopTagIdArray = shopTagIds.split(","); |
| | | ShopRelTag shopRelTag; |
| | | Long tagid; |
| | | StringJoiner shopTagSj = new StringJoiner(","); |
| | | SysTag sysTag; |
| | | for(String str : shopTagIdArray){ |
| | | shopRelTag = new ShopRelTag(); |
| | | tagid = Long.valueOf(str); |
| | | sysTag = sysTagService.getById(tagid); |
| | | shopRelTag.setDelFlag(0); |
| | | shopRelTag.setShopId(shop.getShopId()); |
| | | shopRelTag.setTagId(tagid); |
| | | shopRelTagService.save(shopRelTag); |
| | | shopTagSj.add(sysTag.getTagName()); |
| | | } |
| | | shop.setShopTags(shopTagSj.toString()); |
| | | this.saveOrUpdate(shop); |
| | | } |
| | | //商户关联人员 |
| | | String relUserIds = MGTEditShopDto.getRelUserIds(); |
| | | if(StringUtils.isNotBlank(relUserIds)){ |
| | | String[] relUserIdArray = relUserIds.split(","); |
| | | ShopRelUser shopRelUser; |
| | | Long userId; |
| | | SysUser sysUser; |
| | | for(String str : relUserIdArray){ |
| | | shopRelUser = new ShopRelUser(); |
| | | userId = Long.valueOf(str); |
| | | sysUser = sysUserService.selectUserById(userId); |
| | | shopRelUser.setDelFlag(0); |
| | | shopRelUser.setShopId(shop.getShopId()); |
| | | shopRelUser.setUserId(userId); |
| | | shopRelUser.setUserName(sysUser.getNickName()); |
| | | shopRelUser.setUserMobile(sysUser.getPhonenumber()); |
| | | shopRelUser.setUserDeptId(sysUser.getDeptId()); |
| | | shopRelUserService.save(shopRelUser); |
| | | } |
| | | } |
| | | //商户封面 |
| | | ShopFile shopFile = new ShopFile(); |
| | | shopFile.setDelFlag(0); |
| | | shopFile.setFileType(1); |
| | | shopFile.setFileUrl(MGTEditShopDto.getShopPicture()); |
| | | shopFile.setShopId(shop.getShopId()); |
| | | shopFileService.save(shopFile); |
| | | //商户banner |
| | | if(StringUtils.isNotBlank(MGTEditShopDto.getShopBanners())){ |
| | | String shopBanners= MGTEditShopDto.getShopBanners(); |
| | | String[] shopBannerArray = shopBanners.split(","); |
| | | for(String str : shopBannerArray){ |
| | | shopFile = new ShopFile(); |
| | | shopFile.setDelFlag(0); |
| | | shopFile.setFileType(2); |
| | | shopFile.setFileUrl(str); |
| | | shopFile.setShopId(shop.getShopId()); |
| | | shopFileService.save(shopFile); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 修改合作时间 |
| | | * @param mgtChangeCoopDto |
| | | */ |
| | | @Override |
| | | public void changeCooperationTime(MgtChangeCoopDto mgtChangeCoopDto){ |
| | | Shop shop = this.getById(mgtChangeCoopDto.getShopId()); |
| | | String coopStartTime = mgtChangeCoopDto.getCoopStartTime(); |
| | | String coopEndTime = mgtChangeCoopDto.getCoopEndTime(); |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | try { |
| | | Date coopStartDate = simpleDateFormat.parse(coopStartTime); |
| | | Date coopEndDate = simpleDateFormat.parse(coopEndTime); |
| | | Date nowTime = new Date(); |
| | | shop.setCooperationStartTime(coopStartDate); |
| | | shop.setCooperationEndTime(coopEndDate); |
| | | Boolean inTime = false; |
| | | if(coopStartDate.compareTo(nowTime)<0&&coopEndDate.compareTo(nowTime)>0){ |
| | | inTime = true; |
| | | } |
| | | if(shop.getShopStatus()==2&&inTime){ |
| | | shop.setShopStatus(1); |
| | | } |
| | | shop.setUpdateTime(nowTime); |
| | | shop.setUpdateUserId(mgtChangeCoopDto.getUserId()); |
| | | this.saveOrUpdate(shop); |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 分页获取商户 |
| | | * @param page |
| | | * @param mgtShopPageDto |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<MgtShopPageVo> pageShop(Page page, MgtShopPageDto mgtShopPageDto){ |
| | | List<MgtShopPageVo> mgtShopPageVoList = shopMapper.pageShop(page, mgtShopPageDto); |
| | | return mgtShopPageVoList; |
| | | } |
| | | |
| | | /** |
| | | * 获取商户详情 |
| | | * @param shopId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public MgtShopInfoVo getMgtShopInfo(Long shopId){ |
| | | MgtShopInfoVo mgtShopInfoVo = new MgtShopInfoVo(); |
| | | Shop shop = this.getById(shopId); |
| | | //基本信息拷贝 |
| | | BeanUtils.copyProperties(shop,mgtShopInfoVo); |
| | | //商户标签 |
| | | List<ShopRelTag> shopRelTagList = shopRelTagService.listShopRelTagByShopId(shopId); |
| | | if(shopRelTagList!=null&&!shopRelTagList.isEmpty()){ |
| | | StringJoiner shopTagJs = new StringJoiner(","); |
| | | for(ShopRelTag shopRelTag : shopRelTagList){ |
| | | shopTagJs.add(shopRelTag.getTagId().toString()); |
| | | } |
| | | mgtShopInfoVo.setShopTagIds(shopTagJs.toString()); |
| | | } |
| | | //商户关联用户 |
| | | List<ShopRelUser> shopRelUserList = shopRelUserService.listByShopId(shopId); |
| | | if(shopRelUserList!=null&&!shopRelUserList.isEmpty()){ |
| | | StringJoiner shopUserJs = new StringJoiner(","); |
| | | StringJoiner shopUserNameJs = new StringJoiner(","); |
| | | for(ShopRelUser shopRelUser : shopRelUserList){ |
| | | shopUserJs.add(shopRelUser.getUserId().toString()); |
| | | shopUserNameJs.add(shopRelUser.getUserName()); |
| | | } |
| | | mgtShopInfoVo.setRelUserIds(shopUserJs.toString()); |
| | | mgtShopInfoVo.setRelUsers(shopUserNameJs.toString()); |
| | | } |
| | | //商户图片 |
| | | List<ShopFile> shopFileList = shopFileService.listShopFileByShopId(shopId); |
| | | if(shopFileList!=null&&!shopFileList.isEmpty()){ |
| | | StringJoiner shopBannerJs = new StringJoiner(","); |
| | | for(ShopFile shopFile : shopFileList){ |
| | | if(shopFile.getFileType()==1){ |
| | | mgtShopInfoVo.setShopPicture(shopFile.getFileUrl()); |
| | | }else{ |
| | | shopBannerJs.add(shopFile.getFileUrl()); |
| | | } |
| | | } |
| | | mgtShopInfoVo.setShopBanners(shopBannerJs.toString()); |
| | | } |
| | | //商户证书 |
| | | List<ShopCertificate> shopCertificateList = shopCertificateService.listShopCertificateByShopId(shopId); |
| | | mgtShopInfoVo.setShopCertificateList(shopCertificateList); |
| | | return mgtShopInfoVo; |
| | | } |
| | | |
| | | /** |
| | | * 修改商户标签 |
| | | * @param mgtEditShopTagDto |
| | | */ |
| | | @Override |
| | | public void editShopTag(MgtEditShopTagDto mgtEditShopTagDto){ |
| | | Long shopId = Long.valueOf(mgtEditShopTagDto.getId()); |
| | | String shopTagIds = mgtEditShopTagDto.getShopTagIds(); |
| | | String shopTags = null; |
| | | //删除以前的标签 |
| | | shopRelTagService.deleteByShopId(shopId); |
| | | if(StringUtils.isNotBlank(shopTagIds)){ |
| | | ShopRelTag shopRelTag; |
| | | SysTag sysTag; |
| | | Long tagId; |
| | | String[] shopTagIdArray = shopTagIds.split(","); |
| | | StringJoiner shopTagSj = new StringJoiner(","); |
| | | for(String str : shopTagIdArray){ |
| | | tagId = Long.valueOf(str); |
| | | sysTag = sysTagService.getById(tagId); |
| | | shopRelTag = new ShopRelTag(); |
| | | shopRelTag.setDelFlag(0); |
| | | shopRelTag.setShopId(shopId); |
| | | shopRelTag.setTagId(tagId); |
| | | shopRelTagService.save(shopRelTag); |
| | | shopTagSj.add(sysTag.getTagName()); |
| | | } |
| | | shopTags = shopTagSj.toString(); |
| | | } |
| | | Shop shop = this.getById(shopId); |
| | | shop.setShopTags(shopTags); |
| | | this.saveOrUpdate(shop); |
| | | } |
| | | } |