k94314517
2024-07-25 a75b18a4157ab486e0b51c438ac165ab3a08e3e0
server/service/src/main/java/com/doumee/service/business/impl/ShopServiceImpl.java
@@ -1,5 +1,6 @@
package com.doumee.service.business.impl;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.annotation.excel.ExcelImporter;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
@@ -12,15 +13,17 @@
import com.doumee.dao.admin.request.FcodeImport;
import com.doumee.dao.admin.request.ShopImport;
import com.doumee.dao.admin.request.UpdateShopSortDTO;
import com.doumee.dao.business.CategoryMapper;
import com.doumee.dao.business.CategorySegMapper;
import com.doumee.dao.business.MemberMapper;
import com.doumee.dao.business.SegmentsMapper;
import com.doumee.dao.business.ShopMapper;
import com.doumee.dao.business.UsersMapper;
import com.doumee.dao.business.join.ShopJoinMapper;
import com.doumee.dao.business.model.*;
import com.doumee.dao.business.vo.ShopTree;
import com.doumee.dao.business.vo.ShopTreeVo;
import com.doumee.dao.system.model.SystemUser;
import com.doumee.dao.business.vo.UnitCodeVo;
import com.doumee.dao.web.reqeust.EditShopDTO;
import com.doumee.dao.web.reqeust.ShopQueryByLLDTO;
import com.doumee.service.business.ShopService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
@@ -29,6 +32,7 @@
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.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
@@ -37,11 +41,12 @@
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
/**
 * 志邦组织信息表Service实现
@@ -55,10 +60,17 @@
    private RedisTemplate<String, Object> redisTemplate;
    @Autowired
    private ShopJoinMapper shopMapper;
    @Autowired
    private SegmentsMapper segmentsMapper;
    @Autowired
    private CategorySegMapper categorySegMapper;
    @Autowired
    private UsersMapper usersMapper;
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
    @Autowired
    private MemberMapper memberMapper;
    @Override
    public Long create(Shop shop) {
@@ -88,6 +100,11 @@
    @Override
    public void updateById(Shop shop) {
        shopMapper.updateById(shop);
        usersMapper.update(new UpdateWrapper<Users>().lambda()
                .set(Users::getCardImg,null)
                .isNotNull(Users::getCardImg)
                .eq(Users::getDepartmentId,shop.getId())
        );
    }
    @Override
@@ -254,7 +271,30 @@
                queryWrapper.orderByAsc(sortData.getProperty());
            }
        }
        return PageData.from(shopMapper.selectPage(page, queryWrapper));
        PageData<Shop> pageData = PageData.from(shopMapper.selectPage(page, queryWrapper));
        //查询经营范围信息
        List<CategorySeg> categorySegAllList = categorySegMapper.selectList(new QueryWrapper<CategorySeg>().lambda()
                .isNotNull(CategorySeg::getOrgId)
                .eq(CategorySeg::getIsdeleted,Constants.ZERO));
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(categorySegAllList)){
            for (Shop shop:pageData.getRecords()) {
                if(StringUtils.isBlank(shop.getOrgId())){
                    continue;
                }
                List<CategorySeg> categorySegList = categorySegAllList.stream().filter(i->i.getOrgId().equals(shop.getOrgId())).collect(Collectors.toList());
                List<UnitCodeVo> unitCodeVoList =systemDictDataBiz.getUnitList();
                List<String> seqNameList = new ArrayList<>();
                for(CategorySeg model : categorySegList){
                    String seqName = systemDictDataBiz.getUnitName(model.getUnitCode(),unitCodeVoList);
                    if(Objects.nonNull(seqName)){
                        seqNameList.add(seqName);
                    }
                }
                shop.setSeqNameList(seqNameList);
            }
        }
        return pageData;
    }
    @Override
@@ -375,7 +415,7 @@
    }
    @Async
    private void dealCategoryDataBiz(List<CategoryImport> dataList, Date date, LoginUserInfo loginUserInfo) {
    public void dealCategoryDataBiz(List<CategoryImport> dataList, Date date, LoginUserInfo loginUserInfo) {
        try {
            List<CategorySeg> categorySegList = new ArrayList<>();
            List<Segments> segmentsList = new ArrayList<>();
@@ -841,10 +881,16 @@
                    s.setIdPath(s.getId()+"/");
                    shopMapper.updateById(s);
                }else{
                    String idPath = StringUtils.defaultString(parent.getIdPath(),"")+ shop.getId()+"/";
                    String namePath =StringUtils.defaultString(parent.getNamePath(),"")+"/"+shop.getName();
                    s.setParentId(parent.getId());
                    s.setNamePath(parent.getNamePath()+"/"+s.getName());
                    s.setIdPath(parent.getIdPath()+s.getId()+"/");
                    shopMapper.updateById(s);
                    s.setNamePath(namePath);
                    s.setIdPath(idPath);
                    if(!(Constants.equalsLong(parent.getId(),shop.getParentId())
                            && StringUtils.equals(idPath,shop.getIdPath())
                            &&StringUtils.equals(namePath,shop.getNamePath())) ){
                        shopMapper.updateById(s);
                    }
                }
                if(shop.getChildList()!=null && shop.getChildList().size()>0){
                    updateNamePath(s,shop.getChildList());
@@ -852,4 +898,134 @@
            }
        }
    }
    @Override
    public PageData<Shop> queryShopByLL(PageWrap<Shop> pageWrap) {
        if(Objects.isNull(pageWrap.getModel())
                || Objects.isNull(pageWrap.getModel().getLatitude())
                || Objects.isNull(pageWrap.getModel().getLongitude())){
            return null;
        }
        IPage<Shop> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<Shop> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.select("ID,NAME,ADDRESS,PROVINCE_NAME,CITY_NAME,AREA_NAME,TOWN,AREA_NAME,LEGAL_PHONE " +
                " ,  (6371 * ACOS(COS(RADIANS("+pageWrap.getModel().getLatitude()+")) * COS(RADIANS(latitude)) * COS(RADIANS(longitude) - RADIANS("+pageWrap.getModel().getLongitude()+")) + SIN(RADIANS("+pageWrap.getModel().getLatitude()+")) * SIN(RADIANS(latitude)) ) ) as distance  " )
                .eq("isdeleted",Constants.ZERO)
                .isNotNull("LATITUDE")
                .isNotNull("LONGITUDE")
                .eq("TYPE",Constants.TWO)
                .eq("SECOND_TYPE",Constants.THREE)
                .eq("STATUS",Constants.ONE)
                .orderByAsc(" distance ");
        Utils.MP.blankToNull(pageWrap.getModel());
        PageData<Shop> pageData = PageData.from(shopMapper.selectPage(page, queryWrapper));
        String prefix = StringUtils.trimToNull(systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE,Constants.RESOURCE_PATH).getCode()) +
        StringUtils.trimToNull(systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE,Constants.USERS_FILE).getCode());
        for (Shop shop:pageData.getRecords()) {
            this.dealDistance(shop);
            //查询门店下导购数据
            List<Users> usersList =usersMapper.selectList(new QueryWrapper<Users>().lambda().eq(Users::getDepartmentId,shop.getId())
                    .eq(Users::getIsdeleted,Constants.ZERO)
                    .eq(Users::getStatus,Constants.ONE)
            );
            for (Users users:usersList) {
                if(StringUtils.isNotBlank(users.getImgurl())){
                    users.setImgurlFull(prefix + users.getImgurl());
                }
            }
            shop.setUsersList(usersList);
        }
        return pageData;
    }
    /**
     * 处理门店距离显示
     * @param shop
     */
    public void dealDistance(Shop shop){
        if(Objects.isNull(shop.getDistance())){
            shop.setDistanceStr("-");
        }else{
            //距离小于1公里 显示米
            if(shop.getDistance().compareTo(BigDecimal.ONE)<Constants.ZERO){
                BigDecimal distanceM = shop.getDistance().multiply(new BigDecimal(1000).setScale(0));
                //100米之内
                if(distanceM.compareTo(new BigDecimal(100))<0){
                    shop.setDistanceStr("<100米");
                }else{
                    shop.setDistanceStr(distanceM.divide(BigDecimal.valueOf(1)).setScale(2,BigDecimal.ROUND_HALF_UP) + "m");
                }
            }else{
                shop.setDistanceStr(shop.getDistance().divide(BigDecimal.valueOf(1)).setScale(2,BigDecimal.ROUND_HALF_UP) + "km");
            }
        }
    }
    @Override
    public Shop shopDetail(Long id,Long memberId) {
        QueryWrapper<Shop> queryWrapper = new QueryWrapper<Shop>();
        if(Objects.nonNull(memberId)){
            Member member = memberMapper.selectById(memberId);
            //如果人员没有经纬度信息,则不查询距离
            if(Objects.nonNull(member)&&Objects.nonNull(member.getLatitude())&&Objects.nonNull(member.getLongitude())){
                queryWrapper.select("ID,NAME,ADDRESS,PROVINCE_NAME,CITY_NAME,AREA_NAME,TOWN,AREA_NAME,LEGAL_PHONE " +
                        " ,  (6371 * ACOS(COS(RADIANS("+member.getLatitude()+")) * COS(RADIANS(latitude)) * COS(RADIANS(longitude) - RADIANS("+member.getLongitude()+")) + SIN(RADIANS("+member.getLatitude()+")) * SIN(RADIANS(latitude)) ) ) as distance  " );
            }
        }
        queryWrapper.eq("id",id);
        Shop shop = shopMapper.selectOne(queryWrapper);
        if(Objects.isNull(shop)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        String prefix = StringUtils.trimToNull(systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE,Constants.RESOURCE_PATH).getCode()) +
                StringUtils.trimToNull(systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE,Constants.USERS_FILE).getCode());
        List<Users> usersList =usersMapper.selectList(new QueryWrapper<Users>().lambda().eq(Users::getDepartmentId,shop.getId())
                .eq(Users::getIsdeleted,Constants.ZERO)
                .eq(Users::getStatus,Constants.ONE)
        );
        this.dealDistance(shop);
        for (Users users:usersList) {
            if(StringUtils.isNotBlank(users.getImgurl())){
                users.setImgurlFull(prefix + users.getImgurl());
            }
        }
        shop.setUsersList(usersList);
        //查询经营范围信息
        List<CategorySeg> categorySegList = categorySegMapper.selectList(new QueryWrapper<CategorySeg>().lambda().eq(CategorySeg::getOrgId,shop.getOrgId()).eq(CategorySeg::getIsdeleted,Constants.ZERO));
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(categorySegList)){
            List<UnitCodeVo> unitCodeVoList =systemDictDataBiz.getUnitList();
            List<String> seqNameList = new ArrayList<>();
            for(CategorySeg model : categorySegList){
                String seqName = systemDictDataBiz.getUnitName(model.getUnitCode(),unitCodeVoList);
                if(Objects.nonNull(seqName)){
                    seqNameList.add(seqName);
                }
            }
            shop.setSeqNameList(seqNameList);
        }
        return shop;
    }
    @Override
    public void updShop(EditShopDTO editShopDTO) {
        if(Objects.isNull(editShopDTO)
        || Objects.isNull(editShopDTO.getId())){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        Shop shop = shopMapper.selectById(editShopDTO.getId());
        if(Objects.isNull(shop)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        Shop updShop = new Shop();
        BeanUtils.copyProperties(editShopDTO,updShop);
        shopMapper.updateById(updShop);
        usersMapper.update(new UpdateWrapper<Users>().lambda()
                .set(Users::getCardImg,null)
                .isNotNull(Users::getCardImg)
                .eq(Users::getDepartmentId,shop.getId())
        );
    }
}