feat: 添加商店名称字段并优化用户和商店查询逻辑
在SmartCabinetDTO中添加商店名称字段,优化Ab98UserService和ShopService的查询逻辑,提升代码可维护性和查询效率。
This commit is contained in:
parent
f499939b14
commit
54773aa16b
|
@ -75,9 +75,8 @@ public class Ab98UserApplicationService {
|
||||||
|
|
||||||
|
|
||||||
public void saveAb98User(String openid, Ab98ApiUtil.LoginData loginData) {
|
public void saveAb98User(String openid, Ab98ApiUtil.LoginData loginData) {
|
||||||
Ab98UserEntity ab98UserEntity = getByUserId(loginData.getUserid());
|
Ab98UserEntity ab98UserEntity = userService.selectByOpenidAndUserid(openid, loginData.getUserid());
|
||||||
if (ab98UserEntity != null &&
|
if (ab98UserEntity != null &&
|
||||||
StringUtils.equals(openid, ab98UserEntity.getOpenid()) &&
|
|
||||||
StringUtils.equals(loginData.getName(), ab98UserEntity.getName())
|
StringUtils.equals(loginData.getName(), ab98UserEntity.getName())
|
||||||
) {
|
) {
|
||||||
UpdateAb98UserCommand command = new UpdateAb98UserCommand();
|
UpdateAb98UserCommand command = new UpdateAb98UserCommand();
|
||||||
|
@ -110,9 +109,8 @@ public class Ab98UserApplicationService {
|
||||||
|
|
||||||
|
|
||||||
public void saveAb98UserByToken(String openid, SsoLoginUserinfo loginUserinfo) {
|
public void saveAb98UserByToken(String openid, SsoLoginUserinfo loginUserinfo) {
|
||||||
Ab98UserEntity ab98UserEntity = getByUserId(String.valueOf(loginUserinfo.getId()));
|
Ab98UserEntity ab98UserEntity = userService.selectByOpenidAndUserid(openid, String.valueOf(loginUserinfo.getId()));
|
||||||
if (ab98UserEntity != null &&
|
if (ab98UserEntity != null &&
|
||||||
StringUtils.equals(openid, ab98UserEntity.getOpenid()) &&
|
|
||||||
StringUtils.equals(loginUserinfo.getName(), ab98UserEntity.getName())
|
StringUtils.equals(loginUserinfo.getName(), ab98UserEntity.getName())
|
||||||
) {
|
) {
|
||||||
UpdateAb98UserCommand command = new UpdateAb98UserCommand();
|
UpdateAb98UserCommand command = new UpdateAb98UserCommand();
|
||||||
|
|
|
@ -43,4 +43,7 @@ public interface Ab98UserMapper extends BaseMapper<Ab98UserEntity> {
|
||||||
|
|
||||||
@Select("SELECT * FROM ab98_user WHERE openid = #{openid} LIMIT 1")
|
@Select("SELECT * FROM ab98_user WHERE openid = #{openid} LIMIT 1")
|
||||||
Ab98UserEntity selectByOpenid(String openid);
|
Ab98UserEntity selectByOpenid(String openid);
|
||||||
|
|
||||||
|
@Select("SELECT * FROM ab98_user WHERE openid = #{openid} AND userid = #{userid} LIMIT 1")
|
||||||
|
Ab98UserEntity selectByOpenidAndUserid(@Param("openid")String openid, @Param("userid")String userid);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.agileboot.domain.ab98.user.db;
|
||||||
import com.agileboot.common.core.page.AbstractPageQuery;
|
import com.agileboot.common.core.page.AbstractPageQuery;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -22,4 +23,6 @@ public interface Ab98UserService extends IService<Ab98UserEntity> {
|
||||||
Ab98UserEntity getByOpenid(String openid);
|
Ab98UserEntity getByOpenid(String openid);
|
||||||
|
|
||||||
Ab98UserEntity getByUserid(String userid);
|
Ab98UserEntity getByUserid(String userid);
|
||||||
|
|
||||||
|
Ab98UserEntity selectByOpenidAndUserid(String openid, String userid);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,4 +39,9 @@ public class Ab98UserServiceImpl extends ServiceImpl<Ab98UserMapper, Ab98UserEnt
|
||||||
public Ab98UserEntity getByUserid(String userid) {
|
public Ab98UserEntity getByUserid(String userid) {
|
||||||
return baseMapper.selectByUserid(userid);
|
return baseMapper.selectByUserid(userid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Ab98UserEntity selectByOpenidAndUserid(String openid, String userid) {
|
||||||
|
return baseMapper.selectByOpenidAndUserid(openid, userid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@ import com.agileboot.domain.cabinet.smartCabinet.model.SmartCabinetModelFactory;
|
||||||
import com.agileboot.domain.cabinet.smartCabinet.query.SearchSmartCabinetQuery;
|
import com.agileboot.domain.cabinet.smartCabinet.query.SearchSmartCabinetQuery;
|
||||||
import com.agileboot.domain.shop.goods.db.ShopGoodsEntity;
|
import com.agileboot.domain.shop.goods.db.ShopGoodsEntity;
|
||||||
import com.agileboot.domain.shop.goods.db.ShopGoodsService;
|
import com.agileboot.domain.shop.goods.db.ShopGoodsService;
|
||||||
|
import com.agileboot.domain.shop.shop.db.ShopEntity;
|
||||||
|
import com.agileboot.domain.shop.shop.db.ShopService;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -30,12 +32,24 @@ public class SmartCabinetApplicationService {
|
||||||
private final SmartCabinetModelFactory smartCabinetModelFactory;
|
private final SmartCabinetModelFactory smartCabinetModelFactory;
|
||||||
private final CabinetCellService cabinetCellService;
|
private final CabinetCellService cabinetCellService;
|
||||||
private final ShopGoodsService shopGoodsService;
|
private final ShopGoodsService shopGoodsService;
|
||||||
|
private final ShopService shopService;
|
||||||
|
|
||||||
public PageDTO<SmartCabinetDTO> getSmartCabinetList(SearchSmartCabinetQuery<SmartCabinetEntity> query) {
|
public PageDTO<SmartCabinetDTO> getSmartCabinetList(SearchSmartCabinetQuery<SmartCabinetEntity> query) {
|
||||||
|
List<ShopEntity> shopEntities = shopService.selectAll();
|
||||||
|
|
||||||
Page<SmartCabinetEntity> page = smartCabinetService.getCabinetList(query);
|
Page<SmartCabinetEntity> page = smartCabinetService.getCabinetList(query);
|
||||||
List<SmartCabinetDTO> dtoList = page.getRecords().stream()
|
List<SmartCabinetDTO> dtoList = page.getRecords().stream()
|
||||||
.map(SmartCabinetDTO::new)
|
.map(SmartCabinetDTO::new)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
dtoList.forEach(dto ->
|
||||||
|
dto.setShopName(
|
||||||
|
shopEntities.stream()
|
||||||
|
.filter(shop -> shop.getShopId().equals(dto.getShopId()))
|
||||||
|
.findFirst()
|
||||||
|
.map(ShopEntity::getShopName)
|
||||||
|
.orElse(""))
|
||||||
|
);
|
||||||
return new PageDTO<>(dtoList, page.getTotal());
|
return new PageDTO<>(dtoList, page.getTotal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,9 @@ public class SmartCabinetDTO {
|
||||||
@ExcelColumn(name = "商店ID")
|
@ExcelColumn(name = "商店ID")
|
||||||
private Long shopId;
|
private Long shopId;
|
||||||
|
|
||||||
|
@ExcelColumn(name = "商店名称")
|
||||||
|
private String shopName;
|
||||||
|
|
||||||
@ExcelColumn(name = "柜机模版编号")
|
@ExcelColumn(name = "柜机模版编号")
|
||||||
private String templateNo;
|
private String templateNo;
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ import java.util.List;
|
||||||
* @since 2025-05-09
|
* @since 2025-05-09
|
||||||
*/
|
*/
|
||||||
public interface ShopMapper extends BaseMapper<ShopEntity> {
|
public interface ShopMapper extends BaseMapper<ShopEntity> {
|
||||||
@Select("SELECT shop_id, shop_name " +
|
@Select("SELECT * " +
|
||||||
"FROM shop " +
|
"FROM shop " +
|
||||||
"${ew.customSqlSegment}")
|
"${ew.customSqlSegment}")
|
||||||
Page<ShopEntity> getShopList(
|
Page<ShopEntity> getShopList(
|
||||||
|
@ -32,7 +32,7 @@ public interface ShopMapper extends BaseMapper<ShopEntity> {
|
||||||
"LIMIT 1")
|
"LIMIT 1")
|
||||||
ShopEntity selectFirstShop();
|
ShopEntity selectFirstShop();
|
||||||
|
|
||||||
@Select("SELECT * FROM shop ORDER BY shop_id DESC")
|
@Select("SELECT * FROM shop WHERE deleted = 0 ORDER BY shop_id DESC")
|
||||||
List<ShopEntity> selectAll();
|
List<ShopEntity> selectAll();
|
||||||
|
|
||||||
@Select("SELECT * FROM shop WHERE shop_id = #{shopId} LIMIT 1")
|
@Select("SELECT * FROM shop WHERE shop_id = #{shopId} LIMIT 1")
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
package com.agileboot.domain.shop.shop.db;
|
package com.agileboot.domain.shop.shop.db;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 商店表,每个柜子属于一个商店 服务类
|
* 商店表,每个柜子属于一个商店 服务类
|
||||||
|
@ -12,4 +16,13 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
*/
|
*/
|
||||||
public interface ShopService extends IService<ShopEntity> {
|
public interface ShopService extends IService<ShopEntity> {
|
||||||
|
|
||||||
|
Page<ShopEntity> getShopList(Page<ShopEntity> page, Wrapper<ShopEntity> queryWrapper);
|
||||||
|
|
||||||
|
ShopEntity selectFirstShop();
|
||||||
|
|
||||||
|
List<ShopEntity> selectAll();
|
||||||
|
|
||||||
|
ShopEntity selectByShopId(Long shopId);
|
||||||
|
|
||||||
|
ShopEntity selectByShopName(String shopName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
package com.agileboot.domain.shop.shop.db;
|
package com.agileboot.domain.shop.shop.db;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 商店表,每个柜子属于一个商店 服务实现类
|
* 商店表,每个柜子属于一个商店 服务实现类
|
||||||
|
@ -14,4 +18,28 @@ import org.springframework.stereotype.Service;
|
||||||
@Service
|
@Service
|
||||||
public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopEntity> implements ShopService {
|
public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopEntity> implements ShopService {
|
||||||
|
|
||||||
}
|
@Override
|
||||||
|
public Page<ShopEntity> getShopList(Page<ShopEntity> page, Wrapper<ShopEntity> queryWrapper) {
|
||||||
|
return baseMapper.getShopList(page, queryWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ShopEntity selectFirstShop() {
|
||||||
|
return baseMapper.selectFirstShop();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ShopEntity> selectAll() {
|
||||||
|
return baseMapper.selectAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ShopEntity selectByShopId(Long shopId) {
|
||||||
|
return baseMapper.selectByShopId(shopId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ShopEntity selectByShopName(String shopName) {
|
||||||
|
return baseMapper.selectByShopName(shopName);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue