代码优化,废弃API修改

This commit is contained in:
macro
2022-06-26 20:35:18 +08:00
parent dcb1b79f6a
commit dd4bc8f115
16 changed files with 55 additions and 31 deletions

View File

@@ -3,6 +3,8 @@ package com.macro.mall.service;
import com.macro.mall.dto.PmsProductCategoryParam;
import com.macro.mall.dto.PmsProductCategoryWithChildrenItem;
import com.macro.mall.model.PmsProductCategory;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

View File

@@ -84,4 +84,9 @@ public interface UmsAdminService {
* 获取用户信息
*/
UserDetails loadUserByUsername(String username);
/**
* 获取缓存服务
*/
UmsAdminCacheService getCacheService();
}

View File

@@ -1,5 +1,6 @@
package com.macro.mall.service.impl;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.macro.mall.mapper.CmsSubjectMapper;
import com.macro.mall.model.CmsSubject;
@@ -30,7 +31,7 @@ public class CmsSubjectServiceImpl implements CmsSubjectService {
PageHelper.startPage(pageNum, pageSize);
CmsSubjectExample example = new CmsSubjectExample();
CmsSubjectExample.Criteria criteria = example.createCriteria();
if (!StringUtils.isEmpty(keyword)) {
if (!StrUtil.isEmpty(keyword)) {
criteria.andTitleLike("%" + keyword + "%");
}
return subjectMapper.selectByExample(example);

View File

@@ -1,5 +1,6 @@
package com.macro.mall.service.impl;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.macro.mall.dto.PmsBrandParam;
import com.macro.mall.mapper.PmsBrandMapper;
@@ -37,7 +38,7 @@ public class PmsBrandServiceImpl implements PmsBrandService {
PmsBrand pmsBrand = new PmsBrand();
BeanUtils.copyProperties(pmsBrandParam, pmsBrand);
//如果创建时首字母为空,取名称的第一个为首字母
if (StringUtils.isEmpty(pmsBrand.getFirstLetter())) {
if (StrUtil.isEmpty(pmsBrand.getFirstLetter())) {
pmsBrand.setFirstLetter(pmsBrand.getName().substring(0, 1));
}
return brandMapper.insertSelective(pmsBrand);
@@ -49,7 +50,7 @@ public class PmsBrandServiceImpl implements PmsBrandService {
BeanUtils.copyProperties(pmsBrandParam, pmsBrand);
pmsBrand.setId(id);
//如果创建时首字母为空,取名称的第一个为首字母
if (StringUtils.isEmpty(pmsBrand.getFirstLetter())) {
if (StrUtil.isEmpty(pmsBrand.getFirstLetter())) {
pmsBrand.setFirstLetter(pmsBrand.getName().substring(0, 1));
}
//更新品牌时要更新商品中的品牌名称
@@ -79,7 +80,7 @@ public class PmsBrandServiceImpl implements PmsBrandService {
PmsBrandExample pmsBrandExample = new PmsBrandExample();
pmsBrandExample.setOrderByClause("sort desc");
PmsBrandExample.Criteria criteria = pmsBrandExample.createCriteria();
if (!StringUtils.isEmpty(keyword)) {
if (!StrUtil.isEmpty(keyword)) {
criteria.andNameLike("%" + keyword + "%");
}
return brandMapper.selectByExample(pmsBrandExample);

View File

@@ -1,6 +1,7 @@
package com.macro.mall.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.macro.mall.dao.*;
import com.macro.mall.dto.PmsProductParam;
@@ -98,7 +99,7 @@ public class PmsProductServiceImpl implements PmsProductService {
if(CollectionUtils.isEmpty(skuStockList))return;
for(int i=0;i<skuStockList.size();i++){
PmsSkuStock skuStock = skuStockList.get(i);
if(StringUtils.isEmpty(skuStock.getSkuCode())){
if(StrUtil.isEmpty(skuStock.getSkuCode())){
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
StringBuilder sb = new StringBuilder();
//日期
@@ -215,10 +216,10 @@ public class PmsProductServiceImpl implements PmsProductService {
if (productQueryParam.getVerifyStatus() != null) {
criteria.andVerifyStatusEqualTo(productQueryParam.getVerifyStatus());
}
if (!StringUtils.isEmpty(productQueryParam.getKeyword())) {
if (!StrUtil.isEmpty(productQueryParam.getKeyword())) {
criteria.andNameLike("%" + productQueryParam.getKeyword() + "%");
}
if (!StringUtils.isEmpty(productQueryParam.getProductSn())) {
if (!StrUtil.isEmpty(productQueryParam.getProductSn())) {
criteria.andProductSnEqualTo(productQueryParam.getProductSn());
}
if (productQueryParam.getBrandId() != null) {
@@ -293,7 +294,7 @@ public class PmsProductServiceImpl implements PmsProductService {
PmsProductExample productExample = new PmsProductExample();
PmsProductExample.Criteria criteria = productExample.createCriteria();
criteria.andDeleteStatusEqualTo(0);
if(!StringUtils.isEmpty(keyword)){
if(!StrUtil.isEmpty(keyword)){
criteria.andNameLike("%" + keyword + "%");
productExample.or().andDeleteStatusEqualTo(0).andProductSnLike("%" + keyword + "%");
}

View File

@@ -1,5 +1,6 @@
package com.macro.mall.service.impl;
import cn.hutool.core.util.StrUtil;
import com.macro.mall.dao.PmsSkuStockDao;
import com.macro.mall.mapper.PmsSkuStockMapper;
import com.macro.mall.model.PmsSkuStock;
@@ -26,7 +27,7 @@ public class PmsSkuStockServiceImpl implements PmsSkuStockService {
public List<PmsSkuStock> getList(Long pid, String keyword) {
PmsSkuStockExample example = new PmsSkuStockExample();
PmsSkuStockExample.Criteria criteria = example.createCriteria().andProductIdEqualTo(pid);
if (!StringUtils.isEmpty(keyword)) {
if (!StrUtil.isEmpty(keyword)) {
criteria.andSkuCodeLike("%" + keyword + "%");
}
return skuStockMapper.selectByExample(example);

View File

@@ -1,5 +1,6 @@
package com.macro.mall.service.impl;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.macro.mall.mapper.SmsCouponHistoryMapper;
import com.macro.mall.model.SmsCouponHistory;
@@ -30,7 +31,7 @@ public class SmsCouponHistoryServiceImpl implements SmsCouponHistoryService {
if(useStatus!=null){
criteria.andUseStatusEqualTo(useStatus);
}
if(!StringUtils.isEmpty(orderSn)){
if(!StrUtil.isEmpty(orderSn)){
criteria.andOrderSnEqualTo(orderSn);
}
return historyMapper.selectByExample(example);

View File

@@ -1,5 +1,6 @@
package com.macro.mall.service.impl;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.macro.mall.dao.SmsCouponDao;
import com.macro.mall.dao.SmsCouponProductCategoryRelationDao;
@@ -108,7 +109,7 @@ public class SmsCouponServiceImpl implements SmsCouponService {
public List<SmsCoupon> list(String name, Integer type, Integer pageSize, Integer pageNum) {
SmsCouponExample example = new SmsCouponExample();
SmsCouponExample.Criteria criteria = example.createCriteria();
if(!StringUtils.isEmpty(name)){
if(!StrUtil.isEmpty(name)){
criteria.andNameLike("%"+name+"%");
}
if(type!=null){

View File

@@ -1,5 +1,6 @@
package com.macro.mall.service.impl;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.macro.mall.mapper.SmsFlashPromotionMapper;
import com.macro.mall.model.SmsFlashPromotion;
@@ -55,7 +56,7 @@ public class SmsFlashPromotionServiceImpl implements SmsFlashPromotionService {
public List<SmsFlashPromotion> list(String keyword, Integer pageSize, Integer pageNum) {
PageHelper.startPage(pageNum, pageSize);
SmsFlashPromotionExample example = new SmsFlashPromotionExample();
if (!StringUtils.isEmpty(keyword)) {
if (!StrUtil.isEmpty(keyword)) {
example.createCriteria().andTitleLike("%" + keyword + "%");
}
return flashPromotionMapper.selectByExample(example);

View File

@@ -1,5 +1,6 @@
package com.macro.mall.service.impl;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.macro.mall.mapper.SmsHomeAdvertiseMapper;
import com.macro.mall.model.SmsHomeAdvertise;
@@ -61,13 +62,13 @@ public class SmsHomeAdvertiseServiceImpl implements SmsHomeAdvertiseService {
PageHelper.startPage(pageNum, pageSize);
SmsHomeAdvertiseExample example = new SmsHomeAdvertiseExample();
SmsHomeAdvertiseExample.Criteria criteria = example.createCriteria();
if (!StringUtils.isEmpty(name)) {
if (!StrUtil.isEmpty(name)) {
criteria.andNameLike("%" + name + "%");
}
if (type != null) {
criteria.andTypeEqualTo(type);
}
if (!StringUtils.isEmpty(endTime)) {
if (!StrUtil.isEmpty(endTime)) {
String startStr = endTime + " 00:00:00";
String endStr = endTime + " 23:59:59";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

View File

@@ -1,5 +1,6 @@
package com.macro.mall.service.impl;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.macro.mall.mapper.SmsHomeBrandMapper;
import com.macro.mall.model.SmsHomeBrand;
@@ -58,7 +59,7 @@ public class SmsHomeBrandServiceImpl implements SmsHomeBrandService {
PageHelper.startPage(pageNum,pageSize);
SmsHomeBrandExample example = new SmsHomeBrandExample();
SmsHomeBrandExample.Criteria criteria = example.createCriteria();
if(!StringUtils.isEmpty(brandName)){
if(!StrUtil.isEmpty(brandName)){
criteria.andBrandNameLike("%"+brandName+"%");
}
if(recommendStatus!=null){

View File

@@ -1,5 +1,6 @@
package com.macro.mall.service.impl;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.macro.mall.mapper.SmsHomeNewProductMapper;
import com.macro.mall.model.SmsHomeNewProduct;
@@ -58,7 +59,7 @@ public class SmsHomeNewProductServiceImpl implements SmsHomeNewProductService {
PageHelper.startPage(pageNum,pageSize);
SmsHomeNewProductExample example = new SmsHomeNewProductExample();
SmsHomeNewProductExample.Criteria criteria = example.createCriteria();
if(!StringUtils.isEmpty(productName)){
if(!StrUtil.isEmpty(productName)){
criteria.andProductNameLike("%"+productName+"%");
}
if(recommendStatus!=null){

View File

@@ -1,5 +1,6 @@
package com.macro.mall.service.impl;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.macro.mall.mapper.SmsHomeRecommendProductMapper;
import com.macro.mall.model.SmsHomeRecommendProduct;
@@ -58,7 +59,7 @@ public class SmsHomeRecommendProductServiceImpl implements SmsHomeRecommendProdu
PageHelper.startPage(pageNum,pageSize);
SmsHomeRecommendProductExample example = new SmsHomeRecommendProductExample();
SmsHomeRecommendProductExample.Criteria criteria = example.createCriteria();
if(!StringUtils.isEmpty(productName)){
if(!StrUtil.isEmpty(productName)){
criteria.andProductNameLike("%"+productName+"%");
}
if(recommendStatus!=null){

View File

@@ -1,5 +1,6 @@
package com.macro.mall.service.impl;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.macro.mall.mapper.SmsHomeRecommendSubjectMapper;
import com.macro.mall.model.SmsHomeRecommendSubject;
@@ -58,7 +59,7 @@ public class SmsHomeRecommendSubjectServiceImpl implements SmsHomeRecommendSubje
PageHelper.startPage(pageNum,pageSize);
SmsHomeRecommendSubjectExample example = new SmsHomeRecommendSubjectExample();
SmsHomeRecommendSubjectExample.Criteria criteria = example.createCriteria();
if(!StringUtils.isEmpty(subjectName)){
if(!StrUtil.isEmpty(subjectName)){
criteria.andSubjectNameLike("%"+subjectName+"%");
}
if(recommendStatus!=null){

View File

@@ -14,6 +14,7 @@ import com.macro.mall.mapper.UmsAdminMapper;
import com.macro.mall.mapper.UmsAdminRoleRelationMapper;
import com.macro.mall.model.*;
import com.macro.mall.security.util.JwtTokenUtil;
import com.macro.mall.security.util.SpringUtil;
import com.macro.mall.service.UmsAdminCacheService;
import com.macro.mall.service.UmsAdminService;
import org.slf4j.Logger;
@@ -56,19 +57,17 @@ public class UmsAdminServiceImpl implements UmsAdminService {
private UmsAdminRoleRelationDao adminRoleRelationDao;
@Autowired
private UmsAdminLoginLogMapper loginLogMapper;
@Autowired
private UmsAdminCacheService adminCacheService;
@Override
public UmsAdmin getAdminByUsername(String username) {
UmsAdmin admin = adminCacheService.getAdmin(username);
UmsAdmin admin = getCacheService().getAdmin(username);
if(admin!=null) return admin;
UmsAdminExample example = new UmsAdminExample();
example.createCriteria().andUsernameEqualTo(username);
List<UmsAdmin> adminList = adminMapper.selectByExample(example);
if (adminList != null && adminList.size() > 0) {
admin = adminList.get(0);
adminCacheService.setAdmin(admin);
getCacheService().setAdmin(admin);
return admin;
}
return null;
@@ -159,7 +158,7 @@ public class UmsAdminServiceImpl implements UmsAdminService {
PageHelper.startPage(pageNum, pageSize);
UmsAdminExample example = new UmsAdminExample();
UmsAdminExample.Criteria criteria = example.createCriteria();
if (!StringUtils.isEmpty(keyword)) {
if (!StrUtil.isEmpty(keyword)) {
criteria.andUsernameLike("%" + keyword + "%");
example.or(example.createCriteria().andNickNameLike("%" + keyword + "%"));
}
@@ -182,15 +181,15 @@ public class UmsAdminServiceImpl implements UmsAdminService {
}
}
int count = adminMapper.updateByPrimaryKeySelective(admin);
adminCacheService.delAdmin(id);
getCacheService().delAdmin(id);
return count;
}
@Override
public int delete(Long id) {
adminCacheService.delAdmin(id);
getCacheService().delAdmin(id);
int count = adminMapper.deleteByPrimaryKey(id);
adminCacheService.delResourceList(id);
getCacheService().delResourceList(id);
return count;
}
@@ -212,7 +211,7 @@ public class UmsAdminServiceImpl implements UmsAdminService {
}
adminRoleRelationDao.insertList(list);
}
adminCacheService.delResourceList(adminId);
getCacheService().delResourceList(adminId);
return count;
}
@@ -223,13 +222,13 @@ public class UmsAdminServiceImpl implements UmsAdminService {
@Override
public List<UmsResource> getResourceList(Long adminId) {
List<UmsResource> resourceList = adminCacheService.getResourceList(adminId);
List<UmsResource> resourceList = getCacheService().getResourceList(adminId);
if(CollUtil.isNotEmpty(resourceList)){
return resourceList;
}
resourceList = adminRoleRelationDao.getResourceList(adminId);
if(CollUtil.isNotEmpty(resourceList)){
adminCacheService.setResourceList(adminId,resourceList);
getCacheService().setResourceList(adminId,resourceList);
}
return resourceList;
}
@@ -253,7 +252,7 @@ public class UmsAdminServiceImpl implements UmsAdminService {
}
umsAdmin.setPassword(passwordEncoder.encode(param.getNewPassword()));
adminMapper.updateByPrimaryKey(umsAdmin);
adminCacheService.delAdmin(umsAdmin.getId());
getCacheService().delAdmin(umsAdmin.getId());
return 1;
}
@@ -267,4 +266,9 @@ public class UmsAdminServiceImpl implements UmsAdminService {
}
throw new UsernameNotFoundException("用户名或密码错误");
}
@Override
public UmsAdminCacheService getCacheService() {
return SpringUtil.getBean(UmsAdminCacheService.class);
}
}

View File

@@ -1,5 +1,6 @@
package com.macro.mall.service.impl;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.macro.mall.dao.UmsRoleDao;
import com.macro.mall.mapper.UmsRoleMapper;
@@ -63,7 +64,7 @@ public class UmsRoleServiceImpl implements UmsRoleService {
public List<UmsRole> list(String keyword, Integer pageSize, Integer pageNum) {
PageHelper.startPage(pageNum, pageSize);
UmsRoleExample example = new UmsRoleExample();
if (!StringUtils.isEmpty(keyword)) {
if (!StrUtil.isEmpty(keyword)) {
example.createCriteria().andNameLike("%" + keyword + "%");
}
return roleMapper.selectByExample(example);