jk-GitHub-coder 4 роки тому
батько
коміт
eb6613ff94

+ 162 - 5
YijiaRestful/src/main/java/com/platform/yijia/controller/ElectronicMembershipCardController.java

@@ -54,6 +54,8 @@ public class ElectronicMembershipCardController {
     private IntegralRuleService integralRuleService;
     @Resource
     private CustomerPointsRecordService customerPointsRecordService;
+    @Resource
+    private StationOilGunService stationOilGunService;
 
     //查询该油站是否启用电子会员卡
     @RequestMapping(value = "/getStationCardEnabledFlag", method = RequestMethod.GET)
@@ -80,11 +82,16 @@ public class ElectronicMembershipCardController {
         ResultData resultData = null;
         logger.info("获取用户电子会员卡信息参数:油站ID:"+ stationId+"用户unionId:"+unionId);
         if(stationId !=null && unionId !=null && unionId !=""){
-            CustomerElectronicCard customerElectronicCard = new CustomerElectronicCard();
-            customerElectronicCard.setStationId(stationId);
-            customerElectronicCard.setUnionId(unionId);
-            List<CustomerElectronicCard> electronicCardList = electronicMembershipCardService.getElectronicCardList(customerElectronicCard);
-            resultData = ResultData.success(electronicCardList);
+            String stationCardEnabledFlag = electronicMembershipCardService.getStationCardEnabledFlag(stationId);
+            if(stationCardEnabledFlag.equals("1")){
+                CustomerElectronicCard customerElectronicCard = new CustomerElectronicCard();
+                customerElectronicCard.setStationId(stationId);
+                customerElectronicCard.setUnionId(unionId);
+                List<CustomerElectronicCard> electronicCardList = electronicMembershipCardService.getElectronicCardList(customerElectronicCard);
+                resultData = ResultData.success(electronicCardList);
+            }else {
+                resultData = ResultData.error(CodeMsg.NO_CARDENABLEFLAG);
+            }
         }else {
             resultData = ResultData.error(CodeMsg.REQUEST_FAIL);
         }
@@ -338,6 +345,7 @@ public class ElectronicMembershipCardController {
                     payOrder.setReceivedAmt(Double.valueOf(amt));
                     payOrder.setDzkAmt(Double.valueOf(amt));
                     payOrderService.getUpdatePayOrder(payOrder);
+                    resultMap.put("payTypep","dzk");
                     //更新客户表
                     CustomerManage customerManage = new CustomerManage();
                     customerManage.setStationId(Integer.valueOf(stationId));
@@ -436,6 +444,8 @@ public class ElectronicMembershipCardController {
                         calculateIntegralAndPushIntegral(calculateIntegral, customerManage);
                     }
                     resultData = ResultData.success(CodeMsg.SUCCESS);
+                    //打印小票
+                    this.printReceipt(payOrder);
                 }else {
                     resultData=ResultData.error(CodeMsg.BALANCE_NOT_EENOUGH);
                 }
@@ -452,6 +462,153 @@ public class ElectronicMembershipCardController {
         }
     }
 
+    /**
+     * 打印小票
+     */
+    public void printReceipt(PayOrder payOrder) {
+        Map<String, Object> infoMap = payOrderService.getOrderInfoAndUserInfoByOrderNo(payOrder);
+        //打印机打印小票
+        String content1;
+        String content2;
+        String orderNoP = "";
+        String createdDateP ="";
+        String stationNameP ="";
+        String oilNameP ="";
+        String orderLitersP ="";
+        String oilPirceP ="";
+        String receivableAmtP = "";
+        String discountAmtP = "";
+        String amtP = "";
+        String mobilePhoneP = "";
+        String payWayP = "";
+        String sn;  //打印机编号
+
+        if(StringUtils.isNotBlank(infoMap.get("orderNo").toString())){
+            orderNoP =infoMap.get("orderNo").toString();
+        }
+        if(infoMap.containsKey("createdDate") && infoMap.get("createdDate") !=null ){
+            //格式化日期
+            SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            createdDateP =sdf.format(infoMap.get("createdDate"));
+        }
+        if(infoMap.containsKey("stationName") && infoMap.get("stationName") !=null ){
+            stationNameP =infoMap.get("stationName").toString();
+        }
+        if(infoMap.containsKey("oilName") && infoMap.get("oilName") !=null ){
+            oilNameP =infoMap.get("oilName").toString();
+        }
+        if(infoMap.containsKey("orderType") && infoMap.get("orderType").equals("1")) {
+            //加油升数
+            if (infoMap.containsKey("orderLiters") && infoMap.get("orderLiters") != null) {
+                orderLitersP = infoMap.get("orderLiters") + "";
+            }
+            //油价
+            if (infoMap.containsKey("oilPirce") && infoMap.get("oilPirce") != null) {
+                oilPirceP = infoMap.get("oilPirce") + "";
+            }
+            if(infoMap.containsKey("discountAmt") && infoMap.get("discountAmt") !=null ){
+                discountAmtP =infoMap.get("discountAmt")+"";
+            }
+        }else if(infoMap.containsKey("orderType") && infoMap.get("orderType").equals("2")) {
+            orderLitersP ="0.00";
+            oilPirceP = "0.00";
+            discountAmtP ="0.00";
+            receivableAmtP=infoMap.get("amt")+"";
+        }
+        if(infoMap.containsKey("receivableAmt") && infoMap.get("receivableAmt") !=null ){
+            receivableAmtP =infoMap.get("receivableAmt")+"";
+        }
+
+        if(infoMap.containsKey("amt") && infoMap.get("amt") !=null ){
+            amtP =infoMap.get("amt")+"";
+        }
+        if(infoMap.containsKey("mobilePhone") && infoMap.get("mobilePhone") !=null ){
+            String phone =infoMap.get("mobilePhone")+"";
+            //手机号中间四位****代替
+            mobilePhoneP = phone.substring(0, 3) + "****" + phone.substring(7, phone.length());
+        }
+        if(infoMap.containsKey("payType") && infoMap.get("payType") !=null ){
+            if(infoMap.get("payType").equals("wx")){
+                payWayP ="微信";
+            }
+            if(infoMap.get("payType").equals("dzk")){
+                payWayP ="电子卡";
+            }
+        }
+
+        content1 = "<CB>支付小票--顾客联</CB><BR>";
+        content1 += "订单号:"+orderNoP+"  <BR>";
+        content1 += "时间:"+createdDateP+" <BR>";
+        content1 += "油站:"+stationNameP+"  <BR>";
+        if(infoMap.containsKey("orderType") && infoMap.get("orderType").toString().equals("1")){
+            content1 += "油品: "+oilNameP+"  <BR>";
+            content1 += "油量: "+orderLitersP+"  升<BR>";
+            content1 += "单价: "+oilPirceP+" L/元<BR>";
+        }
+        content1 += "<BOLD><B>原价: "+receivableAmtP+" 元</B></BOLD><BR>";
+        if(infoMap.containsKey("orderType") && infoMap.get("orderType").toString().equals("1")){
+            content1 += "优惠: "+discountAmtP+" 元<BR>";
+        }
+        content1 += "支付: "+amtP+" 元<BR>";
+        content1 += "支付方式: "+payWayP+" <BR>";
+        content1 += "<BR>";
+        //content1 += "--------------------------------<BR>";
+        content1 += "<BR>";
+
+        content2 = "<CB>支付小票--商户联</CB><BR>";
+        content2 += "订单号:"+orderNoP+" <BR>";
+        content2 += "时间:"+createdDateP+"<BR>";
+        content2 += "油站:"+stationNameP+" <BR>";
+        if(infoMap.containsKey("orderType") && infoMap.get("orderType").toString().equals("1")){
+            content2 += "油品: "+oilNameP+" <BR>";
+            content2 += "油量: "+orderLitersP+" 升<BR>";
+            content2 += "单价: "+oilPirceP+" L/元<BR>";
+        }
+        content2 += "<BOLD><B>原价: "+receivableAmtP+" 元</B></BOLD><BR>";
+        if(infoMap.containsKey("orderType") && infoMap.get("orderType").toString().equals("1")){
+            content2 += "优惠: "+discountAmtP+" 元<BR>";
+        }
+        content2 += "支付: "+amtP+" 元<BR>";
+        content2 += "手机号: "+mobilePhoneP+" <BR>";
+        content2 += "支付方式: "+payWayP+" <BR>";
+        content2 += "<BR>";
+        //获取打印机编号
+        //sn = "921611605";     //测试打印机 sn:921611605 key:72338zma
+        Map params  =new HashMap();
+        params.put("stationId", infoMap.get("stationId").toString());
+        params.put("oilGunNo", infoMap.get("oilGun").toString());
+        Map m = stationOilGunService.getPrinterSnByStationIdAndOilGunNo(params);
+        if(m !=null && m.containsKey("printerSn") && m.get("printerSn").toString()!= null && m.get("printerSn").toString()!=""){
+            sn = m.get("printerSn").toString();
+            //开始打印
+            String printInfo="";    //打印信息
+            if(m.containsKey("printSetting") && m.get("printSetting").toString()!= null && m.get("printSetting").toString()!=""){
+                switch (m.get("printSetting").toString()){
+                    case "1":   //1 客户联
+                        printInfo = FeiEPrinterUtil.printReceipt(sn, content1);
+                        break;
+                    case "2":   //2 商户联
+                        printInfo = FeiEPrinterUtil.printReceipt(sn, content2);
+                        break;
+                    case "3":   //3商户联和客户联
+                        printInfo = FeiEPrinterUtil.printReceipt(sn, content1 + content2);
+                        break;
+                }
+            }
+            JSONObject jsonObject = JSONObject.parseObject(printInfo);
+            if(jsonObject != null && jsonObject.getString("msg").equals("ok")){
+                logger.info("打印成功:" + jsonObject.toString());
+                //如果打印成功 添加小票数量
+                PayOrder p = new PayOrder();
+                p.setPrintCount(1);
+                p.setOrderNo(infoMap.get("orderNo").toString());
+                payOrderService.getUpdatePayOrder(p);
+            }
+        }else {
+            logger.info("请正确配置打印机");
+        }
+    }
+
     //用户充值电子会员卡(储蓄卡)拉起随行付支付接口
     @RequestMapping(value = "/rechargeBalanceSXFPay", method = RequestMethod.POST)
     @ResponseBody

+ 53 - 1
YijiaRestful/src/main/java/com/platform/yijia/controller/PosMachineController.java

@@ -141,6 +141,51 @@ public class PosMachineController {
         return  gson.toJson(resultData);
     }
 
+    /*
+     * 获取班结人要班结的订单总和信息
+     * @param stationId
+     * @param userName
+     * @return
+     */
+    @RequestMapping (value = "/getClassStructureListByClassStructureNo", method = RequestMethod.GET)
+    @ResponseBody
+    public String getClassStructureListByClassStructureNo(@RequestParam Integer stationId, String classStructureNo){
+        Gson gson =new Gson();
+        //返回结果集
+        ResultData resultData = null;
+        if(stationId !=null && classStructureNo !=null){
+            StationClassStructure classes =new StationClassStructure();
+            classes.setStationId(stationId);
+            classes.setClassStructureNo(classStructureNo);
+            classes.setGroupBy("");
+            List<Map<String, String>> listSum = stationClassStructureService.selectClassStructureSum(classes);
+            classes.setGroupBy("oilName");
+            List<Map<String, String>> listSumGroupByOilName = stationClassStructureService.selectClassStructureSum(classes);
+            classes.setGroupBy("payType");
+            List<Map<String, String>> listSumGroupByPayType = stationClassStructureService.selectClassStructureSum(classes);
+            classes.setGroupBy("timeAndMan");
+            List<Map<String, String>> timeList = stationClassStructureService.selectClassStructureSum(classes);
+//            if(timeList !=null && listSum.size() ==0){
+//                //第一次班结
+//                if(timeList.get(0).get("beginTime").equals("")){
+//                    PayOrder payOrder = new PayOrder();
+//                    payOrder.setStatus("1");
+//                    payOrder.setStationId(stationId);
+//                    PayOrder payOrderInfoMin = payOrderService.getPayOrderInfoMin(payOrder);
+//                    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+//                    //没有班结过:第一次班结
+//                    timeList.get(0).replace("beginTime", dateFormat.format(payOrderInfoMin.getPayDate()));
+//                }
+//            }
+            Map<String, Object> map = new HashMap();
+            map.put("listSumGroupByOilName", listSumGroupByOilName);
+            map.put("listSum", listSum);
+            map.put("timeList", timeList);
+            map.put("listSumGroupByPayType", listSumGroupByPayType);
+            resultData = ResultData.success(map);
+        }
+        return gson.toJson(resultData);
+    }
 
 
     /*
@@ -364,11 +409,18 @@ public class PosMachineController {
             //根据班结时间查询订单
             PayOrder order=new PayOrder();
             order.setStationId(stationId);
-            order.setEndTime(dateFormat.format(date));
             order.setStatus("1");
+            //获取第一个最早时间的订单
+            PayOrder payOrderInfoMin = payOrderService.getPayOrderInfoMin(order);
+            //没有班结过:第一次班结获取第一个订单的下单时间
+            beginTime =dateFormat.format(payOrderInfoMin.getPayDate());
+            order.setBeginTime(beginTime);
+            order.setEndTime(dateFormat.format(date));
+
             List<PayOrder> list = payOrderService.selectPayOrderList(order);
             for(PayOrder payOrder:list){
                 StationClassStructure stationclass =new StationClassStructure();
+                stationclass.setClassStartDate(payOrderInfoMin.getPayDate());
                 stationclass.setStationId(payOrder.getStationId());
                 stationclass.setStationName(payOrder.getStationName());
                 stationclass.setClassStructureMan(username);

+ 5 - 0
YijiaRestful/src/main/java/com/platform/yijia/dao/StationClassStructureMapper.java

@@ -3,6 +3,7 @@ package com.platform.yijia.dao;
 import com.platform.yijia.pojo.StationClassStructure;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * 班结管理Mapper接口
@@ -12,6 +13,10 @@ import java.util.List;
  */
 public interface StationClassStructureMapper
 {
+
+    //查询班结数据总和
+    List<Map<String, String>> selectClassStructureSum(StationClassStructure stationClassStructure);
+
     /**
      * 查询班结管理
      *

+ 1 - 0
YijiaRestful/src/main/java/com/platform/yijia/pojo/StationClassStructure.java

@@ -16,6 +16,7 @@ import org.apache.commons.lang3.builder.ToStringStyle;
 @Data
 public class StationClassStructure {
 
+    private String groupBy;
     /** $column.columnComment */
     private Long id;
 

+ 6 - 0
YijiaRestful/src/main/java/com/platform/yijia/service/IStationClassStructureService.java

@@ -3,6 +3,7 @@ package com.platform.yijia.service;
 import com.platform.yijia.pojo.StationClassStructure;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * 班结管理Service接口
@@ -12,6 +13,11 @@ import java.util.List;
  */
 public interface IStationClassStructureService
 {
+
+    //获取要班结的总和信息
+    List<Map<String, String>> selectClassStructureSum(StationClassStructure stationClassStructure);
+
+
     /**
      * 查询班结管理
      *

+ 7 - 0
YijiaRestful/src/main/java/com/platform/yijia/service/impl/StationClassStructureServiceImpl.java

@@ -1,6 +1,7 @@
 package com.platform.yijia.service.impl;
 
 import java.util.List;
+import java.util.Map;
 
 import com.platform.yijia.dao.StationClassStructureMapper;
 import com.platform.yijia.pojo.StationClassStructure;
@@ -22,6 +23,12 @@ public class StationClassStructureServiceImpl implements IStationClassStructureS
     @Resource
     private StationClassStructureMapper stationClassStructureMapper;
 
+    //获取要班结的总和信息
+    @Override
+    public List<Map<String, String>> selectClassStructureSum(StationClassStructure stationClassStructure) {
+        return stationClassStructureMapper.selectClassStructureSum(stationClassStructure);
+    }
+
     /**
      * 查询班结管理
      *

+ 1 - 0
YijiaRestful/src/main/java/com/platform/yijia/utils/CodeMsg.java

@@ -25,6 +25,7 @@ public class CodeMsg {
     public static CodeMsg UPDATE_FAIL = new CodeMsg(004,"修改失败");
     public static CodeMsg REQUEST_FAIL = new CodeMsg(005,"传参失败");
     public static CodeMsg YEWU_FAIL = new CodeMsg(006,"业务失败");
+    public static CodeMsg NO_CARDENABLEFLAG = new CodeMsg(-2,"未启用电会员卡");
 
     public static CodeMsg CHECK_DATA = new CodeMsg(007,"与后台检验不一致,请联系……");
     public static CodeMsg PARAMS_NUll = new CodeMsg(010,"请求失败,参数缺失");

+ 1 - 0
YijiaRestful/src/main/resources/mapper/PayOrderMapper.xml

@@ -841,6 +841,7 @@
         A.station_id		    AS stationId,
         A.status 				AS status,
         A.pay_way				AS payWay,
+        A.pay_type				AS payType,
         A.oil_name 				AS oilName,
         A.oil_gun               AS oilGun,
         A.order_liters 			AS orderLiters,

+ 111 - 0
YijiaRestful/src/main/resources/mapper/StationClassStructureMapper.xml

@@ -53,6 +53,103 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="xjNum"    column="xj_num"    />
     </resultMap>
 
+    <select id="selectClassStructureSum" parameterType="com.platform.yijia.pojo.StationClassStructure" resultType="Map">
+        <if test="groupBy !=null and groupBy =='oilName'">
+            <include refid="Base_Column_List_oilName"/>
+        </if>
+        <if test="groupBy !=null and groupBy =='payType'">
+            <include refid="Base_Column_List_payType"/>
+        </if>
+        <if test="groupBy ==''">
+            <include refid="Base_Column_List_NoGroupBy"/>
+        </if>
+        <if test="groupBy =='timeAndMan'">
+            <include refid="Base_Column_List_timeAndMan"/>
+        </if>
+    </select>
+
+    <sql id="Base_Column_List_oilName">
+        SELECT
+            T1.dict_label                         AS oilName,
+            COUNT(T2.order_no)                    AS orderSum,
+            SUM(IFNULL(T2.order_liters,0))        AS orderLitersSum,
+            SUM(IFNULL(T2.receivable_amt,0))      AS receivableAmtSum,
+            SUM(IFNULL(T2.discount_amt,0))        AS discountAmtSum,
+            SUM(IFNULL(T2.amt,0))                 AS amtSum
+        FROM         sys_dict_data                AS T1
+        LEFT JOIN    station_class_structure      AS T2   ON T1.dict_label = T2.oil_name
+        <if test="stationId !=null">
+            AND T2.station_id= #{stationId}
+        </if>
+        <if test="classStructureNo !=null">
+            AND T2.class_structure_no= #{classStructureNo}
+        </if>
+        WHERE
+            T1.dict_type ="oil_name"
+        GROUP BY T1.dict_label
+        ORDER BY amtSum DESC
+    </sql>
+    <sql id="Base_Column_List_payType">
+        SELECT
+            T1.dict_label                         AS payType,
+            COUNT(T2.order_no)                    AS orderSum,
+            SUM(IFNULL(T2.order_liters,0))        AS orderLitersSum,
+            SUM(IFNULL(T2.receivable_amt,0))      AS receivableAmtSum,
+            SUM(IFNULL(T2.discount_amt,0))        AS discountAmtSum,
+            SUM(IFNULL(T2.amt,0))                 AS amtSum
+        FROM         sys_dict_data                AS T1
+        LEFT JOIN    station_class_structure      AS T2   ON T1.dict_value = T2.pay_type
+        <if test="stationId !=null">
+            AND T2.station_id= #{stationId}
+        </if>
+        <if test="classStructureNo !=null">
+            AND T2.class_structure_no= #{classStructureNo}
+        </if>
+        WHERE
+            T1.dict_type ="pay_type"
+        GROUP BY T1.dict_label
+        ORDER BY amtSum DESC
+    </sql>
+    <sql id="Base_Column_List_NoGroupBy">
+        SELECT
+            COUNT(T2.order_no)                  AS orderSum,
+            SUM(IFNULL(T2.order_liters,0))      AS orderLitersSum,
+            SUM(IFNULL(T2.receivable_amt,0))    AS receivableAmtSum,
+            SUM(IFNULL(T2.discount_amt,0))      AS discountAmtSum,
+            SUM(IFNULL(T2.amt,0))               AS amtSum,
+            SUM(IFNULL(T2.received_amt,0))      AS receivedAmtSum,
+            SUM(IFNULL(T2.print_num,0))         AS printCountSum
+        FROM
+            station_class_structure             AS T2
+        <where>
+            <if test="stationId !=null">
+                T2.station_id= #{stationId}
+            </if>
+            <if test="classStructureNo !=null">
+                AND T2.class_structure_no= #{classStructureNo}
+            </if>
+        </where>
+    </sql>
+    <sql id="Base_Column_List_timeAndMan">
+        SELECT
+            T2.class_structure_no                                                    AS classStructureNo,
+            IFNULL(DATE_FORMAT(T2.class_start_date, '%Y-%m-%d %H:%i:%s'), "")        AS beginTime,
+            DATE_FORMAT(T2.class_structure_date, '%Y-%m-%d %H:%i:%s')                AS endTime,
+            T2.class_structure_man                                                   AS classStructureMan
+        FROM
+            station_class_structure                                                  AS T2
+        <where>
+            <if test="stationId !=null">
+                T2.station_id= #{stationId}
+            </if>
+            <if test="classStructureNo !=null">
+                AND T2.class_structure_no= #{classStructureNo}
+            </if>
+        </where>
+        ORDER BY  T2.class_structure_no ASC LIMIT 0,1
+    </sql>
+
+
     <sql id="selectStationClassStructureVo">
         select id, order_no, station_id, station_name, oil_gun, oil_name, oil_pirce, oil_type, consumer_id, consumer, amt, order_liters, pay_type, pay_way, pay_date, oil_personnel, order_type, print_num, class_structure_no, class_start_date, class_structure_date, class_structure_man, oils, receivable_amt, received_amt, discount_amt, discount_coupon_amt, discount_coupon, wx_amt, zfb_amt, pos_amt, xj_amt, didi_app_amt, ty_app_amt, other_amt, dzk_amt, score, member_no, member_amt, car_no, customer_phone, customer_grade from station_class_structure
     </sql>
@@ -197,6 +294,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         )
     </select>
 
+    <!--批量插入-->
+<!--    <insert id="insertStationClassStructureAll" >-->
+<!--        INSERT INTO-->
+<!--            station_class_structure-->
+<!--        (<include refid="selectStationClassStructureVo"/>)-->
+<!--        VALUES-->
+<!--        <foreach collection="list" item="item" index="index" separator=",">-->
+
+<!--        </foreach>-->
+
+
+<!--    </insert>-->
+
+
     <insert id="insertStationClassStructure" parameterType="com.platform.yijia.pojo.StationClassStructure" useGeneratedKeys="true" keyProperty="id">
         insert into station_class_structure
         <trim prefix="(" suffix=")" suffixOverrides=",">