增加打印开启关闭接口
This commit is contained in:
parent
4d066a4306
commit
9f96697d78
@ -33,7 +33,7 @@ public class ShopStorePrinterLog implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public ShopStorePrinterLog(Integer category,Integer storeId,String orderId,Long templateId,String templateValue, String templateData,String printContent) {
|
||||
public ShopStorePrinterLog(Integer category,Integer storeId,String orderId,Long templateId,String templateValue, String templateData,String printContent,String feiePrintNo,String printerSn) {
|
||||
this.category = category;
|
||||
this.store_id = storeId;
|
||||
this.order_id = orderId;
|
||||
@ -41,6 +41,8 @@ public class ShopStorePrinterLog implements Serializable {
|
||||
this.template_data = templateData;
|
||||
this.template_value = templateValue;
|
||||
this.print_content = printContent;
|
||||
this.feie_print_no = feiePrintNo;
|
||||
this.printer_sn = printerSn;
|
||||
}
|
||||
|
||||
@ApiModelProperty(value = "日志自增ID")
|
||||
@ -68,6 +70,12 @@ public class ShopStorePrinterLog implements Serializable {
|
||||
@ApiModelProperty(value = "最终打印的内容")
|
||||
private String print_content;
|
||||
|
||||
@ApiModelProperty(value = "飞鹅返回到打印编号")
|
||||
private String feie_print_no;
|
||||
|
||||
@ApiModelProperty(value = "打印机编号")
|
||||
private String printer_sn;
|
||||
|
||||
@ApiModelProperty(value = "状态:1-有效;2-无效;")
|
||||
private Integer status;
|
||||
|
||||
|
||||
@ -46,7 +46,8 @@ public class ShopStorePrinterController {
|
||||
@RequestParam(name = "printer_sn", required = true) String printer_sn,
|
||||
@RequestParam(name = "printer_key", required = true) String printer_key,
|
||||
@RequestParam(name = "region_id", required = true) Integer region_id,
|
||||
@RequestParam(name = "paper_with", defaultValue = "58") Integer paper_with) {
|
||||
@RequestParam(name = "paper_with", defaultValue = "58") Integer paper_with,
|
||||
@RequestParam(name = "website_url", defaultValue = "") String website_url) {
|
||||
|
||||
ShopStorePrinter shopStorePrinter = new ShopStorePrinter();
|
||||
shopStorePrinter.setModel_id(model_id);
|
||||
@ -56,6 +57,7 @@ public class ShopStorePrinterController {
|
||||
shopStorePrinter.setPrinter_key(printer_key);
|
||||
shopStorePrinter.setRegion_id(region_id);
|
||||
shopStorePrinter.setPaper_with(paper_with);
|
||||
shopStorePrinter.setWebsite_url(website_url);
|
||||
|
||||
return shopStorePrinterService.addNewShopStorePrinter(shopStorePrinter);
|
||||
}
|
||||
@ -68,7 +70,8 @@ public class ShopStorePrinterController {
|
||||
@RequestParam(name = "printer_sn", required = true) String printer_sn,
|
||||
@RequestParam(name = "printer_key", required = true) String printer_key,
|
||||
@RequestParam(name = "region_id", required = true) Integer region_id,
|
||||
@RequestParam(name = "paper_with", defaultValue = "58") Integer paper_with) {
|
||||
@RequestParam(name = "paper_with", defaultValue = "58") Integer paper_with,
|
||||
@RequestParam(name = "website_url", defaultValue = "") String website_url) {
|
||||
|
||||
ShopStorePrinter shopStorePrinter = new ShopStorePrinter();
|
||||
shopStorePrinter.setPrinter_id(printer_id);
|
||||
@ -78,10 +81,18 @@ public class ShopStorePrinterController {
|
||||
shopStorePrinter.setPrinter_key(printer_key);
|
||||
shopStorePrinter.setRegion_id(region_id);
|
||||
shopStorePrinter.setPaper_with(paper_with);
|
||||
shopStorePrinter.setWebsite_url(website_url);
|
||||
|
||||
return shopStorePrinterService.updateShopStorePrinter(shopStorePrinter);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "门店开启/关闭一个打票机", notes = "门店开启/关闭一个打票机")
|
||||
@RequestMapping(value = "/status/update", method = {RequestMethod.POST})
|
||||
public CommonResult updateShopStorePrinterStatus(@RequestParam(name = "printer_id" , required = true) Long printerId,
|
||||
@RequestParam(name = "status" , required = true) Integer status) {
|
||||
return shopStorePrinterService.updateShopStorePrinterStatus(printerId, status);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "门店删除一个打票机", notes = "门店删除一个打票机")
|
||||
@RequestMapping(value = "/delete", method = {RequestMethod.POST})
|
||||
public CommonResult deleteShopStorePrinter(@RequestParam(name = "printer_id" , required = true) Long printer_id) {
|
||||
|
||||
@ -37,11 +37,11 @@ public class ShopStorePrinterRegionController {
|
||||
@ApiOperation(value = "门店新增一个打票机摆放区域", notes = "门店新增一个打票机摆放区域")
|
||||
@RequestMapping(value = "/add/new", method = {RequestMethod.POST})
|
||||
public CommonResult addNewShopStorePrinterRegion(
|
||||
@RequestParam(name = "region", required = true) String model_name,
|
||||
@RequestParam(name = "region", required = true) String region,
|
||||
@RequestParam(name = "intro", defaultValue = "") String intro) {
|
||||
|
||||
ShopStorePrinterRegion shopStorePrinterRegion = new ShopStorePrinterRegion();
|
||||
shopStorePrinterRegion.setRegion(model_name);
|
||||
shopStorePrinterRegion.setRegion(region);
|
||||
shopStorePrinterRegion.setIntro(intro);
|
||||
|
||||
return shopStorePrinterRegionService.addNewShopStorePrinterRegion(shopStorePrinterRegion);
|
||||
|
||||
@ -3,6 +3,8 @@ package com.suisung.mall.shop.store.service;
|
||||
import com.suisung.mall.common.modules.store.ShopStorePrinterLog;
|
||||
import com.suisung.mall.core.web.service.IBaseService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ShopStorePrinterLogService extends IBaseService<ShopStorePrinterLog> {
|
||||
|
||||
/**
|
||||
@ -13,5 +15,12 @@ public interface ShopStorePrinterLogService extends IBaseService<ShopStorePrinte
|
||||
*/
|
||||
Boolean insertShopStorePrinterLog(ShopStorePrinterLog record);
|
||||
|
||||
|
||||
/**
|
||||
* 批量新增打票机打印日志
|
||||
* @param records
|
||||
*/
|
||||
void insertShopStorePrinterLogBatch(List<ShopStorePrinterLog> records);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -46,6 +46,14 @@ public interface ShopStorePrinterService extends IBaseService<ShopStorePrinter>
|
||||
*/
|
||||
CommonResult updateShopStorePrinter(ShopStorePrinter record);
|
||||
|
||||
/**
|
||||
* 门店开启/关闭一个打票机
|
||||
* @param printer_id
|
||||
* @param status
|
||||
* @return
|
||||
*/
|
||||
CommonResult updateShopStorePrinterStatus(Long printer_id, Integer status);
|
||||
|
||||
/**
|
||||
* 门店删除一个打票机
|
||||
*
|
||||
|
||||
@ -60,4 +60,23 @@ public class ShopStorePrinterLogServiceImpl extends BaseServiceImpl<ShopStorePri
|
||||
|
||||
return add(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertShopStorePrinterLogBatch(List<ShopStorePrinterLog> records) {
|
||||
if (CollUtil.isEmpty(records)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (ShopStorePrinterLog record : records) {
|
||||
if (record.getStore_id() == null ||
|
||||
StrUtil.isBlank(record.getOrder_id()) ||
|
||||
StrUtil.isBlank(record.getTemplate_value()) ||
|
||||
StrUtil.isBlank(record.getPrint_content())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
add(record);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -30,6 +30,7 @@ import com.suisung.mall.shop.store.utis.FeieUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.util.Pair;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@ -172,7 +173,7 @@ public class ShopStorePrinterServiceImpl extends BaseServiceImpl<ShopStorePrinte
|
||||
updateWrapper.eq("printer_id", record.getPrinter_id());
|
||||
updateWrapper.set("printer_name", record.getPrinter_name());
|
||||
updateWrapper.set("model_id", record.getModel_id());
|
||||
updateWrapper.set("region", record.getRegion_id());
|
||||
updateWrapper.set("region_id", record.getRegion_id());
|
||||
updateWrapper.set("paper_with", record.getPaper_with());
|
||||
updateWrapper.set("website_url", record.getWebsite_url());
|
||||
updateWrapper.set("status", record.getStatus());
|
||||
@ -215,6 +216,36 @@ public class ShopStorePrinterServiceImpl extends BaseServiceImpl<ShopStorePrinte
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult updateShopStorePrinterStatus(Long printerId, Integer status) {
|
||||
|
||||
// 判断有没有权限
|
||||
UserDto user = getCurrentUser();
|
||||
if (!user.isStore()) {
|
||||
return CommonResult.failed("用户信息异常!");
|
||||
}
|
||||
|
||||
ShopStorePrinter record = getById(printerId);
|
||||
if (record == null || record.getPrinter_id() <= 0) {
|
||||
return CommonResult.failed("打票机不存在,无法操作!");
|
||||
}
|
||||
|
||||
if(status.equals(record.getStatus())) {
|
||||
return CommonResult.success();
|
||||
}
|
||||
|
||||
UpdateWrapper<ShopStorePrinter> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("printer_id", printerId);
|
||||
updateWrapper.set("flag", status);
|
||||
|
||||
boolean success = update(updateWrapper);
|
||||
if (success) {
|
||||
return CommonResult.success();
|
||||
}
|
||||
|
||||
return CommonResult.failed("操作失败!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult deleteShopStorePrinter(Long printer_id) {
|
||||
|
||||
@ -373,15 +404,30 @@ public class ShopStorePrinterServiceImpl extends BaseServiceImpl<ShopStorePrinte
|
||||
}
|
||||
|
||||
// 调用打票机,打印小票
|
||||
boolean success = feieUtil.printContent(printerList.get(0).getPrinter_sn(), printContent);
|
||||
if (!success) {
|
||||
List<String> printerSnList = new ArrayList<>();
|
||||
for (ShopStorePrinter printer : printerList) {
|
||||
printerSnList.add(printer.getPrinter_sn());
|
||||
}
|
||||
|
||||
List<Pair<String,String>> respList = feieUtil.printContentByList(printerSnList, printContent);
|
||||
if (CollUtil.isEmpty(respList)) {
|
||||
// 只需一台打印机能打印,就算成功了
|
||||
logger.info("订单{}信息打印,调用飞鹅打印机打印失败。", orderId);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 打印成功,新增打印日志记录,以备下次查看和打印
|
||||
ShopStorePrinterLog shopStorePrinterLog = new ShopStorePrinterLog(template.getCategory(), storeId, orderId, template.getTemplate_id(), template.getTemplate_value(), JsonUtil.object2json(binding), printContent);
|
||||
shopStorePrinterLogService.insertShopStorePrinterLog(shopStorePrinterLog);
|
||||
// String repsNo = feieUtil.printContent(printerList.get(0).getPrinter_sn(), printContent);
|
||||
// if (StrUtil.isBlank(repsNo)) {
|
||||
// logger.info("订单{}信息打印,调用飞鹅打印机打印失败。", orderId);
|
||||
// return false;
|
||||
// }
|
||||
|
||||
for (Pair<String,String> respSn : respList) {
|
||||
// 打印成功,新增打印日志记录,以备下次查看和打印
|
||||
ShopStorePrinterLog shopStorePrinterLog = new ShopStorePrinterLog(template.getCategory(), storeId, orderId, template.getTemplate_id(), template.getTemplate_value(), JsonUtil.object2json(binding), printContent, respSn.getSecond(),respSn.getFirst());
|
||||
shopStorePrinterLogService.insertShopStorePrinterLog(shopStorePrinterLog);
|
||||
}
|
||||
|
||||
|
||||
logger.debug("#### 调用飞鹅打票机的打印操作结束 ####");
|
||||
|
||||
|
||||
@ -20,6 +20,7 @@ import org.apache.http.util.EntityUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.util.Pair;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -130,18 +131,53 @@ public class FeieUtil {
|
||||
* @param printContent 打印等内容,参考 飞鹅 模版格式
|
||||
* @return
|
||||
*/
|
||||
public boolean printContent(String sn, String printContent) {
|
||||
public String printContent(String sn, String printContent) {
|
||||
if (StrUtil.isBlank(sn) || StrUtil.isBlank(printContent)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
|
||||
nvps.add(new BasicNameValuePair("sn", sn));
|
||||
nvps.add(new BasicNameValuePair("content", printContent));
|
||||
|
||||
FeiePrinterApiRes<String> reps = sendHttpPost("Open_printMsg", nvps);
|
||||
if (reps != null && reps.getRet().equals(0)) {
|
||||
return true;
|
||||
// 返回打印编号,如:816501678_20160919184316_1419533539
|
||||
return reps.getData();
|
||||
}
|
||||
|
||||
logger.error("飞鹅打印操作失败:{}", reps.getMsg());
|
||||
return false;
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 多个打印机打印同一个订单
|
||||
* @param printerSnList 多个打印机编号
|
||||
* @param printContent
|
||||
* @return
|
||||
*/
|
||||
public List<Pair<String,String>> printContentByList(List<String> printerSnList, String printContent) {
|
||||
if (CollectionUtil.isEmpty(printerSnList)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<Pair<String,String>> retList = new ArrayList<>();
|
||||
for (String sn : printerSnList) {
|
||||
if (StrUtil.isBlank(sn)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String respNo = printContent(sn, printContent);
|
||||
if (StrUtil.isNotBlank(respNo)) {
|
||||
retList.add(Pair.of(sn, respNo));
|
||||
}
|
||||
}
|
||||
|
||||
if (CollectionUtil.isEmpty(retList)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return retList;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
<result column="Card_no" property="card_no" jdbcType="VARCHAR" />
|
||||
<result column="Website_url" property="website_url" jdbcType="VARCHAR" />
|
||||
<result column="Region_id" property="region_id" jdbcType="INTEGER" />
|
||||
<result column="Region" property="region" jdbcType="INTEGER" />
|
||||
<result column="Region" property="region" jdbcType="VARCHAR" />
|
||||
<result column="Paper_with" property="paper_with" jdbcType="INTEGER" />
|
||||
<result column="Intro" property="intro" jdbcType="VARCHAR" />
|
||||
<result column="Flag" property="flag" jdbcType="INTEGER" />
|
||||
|
||||
Loading…
Reference in New Issue
Block a user