doum
昨天 22aaacd9e51da58ed10221639b6bd2fd9a13c6e5
server/dmmall_service/src/main/java/com/doumee/service/business/impl/ShopServiceImpl.java
@@ -10,9 +10,7 @@
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.MemberMapper;
import com.doumee.dao.business.ShopJoinMapper;
import com.doumee.dao.business.ShopMapper;
import com.doumee.dao.business.*;
import com.doumee.dao.business.join.ProductLabelJoinMapper;
import com.doumee.dao.business.model.*;
import com.doumee.dao.business.model.Labels;
@@ -24,6 +22,7 @@
import com.doumee.dao.web.dto.CouponDTO;
import com.doumee.dao.web.dto.MemberDTO;
import com.doumee.dao.web.dto.MultiFileDTO;
import com.doumee.dao.web.dto.ResetSystemUserPwdDTO;
import com.doumee.dao.web.dto.shop.*;
import com.doumee.service.business.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -31,6 +30,7 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.shiro.SecurityUtils;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang3.StringUtils;
@@ -58,6 +58,12 @@
    @Autowired
    private ShopMapper shopMapper;
    @Autowired
    private GoodsMapper goodsMapper;
    @Autowired
    private GoodsSkuMapper goodsSkuMapper;
    @Autowired
    private ShopGoodsRelationMapper shopGoodsRelationMapper;
    @Autowired
    private ShopCommentService shopCommentService;
@@ -101,6 +107,8 @@
    @Autowired
    private ShopNewsService shopNewsService;
    @Autowired
    private LabelsMapper labelsMapper;
    @Autowired
    private MultifileService multifileService;
@@ -112,44 +120,68 @@
        isCreateParamValid(shop,user);
        shop.setCreator(user.getId());
        shop.setCreateDate(new Date());
        shop.setEditor(user.getId());
        shop.setEditDate(shop.getCreateDate());
        shop.setIsdeleted(Constants.ZERO);
        shop.setStatus(Constants.ZERO);
        shop.setIsrec(Constants.ONE);
        shop.setOrigin(Constants.ONE);
        shop.setSaleType(Constants.formatIntegerNum(shop.getSaleType()));
        String salt = RandomStringUtils.randomAlphabetic(6);
        shop.setPassword(shop.getCode()+"@123456");
        // 生成密码
        shop.setPassword(Utils.Secure.encryptPassword(shop.getPassword(), salt));
        shop.setSalt(salt);
        shopMapper.insert(shop);
        return shop.getId();
    }
    public void isCreateParamValid(Shop shop , LoginUserInfo user){
        if(StringUtils.isBlank(shop.getName())||
        StringUtils.isBlank(shop.getImgurl())||
                shop.getMemberId()==null
        ){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), ResponseStatus.BAD_REQUEST.getMessage());
        try {
            String[] ss = shop.getLocationInfo().split(",");
            shop.setLatitude(BigDecimal.valueOf(Double.parseDouble(ss[0])));
            shop.setLongitude(BigDecimal.valueOf(Double.parseDouble(ss[1])));
        }catch (Exception e){
        }
        Member member=memberMapper.selectById(shop.getMemberId());
        if(Objects.isNull(member)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"店铺负责人不存在");
        if(StringUtils.isBlank(shop.getUsername())
                ||  StringUtils.isBlank(shop.getPhone())
                ||  StringUtils.isBlank(shop.getBusinessImg())
                ||  StringUtils.isBlank(shop.getStartTime())
                ||   shop.getLatitude()==null
                ||   shop.getLongitude()==null
                ||   shop.getBigAreaId()==null
                ||   shop.getAreaId()==null
                ||  StringUtils.isBlank(shop.getRealname())
                ||  StringUtils.isBlank(shop.getName())
                ||  StringUtils.isBlank(shop.getCode())){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        if(AreasServiceImpl.getAddressByAreaId(shop.getAreaId()) ==null){
        Shop query=new Shop();
        query.setIsdeleted(Constants.ZERO);
        query.setMemberId(shop.getMemberId());
        if(shop.getId()!=null){
            Shop result= shopMapper.selectOne(new QueryWrapper<>(query)
            .last("limit 1")
            );
            if(!Constants.equalsInteger(result.getId(),shop.getId())){
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"店铺负责人已被关联,请从新选择负责人");
            }
        }else{
            List<Shop> result= shopMapper.selectList(new QueryWrapper<>(query));
            if(org.apache.commons.collections.CollectionUtils.isNotEmpty(result)){
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"店铺负责人已存在,请从新选择负责人");
            }
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"请选择正确的省市区信息~");
        }
        if(labelsMapper.selectById(shop.getBigAreaId()) ==null){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"请选择正确的区域信息~");
        }
        if(shopMapper.selectCount(new QueryWrapper<Shop>().lambda()
                .eq(Shop::getName,shop.getName())
                .ne(shop.getId()!=null,Shop::getId,shop.getId())
                .eq(Shop::getIsdeleted,Constants.ZERO))>0){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"经销商名称重复,请返回修改~");
        }
        if(shopMapper.selectCount(new QueryWrapper<Shop>().lambda()
                .eq(Shop::getCode,shop.getCode())
                .ne(shop.getId()!=null,Shop::getId,shop.getId())
                .eq(Shop::getIsdeleted,Constants.ZERO))>0){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"门店ID重复,请返回修改~");
        }
        if(shopMapper.selectCount(new QueryWrapper<Shop>().lambda()
                .eq(Shop::getUsername,shop.getUsername())
                .ne(shop.getId()!=null,Shop::getId,shop.getId())
                .eq(Shop::getIsdeleted,Constants.ZERO))>0){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"登录账号重复,请返回修改~");
        }
    }
    @Override
@@ -180,7 +212,7 @@
    @Override
    public void updateById(Shop shop) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(shop.getId()==null){
        if(shop.getId()==null ){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), ResponseStatus.BAD_REQUEST.getMessage());
        }
        isCreateParamValid(shop,user);
@@ -279,6 +311,10 @@
        if(Objects.nonNull(shop)&&StringUtils.isNotBlank(shop.getImgurl())){
            shop.setImgFullUrl(path+shop.getImgurl());
        }
        shop.setAreas(AreasServiceImpl.getAddressByAreaId(shop.getAreaId()));
        if(shop.getLatitude()!=null && shop.getLongitude()!=null){
            shop.setLocationInfo(shop.getLatitude().doubleValue()+","+shop.getLongitude().doubleValue());
        }
        MPJLambdaWrapper<ProductLabel> queryproduct = new MPJLambdaWrapper<>();
        queryproduct.selectAs(Labels::getName,ProductLabel::getLablesName);
        queryproduct.eq(ProductLabel::getIsdeleted,Constants.ZERO);
@@ -297,6 +333,7 @@
    @Override
    public List<Shop> findList(Shop shop) {
        shop.setIsdeleted(Constants.ZERO);
        QueryWrapper<Shop> wrapper = new QueryWrapper<>(shop);
        return shopMapper.selectList(wrapper);
    }
@@ -308,24 +345,39 @@
        Utils.MP.blankToNull(pageWrap.getModel());
        queryWrapper.selectAll(Shop.class);
        if(pageWrap.getModel().getGoodsId()!=null){
            //查询某商品的供货价
            queryWrapper.select("(select s.price from shop_goods_relation s where s.ISDELETED=0 and s.shop_id = t.id and s.GOODS_ID="+pageWrap.getModel().getGoodsId()+") as goodsPrice ");
        }
        queryWrapper.selectAs(Labels::getName,Shop::getBigAreaName);
        queryWrapper.selectAs(Member::getNickname,Shop::getNickName);
        queryWrapper.selectAs(Member::getImgurl,Shop::getMemberImgurl);
        queryWrapper.selectAs(Member::getPhone,Shop::getMemberPhone);
        queryWrapper.leftJoin(Member.class,Member::getId,Shop::getMemberId);
        queryWrapper.leftJoin(Labels.class,Labels::getId,Shop::getBigAreaId);
        queryWrapper.eq(Shop::getIsdeleted, Constants.ZERO);
        queryWrapper.and(StringUtils.isNotBlank(pageWrap.getModel().getName()),s->s.like(Shop::getName,pageWrap.getModel().getName()));
        queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getCode()) ,Shop::getCode,pageWrap.getModel().getCode());
        queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getUsername()) ,Shop::getName,pageWrap.getModel().getUsername());
        queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getName()) ,Shop::getName,pageWrap.getModel().getName());
        queryWrapper.eq(pageWrap.getModel().getSaleType()!=null, Shop::getSaleType, pageWrap.getModel().getSaleType());
        queryWrapper.eq(pageWrap.getModel().getStatus()!=null, Shop::getStatus, pageWrap.getModel().getStatus());
        queryWrapper.eq(pageWrap.getModel().getIsrec()!=null, Shop::getIsrec, pageWrap.getModel().getIsrec());
        queryWrapper.orderByDesc(Shop::getCreateDate);
        if(pageWrap.getModel().getGoodsId()!=null){
            queryWrapper.orderByAsc("goodsPrice");
        }
        queryWrapper.orderByDesc(Shop::getId);
        IPage<Shop> result = shopJoinMapper.selectJoinPage(page, Shop.class, queryWrapper);
        String path = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.SHOP_FILE).getCode();
        for(Shop model:result.getRecords()){
            model.setImgFullUrl(path);
            model.setAreas( AreasServiceImpl.getAddressByAreaId(model.getAreaId()));
            if(model.getLatitude()!=null && model.getLongitude()!=null){
                model.setLocationInfo(model.getLatitude().doubleValue()+","+model.getLongitude().doubleValue());
            }
        }
        return PageData.from(result );
    }
@@ -498,16 +550,16 @@
        memberCoupon.setShopId(shopId);
        memberCoupon.setType(Constants.ZERO);
        memberCoupon.setStatus(Constants.ONE);
        Integer shopCouponUseCount = memberCouponService.count(memberCoupon);
        long shopCouponUseCount = memberCouponService.count(memberCoupon);
        ShopFollow shopFollow = new ShopFollow();
        shopFollow.setObjId(shopId);
        shopFollow.setObjType(Constants.ZERO);
        Integer shopFansCount = shopFollowService.count(shopFollow);
        long shopFansCount = shopFollowService.count(shopFollow);
        ShopNews shopNews = new ShopNews();
        shopNews.setShopId(shopId);
        Integer shopNewCount = shopNewsService.count(shopNews);
        long shopNewCount = shopNewsService.count(shopNews);
        ShopDataStatisticsDTO shopDataStatisticsDTO = new ShopDataStatisticsDTO();
        shopDataStatisticsDTO.setShopCouponUseCount(shopCouponUseCount)
                .setShopFansCount(shopFansCount).setShopNewCount(shopNewCount);
@@ -530,4 +582,58 @@
        shopScan.setMemberId(shop.getMemberId());
        shopScanService.create(shopScan);
    }
    @Override
    public void resetPwd(Shop dto) {
        // 查询用户
        Shop shop = findById(dto.getId());
        if (shop == null) {
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        // 修改密码
        Shop updateUserDto = new Shop();
        updateUserDto.setId(dto.getId());
        updateUserDto.setPassword(Utils.Secure.encryptPassword( shop.getCode()+"@123456", shop.getSalt()));
        shopMapper.updateById(updateUserDto);
    }
    @Override
    @Transactional
    public  String setGoodsPrice(Shop dto){
        // 查询用户
        Shop shop = shopMapper.selectById(dto.getId());
        if (shop == null) {
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,供销商信息查询无效!");
        }
        GoodsSku queryGoodsSku=new GoodsSku();
        queryGoodsSku.setGoodsId(dto.getGoodsId());
        queryGoodsSku.setIsdeleted(Constants.ZERO);
        List<GoodsSku> goodsSkuList=goodsSkuMapper.selectList(new QueryWrapper<>(queryGoodsSku));
        if(goodsSkuList==null || goodsSkuList.size() ==0){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,请确认商品信息有效且【销售价】已设置!");
        }
        //默认sku信息
        GoodsSku goodsSku = goodsSkuList.get(0);
        if(Constants.formatBigdecimal(goodsSku.getPrice()).compareTo(Constants.formatBigdecimal(dto.getGoodsPrice())) >=0){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,供货价不允许大于商品销售价!");
        }
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        //先删除原来的数据
        shopGoodsRelationMapper.delete(new QueryWrapper<ShopGoodsRelation>().lambda()
                .eq(ShopGoodsRelation::getGoodsId,dto.getGoodsId())
                .eq(ShopGoodsRelation::getShopId,shop.getId())
         );
        ShopGoodsRelation add =new ShopGoodsRelation();
        add.setCreator(user.getId());
        add.setCreateDate(new Date());
        add.setIsdeleted(Constants.ZERO);
        add.setEditor(add.getCreator());
        add.setEditDate(add.getCreateDate());
        add.setShopId(dto.getId());
        add.setGoodsId(dto.getGoodsId());
        add.setGoodsSkuId(goodsSku.getId());
        add.setPrice(dto.getGoodsPrice());
        add.setStatus(Constants.ZERO);
        shopGoodsRelationMapper.insert(add);
        return "操作成功";
    }
}