Compare commits
4 Commits
fe5a19157a
...
931bbd1a4b
Author | SHA1 | Date |
---|---|---|
|
931bbd1a4b | |
|
fa900ef3f5 | |
|
a1416fa7d7 | |
|
42df4996e4 |
|
@ -0,0 +1,68 @@
|
|||
package com.agileboot.admin.controller.cabinet;
|
||||
|
||||
import com.agileboot.admin.customize.aop.accessLog.AccessLog;
|
||||
import com.agileboot.common.core.base.BaseController;
|
||||
import com.agileboot.common.core.dto.ResponseDTO;
|
||||
import com.agileboot.common.core.page.PageDTO;
|
||||
import com.agileboot.common.enums.common.BusinessTypeEnum;
|
||||
import com.agileboot.domain.cabinet.mqtt.MqttServerApplicationService;
|
||||
import com.agileboot.domain.cabinet.mqtt.command.AddMqttServerCommand;
|
||||
import com.agileboot.domain.cabinet.mqtt.command.UpdateMqttServerCommand;
|
||||
import com.agileboot.domain.cabinet.mqtt.db.MqttServerEntity;
|
||||
import com.agileboot.domain.cabinet.mqtt.dto.MqttServerDTO;
|
||||
import com.agileboot.domain.cabinet.mqtt.query.SearchMqttServerQuery;
|
||||
import com.agileboot.domain.common.command.BulkOperationCommand;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import java.util.List;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/cabinet/mqttServer")
|
||||
@RequiredArgsConstructor
|
||||
@Validated
|
||||
public class MqttServerController extends BaseController {
|
||||
|
||||
private final MqttServerApplicationService mqttServerApplicationService;
|
||||
|
||||
@Operation(summary = "MQTT服务列表")
|
||||
@GetMapping
|
||||
public ResponseDTO<PageDTO<MqttServerDTO>> list(SearchMqttServerQuery<MqttServerEntity> query) {
|
||||
PageDTO<MqttServerDTO> page = mqttServerApplicationService.getMqttServerList(query);
|
||||
return ResponseDTO.ok(page);
|
||||
}
|
||||
|
||||
@Operation(summary = "新增MQTT服务")
|
||||
@AccessLog(title = "MQTT服务管理", businessType = BusinessTypeEnum.ADD)
|
||||
@PostMapping
|
||||
public ResponseDTO<Void> add(@Validated @RequestBody AddMqttServerCommand command) {
|
||||
mqttServerApplicationService.addMqttServer(command);
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
@Operation(summary = "修改MQTT服务")
|
||||
@AccessLog(title = "MQTT服务管理", businessType = BusinessTypeEnum.MODIFY)
|
||||
@PutMapping("/{serverId}")
|
||||
public ResponseDTO<Void> edit(@PathVariable Long serverId, @Validated @RequestBody UpdateMqttServerCommand command) {
|
||||
command.setMqttServerId(serverId);
|
||||
mqttServerApplicationService.updateMqttServer(command);
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
@Operation(summary = "删除MQTT服务")
|
||||
@AccessLog(title = "MQTT服务管理", businessType = BusinessTypeEnum.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public ResponseDTO<Void> remove(@PathVariable @NotNull List<Long> ids) {
|
||||
mqttServerApplicationService.deleteMqttServer(new BulkOperationCommand<>(ids));
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.agileboot.admin.controller.shop;
|
||||
|
||||
import com.agileboot.admin.customize.aop.accessLog.AccessLog;
|
||||
import com.agileboot.common.core.base.BaseController;
|
||||
import com.agileboot.common.core.dto.ResponseDTO;
|
||||
import com.agileboot.common.core.page.PageDTO;
|
||||
import com.agileboot.common.enums.common.BusinessTypeEnum;
|
||||
import com.agileboot.domain.common.command.BulkOperationCommand;
|
||||
import com.agileboot.domain.shop.shop.ShopApplicationService;
|
||||
import com.agileboot.domain.shop.shop.command.AddShopCommand;
|
||||
import com.agileboot.domain.shop.shop.command.UpdateShopCommand;
|
||||
import com.agileboot.domain.shop.shop.db.ShopEntity;
|
||||
import com.agileboot.domain.shop.shop.dto.ShopDTO;
|
||||
import com.agileboot.domain.shop.shop.query.SearchShopQuery;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import java.util.List;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/shop/shops")
|
||||
@RequiredArgsConstructor
|
||||
@Validated
|
||||
public class ShopController extends BaseController {
|
||||
|
||||
private final ShopApplicationService shopApplicationService;
|
||||
|
||||
@Operation(summary = "商店列表")
|
||||
@GetMapping
|
||||
public ResponseDTO<PageDTO<ShopDTO>> list(SearchShopQuery<ShopEntity> query) {
|
||||
PageDTO<ShopDTO> page = shopApplicationService.getShopList(query);
|
||||
return ResponseDTO.ok(page);
|
||||
}
|
||||
|
||||
@Operation(summary = "新增商店")
|
||||
@AccessLog(title = "商店管理", businessType = BusinessTypeEnum.ADD)
|
||||
@PostMapping
|
||||
public ResponseDTO<Void> add(@Validated @RequestBody AddShopCommand command) {
|
||||
shopApplicationService.addShop(command);
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
@Operation(summary = "修改商店")
|
||||
@AccessLog(title = "商店管理", businessType = BusinessTypeEnum.MODIFY)
|
||||
@PutMapping("/{id}")
|
||||
public ResponseDTO<Void> edit(@PathVariable Long id, @Validated @RequestBody UpdateShopCommand command) {
|
||||
command.setShopId(id);
|
||||
shopApplicationService.updateShop(command);
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
@Operation(summary = "删除商店")
|
||||
@AccessLog(title = "商店管理", businessType = BusinessTypeEnum.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public ResponseDTO<Void> remove(@PathVariable @NotNull List<Long> ids) {
|
||||
shopApplicationService.deleteShop(new BulkOperationCommand<>(ids));
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
}
|
|
@ -12,6 +12,8 @@ import com.agileboot.domain.cabinet.operation.model.CabinetCellOperationModel;
|
|||
import com.agileboot.domain.cabinet.operation.model.CabinetCellOperationModelFactory;
|
||||
import com.agileboot.domain.cabinet.smartCabinet.SmartCabinetApplicationService;
|
||||
import com.agileboot.domain.cabinet.smartCabinet.dto.CabinetDetailDTO;
|
||||
import com.agileboot.domain.cabinet.smartCabinet.model.SmartCabinetModel;
|
||||
import com.agileboot.domain.cabinet.smartCabinet.model.SmartCabinetModelFactory;
|
||||
import com.agileboot.domain.mqtt.MqttService;
|
||||
import com.agileboot.domain.shop.goods.model.GoodsModel;
|
||||
import com.agileboot.domain.shop.goods.model.GoodsModelFactory;
|
||||
|
@ -33,14 +35,15 @@ public class CabinetCellController {
|
|||
private final CabinetCellOperationModelFactory cabinetCellOperationModelFactory;
|
||||
private final CabinetCellModelFactory cabinetCellModelFactory;
|
||||
private final GoodsModelFactory goodsModelFactory;
|
||||
private final SmartCabinetModelFactory smartCabinetModelFactory;
|
||||
|
||||
@GetMapping("/detail")
|
||||
public ResponseDTO<List<CabinetDetailDTO>> getCabinetDetail() {
|
||||
return ResponseDTO.ok(smartCabinetApplicationService.getCabinetDetail());
|
||||
}
|
||||
|
||||
@PostMapping("/openCabinet/{lockControlNo}/{pinNo}")
|
||||
public ResponseDTO<?> openCabinet(@PathVariable Integer lockControlNo, @PathVariable Integer pinNo,
|
||||
@PostMapping("/openCabinet/{cabinetId}/{pinNo}")
|
||||
public ResponseDTO<?> openCabinet(@PathVariable Long cabinetId, @PathVariable Integer pinNo,
|
||||
@RequestBody AddCabinetCellOperationCommand operationCommand) {
|
||||
if (null == operationCommand){
|
||||
operationCommand = new AddCabinetCellOperationCommand();
|
||||
|
@ -49,13 +52,16 @@ public class CabinetCellController {
|
|||
operationCommand.setStatus(1);
|
||||
|
||||
CabinetCellOperationModel cellOperationModel = cabinetCellOperationModelFactory.create();
|
||||
|
||||
SmartCabinetModel smartCabinetModel = smartCabinetModelFactory.loadById(cabinetId);
|
||||
Integer lockControlNo = smartCabinetModel.getLockControlNo();
|
||||
// 发送指令
|
||||
String mqttDate = "8A";
|
||||
mqttDate += String.format("%02X", lockControlNo);
|
||||
mqttDate += String.format("%02X", pinNo);
|
||||
mqttDate += "11";
|
||||
try {
|
||||
mqttService.publish(mqttDate);
|
||||
mqttService.publish(mqttDate, smartCabinetModel.getMqttServerId());
|
||||
} catch (Exception e) {
|
||||
log.error("mqtt publish error", e);
|
||||
operationCommand.setStatus(2);
|
||||
|
|
|
@ -20,9 +20,9 @@ public class MqttController {
|
|||
|
||||
|
||||
@GetMapping("/opencell")
|
||||
public String opencell(@RequestParam String data) {
|
||||
public String opencell(@RequestParam String data, @RequestParam Long cabinetId) {
|
||||
try {
|
||||
mqttService.publish(data);
|
||||
mqttService.publish(data, cabinetId);
|
||||
return "success";
|
||||
} catch (Exception e) {
|
||||
log.error("getPermanentCode error", e);
|
||||
|
|
|
@ -39,7 +39,8 @@ public class ShopController {
|
|||
private final CategoryApplicationService categoryApplicationService;
|
||||
|
||||
@GetMapping("/goods")
|
||||
public ResponseDTO<ShopGoodsResponse> getShopGoodsInfo() {
|
||||
public ResponseDTO<ShopGoodsResponse> getShopGoodsInfo(@RequestParam(required = false) Long shopId) {
|
||||
log.info("getShopGoodsInfo shopId: {}", shopId);
|
||||
/*// 获取商品列表
|
||||
List<ShopGoodsEntity> goodsList = goodsApplicationService.getGoodsAll();
|
||||
goodsList.forEach(goods -> {
|
||||
|
@ -52,7 +53,7 @@ public class ShopController {
|
|||
List<ShopCategoryDTO> categoryList = categoryApplicationService.getCategoryAll();*/
|
||||
|
||||
// 客户端显示商品列表按柜机格口
|
||||
List<SearchGoodsWithCabinetDO> goodsWithCabinetList = goodsApplicationService.getGoodsWithCabinetList();
|
||||
List<SearchGoodsWithCabinetDO> goodsWithCabinetList = goodsApplicationService.getGoodsWithCabinetList(shopId);
|
||||
goodsWithCabinetList.forEach(goodsWithCabinet -> {
|
||||
goodsWithCabinet.setCategoryId(goodsWithCabinet.getCabinetId());
|
||||
});
|
||||
|
@ -75,12 +76,10 @@ public class ShopController {
|
|||
*/
|
||||
@GetMapping("/wechatAuth")
|
||||
public RedirectView wechatAuthRedirect(HttpServletRequest request) {
|
||||
/*java.util.StringJoiner joiner = new java.util.StringJoiner("&");
|
||||
String shopId = request.getParameter("shopId");
|
||||
request.getParameterMap().forEach((key, values) -> {
|
||||
joiner.add(key + "=" + String.join(",", values));
|
||||
log.info("wechatAuth key: {} value: {}", key, values[0]);
|
||||
});
|
||||
log.info("wechatAuth 参数:{}", joiner.toString());*/
|
||||
|
||||
// 从请求参数中提取包含token的参数名(参数名本身可能包含"token=")
|
||||
String token = request.getParameterMap().keySet().stream()
|
||||
|
@ -99,10 +98,14 @@ public class ShopController {
|
|||
state = "state";
|
||||
}
|
||||
|
||||
String redirect_uri = "http%3A%2F%2Fwxshop.ab98.cn%2Fshop";
|
||||
if (StringUtils.isNotBlank(shopId)) {
|
||||
redirect_uri += "%3FshopId%3D" + shopId;
|
||||
}
|
||||
// 构造微信网页授权URL
|
||||
String authUrl = "https://open.weixin.qq.com/connect/oauth2/authorize"
|
||||
+ "?appid=" + WeixinConstants.appid
|
||||
+ "&redirect_uri=http%3A%2F%2Fwxshop.ab98.cn%2Fshop"
|
||||
+ "&redirect_uri=" + redirect_uri
|
||||
+ "&response_type=code"
|
||||
+ "&scope=snsapi_base"
|
||||
+ "&state=" + state
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
package com.agileboot.domain.cabinet.mqtt;
|
||||
|
||||
import com.agileboot.common.core.page.PageDTO;
|
||||
import com.agileboot.domain.common.command.BulkOperationCommand;
|
||||
import com.agileboot.domain.cabinet.mqtt.command.AddMqttServerCommand;
|
||||
import com.agileboot.domain.cabinet.mqtt.command.UpdateMqttServerCommand;
|
||||
import com.agileboot.domain.cabinet.mqtt.db.MqttServerEntity;
|
||||
import com.agileboot.domain.cabinet.mqtt.db.MqttServerService;
|
||||
import com.agileboot.domain.cabinet.mqtt.dto.MqttServerDTO;
|
||||
import com.agileboot.domain.cabinet.mqtt.model.MqttServerModel;
|
||||
import com.agileboot.domain.cabinet.mqtt.model.MqttServerModelFactory;
|
||||
import com.agileboot.domain.cabinet.mqtt.query.SearchMqttServerQuery;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class MqttServerApplicationService {
|
||||
private final MqttServerService mqttServerService;
|
||||
private final MqttServerModelFactory mqttServerModelFactory;
|
||||
|
||||
public PageDTO<MqttServerDTO> getMqttServerList(SearchMqttServerQuery<MqttServerEntity> query) {
|
||||
Page<MqttServerEntity> page = mqttServerService.getServerList(query);
|
||||
List<MqttServerDTO> dtoList = page.getRecords().stream()
|
||||
.map(MqttServerDTO::new)
|
||||
.collect(Collectors.toList());
|
||||
return new PageDTO<>(dtoList, page.getTotal());
|
||||
}
|
||||
|
||||
public MqttServerEntity getByServerId(Long serverId) {
|
||||
return mqttServerService.getById(serverId);
|
||||
}
|
||||
|
||||
public void addMqttServer(AddMqttServerCommand command) {
|
||||
MqttServerModel model = mqttServerModelFactory.create();
|
||||
model.loadAddCommand(command);
|
||||
model.insert();
|
||||
}
|
||||
|
||||
public void updateMqttServer(UpdateMqttServerCommand command) {
|
||||
MqttServerModel model = mqttServerModelFactory.loadById(command.getMqttServerId());
|
||||
model.loadUpdateCommand(command);
|
||||
model.updateById();
|
||||
}
|
||||
|
||||
public void deleteMqttServer(BulkOperationCommand<Long> command) {
|
||||
for (Long id : command.getIds()) {
|
||||
MqttServerModel model = mqttServerModelFactory.loadById(id);
|
||||
model.deleteById();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.agileboot.domain.cabinet.mqtt.command;
|
||||
|
||||
import com.agileboot.domain.cabinet.mqtt.db.MqttServerEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class AddMqttServerCommand extends MqttServerEntity {
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.agileboot.domain.cabinet.mqtt.command;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.PositiveOrZero;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class UpdateMqttServerCommand extends AddMqttServerCommand {
|
||||
|
||||
@NotNull
|
||||
@PositiveOrZero
|
||||
private Long mqttServerId;
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package com.agileboot.domain.cabinet.mqtt.db;
|
||||
|
||||
import com.agileboot.common.core.base.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* MQTT服务配置表
|
||||
* </p>
|
||||
*
|
||||
* @author valarchie
|
||||
* @since 2025-05-08
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@TableName("mqtt_server")
|
||||
@ApiModel(value = "MqttServerEntity对象", description = "MQTT服务配置表")
|
||||
public class MqttServerEntity extends BaseEntity<MqttServerEntity> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("主键ID")
|
||||
@TableId(value = "mqtt_server_id", type = IdType.AUTO)
|
||||
private Long mqttServerId;
|
||||
|
||||
@ApiModelProperty("MQTT服务器地址")
|
||||
@TableField("server_url")
|
||||
private String serverUrl;
|
||||
|
||||
@ApiModelProperty("连接账号")
|
||||
@TableField("username")
|
||||
private String username;
|
||||
|
||||
@ApiModelProperty("连接密码")
|
||||
@TableField("`password`")
|
||||
private String password;
|
||||
|
||||
@ApiModelProperty("订阅主题过滤器")
|
||||
@TableField("topic_filter")
|
||||
private String topicFilter;
|
||||
|
||||
@ApiModelProperty("发布主题")
|
||||
@TableField("publish_topic")
|
||||
private String publishTopic;
|
||||
|
||||
|
||||
@Override
|
||||
public Serializable pkVal() {
|
||||
return this.mqttServerId;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.agileboot.domain.cabinet.mqtt.db;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* MQTT服务配置表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author valarchie
|
||||
* @since 2025-05-08
|
||||
*/
|
||||
public interface MqttServerMapper extends BaseMapper<MqttServerEntity> {
|
||||
|
||||
@Select("SELECT mqtt_server_id, server_url, username, password, topic_filter, publish_topic " +
|
||||
"FROM mqtt_server " +
|
||||
"${ew.customSqlSegment}")
|
||||
Page<MqttServerEntity> getMqttServerList(
|
||||
Page<MqttServerEntity> page,
|
||||
@Param(Constants.WRAPPER) Wrapper<MqttServerEntity> queryWrapper
|
||||
);
|
||||
|
||||
@Select("SELECT * FROM mqtt_server WHERE server_url = #{serverUrl} LIMIT 1")
|
||||
MqttServerEntity selectByServerUrl(String serverUrl);
|
||||
|
||||
@Select("SELECT * FROM mqtt_server WHERE mqtt_server_id = #{id} LIMIT 1")
|
||||
MqttServerEntity selectById(Long id);
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.agileboot.domain.cabinet.mqtt.db;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* MQTT服务配置表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author valarchie
|
||||
* @since 2025-05-08
|
||||
*/
|
||||
import com.agileboot.common.core.page.AbstractPageQuery;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import java.util.List;
|
||||
|
||||
public interface MqttServerService extends IService<MqttServerEntity> {
|
||||
Page<MqttServerEntity> getServerList(AbstractPageQuery<MqttServerEntity> query);
|
||||
|
||||
List<MqttServerEntity> selectAll();
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.agileboot.domain.cabinet.mqtt.db;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* MQTT服务配置表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author valarchie
|
||||
* @since 2025-05-08
|
||||
*/
|
||||
import com.agileboot.common.core.page.AbstractPageQuery;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class MqttServerServiceImpl extends ServiceImpl<MqttServerMapper, MqttServerEntity> implements MqttServerService {
|
||||
@Override
|
||||
public Page<MqttServerEntity> getServerList(AbstractPageQuery<MqttServerEntity> query) {
|
||||
return this.page(query.toPage(), query.toQueryWrapper());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MqttServerEntity> selectAll() {
|
||||
LambdaQueryWrapper<MqttServerEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(MqttServerEntity::getDeleted, false)
|
||||
.orderByDesc(MqttServerEntity::getCreateTime);
|
||||
return this.list(wrapper);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.agileboot.domain.cabinet.mqtt.dto;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.agileboot.common.annotation.ExcelColumn;
|
||||
import com.agileboot.common.annotation.ExcelSheet;
|
||||
import com.agileboot.domain.cabinet.mqtt.db.MqttServerEntity;
|
||||
import com.agileboot.domain.common.cache.CacheCenter;
|
||||
import com.agileboot.domain.system.user.db.SysUserEntity;
|
||||
import lombok.Data;
|
||||
|
||||
@ExcelSheet(name = "MQTT服务配置列表")
|
||||
@Data
|
||||
public class MqttServerDTO {
|
||||
|
||||
public MqttServerDTO(MqttServerEntity entity) {
|
||||
if (entity != null) {
|
||||
BeanUtil.copyProperties(entity, this);
|
||||
}
|
||||
}
|
||||
|
||||
@ExcelColumn(name = "服务ID")
|
||||
private Long mqttServerId;
|
||||
|
||||
@ExcelColumn(name = "服务器地址")
|
||||
private String serverUrl;
|
||||
|
||||
@ExcelColumn(name = "用户名")
|
||||
private String username;
|
||||
|
||||
@ExcelColumn(name = "密码")
|
||||
private String password;
|
||||
|
||||
@ExcelColumn(name = "订阅主题")
|
||||
private String topicFilter;
|
||||
|
||||
@ExcelColumn(name = "发布主题")
|
||||
private String publishTopic;
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.agileboot.domain.cabinet.mqtt.model;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.agileboot.domain.cabinet.mqtt.db.MqttServerEntity;
|
||||
import com.agileboot.domain.cabinet.mqtt.command.AddMqttServerCommand;
|
||||
import com.agileboot.domain.cabinet.mqtt.command.UpdateMqttServerCommand;
|
||||
import com.agileboot.domain.cabinet.mqtt.db.MqttServerService;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class MqttServerModel extends MqttServerEntity {
|
||||
|
||||
private MqttServerService mqttServerService;
|
||||
|
||||
public MqttServerModel(MqttServerEntity entity, MqttServerService mqttServerService) {
|
||||
this(mqttServerService);
|
||||
if (entity != null) {
|
||||
BeanUtil.copyProperties(entity, this);
|
||||
}
|
||||
}
|
||||
|
||||
public MqttServerModel(MqttServerService mqttServerService) {
|
||||
this.mqttServerService = mqttServerService;
|
||||
}
|
||||
|
||||
public void loadAddCommand(AddMqttServerCommand command) {
|
||||
if (command != null) {
|
||||
BeanUtil.copyProperties(command, this, "mqttServerId");
|
||||
}
|
||||
}
|
||||
|
||||
public void loadUpdateCommand(UpdateMqttServerCommand command) {
|
||||
if (command != null) {
|
||||
loadAddCommand(command);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.agileboot.domain.cabinet.mqtt.model;
|
||||
|
||||
import com.agileboot.common.exception.ApiException;
|
||||
import com.agileboot.common.exception.error.ErrorCode;
|
||||
import com.agileboot.domain.cabinet.mqtt.db.MqttServerEntity;
|
||||
import com.agileboot.domain.cabinet.mqtt.db.MqttServerService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class MqttServerModelFactory {
|
||||
|
||||
private final MqttServerService mqttServerService;
|
||||
|
||||
public MqttServerModel loadById(Long mqttServerId) {
|
||||
MqttServerEntity entity = mqttServerService.getById(mqttServerId);
|
||||
if (entity == null) {
|
||||
throw new ApiException(ErrorCode.Business.COMMON_OBJECT_NOT_FOUND, mqttServerId, "MQTT服务器配置");
|
||||
}
|
||||
return new MqttServerModel(entity, mqttServerService);
|
||||
}
|
||||
|
||||
public MqttServerModel create() {
|
||||
return new MqttServerModel(mqttServerService);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package com.agileboot.domain.cabinet.mqtt.query;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.agileboot.common.core.page.AbstractPageQuery;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class SearchMqttServerQuery<T> extends AbstractPageQuery<T> {
|
||||
|
||||
private Long mqttServerId;
|
||||
private String serverUrl;
|
||||
private String username;
|
||||
private String password;
|
||||
private String topicFilter;
|
||||
private String publishTopic;
|
||||
private Date startTime;
|
||||
private Date endTime;
|
||||
|
||||
@Override
|
||||
public QueryWrapper<T> addQueryCondition() {
|
||||
QueryWrapper<T> queryWrapper = new QueryWrapper<>();
|
||||
|
||||
queryWrapper
|
||||
.eq(mqttServerId != null, "mqtt_server_id", mqttServerId)
|
||||
.like(StrUtil.isNotEmpty(serverUrl), "server_url", serverUrl)
|
||||
.eq(StrUtil.isNotEmpty(username), "username", username)
|
||||
.eq(StrUtil.isNotEmpty(password), "password", password)
|
||||
.like(StrUtil.isNotEmpty(topicFilter), "topic_filter", topicFilter)
|
||||
.like(StrUtil.isNotEmpty(publishTopic), "publish_topic", publishTopic)
|
||||
.between(startTime != null && endTime != null, "create_time", startTime, endTime);
|
||||
|
||||
this.timeRangeColumn = "create_time";
|
||||
|
||||
return queryWrapper;
|
||||
}
|
||||
}
|
|
@ -39,6 +39,14 @@ public class SmartCabinetEntity extends BaseEntity<SmartCabinetEntity> {
|
|||
@TableField("cabinet_type")
|
||||
private Integer cabinetType;
|
||||
|
||||
@ApiModelProperty("MQTT服务ID")
|
||||
@TableField("mqtt_server_id")
|
||||
private Long mqttServerId;
|
||||
|
||||
@ApiModelProperty("商店ID")
|
||||
@TableField("shop_id")
|
||||
private Long shopId;
|
||||
|
||||
@ApiModelProperty("柜机模版编号")
|
||||
@TableField("template_no")
|
||||
private String templateNo;
|
||||
|
|
|
@ -6,6 +6,8 @@ import com.agileboot.common.annotation.ExcelSheet;
|
|||
import com.agileboot.domain.common.cache.CacheCenter;
|
||||
import com.agileboot.domain.cabinet.smartCabinet.db.SmartCabinetEntity;
|
||||
import com.agileboot.domain.system.user.db.SysUserEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@ExcelSheet(name = "智能柜信息表")
|
||||
|
@ -32,6 +34,12 @@ public class SmartCabinetDTO {
|
|||
@ExcelColumn(name = "柜机类型(0主柜 1副柜)")
|
||||
private Integer cabinetType;
|
||||
|
||||
@ExcelColumn(name = "MQTT服务ID")
|
||||
private Long mqttServerId;
|
||||
|
||||
@ExcelColumn(name = "商店ID")
|
||||
private Long shopId;
|
||||
|
||||
@ExcelColumn(name = "柜机模版编号")
|
||||
private String templateNo;
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@ public class SearchSmartCabinetQuery<T> extends AbstractPageQuery<T> {
|
|||
private String templateNo;
|
||||
private Date startTime;
|
||||
private Date endTime;
|
||||
private Long mqttServerId;
|
||||
private Long shopId;
|
||||
|
||||
@Override
|
||||
public QueryWrapper<T> addQueryCondition() {
|
||||
|
@ -24,6 +26,8 @@ public class SearchSmartCabinetQuery<T> extends AbstractPageQuery<T> {
|
|||
queryWrapper
|
||||
.like(StrUtil.isNotEmpty(cabinetName), "cabinet_name", cabinetName)
|
||||
.eq(cabinetType != null, "cabinet_type", cabinetType)
|
||||
.eq(mqttServerId!= null, "mqtt_server_id", mqttServerId)
|
||||
.eq(shopId!= null, "shop_id", shopId)
|
||||
.eq(StrUtil.isNotEmpty(templateNo), "template_no", templateNo)
|
||||
.eq("deleted", false)
|
||||
.between(startTime != null && endTime != null, "create_time", startTime, endTime);
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.agileboot.domain.mqtt;
|
||||
|
||||
import com.agileboot.domain.cabinet.mqtt.db.MqttServerEntity;
|
||||
import com.agileboot.domain.cabinet.mqtt.db.MqttServerService;
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -18,35 +18,15 @@ import java.util.List;
|
|||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class MqttService implements MqttCallback {
|
||||
private final MqttServerService mqttServerService;
|
||||
private final List<ClientConfig> clientConfigs = new ArrayList<>();
|
||||
|
||||
@AllArgsConstructor
|
||||
private static class ClientConfig {
|
||||
private final MqttClient client;
|
||||
private final MqttConfig config;
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
private enum MqttConfig {
|
||||
LOCK("lock", "lock@ys#6785$", "lock/up/S4202414S", "lock/down/S4202414S"),
|
||||
SELL("sell", "sell@ys#6785$", "lock/up/S5200184S", "lock/down/S5200184S");
|
||||
|
||||
private final String username;
|
||||
private final String password;
|
||||
private final String topicFilter;
|
||||
private final String publishTopic;
|
||||
private final MqttServerEntity config;
|
||||
}
|
||||
|
||||
private static final String SERVER_URL = "tcp://221.7.159.46:1883";
|
||||
// private static final String USERNAME = "sell";
|
||||
// private static final String PASSWORD = "sell@ys#6785$";
|
||||
// private static final String TOPIC_FILTER = "lock/up/S5200184S";
|
||||
// private static final String TOPIC = "lock/down/S5200184S";
|
||||
// private static final String USERNAME = "iot";
|
||||
// private static final String PASSWORD = "iot@ys#9963$";
|
||||
// private static final String TOPIC_FILTER = "hongfa/2401310026C50D24FE/upload/";
|
||||
// private static final String TOPIC = "hongfa/2401310026C50D24FE/download/";
|
||||
|
||||
// private MqttClient client;
|
||||
@Setter
|
||||
|
@ -70,8 +50,8 @@ public class MqttService implements MqttCallback {
|
|||
}
|
||||
|
||||
public void connect() throws MqttException {
|
||||
for (MqttConfig config : MqttConfig.values()) {
|
||||
MqttClient client = new MqttClient(SERVER_URL, MqttClient.generateClientId(), new MemoryPersistence());
|
||||
for (MqttServerEntity config : mqttServerService.selectAll()) {
|
||||
MqttClient client = new MqttClient(config.getServerUrl(), MqttClient.generateClientId(), new MemoryPersistence());
|
||||
MqttConnectOptions options = new MqttConnectOptions();
|
||||
options.setUserName(config.getUsername());
|
||||
options.setPassword(config.getPassword().toCharArray());
|
||||
|
@ -89,27 +69,27 @@ public class MqttService implements MqttCallback {
|
|||
client.connect(options);
|
||||
client.subscribe(config.getTopicFilter());
|
||||
clientConfigs.add(new ClientConfig(client, config));
|
||||
log.info("成功连接MQTT账号:{}", config.getUsername());
|
||||
log.info("成功连接MQTT服务器:{} 账号:{}", config.getServerUrl(), config.getUsername());
|
||||
}
|
||||
|
||||
log.info("连接 MQTT 服务器 {}", SERVER_URL);
|
||||
}
|
||||
|
||||
/*public void subscribe(String topic) throws MqttException {
|
||||
client.subscribe(topic);
|
||||
}*/
|
||||
|
||||
public void publish(String data) throws MqttException {
|
||||
public void publish(String data, Long mqttServerId) throws MqttException {
|
||||
// lockCmd((byte) 0x8A, (byte) 0x01, (byte) 0x01, (byte) 0x33, null);
|
||||
String bcc = BCCCalculator.calculateBCC(data);
|
||||
MqttMessage message = new MqttMessage(BCCCalculator.hexStringToByteArray(data + bcc));
|
||||
clientConfigs.forEach(cc -> {
|
||||
try {
|
||||
cc.client.publish(cc.config.getPublishTopic(), message);
|
||||
} catch (MqttException e) {
|
||||
log.error("消息发送失败", e);
|
||||
}
|
||||
});
|
||||
clientConfigs.stream()
|
||||
.filter(cc -> cc.config.getMqttServerId().equals(mqttServerId))
|
||||
.forEach(cc -> {
|
||||
try {
|
||||
cc.client.publish(cc.config.getPublishTopic(), message);
|
||||
} catch (MqttException e) {
|
||||
log.error("消息发送失败", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void disconnect() throws MqttException {
|
||||
|
|
|
@ -62,8 +62,8 @@ public class GoodsApplicationService {
|
|||
}
|
||||
|
||||
|
||||
public List<SearchGoodsWithCabinetDO> getGoodsWithCabinetList() {
|
||||
return shopGoodsService.getGoodsWithCabinetList();
|
||||
public List<SearchGoodsWithCabinetDO> getGoodsWithCabinetList(Long shopId) {
|
||||
return shopGoodsService.getGoodsWithCabinetList(shopId);
|
||||
}
|
||||
|
||||
public ShopGoodsDTO getGoodsInfo(Long goodsId) {
|
||||
|
|
|
@ -28,6 +28,9 @@ public class SearchGoodsWithCabinetDO extends BaseEntity<SearchGoodsWithCabinetD
|
|||
@TableField("sc.cabinet_name")
|
||||
private String cabinetName;
|
||||
|
||||
@TableField("sc.shop_id")
|
||||
private Long shopId;
|
||||
|
||||
@TableField("cc.cell_id")
|
||||
private Long cellId;
|
||||
}
|
|
@ -72,6 +72,16 @@ public interface ShopGoodsMapper extends BaseMapper<ShopGoodsEntity> {
|
|||
"WHERE g.deleted = 0 AND sc.deleted = 0 AND cc.deleted = 0 AND cc.goods_id IS NOT NULL ")
|
||||
List<SearchGoodsWithCabinetDO> getGoodsWithCabinetList();
|
||||
|
||||
@Select("SELECT g.goods_id, g.goods_name, g.category_id, g.price, " +
|
||||
"g.status, g.cover_img, g.goods_detail, " +
|
||||
"g.creator_id, g.create_time, g.updater_id, g.update_time, g.remark, g.deleted, " +
|
||||
"sc.cabinet_id, sc.cabinet_name, sc.shop_id, cc.stock, cc.cell_id " +
|
||||
"FROM shop_goods g " +
|
||||
"LEFT JOIN cabinet_cell cc ON g.goods_id = cc.goods_id " +
|
||||
"LEFT JOIN smart_cabinet sc ON cc.cabinet_id = sc.cabinet_id " +
|
||||
"WHERE g.deleted = 0 AND sc.deleted = 0 AND sc.shop_id = #{shopId} AND cc.deleted = 0 AND cc.goods_id IS NOT NULL ")
|
||||
List<SearchGoodsWithCabinetDO> getGoodsWithCabinetListByShopId(@Param("shopId")Long shopId);
|
||||
|
||||
@Select("SELECT g.goods_id, g.goods_name, g.category_id, g.price, " +
|
||||
"g.stock, g.status, g.auto_approval, g.cover_img, SUM(cc.stock) AS total_stock, " +
|
||||
"GROUP_CONCAT(DISTINCT cc.cell_no) AS cell_no_str, " +
|
||||
|
|
|
@ -19,7 +19,7 @@ public interface ShopGoodsService extends IService<ShopGoodsEntity> {
|
|||
|
||||
List<ShopGoodsEntity> selectAll();
|
||||
|
||||
List<SearchGoodsWithCabinetDO> getGoodsWithCabinetList();
|
||||
List<SearchGoodsWithCabinetDO> getGoodsWithCabinetList(Long shopId);
|
||||
|
||||
SearchGoodsDO getGoodsInfo(Long goodsId);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.agileboot.common.core.page.AbstractPageQuery;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -15,6 +16,7 @@ import java.util.List;
|
|||
* @author valarchie
|
||||
* @since 2025-03-03
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ShopGoodsServiceImpl extends ServiceImpl<ShopGoodsMapper, ShopGoodsEntity> implements ShopGoodsService {
|
||||
@Override
|
||||
|
@ -31,8 +33,13 @@ public class ShopGoodsServiceImpl extends ServiceImpl<ShopGoodsMapper, ShopGoods
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<SearchGoodsWithCabinetDO> getGoodsWithCabinetList() {
|
||||
return baseMapper.getGoodsWithCabinetList();
|
||||
public List<SearchGoodsWithCabinetDO> getGoodsWithCabinetList(Long shopId) {
|
||||
if (shopId == null) {
|
||||
return baseMapper.getGoodsWithCabinetList();
|
||||
} else {
|
||||
log.info("getGoodsWithCabinetList shopId: {}", shopId);
|
||||
return baseMapper.getGoodsWithCabinetListByShopId(shopId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -124,7 +124,7 @@ public class OrderApplicationService {
|
|||
mqttDate += String.format("%02X", cabinetCellEntity.getPinNo());
|
||||
mqttDate += "11";
|
||||
try {
|
||||
mqttService.publish(mqttDate);
|
||||
mqttService.publish(mqttDate, smartCabinet.getMqttServerId());
|
||||
} catch (Exception e) {
|
||||
log.error("mqtt publish error", e);
|
||||
operationCommand.setStatus(2);
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package com.agileboot.domain.shop.shop;
|
||||
|
||||
import com.agileboot.common.core.page.PageDTO;
|
||||
import com.agileboot.domain.common.command.BulkOperationCommand;
|
||||
import com.agileboot.domain.shop.shop.command.AddShopCommand;
|
||||
import com.agileboot.domain.shop.shop.command.UpdateShopCommand;
|
||||
import com.agileboot.domain.shop.shop.db.ShopEntity;
|
||||
import com.agileboot.domain.shop.shop.db.ShopService;
|
||||
import com.agileboot.domain.shop.shop.dto.ShopDTO;
|
||||
import com.agileboot.domain.shop.shop.model.ShopModel;
|
||||
import com.agileboot.domain.shop.shop.model.ShopModelFactory;
|
||||
import com.agileboot.domain.shop.shop.query.SearchShopQuery;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class ShopApplicationService {
|
||||
private final ShopService shopService;
|
||||
private final ShopModelFactory shopModelFactory;
|
||||
|
||||
public PageDTO<ShopDTO> getShopList(SearchShopQuery<ShopEntity> query) {
|
||||
Page<ShopEntity> page = shopService.page(query.toPage(), query.toQueryWrapper());
|
||||
List<ShopDTO> dtoList = page.getRecords().stream()
|
||||
.map(ShopDTO::new)
|
||||
.collect(Collectors.toList());
|
||||
return new PageDTO<>(dtoList, page.getTotal());
|
||||
}
|
||||
|
||||
public void addShop(AddShopCommand command) {
|
||||
ShopModel model = shopModelFactory.create();
|
||||
model.loadAddCommand(command);
|
||||
model.insert();
|
||||
}
|
||||
|
||||
public void updateShop(UpdateShopCommand command) {
|
||||
ShopModel model = shopModelFactory.loadById(command.getShopId());
|
||||
model.loadUpdateCommand(command);
|
||||
model.updateById();
|
||||
}
|
||||
|
||||
public void deleteShop(BulkOperationCommand<Long> command) {
|
||||
for (Long shopId : command.getIds()) {
|
||||
ShopModel model = shopModelFactory.loadById(shopId);
|
||||
model.deleteById();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.agileboot.domain.shop.shop.command;
|
||||
|
||||
import com.agileboot.domain.shop.shop.db.ShopEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class AddShopCommand extends ShopEntity {
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.agileboot.domain.shop.shop.command;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.PositiveOrZero;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class UpdateShopCommand extends AddShopCommand {
|
||||
|
||||
@NotNull
|
||||
@PositiveOrZero
|
||||
private Long shopId;
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.agileboot.domain.shop.shop.db;
|
||||
|
||||
import com.agileboot.common.core.base.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 商店表,每个柜子属于一个商店
|
||||
* </p>
|
||||
*
|
||||
* @author valarchie
|
||||
* @since 2025-05-09
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@TableName("shop")
|
||||
@ApiModel(value = "ShopEntity对象", description = "商店表,每个柜子属于一个商店")
|
||||
public class ShopEntity extends BaseEntity<ShopEntity> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("主键ID")
|
||||
@TableId(value = "shop_id", type = IdType.AUTO)
|
||||
private Long shopId;
|
||||
|
||||
@ApiModelProperty("商店名称")
|
||||
@TableField("shop_name")
|
||||
private String shopName;
|
||||
|
||||
|
||||
@Override
|
||||
public Serializable pkVal() {
|
||||
return this.shopId;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.agileboot.domain.shop.shop.db;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 商店表,每个柜子属于一个商店 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author valarchie
|
||||
* @since 2025-05-09
|
||||
*/
|
||||
public interface ShopMapper extends BaseMapper<ShopEntity> {
|
||||
@Select("SELECT shop_id, shop_name " +
|
||||
"FROM shop " +
|
||||
"${ew.customSqlSegment}")
|
||||
Page<ShopEntity> getShopList(
|
||||
Page<ShopEntity> page,
|
||||
@Param(Constants.WRAPPER) Wrapper<ShopEntity> queryWrapper
|
||||
);
|
||||
|
||||
@Select("SELECT * " +
|
||||
"FROM shop " +
|
||||
"ORDER BY shop_id DESC " +
|
||||
"LIMIT 1")
|
||||
ShopEntity selectFirstShop();
|
||||
|
||||
@Select("SELECT * FROM shop ORDER BY shop_id DESC")
|
||||
List<ShopEntity> selectAll();
|
||||
|
||||
@Select("SELECT * FROM shop WHERE shop_id = #{shopId} LIMIT 1")
|
||||
ShopEntity selectByShopId(Long shopId);
|
||||
|
||||
@Select("SELECT * FROM shop WHERE shop_name = #{shopName} LIMIT 1")
|
||||
ShopEntity selectByShopName(String shopName);
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.agileboot.domain.shop.shop.db;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 商店表,每个柜子属于一个商店 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author valarchie
|
||||
* @since 2025-05-09
|
||||
*/
|
||||
public interface ShopService extends IService<ShopEntity> {
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.agileboot.domain.shop.shop.db;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 商店表,每个柜子属于一个商店 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author valarchie
|
||||
* @since 2025-05-09
|
||||
*/
|
||||
@Service
|
||||
public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopEntity> implements ShopService {
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.agileboot.domain.shop.shop.dto;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.agileboot.common.annotation.ExcelColumn;
|
||||
import com.agileboot.common.annotation.ExcelSheet;
|
||||
import com.agileboot.domain.common.cache.CacheCenter;
|
||||
import com.agileboot.domain.shop.shop.db.ShopEntity;
|
||||
import com.agileboot.domain.system.user.db.SysUserEntity;
|
||||
import lombok.Data;
|
||||
|
||||
@ExcelSheet(name = "商店列表")
|
||||
@Data
|
||||
public class ShopDTO {
|
||||
|
||||
public ShopDTO(ShopEntity entity) {
|
||||
if (entity != null) {
|
||||
BeanUtil.copyProperties(entity, this);
|
||||
}
|
||||
}
|
||||
|
||||
@ExcelColumn(name = "商店ID")
|
||||
private Long shopId;
|
||||
|
||||
@ExcelColumn(name = "商店名称")
|
||||
private String shopName;
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.agileboot.domain.shop.shop.model;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.agileboot.domain.shop.shop.command.AddShopCommand;
|
||||
import com.agileboot.domain.shop.shop.command.UpdateShopCommand;
|
||||
import com.agileboot.domain.shop.shop.db.ShopEntity;
|
||||
import com.agileboot.domain.shop.shop.db.ShopService;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class ShopModel extends ShopEntity {
|
||||
|
||||
private ShopService shopService;
|
||||
|
||||
public ShopModel(ShopEntity entity, ShopService shopService) {
|
||||
this(shopService);
|
||||
if (entity != null) {
|
||||
BeanUtil.copyProperties(entity, this);
|
||||
}
|
||||
}
|
||||
|
||||
public ShopModel(ShopService shopService) {
|
||||
this.shopService = shopService;
|
||||
}
|
||||
|
||||
public void loadAddCommand(AddShopCommand command) {
|
||||
if (command != null) {
|
||||
BeanUtil.copyProperties(command, this, "id");
|
||||
}
|
||||
}
|
||||
|
||||
public void loadUpdateCommand(UpdateShopCommand command) {
|
||||
if (command != null) {
|
||||
loadAddCommand(command);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.agileboot.domain.shop.shop.model;
|
||||
|
||||
import com.agileboot.common.exception.ApiException;
|
||||
import com.agileboot.common.exception.error.ErrorCode;
|
||||
import com.agileboot.domain.shop.shop.db.ShopEntity;
|
||||
import com.agileboot.domain.shop.shop.db.ShopService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ShopModelFactory {
|
||||
|
||||
private final ShopService shopService;
|
||||
|
||||
public ShopModel loadById(Long shopId) {
|
||||
ShopEntity entity = shopService.getById(shopId);
|
||||
if (entity == null) {
|
||||
throw new ApiException(ErrorCode.Business.COMMON_OBJECT_NOT_FOUND, shopId, "店铺");
|
||||
}
|
||||
return new ShopModel(entity, shopService);
|
||||
}
|
||||
|
||||
public ShopModel create() {
|
||||
return new ShopModel(shopService);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.agileboot.domain.shop.shop.query;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.agileboot.common.core.page.AbstractPageQuery;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class SearchShopQuery<T> extends AbstractPageQuery<T> {
|
||||
|
||||
private String shopName;
|
||||
private String enable;
|
||||
private Date startTime;
|
||||
private Date endTime;
|
||||
|
||||
@Override
|
||||
public QueryWrapper<T> addQueryCondition() {
|
||||
QueryWrapper<T> queryWrapper = new QueryWrapper<>();
|
||||
|
||||
queryWrapper
|
||||
.like(StrUtil.isNotEmpty(shopName), "shop_name", shopName)
|
||||
.eq(StrUtil.isNotEmpty(enable), "enable", enable)
|
||||
.between(startTime != null && endTime != null, "create_time", startTime, endTime);
|
||||
|
||||
this.timeRangeColumn = "create_time";
|
||||
|
||||
return queryWrapper;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.agileboot.domain.cabinet.mqtt.db.MqttServerMapper">
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.agileboot.domain.shop.shop.db.ShopMapper">
|
||||
|
||||
</mapper>
|
|
@ -61,7 +61,7 @@ public class CodeGenerator {
|
|||
//生成的类 放在orm子模块下的/target/generated-code目录底下
|
||||
.module("/agileboot-orm/target/generated-code")
|
||||
.parentPackage("com.agileboot")
|
||||
.tableName("payment_operation_log")
|
||||
.tableName("shop")
|
||||
// 决定是否继承基类
|
||||
.isExtendsFromBaseEntity(true)
|
||||
.build();
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
DROP TABLE IF EXISTS `mqtt_server`;
|
||||
|
||||
CREATE TABLE `mqtt_server` (
|
||||
`mqtt_server_id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`server_url` VARCHAR(200) NOT NULL COMMENT 'MQTT服务器地址',
|
||||
`username` VARCHAR(100) NOT NULL COMMENT '连接账号',
|
||||
`password` VARCHAR(200) NOT NULL COMMENT '连接密码',
|
||||
`topic_filter` VARCHAR(200) NOT NULL COMMENT '订阅主题过滤器',
|
||||
`publish_topic` VARCHAR(200) NOT NULL COMMENT '发布主题',
|
||||
`creator_id` BIGINT NULL DEFAULT 0 COMMENT '创建者ID',
|
||||
`create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`updater_id` BIGINT NULL DEFAULT 0 COMMENT '更新者ID',
|
||||
`update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`deleted` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '删除标志(0存在 1删除)',
|
||||
PRIMARY KEY (`mqtt_server_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='MQTT服务配置表';
|
||||
|
||||
|
||||
ALTER TABLE `smart_cabinet`
|
||||
ADD COLUMN `mqtt_server_id` BIGINT NULL COMMENT 'MQTT服务ID'
|
||||
AFTER `cabinet_type`;
|
||||
|
||||
DROP TABLE IF EXISTS `shop`;
|
||||
|
||||
CREATE TABLE `shop` (
|
||||
`shop_id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`shop_name` VARCHAR(100) NOT NULL COMMENT '商店名称',
|
||||
`creator_id` BIGINT NULL DEFAULT 0 COMMENT '创建者ID',
|
||||
`create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`updater_id` BIGINT NULL DEFAULT 0 COMMENT '更新者ID',
|
||||
`update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`deleted` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '删除标志(0存在 1删除)',
|
||||
PRIMARY KEY (`shop_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='商店表,每个柜子属于一个商店';
|
||||
|
||||
ALTER TABLE `smart_cabinet`
|
||||
ADD COLUMN `shop_id` BIGINT NULL COMMENT '归属商店ID'
|
||||
AFTER `cabinet_type`;
|
Loading…
Reference in New Issue