浏览代码

fixed 云打印机功能

fushengqian 11 月之前
父节点
当前提交
088ea05ba7

+ 71 - 0
fuint-application/src/main/java/com/fuint/common/service/PrinterService.java

@@ -0,0 +1,71 @@
+package com.fuint.common.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.fuint.framework.pagination.PaginationRequest;
+import com.fuint.framework.pagination.PaginationResponse;
+import com.fuint.repository.model.MtPrinter;
+import com.fuint.framework.exception.BusinessCheckException;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 打印机业务接口
+ *
+ * Created by FSQ
+ * CopyRight https://www.fuint.cn
+ */
+public interface PrinterService extends IService<MtPrinter> {
+
+    /**
+     * 分页查询列表
+     *
+     * @param paginationRequest
+     * @return
+     */
+    PaginationResponse<MtPrinter> queryPrinterListByPagination(PaginationRequest paginationRequest) throws BusinessCheckException;
+
+    /**
+     * 添加打印机
+     *
+     * @param  mtPrinter
+     * @throws BusinessCheckException
+     * @return
+     */
+    MtPrinter addPrinter(MtPrinter mtPrinter) throws BusinessCheckException;
+
+    /**
+     * 根据ID获取打印机信息
+     *
+     * @param id ID
+     * @throws BusinessCheckException
+     * @return
+     */
+    MtPrinter queryPrinterById(Integer id) throws BusinessCheckException;
+
+    /**
+     * 根据ID删除打印机
+     *
+     * @param id ID
+     * @param operator 操作人
+     * @throws BusinessCheckException
+     * @return
+     */
+    void deletePrinter(Integer id, String operator) throws BusinessCheckException;
+
+    /**
+     * 更新打印机
+     * @param  mtPrinter
+     * @throws BusinessCheckException
+     * @return
+     * */
+    MtPrinter updatePrinter(MtPrinter mtPrinter) throws BusinessCheckException;
+
+    /**
+     * 根据条件搜索打印机
+     *
+     * @param params 查询参数
+     * @throws BusinessCheckException
+     * @return
+     * */
+    List<MtPrinter> queryPrinterListByParams(Map<String, Object> params) throws BusinessCheckException;
+}

+ 167 - 0
fuint-application/src/main/java/com/fuint/common/service/impl/PrinterServiceImpl.java

@@ -0,0 +1,167 @@
+package com.fuint.common.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fuint.framework.annoation.OperationServiceLog;
+import com.fuint.framework.exception.BusinessCheckException;
+import com.fuint.framework.pagination.PaginationRequest;
+import com.fuint.framework.pagination.PaginationResponse;
+import com.fuint.repository.model.MtPrinter;
+import com.fuint.common.service.PrinterService;
+import com.fuint.common.enums.StatusEnum;
+import com.fuint.repository.mapper.MtPrinterMapper;
+import com.github.pagehelper.PageHelper;
+import lombok.AllArgsConstructor;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import com.github.pagehelper.Page;
+import org.springframework.data.domain.PageImpl;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import java.util.*;
+
+/**
+ * 打印机服务接口
+ *
+ * Created by FSQ
+ * CopyRight https://www.fuint.cn
+ */
+@Service
+@AllArgsConstructor
+public class PrinterServiceImpl extends ServiceImpl<MtPrinterMapper, MtPrinter> implements PrinterService {
+
+    private static final Logger logger = LoggerFactory.getLogger(PrinterServiceImpl.class);
+
+    private MtPrinterMapper mtPrinterMapper;
+
+    /**
+     * 分页查询数据列表
+     *
+     * @param paginationRequest
+     * @return
+     */
+    @Override
+    public PaginationResponse<MtPrinter> queryPrinterListByPagination(PaginationRequest paginationRequest) {
+        Page<MtPrinter> pageHelper = PageHelper.startPage(paginationRequest.getCurrentPage(), paginationRequest.getPageSize());
+        LambdaQueryWrapper<MtPrinter> lambdaQueryWrapper = Wrappers.lambdaQuery();
+        lambdaQueryWrapper.ne(MtPrinter::getStatus, StatusEnum.DISABLE.getKey());
+
+        lambdaQueryWrapper.orderByAsc(MtPrinter::getId);
+        List<MtPrinter> dataList = mtPrinterMapper.selectList(lambdaQueryWrapper);
+
+        PageRequest pageRequest = PageRequest.of(paginationRequest.getCurrentPage(), paginationRequest.getPageSize());
+        PageImpl pageImpl = new PageImpl(dataList, pageRequest, pageHelper.getTotal());
+        PaginationResponse<MtPrinter> paginationResponse = new PaginationResponse(pageImpl, MtPrinter.class);
+        paginationResponse.setTotalPages(pageHelper.getPages());
+        paginationResponse.setTotalElements(pageHelper.getTotal());
+        paginationResponse.setContent(dataList);
+
+        return paginationResponse;
+    }
+
+    /**
+     * 添加打印机
+     *
+     * @param mtPrinter 打印机信息
+     * @return
+     */
+    @Override
+    @OperationServiceLog(description = "新增打印机")
+    public MtPrinter addPrinter(MtPrinter mtPrinter) throws BusinessCheckException {
+        mtPrinter.setStatus(StatusEnum.ENABLED.getKey());
+        mtPrinter.setUpdateTime(new Date());
+        mtPrinter.setCreateTime(new Date());
+        Integer id = mtPrinterMapper.insert(mtPrinter);
+        if (id > 0) {
+            return mtPrinter;
+        } else {
+            throw new BusinessCheckException("新增打印机数据失败");
+        }
+    }
+
+    /**
+     * 根据ID获打印机取息
+     *
+     * @param id 打印机ID
+     * @return
+     */
+    @Override
+    public MtPrinter queryPrinterById(Integer id) {
+        return mtPrinterMapper.selectById(id);
+    }
+
+    /**
+     * 根据ID删除打印机
+     *
+     * @param id 打印机ID
+     * @param operator 操作人
+     * @return
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    @OperationServiceLog(description = "删除打印机")
+    public void deletePrinter(Integer id, String operator) {
+        MtPrinter mtPrinter = queryPrinterById(id);
+        if (null == mtPrinter) {
+            return;
+        }
+        mtPrinter.setStatus(StatusEnum.DISABLE.getKey());
+        mtPrinter.setUpdateTime(new Date());
+        mtPrinterMapper.updateById(mtPrinter);
+    }
+
+    /**
+     * 修改打印机数据
+     *
+     * @param mtPrinter
+     * @throws BusinessCheckException
+     * @return
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    @OperationServiceLog(description = "更新打印机")
+    public MtPrinter updatePrinter(MtPrinter mtPrinter) throws BusinessCheckException {
+        mtPrinter = queryPrinterById(mtPrinter.getId());
+        if (mtPrinter == null) {
+            throw new BusinessCheckException("该打印机状态异常");
+        }
+        mtPrinter.setUpdateTime(new Date());
+        mtPrinterMapper.updateById(mtPrinter);
+        return mtPrinter;
+    }
+
+   /**
+    * 根据条件搜索打印机
+    *
+    * @param params 查询参数
+    * @throws BusinessCheckException
+    * @return
+    * */
+    @Override
+    public List<MtPrinter> queryPrinterListByParams(Map<String, Object> params) {
+        String status =  params.get("status") == null ? StatusEnum.ENABLED.getKey(): params.get("status").toString();
+        String storeId =  params.get("storeId") == null ? "" : params.get("storeId").toString();
+        String merchantId =  params.get("merchantId") == null ? "" : params.get("merchantId").toString();
+
+        LambdaQueryWrapper<MtPrinter> lambdaQueryWrapper = Wrappers.lambdaQuery();
+        if (StringUtils.isNotBlank(status)) {
+            lambdaQueryWrapper.eq(MtPrinter::getStatus, status);
+        }
+        if (StringUtils.isNotBlank(merchantId)) {
+            lambdaQueryWrapper.eq(MtPrinter::getMerchantId, merchantId);
+        }
+        if (StringUtils.isNotBlank(storeId)) {
+            lambdaQueryWrapper.and(wq -> wq
+                    .eq(MtPrinter::getStoreId, 0)
+                    .or()
+                    .eq(MtPrinter::getStoreId, storeId));
+        }
+
+        lambdaQueryWrapper.orderByAsc(MtPrinter::getId);
+        List<MtPrinter> dataList = mtPrinterMapper.selectList(lambdaQueryWrapper);
+        return dataList;
+    }
+}

+ 203 - 0
fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendPrinterController.java

@@ -0,0 +1,203 @@
+package com.fuint.module.backendApi.controller;
+
+import com.fuint.common.dto.AccountInfo;
+import com.fuint.common.service.PrinterService;
+import com.fuint.common.util.TokenUtil;
+import com.fuint.framework.web.BaseController;
+import com.fuint.framework.web.ResponseObject;
+import com.fuint.common.Constants;
+import com.fuint.common.enums.StatusEnum;
+import com.fuint.framework.pagination.PaginationRequest;
+import com.fuint.framework.pagination.PaginationResponse;
+import com.fuint.framework.exception.BusinessCheckException;
+import com.fuint.repository.model.MtPrinter;
+import com.fuint.utils.StringUtil;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.AllArgsConstructor;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+import javax.servlet.http.HttpServletRequest;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 打印机管理类controller
+ *
+ * Created by FSQ
+ * CopyRight https://www.fuint.cn
+ */
+@Api(tags="管理端-打印机相关接口")
+@RestController
+@AllArgsConstructor
+@RequestMapping(value = "/backendApi/printer")
+public class BackendPrinterController extends BaseController {
+
+    /**
+     * 打印机服务接口
+     */
+    private PrinterService printerService;
+
+    /**
+     * 打印机列表查询
+     *
+     * @param  request HttpServletRequest对象
+     * @return 打印机列表
+     */
+    @ApiOperation(value = "打印机列表查询")
+    @RequestMapping(value = "/list", method = RequestMethod.GET)
+    @CrossOrigin
+    @PreAuthorize("@pms.hasPermission('printer:list')")
+    public ResponseObject list(HttpServletRequest request) throws BusinessCheckException {
+        String token = request.getHeader("Access-Token");
+        Integer page = request.getParameter("page") == null ? Constants.PAGE_NUMBER : Integer.parseInt(request.getParameter("page"));
+        Integer pageSize = request.getParameter("pageSize") == null ? Constants.PAGE_SIZE : Integer.parseInt(request.getParameter("pageSize"));
+        String title = request.getParameter("title");
+        String status = request.getParameter("status");
+        String searchStoreId = request.getParameter("storeId");
+
+        AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
+        Integer storeId;
+        if (accountInfo == null) {
+            return getFailureResult(1001, "请先登录");
+        } else {
+            storeId = accountInfo.getStoreId();
+        }
+
+        PaginationRequest paginationRequest = new PaginationRequest();
+        paginationRequest.setCurrentPage(page);
+        paginationRequest.setPageSize(pageSize);
+
+        Map<String, Object> params = new HashMap<>();
+        if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
+            params.put("merchantId", accountInfo.getMerchantId());
+        }
+        if (StringUtil.isNotEmpty(title)) {
+            params.put("title", title);
+        }
+        if (StringUtil.isNotEmpty(status)) {
+            params.put("status", status);
+        }
+        if (StringUtil.isNotEmpty(searchStoreId)) {
+            params.put("storeId", searchStoreId);
+        }
+        if (storeId != null && storeId > 0) {
+            params.put("storeId", storeId);
+        }
+        paginationRequest.setSearchParams(params);
+        PaginationResponse<MtPrinter> paginationResponse = printerService.queryPrinterListByPagination(paginationRequest);
+
+        Map<String, Object> paramsStore = new HashMap<>();
+        paramsStore.put("status", StatusEnum.ENABLED.getKey());
+        if (accountInfo.getStoreId() != null && accountInfo.getStoreId() > 0) {
+            paramsStore.put("storeId", accountInfo.getStoreId().toString());
+        }
+        if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
+            paramsStore.put("merchantId", accountInfo.getMerchantId());
+        }
+
+        Map<String, Object> result = new HashMap<>();
+        result.put("paginationResponse", paginationResponse);
+
+        return getSuccessResult(result);
+    }
+
+    /**
+     * 更新打印机状态
+     *
+     * @return
+     */
+    @ApiOperation(value = "更新打印机状态")
+    @RequestMapping(value = "/updateStatus", method = RequestMethod.POST)
+    @CrossOrigin
+    @PreAuthorize("@pms.hasPermission('printer:edit')")
+    public ResponseObject updateStatus(HttpServletRequest request, @RequestBody Map<String, Object> params) throws BusinessCheckException {
+        String token = request.getHeader("Access-Token");
+        String status = params.get("status") != null ? params.get("status").toString() : StatusEnum.ENABLED.getKey();
+        Integer id = params.get("id") == null ? 0 : Integer.parseInt(params.get("id").toString());
+
+        AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
+        if (accountInfo == null) {
+            return getFailureResult(1001, "请先登录");
+        }
+
+        MtPrinter mtPrinter = printerService.queryPrinterById(id);
+        if (mtPrinter == null) {
+            return getFailureResult(201);
+        }
+
+        String operator = accountInfo.getAccountName();
+        mtPrinter.setOperator(operator);
+        mtPrinter.setStatus(status);
+        printerService.updatePrinter(mtPrinter);
+
+        return getSuccessResult(true);
+    }
+
+    /**
+     * 保存打印机
+     *
+     * @param request HttpServletRequest对象
+     * @return
+     */
+    @ApiOperation(value = "保存打印机")
+    @RequestMapping(value = "/save", method = RequestMethod.POST)
+    @CrossOrigin
+    @PreAuthorize("@pms.hasPermission('printer:add')")
+    public ResponseObject saveHandler(HttpServletRequest request, @RequestBody Map<String, Object> params) throws BusinessCheckException {
+        String token = request.getHeader("Access-Token");
+        String id = params.get("id") == null ? "" : params.get("id").toString();
+        String status = params.get("status") == null ? "" : params.get("status").toString();
+        String storeId = params.get("storeId") == null ? "0" : params.get("storeId").toString();
+        String name = params.get("name") == null ? "" : params.get("name").toString();
+        String sn = params.get("sn") == null ? "" : params.get("sn").toString();
+        String description = params.get("description") == null ? "" : params.get("description").toString();
+
+        AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
+        if (accountInfo == null) {
+            return getFailureResult(1001, "请先登录");
+        }
+
+        MtPrinter mtPrinter = new MtPrinter();
+        mtPrinter.setOperator(accountInfo.getAccountName());
+        mtPrinter.setStatus(status);
+        mtPrinter.setStoreId(Integer.parseInt(storeId));
+        mtPrinter.setName(name);
+        mtPrinter.setSn(sn);
+        mtPrinter.setDescription(description);
+        mtPrinter.setMerchantId(accountInfo.getMerchantId());
+        if (StringUtil.isNotEmpty(id)) {
+            mtPrinter.setId(Integer.parseInt(id));
+            printerService.updatePrinter(mtPrinter);
+        } else {
+            printerService.addPrinter(mtPrinter);
+        }
+
+        return getSuccessResult(true);
+    }
+
+    /**
+     * 获取打印机详情
+     *
+     * @param id
+     * @return
+     */
+    @ApiOperation(value = "获取打印机详情")
+    @RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
+    @CrossOrigin
+    @PreAuthorize("@pms.hasPermission('printer:list')")
+    public ResponseObject info(HttpServletRequest request, @PathVariable("id") Integer id) throws BusinessCheckException {
+        String token = request.getHeader("Access-Token");
+        AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
+        if (accountInfo == null) {
+            return getFailureResult(1001, "请先登录");
+        }
+
+        MtPrinter printerInfo = printerService.queryPrinterById(id);
+
+        Map<String, Object> result = new HashMap<>();
+        result.put("printerInfo", printerInfo);
+
+        return getSuccessResult(result);
+    }
+}

+ 14 - 0
fuint-repository/src/main/java/com/fuint/repository/mapper/MtPrinterMapper.java

@@ -0,0 +1,14 @@
+package com.fuint.repository.mapper;
+
+import com.fuint.repository.model.MtPrinter;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * 打印机 Mapper 接口
+ *
+ * Created by FSQ
+ * CopyRight https://www.fuint.cn
+ */
+public interface MtPrinterMapper extends BaseMapper<MtPrinter> {
+
+}

+ 57 - 0
fuint-repository/src/main/java/com/fuint/repository/model/MtPrinter.java

@@ -0,0 +1,57 @@
+package com.fuint.repository.model;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import java.io.Serializable;
+import java.util.Date;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 打印机实体
+ * 
+ * @Created by FSQ
+ * CopyRight https://www.fuint.cn
+ */
+@Getter
+@Setter
+@TableName("mt_printer")
+@ApiModel(value = "printer表对象", description = "printer表对象")
+public class MtPrinter implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty("自增ID")
+    private Integer id;
+
+    @ApiModelProperty("所属商户ID")
+    private Integer merchantId;
+
+    @ApiModelProperty("所属店铺ID")
+    private Integer storeId;
+
+    @ApiModelProperty("打印机编号")
+    private String sn;
+
+    @ApiModelProperty("打印机名称")
+    private String name;
+
+    @ApiModelProperty("创建时间")
+    private Date createTime;
+
+    @ApiModelProperty("更新时间")
+    private Date updateTime;
+
+    @ApiModelProperty("备注说明")
+    private String description;
+
+    @ApiModelProperty("最后操作人")
+    private String operator;
+
+    @ApiModelProperty("状态,A正常;D作废")
+    private String status;
+
+}

+ 5 - 0
fuint-repository/src/main/resources/mapper/MtPrinterMapper.xml

@@ -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.fuint.repository.mapper.MtPrinterMapper}">
+
+</mapper>