Search in sources :

Example 1 with ServiceException

use of cn.lili.common.exception.ServiceException in project lilishop by lilishop.

the class PlatformViewServiceImpl method list.

@Override
public List<PlatformViewVO> list(StatisticsQueryParam queryParam) {
    List<PlatformViewVO> result = new ArrayList<>();
    // 查询开始时间和结束时间,用于数据库查询
    Date endTime = null, startTime = null;
    // 搜索类型判定,如果不为空,则按照搜索类型进行查询
    if (StringUtils.isNotEmpty(queryParam.getSearchType())) {
        SearchTypeEnum searchTypeEnum = SearchTypeEnum.valueOf(queryParam.getSearchType());
        switch(searchTypeEnum) {
            case TODAY:
                PlatformViewVO today = new PlatformViewVO();
                // 查询 平台流量
                if (StringUtils.isEmpty(queryParam.getStoreId())) {
                    // 设置PV UV属性
                    String pv = cache.getString(CachePrefix.PV.getPrefix() + StatisticsSuffix.suffix());
                    if (pv == null) {
                        pv = "0";
                    }
                    today.setPvNum(Long.valueOf(pv));
                    today.setUvNum(cache.counter(CachePrefix.UV.getPrefix() + StatisticsSuffix.suffix()).longValue());
                } else // 店铺流量
                {
                    // 设置PV UV属性
                    String pv = cache.getString(CachePrefix.STORE_PV.getPrefix() + StatisticsSuffix.suffix(queryParam.getStoreId()));
                    if (pv == null) {
                        pv = "0";
                    }
                    today.setPvNum(Long.valueOf(pv));
                    today.setUvNum(cache.counter(CachePrefix.STORE_UV.getPrefix() + StatisticsSuffix.suffix(queryParam.getStoreId())).longValue());
                }
                today.setDate(new Date());
                result.add(today);
                break;
            case YESTERDAY:
            case LAST_SEVEN:
            case LAST_THIRTY:
                {
                    Date[] dates = StatisticsDateUtil.getDateArray(searchTypeEnum);
                    endTime = dates[1];
                    startTime = dates[0];
                    break;
                }
            default:
                throw new ServiceException(ResultCode.ERROR);
        }
    } else {
        // 根据查询时间来确定查询参数
        Integer year = queryParam.getYear();
        Integer month = queryParam.getMonth();
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.set(year, month - 1, 1);
        startTime = calendar.getTime();
        calendar.set(year, month, -1);
        endTime = calendar.getTime();
    }
    // 时间不为空则按照时间开始数据查询
    if (startTime != null) {
        LambdaQueryWrapper<PlatformViewData> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.between(PlatformViewData::getDate, startTime, endTime);
        lambdaQueryWrapper.eq(PlatformViewData::getStoreId, StringUtils.isEmpty(queryParam.getStoreId()) ? "-1" : queryParam.getStoreId());
        List<PlatformViewData> dataList = this.list(lambdaQueryWrapper);
        result = builderVOS(startTime, endTime, dataList);
    }
    return result;
}
Also used : Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) PlatformViewVO(cn.lili.modules.statistics.entity.vo.PlatformViewVO) Date(java.util.Date) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) PlatformViewData(cn.lili.modules.statistics.entity.dos.PlatformViewData) ServiceException(cn.lili.common.exception.ServiceException) SearchTypeEnum(cn.lili.modules.statistics.entity.enums.SearchTypeEnum)

Example 2 with ServiceException

use of cn.lili.common.exception.ServiceException in project lilishop by lilishop.

the class FreightTemplateServiceImpl method editFreightTemplate.

@Override
@Transactional(rollbackFor = Exception.class)
public FreightTemplateVO editFreightTemplate(FreightTemplateVO freightTemplateVO) {
    // 获取当前登录商家账号
    AuthUser tokenUser = UserContext.getCurrentUser();
    if (freightTemplateVO.getId().equals(tokenUser.getStoreId())) {
        throw new ServiceException(ResultCode.USER_AUTHORITY_ERROR);
    }
    FreightTemplate freightTemplate = new FreightTemplate();
    // 复制属性
    BeanUtils.copyProperties(freightTemplateVO, freightTemplate);
    // 修改运费模板
    this.updateById(freightTemplate);
    // 删除模板子内容
    freightTemplateChildService.removeFreightTemplate(freightTemplateVO.getId());
    // 给子模板赋父模板的id
    List<FreightTemplateChild> list = new ArrayList<>();
    for (FreightTemplateChild freightTemplateChild : freightTemplateVO.getFreightTemplateChildList()) {
        freightTemplateChild.setFreightTemplateId(freightTemplate.getId());
        list.add(freightTemplateChild);
    }
    // 添加模板子内容
    freightTemplateChildService.addFreightTemplateChild(list);
    // 更新缓存
    cache.remove(CachePrefix.SHIP_TEMPLATE.getPrefix() + tokenUser.getStoreId());
    return null;
}
Also used : ServiceException(cn.lili.common.exception.ServiceException) ArrayList(java.util.ArrayList) AuthUser(cn.lili.common.security.AuthUser) FreightTemplateChild(cn.lili.modules.store.entity.dos.FreightTemplateChild) FreightTemplate(cn.lili.modules.store.entity.dos.FreightTemplate) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with ServiceException

use of cn.lili.common.exception.ServiceException in project lilishop by lilishop.

the class StoreServiceImpl method add.

@Override
@Transactional(rollbackFor = Exception.class)
public Store add(AdminStoreApplyDTO adminStoreApplyDTO) {
    // 判断店铺名称是否存在
    QueryWrapper<Store> queryWrapper = Wrappers.query();
    queryWrapper.eq("store_name", adminStoreApplyDTO.getStoreName());
    if (this.getOne(queryWrapper) != null) {
        throw new ServiceException(ResultCode.STORE_NAME_EXIST_ERROR);
    }
    Member member = memberService.getById(adminStoreApplyDTO.getMemberId());
    // 判断用户是否存在
    if (member == null) {
        throw new ServiceException(ResultCode.USER_NOT_EXIST);
    }
    // 判断是否拥有店铺
    if (Boolean.TRUE.equals(member.getHaveStore())) {
        throw new ServiceException(ResultCode.STORE_APPLY_DOUBLE_ERROR);
    }
    // 添加店铺
    Store store = new Store(member, adminStoreApplyDTO);
    this.save(store);
    // 判断是否存在店铺详情,如果没有则进行新建,如果存在则进行修改
    StoreDetail storeDetail = new StoreDetail(store, adminStoreApplyDTO);
    storeDetailService.save(storeDetail);
    // 设置会员-店铺信息
    memberService.update(new LambdaUpdateWrapper<Member>().eq(Member::getId, member.getId()).set(Member::getHaveStore, true).set(Member::getStoreId, store.getId()));
    return store;
}
Also used : LambdaUpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper) StoreDetail(cn.lili.modules.store.entity.dos.StoreDetail) ServiceException(cn.lili.common.exception.ServiceException) Store(cn.lili.modules.store.entity.dos.Store) Member(cn.lili.modules.member.entity.dos.Member) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with ServiceException

use of cn.lili.common.exception.ServiceException in project lilishop by lilishop.

the class StoreServiceImpl method disable.

@Override
public boolean disable(String id) {
    Store store = this.getById(id);
    if (store != null) {
        store.setStoreDisable(StoreStatusEnum.CLOSED.value());
        // 下架所有此店铺商品
        goodsService.underStoreGoods(id);
        return this.updateById(store);
    }
    throw new ServiceException(ResultCode.STORE_NOT_EXIST);
}
Also used : ServiceException(cn.lili.common.exception.ServiceException) Store(cn.lili.modules.store.entity.dos.Store)

Example 5 with ServiceException

use of cn.lili.common.exception.ServiceException in project lilishop by lilishop.

the class LogisticsServiceImpl method getOrderTracesByJson.

/**
 * 获取物流信息
 *
 * @param logisticsId 物流公司ID
 * @param expNo       物流单号
 * @param customerName 手机号后四位
 * @return 物流信息
 * @throws Exception
 */
private Traces getOrderTracesByJson(String logisticsId, String expNo, String customerName) throws Exception {
    Setting setting = settingService.get(SettingEnum.KUAIDI_SETTING.name());
    if (CharSequenceUtil.isBlank(setting.getSettingValue())) {
        throw new ServiceException(ResultCode.LOGISTICS_NOT_SETTING);
    }
    KuaidiSetting kuaidiSetting = new Gson().fromJson(setting.getSettingValue(), KuaidiSetting.class);
    // ID
    String EBusinessID = kuaidiSetting.getEbusinessID();
    // KEY
    String AppKey = kuaidiSetting.getAppKey();
    // 请求url
    String ReqURL = kuaidiSetting.getReqURL();
    Logistics logistics = this.getById(logisticsId);
    if (logistics != null) {
        String requestData = "{'OrderCode':'','ShipperCode':'" + logistics.getCode() + "','LogisticCode':'" + expNo + "'" + ",'CustomerName':'" + customerName + "'" + "}";
        Map<String, String> params = new HashMap<>(8);
        params.put("RequestData", urlEncoder(requestData, "UTF-8"));
        params.put("EBusinessID", EBusinessID);
        params.put("RequestType", "1002");
        String dataSign = encrypt(requestData, AppKey, "UTF-8");
        params.put("DataSign", urlEncoder(dataSign, "UTF-8"));
        params.put("DataType", "2");
        String result = sendPost(ReqURL, params);
        Map map = (Map) JSON.parse(result);
        return new Traces(logistics.getName(), expNo, (List<Map>) map.get("Traces"));
    }
    return null;
}
Also used : KuaidiSetting(cn.lili.modules.system.entity.dto.KuaidiSetting) ServiceException(cn.lili.common.exception.ServiceException) HashMap(java.util.HashMap) Traces(cn.lili.modules.system.entity.vo.Traces) KuaidiSetting(cn.lili.modules.system.entity.dto.KuaidiSetting) Setting(cn.lili.modules.system.entity.dos.Setting) Gson(com.google.gson.Gson) HashMap(java.util.HashMap) Map(java.util.Map) Logistics(cn.lili.modules.system.entity.dos.Logistics)

Aggregations

ServiceException (cn.lili.common.exception.ServiceException)179 Transactional (org.springframework.transaction.annotation.Transactional)51 AuthUser (cn.lili.common.security.AuthUser)34 Member (cn.lili.modules.member.entity.dos.Member)26 JSONObject (cn.hutool.json.JSONObject)22 ApiOperation (io.swagger.annotations.ApiOperation)19 Setting (cn.lili.modules.system.entity.dos.Setting)18 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)18 Order (cn.lili.modules.order.order.entity.dos.Order)16 GoodsSku (cn.lili.modules.goods.entity.dos.GoodsSku)15 CashierParam (cn.lili.modules.payment.kit.params.dto.CashierParam)12 PromotionGoods (cn.lili.modules.promotion.entity.dos.PromotionGoods)10 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)10 ConnectAuthUser (cn.lili.modules.connect.entity.dto.ConnectAuthUser)8 WechatPaymentSetting (cn.lili.modules.system.entity.dto.payment.WechatPaymentSetting)8 Goods (cn.lili.modules.goods.entity.dos.Goods)7 OrderItem (cn.lili.modules.order.order.entity.dos.OrderItem)7 JSONUtil (cn.hutool.json.JSONUtil)6 ResultCode (cn.lili.common.enums.ResultCode)6 ArrayList (java.util.ArrayList)6