添加结算打印小票

This commit is contained in:
韩鹏辉
2024-04-03 10:56:59 +08:00
parent a2f467038b
commit 97da8f8392
6 changed files with 135 additions and 13 deletions

View File

@@ -38,11 +38,20 @@ public class CloudPrinterController {
return cloudPrinterService.printReceipt(type,orderId,ispre);
}
// public Result handoverPrint( @RequestHeader("token") String token,
// @RequestHeader("loginName") String loginName,
// @RequestHeader("clientType") String clientType,
// @RequestParam("tradeDay") String tradeDay
// ){
//
// }
/**
* 打印结算小票
* @param token
* @param loginName
* @param clientType
* @param tradeDay
* @return
*/
@GetMapping("handoverPrint")
public Result handoverPrint( @RequestHeader("token") String token,
@RequestHeader("loginName") String loginName,
@RequestHeader("clientType") String clientType,
@RequestParam("tradeDay") String tradeDay
){
return cloudPrinterService.handoverprintData(token,tradeDay,loginName);
}
}

View File

@@ -1,10 +1,14 @@
package com.chaozhanggui.system.cashierservice.dao;
import com.chaozhanggui.system.cashierservice.entity.ShopUserDutyPay;
import com.chaozhanggui.system.cashierservice.model.HandoverInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
@Component
@Mapper
public interface ShopUserDutyPayMapper {
@@ -21,4 +25,7 @@ public interface ShopUserDutyPayMapper {
int updateByPrimaryKey(ShopUserDutyPay record);
ShopUserDutyPay selectByDuctIdAndType(@Param("dutyId") Integer dutyId,@Param("payType") String payType);
List<Map<String,Object>> selectByDutyId(Integer dutyId);
}

View File

@@ -18,6 +18,6 @@ public class WebAppConfigurer implements WebMvcConfigurer {
registry.addInterceptor(signInterceptor)
.addPathPatterns("/**")
.excludePathPatterns("/login/login")
.excludePathPatterns("/cloudPrinter/print");
;
}
}

View File

@@ -5,14 +5,13 @@ import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.model.CategoryInfo;
import com.chaozhanggui.system.cashierservice.model.HandoverInfo;
import com.chaozhanggui.system.cashierservice.model.OrderDetailPO;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result;
import com.chaozhanggui.system.cashierservice.util.DateUtils;
import com.chaozhanggui.system.cashierservice.util.FeieyunPrintUtil;
import com.chaozhanggui.system.cashierservice.util.JSONUtil;
import com.chaozhanggui.system.cashierservice.util.PrinterUtils;
import com.chaozhanggui.system.cashierservice.util.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -20,6 +19,7 @@ import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service
@Slf4j
@@ -44,6 +44,21 @@ public class CloudPrinterService {
@Autowired
private TbOrderDetailMapper tbOrderDetailMapper;
@Autowired
private TbmerchantAccountMapper tbmerchantAccountMapper;
@Autowired
private ShopUserDutyMapper shopUserDutyMapper;
@Autowired
private TbPlussShopStaffMapper tbPlussShopStaffMapper;
@Autowired
ShopUserDutyPayMapper shopUserDutyPayMapper;
@@ -342,6 +357,80 @@ public class CloudPrinterService {
}
public Result handoverprintData(String token,String tradeDay,String loginName){
JSONObject info= TokenUtil.parseParamFromToken(token);
MsgException.checkNull(info,"获取信息失败");
TbmerchantAccount tbmerchantAccount= tbmerchantAccountMapper.selectByPrimaryKey(Integer.valueOf(info.get("accountId").toString()));
MsgException.checkNull(tbmerchantAccount,"商户信息不存在");
TbShopInfo tbShopInfo= tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(tbmerchantAccount.getShopId()));
MsgException.checkNull(tbShopInfo,"店铺信息不存在");
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(tbShopInfo.getId());
if (ObjectUtil.isEmpty(shopInfo)) {
log.error("店铺信息不存在");
return Result.fail(CodeEnum.SHOPINFONOEXIST);
}
List<TbPrintMachineWithBLOBs> bloBsList = tbPrintMachineMapper.selectByShopId(tbShopInfo.getId().toString());
if (ObjectUtil.isEmpty(bloBsList) || bloBsList.size() <= 0) {
log.error("此店铺没有对应的打印机设备");
return Result.fail(CodeEnum.printmachinenoexsit);
}
bloBsList.parallelStream().forEach(it->{
if (!"network".equals(it.getConnectionType())) {
log.error("非网络打印机");
return;
}
if (!"1".equals(it.getStatus().toString())) {
log.error("打印机状态异常");
return;
}
if(!it.getSubType().equals("cash")){
log.error("非小票打印机");
return;
}
ShopUserDuty shopUserDuty=shopUserDutyMapper.selectByShopIdAndTrade(tbShopInfo.getId(),tradeDay);
MsgException.checkNull(shopUserDuty,"交班信息不存在");
TbPlussShopStaff shopStaff= tbPlussShopStaffMapper.selectByPrimaryKey(Integer.valueOf(info.get("staffId").toString()));
MsgException.checkNull(shopStaff,"员工信息不存在");
List<HandoverInfo.PayInfo> list=null;
List<HandoverInfo.MemberData> memberData=null;
List<Map<String,Object>> mapList= shopUserDutyPayMapper.selectByDutyId(shopUserDuty.getId());
if(ObjectUtil.isNotEmpty(mapList)&&mapList.size()>0){
list= JSONUtil.parseJSONStr2TList(JSONUtil.toJSONString(mapList), HandoverInfo.PayInfo.class);
}
ShopUserDutyPay shopUserDutyPay=shopUserDutyPayMapper.selectByDuctIdAndType(shopUserDuty.getId(),"deposit");
if(ObjectUtil.isNotEmpty(shopUserDutyPay)){
memberData=new ArrayList<>();
memberData.add(new HandoverInfo.MemberData(shopUserDutyPay.getAmount().toPlainString(),"储值卡支付"));
}
HandoverInfo handoverInfo=new HandoverInfo(tbShopInfo.getShopName(),ObjectUtil.isNotEmpty(shopUserDuty.getLoginTime())?DateUtils.getTime(shopUserDuty.getLoginTime()):null,ObjectUtil.isNotEmpty(shopUserDuty.getLoginOutTime())?DateUtils.getTime(shopUserDuty.getLoginOutTime()):"",ObjectUtil.isNull(shopStaff.getName())?"":shopStaff.getName(),list,memberData,shopUserDuty.getAmount().toPlainString(),"0",shopUserDuty.getAmount().toPlainString(),shopUserDuty.getAmount().toPlainString(),shopUserDuty.getOrderNum().toString());
PrinterUtils.printTickets(1,1,it.getAddress(),PrinterUtils.handoverprintData(handoverInfo));
});
return Result.success(CodeEnum.SUCCESS);
}

View File

@@ -2,9 +2,9 @@ spring:
profiles:
active: hph
server:
servlet:
context-path: /cashier-client/
port: 10587
# 日志配置
logging:
level:

View File

@@ -83,4 +83,21 @@
amount = #{amount,jdbcType=DECIMAL}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectByDutyId" resultType="java.util.Map">
SELECT
case type
when 'scanCode' then '扫码支付'
when 'cash' then '现金支付'
when 'wx_lite' then '小程序支付'
when 'deposit' then '储值卡支付'
when 'bank' then '银行卡支付'
end as payType,
amount as amount
FROM
tb_shop_user_duty_pay
WHERE
duty_id = #{dutyId}
</select>
</mapper>