| @@ -6,6 +6,7 @@ import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.dto.NeuPosUpdatePayDto; | |||
| import com.iformall.domain.po.NeuPosOrderMasterExt; | |||
| import com.iformall.domain.po.NeuPosShiftTradeMasterExt; | |||
| import com.iformall.domain.vo.NeuPosOrderDataBVo; | |||
| import com.iformall.domain.vo.NeuPosSumDataBVo; | |||
| import com.iformall.service.NeuPosOrderService; | |||
| @@ -284,4 +285,44 @@ public class NeuPosAdminController extends BaseController { | |||
| } | |||
| @ApiOperation("交接班数据") | |||
| @GetMapping("shiftTradelist") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "tenantId", value = "租户号", dataType = "String", paramType = "query", required = true)}) | |||
| public ResultData shiftTradelist(@ModelAttribute NeuPosShiftTradeMasterExt example, Integer pageNum, Integer pageSize,String tenantId) { | |||
| if (!tenantValid(tenantId)) { | |||
| return new ResultData(Result.ERROR,"未安装POS系统"); | |||
| } | |||
| if (null == example.getCreateBegin() || null == example.getCreateEnd()) { | |||
| return new ResultData(Result.ERROR,"请选择时间区间"); | |||
| } | |||
| example.setOrgId(24); | |||
| PageInfo<Map> maplist = neuPosOrderService.queryShiftTradeList(example,pageNum,pageSize); | |||
| return new ResultData(maplist); | |||
| } | |||
| // @GetMapping("exportShiftTradelist") | |||
| // @ApiImplicitParams({ | |||
| // @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||
| // @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true), | |||
| // @ApiImplicitParam(name = "tenantId", value = "租户号", dataType = "String", paramType = "query", required = true)}) | |||
| // public void exportShiftTradelist(@ModelAttribute NeuPosShiftTradeMasterExt example,String tenantId, HttpServletRequest request, HttpServletResponse response) { | |||
| // if (!tenantValid(tenantId)) { | |||
| // return; | |||
| // } | |||
| // if (null == example.getCreateBegin() || null == example.getCreateEnd()) { | |||
| // return ; | |||
| // } | |||
| // example.setOrgId(24); | |||
| // PageInfo<Map> maplist = neuPosOrderService.queryShiftTradeList(example,1,10000); | |||
| // if (null != maplist && null != maplist.getList()) { | |||
| // neuPosOrderService.exportData(maplist.getList(),new String[] {"上班时间","退出时间","收银员","现金收银","银行卡(MISPOS)","微信(二维码)","支付宝(二维码)","上午实收","下午实收","全天实收"}, | |||
| // new String[] {"loginTime","shiftTime","username","payCount","refundAmount","refundCount","amount"},"门店pos交易汇总",new NeuPosSumDataBVo(), request, response); | |||
| // } | |||
| // } | |||
| } | |||
| @@ -18,4 +18,5 @@ public class NeuPosOrderMasterExt extends BaseEntity{ | |||
| private Date createBegin; | |||
| private Date createEnd; | |||
| private List<String> payTypeList; | |||
| private String createBy; | |||
| } | |||
| @@ -0,0 +1,21 @@ | |||
| package com.iformall.domain.po; | |||
| import com.iformall.domain.po.base.BaseEntity; | |||
| import lombok.Data; | |||
| import lombok.EqualsAndHashCode; | |||
| import lombok.ToString; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| @Data | |||
| @ToString(callSuper = true) | |||
| @EqualsAndHashCode(callSuper = true) | |||
| public class NeuPosShiftTradeMasterExt extends BaseEntity{ | |||
| private static final long serialVersionUID = 8299224510517624828L; | |||
| private Integer orgId; | |||
| private Integer shopId; | |||
| private Date createBegin; | |||
| private Date createEnd; | |||
| private String customerNumber; | |||
| } | |||
| @@ -4,6 +4,8 @@ package com.iformall.mapper; | |||
| import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
| import com.iformall.domain.dto.NeuPosUpdatePayDto; | |||
| import com.iformall.domain.po.NeuPosOrderMasterExt; | |||
| import com.iformall.domain.po.NeuPosShiftTradeMasterExt; | |||
| import org.apache.ibatis.annotations.Param; | |||
| import java.util.List; | |||
| @@ -16,6 +18,8 @@ public interface NeuPosOrderMasterExtMapper extends BaseMapper<NeuPosOrderMaster | |||
| List<Map> queryShopPayOrderList(NeuPosOrderMasterExt example); | |||
| List<Map> queryShopPayOrderListV1(NeuPosOrderMasterExt example); | |||
| List<Map> queryShiftTradeList(NeuPosShiftTradeMasterExt example); | |||
| List<Map> queryShiftTradeSummary(NeuPosOrderMasterExt example); | |||
| List<Map> queryShopPayOrderSum(NeuPosOrderMasterExt example); | |||
| List<Map> queryShopPayOrderSumV1(NeuPosOrderMasterExt example); | |||
| @@ -3,6 +3,7 @@ package com.iformall.service; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.domain.dto.NeuPosUpdatePayDto; | |||
| import com.iformall.domain.po.NeuPosOrderMasterExt; | |||
| import com.iformall.domain.po.NeuPosShiftTradeMasterExt; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| @@ -20,6 +21,8 @@ public interface NeuPosOrderService { | |||
| PageInfo<Map> queryShopPayOrderListByType(NeuPosOrderMasterExt example,Integer pageIndex, Integer pageSize); | |||
| PageInfo<Map> queryShiftTradeList(NeuPosShiftTradeMasterExt example,Integer pageIndex, Integer pageSize); | |||
| List<Map> queryShopPayOrderSum(NeuPosOrderMasterExt example); | |||
| List<Map> queryShopPayOrderSumByType(NeuPosOrderMasterExt example); | |||
| @@ -5,9 +5,12 @@ import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.domain.dto.NeuPosUpdatePayDto; | |||
| import com.iformall.domain.po.NeuPosOrderMasterExt; | |||
| import com.iformall.domain.po.NeuPosShiftTradeMasterExt; | |||
| import com.iformall.mapper.NeuPosOrderMasterExtMapper; | |||
| import com.iformall.service.ExcelService; | |||
| import com.iformall.service.NeuPosOrderService; | |||
| import com.iformall.utils.DateUtils; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import org.springframework.transaction.annotation.Propagation; | |||
| @@ -15,6 +18,8 @@ import org.springframework.transaction.annotation.Transactional; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| import java.math.BigDecimal; | |||
| import java.util.*; | |||
| @Service | |||
| @@ -66,6 +71,69 @@ public class NeuPosOrderServiceImpl implements NeuPosOrderService { | |||
| } | |||
| return pageInfo; | |||
| } | |||
| @Override | |||
| public PageInfo<Map> queryShiftTradeList(NeuPosShiftTradeMasterExt example,Integer pageIndex, Integer pageSize) { | |||
| PageInfo<Map> pageInfo = PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> neuPosOrderMasterExtMapper.queryShiftTradeList(example)); | |||
| if (null == pageInfo || null == pageInfo.getList() || pageInfo.getList().size()<=0 ) { | |||
| return pageInfo; | |||
| } | |||
| List<Map> payOrderList = pageInfo.getList(); | |||
| //3.查询支付渠道信息 | |||
| //排除不统计的渠道 | |||
| Map<String,String> typeColumn = new HashMap<String,String>(); | |||
| typeColumn.put("6","6payType"); | |||
| typeColumn.put("24","24payType"); | |||
| typeColumn.put("31","31payType"); | |||
| typeColumn.put("32","32payType"); | |||
| List<Map> payTypeMap = neuPosOrderMasterExtMapper.selectPayTypeList(); | |||
| List<Integer> payTypeList = new ArrayList<Integer>(); | |||
| Map<Integer,String> typeMap = new HashMap<Integer,String>(); | |||
| for (Map payt:payTypeMap) { | |||
| String payttye = (String)payt.get("pay_type"); | |||
| if (typeColumn.containsKey(payttye)) { | |||
| typeMap.put(Integer.parseInt(payttye), (String)payt.get("name")); | |||
| payTypeList.add(Integer.parseInt(payttye)); | |||
| } | |||
| } | |||
| for (Map payOrder:payOrderList ) { | |||
| String createBy = payOrder.get("username").toString(); | |||
| Date loginTime = DateUtils.stringToDate(payOrder.get("loginTime").toString(),DateUtils.DATE_TIME_PATTERN); | |||
| Date logoutTime = DateUtils.stringToDate(payOrder.get("shiftTime").toString(),DateUtils.DATE_TIME_PATTERN); | |||
| NeuPosOrderMasterExt omq = new NeuPosOrderMasterExt(); | |||
| omq.setOrgId(example.getOrgId()); | |||
| omq.setCreateBegin(loginTime); | |||
| omq.setCreateEnd(logoutTime); | |||
| omq.setCreateBy(createBy); | |||
| List<Map> tradeList = neuPosOrderMasterExtMapper.queryShiftTradeSummary(omq); | |||
| Map currentUserMap =null; | |||
| if(tradeList.size()>0) { | |||
| currentUserMap = tradeList.get(0); | |||
| }else { | |||
| continue; | |||
| } | |||
| List<Map> payTypeTrades = new ArrayList<Map>(); | |||
| for (Integer payt:payTypeList) { | |||
| Map ptrade = new HashMap(); | |||
| ptrade.put("payType", payt); | |||
| ptrade.put("payTypeName", typeMap.get(payt).toString()); | |||
| String typeColumnName = typeColumn.get(String.valueOf(payt)); | |||
| BigDecimal paid = new BigDecimal(currentUserMap.get(typeColumnName).toString()); | |||
| BigDecimal refund = new BigDecimal(currentUserMap.get(typeColumnName+"Refund").toString()); | |||
| ptrade.put("payAmount", paid); | |||
| ptrade.put("refundAmount", refund); | |||
| ptrade.put("amount", paid.subtract(refund)); | |||
| payTypeTrades.add(ptrade); | |||
| } | |||
| payOrder.put("payTypeOrders", payTypeTrades); | |||
| payOrder.put("amountAM", currentUserMap.get("amPaidAmount").toString()); | |||
| payOrder.put("amountPM", currentUserMap.get("pmPaidAmount").toString()); | |||
| payOrder.put("totalAmount", currentUserMap.get("paidAmount").toString()); | |||
| } | |||
| return pageInfo; | |||
| } | |||
| @Override | |||
| public PageInfo<Map> queryShopPayOrderList(NeuPosOrderMasterExt example,Integer pageIndex, Integer pageSize) { | |||
| @@ -356,4 +356,96 @@ SELECT | |||
| SELECT us.`shop`,ui.id,ui.`username`,ui.`nickname` FROM user_info ui LEFT JOIN user_shop us ON ui.id = us.`usr` | |||
| WHERE ui.org = #{orgId} AND ui.activated = TRUE AND ui.username = #{username} | |||
| </select> | |||
| <select id="queryShiftTradeList" parameterType="com.iformall.domain.po.NeuPosShiftTradeMasterExt" resultType="java.util.Map"> | |||
| select * from | |||
| (select org_id, shop_id, username, serial_no, | |||
| min(case when status=1 then created_at else '3109-12-30 23:59:59' end) as loginTime, | |||
| max(case when status=2 and is_shift=1 then created_at else 0 end) as shiftTime | |||
| from user_login_record | |||
| where org_id = #{orgId} and created_at > #{createBegin} and created_at <= #{createEnd} | |||
| <if test="customerNumber != null"> and username = #{customerNumber}</if> | |||
| <if test="shopId != null"> and shop_id = #{shopId}</if> | |||
| GROUP BY username) as a | |||
| where shiftTime > 0 | |||
| </select> | |||
| <select id="queryShiftTradeSummary" parameterType="com.iformall.domain.po.NeuPosOrderMasterExt" resultType="java.util.Map"> | |||
| SELECT | |||
| po.createdBy, | |||
| sum( IF ( po.payType = 6, po.paidAmount, 0 ) ) AS "6payType", | |||
| sum( IF ( po.payType = 24, po.paidAmount, 0 ) ) AS "24payType", | |||
| sum( IF ( po.payType = 31, po.paidAmount, 0 ) ) AS "31payType", | |||
| sum( IF ( po.payType = 32, po.paidAmount, 0 ) ) AS "32payType", | |||
| sum( IF ( po.payType = 6, IFNULL(ro.refundAmount,0), 0 ) ) AS "6payTypeRefund", | |||
| sum( IF ( po.payType = 24, IFNULL(ro.refundAmount,0), 0 ) ) AS "24payTypeRefund", | |||
| sum( IF ( po.payType = 31, IFNULL(ro.refundAmount,0), 0 ) ) AS "31payTypeRefund", | |||
| sum( IF ( po.payType = 32, IFNULL(ro.refundAmount,0), 0 ) ) AS "32payTypeRefund", | |||
| sum( IF ( po.createdHour > 12, po.paidAmount - IFNULL(ro.refundAmount,0), 0 ) ) AS pmPaidAmount, | |||
| sum( IF ( 12 >= po.createdHour, po.paidAmount - IFNULL(ro.refundAmount, 0),0 ) ) AS amPaidAmount, | |||
| sum( po.paidAmount - IFNULL(ro.refundAmount, 0) ) AS paidAmount | |||
| FROM | |||
| ( | |||
| SELECT | |||
| o.created_by AS createdBy, | |||
| o.order_number AS orderNumber, | |||
| p.pay_type AS payType, | |||
| p.pay_type_name AS payTypeName, | |||
| sum( IFNULL( pay_amount, 0 ) ) / 100 AS paidAmount, | |||
| HOUR ( o.created_at ) AS createdHour | |||
| FROM | |||
| pay_order_v2 AS p | |||
| LEFT JOIN order_master_v2 AS o ON p.m_order_number = o.order_number | |||
| where order_master_v2.org_id = #{orgId} | |||
| <if test=" shopId != null"> | |||
| and order_master_v2.shop_id = #{shopId} | |||
| </if> | |||
| <if test=" createBegin != null"> | |||
| and pay_order_v2.created_at >= #{createBegin} | |||
| </if> | |||
| <if test=" createEnd != null"> | |||
| and pay_order_v2.created_at <= #{createEnd} | |||
| </if> | |||
| <if test=" createBy != null"> | |||
| and pay_order_v2.created_by = #{createBy} | |||
| </if> | |||
| AND ( p.pay_status = 2 OR p.pay_status = 5 OR p.pay_status = 4 ) | |||
| AND p.pay_type != 29 | |||
| AND p.pay_type != 30 | |||
| GROUP BY | |||
| o.order_number, | |||
| p.pay_type | |||
| ) AS po | |||
| LEFT JOIN ( | |||
| SELECT | |||
| o.order_number AS orderNumber, | |||
| r.pay_type AS payType, | |||
| sum( IFNULL( r.refunded_amount, 0 ) ) / 100 AS refundAmount | |||
| FROM | |||
| pay_refund_order_v2 AS r | |||
| LEFT JOIN order_master_v2 AS o ON r.m_order_number = o.order_number | |||
| where order_master_v2.org_id = #{orgId} | |||
| <if test=" shopId != null"> | |||
| and order_master_v2.shop_id = #{shopId} | |||
| </if> | |||
| <if test=" createBegin != null"> | |||
| and pay_order_v2.created_at >= #{createBegin} | |||
| </if> | |||
| <if test=" createEnd != null"> | |||
| and pay_order_v2.created_at <= #{createEnd} | |||
| </if> | |||
| <if test=" createBy != null"> | |||
| and pay_order_v2.created_by = #{createBy} | |||
| </if> | |||
| AND ( r.refund_status = 2 ) | |||
| AND r.pay_type != 29 | |||
| AND r.pay_type != 30 | |||
| GROUP BY | |||
| o.order_number, | |||
| r.pay_type | |||
| ) AS ro ON ro.orderNumber = po.orderNumber and po.payType=ro.payType | |||
| GROUP BY | |||
| createdBy | |||
| </select> | |||
| </mapper> | |||