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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations