rk
10 小时以前 cf17c2f7012fc4351f66c71d66a4aa3a9fe9e34a
server/services/src/main/java/com/doumee/service/business/impl/ShopInfoServiceImpl.java
@@ -26,6 +26,12 @@
import com.doumee.dao.business.model.Orders;
import com.doumee.dao.business.model.PricingRule;
import com.doumee.dao.business.model.ShopInfo;
import com.doumee.config.xyy.XyyConfig;
import com.doumee.config.xyy.dto.AddPrinterRequest;
import com.doumee.config.xyy.dto.AddPrinterRequestItem;
import com.doumee.config.xyy.dto.DelPrinterRequest;
import com.doumee.config.xyy.vo.ObjectRestResponse;
import com.doumee.config.xyy.vo.PrinterResult;
import com.doumee.dao.dto.*;
import com.doumee.dao.system.model.SystemDictData;
import com.doumee.dao.system.SystemUserMapper;
@@ -93,6 +99,12 @@
    @Autowired
    private SmsrecordMapper smsrecordMapper;
    @Autowired
    private PrintService printService;
    @Autowired
    private XyyConfig xyyConfig;
    @Override
    public Integer create(ShopInfo shopInfo) {
        shopInfoMapper.insert(shopInfo);
@@ -870,6 +882,7 @@
        vo.setFeeStandard(shop.getFeeStandard());
        vo.setLatitude(shop.getLatitude());
        vo.setLongitude(shop.getLongitude());
        vo.setLinkPhone(shop.getLinkPhone());
        // 门头照 + 内部照 全路径集合
        String imgPrefix = getShopPrefix();
@@ -1082,6 +1095,7 @@
        // 存件门店
        List<Orders> depositSalesOrders = ordersMapper.selectList(new QueryWrapper<Orders>().lambda()
                .eq(Orders::getDeleted, Constants.ZERO)
                .notIn(Orders::getStatus,Constants.OrderStatus.cancelled.getStatus(),Constants.OrderStatus.waitPay.getStatus())
                .ge(Orders::getCreateTime, startTime)
                .lt(Orders::getCreateTime, endTime)
                .eq(Orders::getDepositShopId, shopId));
@@ -1089,6 +1103,7 @@
        List<Orders> takeSalesOrders = ordersMapper.selectList(new QueryWrapper<Orders>().lambda()
                .eq(Orders::getDeleted, Constants.ZERO)
                .eq(Orders::getType,Constants.ONE)
                .notIn(Orders::getStatus,Constants.OrderStatus.cancelled.getStatus(),Constants.OrderStatus.waitPay.getStatus())
                .ge(Orders::getCreateTime, startTime)
                .lt(Orders::getCreateTime, endTime)
                .eq(Orders::getTakeShopId, shopId));
@@ -1161,7 +1176,10 @@
                .last("limit 1")
        );
        if(shop==null){
            throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT);
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"请核对登录手机号是否正确");
        }
        if(Constants.equalsInteger(shop.getStatus(),Constants.ONE)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"门店已禁用,请联系管理员");
        }
        if(!Constants.equalsInteger(shop.getAuditStatus(),Constants.THREE)){
            if(Constants.equalsInteger(shop.getAuditStatus(),Constants.ONE)){
@@ -1219,6 +1237,9 @@
                .last("limit 1"));
        if (shop == null) {
            return null;
        }
        if(Constants.equalsInteger(shop.getStatus(),Constants.ONE)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"门店已禁用,请联系管理员");
        }
        // 创建token(generateTokenForRedis 已自动清除该用户旧token,保证唯一有效)
        String token = JwtTokenUtil.generateTokenForRedis(shop.getId(), Constants.TWO, JSONObject.toJSONString(shop), redisTemplate);
@@ -1418,56 +1439,57 @@
        }
    }
    @Autowired
    private com.doumee.core.utils.xpyun.XpyunPrintService xpyunPrintService;
    @Override
    public void bindPrinter(com.doumee.dao.dto.PrinterBindDTO dto) {
        ShopInfo shop = shopInfoMapper.selectById(dto.getShopId());
    public void maintainPrinterSn(ShopPrinterDTO dto) {
        ShopInfo shop = shopInfoMapper.selectById(dto.getId());
        if (shop == null || Constants.equalsInteger(shop.getDeleted(), Constants.ONE)) {
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        // 调用芯烨云注册打印机
        com.doumee.core.utils.xpyun.XpyunResponse resp = xpyunPrintService.addPrinter(
                dto.getPrinterSn(), shop.getName());
        if (resp.getCode() != null && resp.getCode() == 0) {
            log.info("芯烨云打印机注册成功: sn={}", dto.getPrinterSn());
        } else {
            log.warn("芯烨云打印机注册返回非0: sn={}, code={}, msg={}",
                    dto.getPrinterSn(), resp.getCode(), resp.getMsg());
        String oldSn = shop.getPrinterSn();
        String newSn = dto.getPrinterSn();
        boolean hasNewSn = StringUtils.isNotBlank(newSn);
        boolean hasOldSn = StringUtils.isNotBlank(oldSn);
        if (!hasNewSn) {
            // 未传打印机SN → 删除逻辑
            if (hasOldSn) {
                delPrinterFromXyy(oldSn);
                shop.setPrinterSn(null);
                shopInfoMapper.updateById(shop);
            }
            return;
        }
        // 无论云端是否成功,都绑定到门店(可后续重试云端注册)
        ShopInfo update = new ShopInfo();
        update.setId(dto.getShopId());
        update.setPrinterSn(dto.getPrinterSn());
        shopInfoMapper.updateById(update);
        // 传了打印机SN → 如果旧绑定存在,先删除
        if (hasOldSn) {
            delPrinterFromXyy(oldSn);
        }
        // 绑定新打印机
        AddPrinterRequest addReq = new AddPrinterRequest();
        xyyConfig.createRequestHeader(addReq);
        addReq.setItems(new AddPrinterRequestItem[]{new AddPrinterRequestItem() {{
            setSn(newSn);
            setName(shop.getName());
        }}});
        ObjectRestResponse<PrinterResult> addResp = printService.addPrinters(addReq);
        if (addResp.getCode() != 0) {
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "绑定打印机失败:" + addResp.getMsg());
        }
        log.info("绑定成功:{}", newSn);
        shop.setPrinterSn(newSn);
        shopInfoMapper.updateById(shop);
    }
    @Override
    public void unbindPrinter(Integer shopId) {
        ShopInfo shop = shopInfoMapper.selectById(shopId);
        if (shop == null || Constants.equalsInteger(shop.getDeleted(), Constants.ONE)) {
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
    private void delPrinterFromXyy(String sn) {
        DelPrinterRequest delReq = new DelPrinterRequest();
        xyyConfig.createRequestHeader(delReq);
        delReq.setSnlist(new String[]{sn});
        ObjectRestResponse<PrinterResult> delResp = printService.delPrinters(delReq);
        if (delResp.getCode() != 0) {
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "解绑打印机失败:" + delResp.getMsg());
        }
        if (StringUtils.isNotBlank(shop.getPrinterSn())) {
            xpyunPrintService.deletePrinter(shop.getPrinterSn());
        }
        ShopInfo update = new ShopInfo();
        update.setId(shopId);
        update.setPrinterSn(null);
        shopInfoMapper.updateById(update);
    }
    @Override
    public Object queryPrinterStatus(Integer shopId) {
        ShopInfo shop = shopInfoMapper.selectById(shopId);
        if (shop == null || Constants.equalsInteger(shop.getDeleted(), Constants.ONE)) {
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        if (StringUtils.isBlank(shop.getPrinterSn())) {
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "该门店未绑定打印机");
        }
        return xpyunPrintService.queryPrinterStatus(shop.getPrinterSn());
        log.info("解绑成功:{}", sn);
    }
}