package com.minpay.shouhuo; import com.minpay.common.bean.User; import com.minpay.common.format.IFormatService; import com.minpay.common.service.ILogService; import com.minpay.common.service.IPropertiesService; import com.minpay.common.util.CommonUtil; import com.minpay.common.util.DateUtil; import com.minpay.common.util.HttpPostUtil; import com.minpay.db.table.mapper.VmDeliveryInfMapper; import com.minpay.db.table.mapper.VmOrderDetailsMapper; import com.minpay.db.table.mapper.VmOrderInfMapper; import com.minpay.db.table.model.VmDeliveryInf; import com.minpay.db.table.model.VmOrderDetails; import com.minpay.db.table.model.VmOrderInf; import com.minpay.db.table.own.mapper.OrderManageMapper; import com.startup.minpay.frame.business.IMINAction; import com.startup.minpay.frame.business.res.MINActionResult; import com.startup.minpay.frame.constant.IMINBusinessConstant; import com.startup.minpay.frame.data.format.MINCopyFormat; import com.startup.minpay.frame.exception.MINBusinessException; import com.startup.minpay.frame.jdbc.MINRowBounds; import com.startup.minpay.frame.service.base.IMINDataBaseService; import com.startup.minpay.frame.service.base.Service; import com.startup.minpay.frame.session.MINSession; import com.startup.minpay.frame.target.MINAction; import com.startup.minpay.frame.target.MINComponent; import com.startup.minpay.frame.target.MINParam; import net.sf.json.JSONObject; import org.apache.commons.lang.StringUtils; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.*; /** * 财务管理 * * @author wlm */ @MINComponent public class invCardManageAction implements IMINAction { /**查询订单详情**/ public final static String SELECT_ORDER_DETAIL = "selectOrderDetail"; /**取货、作废**/ public final static String UPDATE_ORDER_STT = "updateOrderStt"; /**查询取货记录**/ public final static String SELECT_PICKUP_RECORD = "selectPickupRecord"; /** 收入统计 **/ public final static String SELECT_INCOME_STATISTICS = "selectIncomeStatistics"; /** 收入统计 **/ public final static String SELECT_ALL_INCOME = "selectAllIncome"; /** 销售数据 **/ public final static String SELECT_SALES_DATA = "selectSalesData"; /** 销售数据2 **/ public final static String SELECT_ALL_SALE = "selectAllSale"; /** 时间轴查询销售金额、预估利润 **/ public final static String SELECT_INCOME_BYDATE = "selectIncomeBydate"; /** * 时间轴查询销售金额、预估利润 * @param session * @return * @throws Exception */ @MINAction(value = SELECT_INCOME_BYDATE) public MINActionResult selectIncomeBydate ( @MINParam(key = "dateFlag") String dateFlag, MINSession session) throws Exception { MINActionResult res = new MINActionResult(); User user = session.getUser(); //获取当前时间 Date currentTime = new Date(); String nowDate = DateUtil.format(currentTime,"yyyyMMdd"); Map m = new HashMap(); //昨天 String yesDate = DateUtil.getDifferentDate(-1).substring(0,8); //本周第一天 Calendar cal=Calendar.getInstance(); cal.add(Calendar.WEEK_OF_MONTH, 0); cal.set(Calendar.DAY_OF_WEEK, 2); Date weekFristDate = cal.getTime(); String weekDate = DateUtil.format(weekFristDate,"yyyyMMdd"); //按时间查询 String time = null; if("0".equals(dateFlag)) { m.put("nowDate", nowDate); Date parse = new SimpleDateFormat("yyyyMMdd").parse(nowDate); String dateString = new SimpleDateFormat("yyyy-MM-dd").format(parse); time = dateString; }else if("1".equals(dateFlag)) { m.put("yesDate", yesDate); Date parse = new SimpleDateFormat("yyyyMMdd").parse(yesDate); String dateString = new SimpleDateFormat("yyyy-MM-dd").format(parse); time = dateString; }else if("2".equals(dateFlag)) { m.put("weekDate", weekDate); Date parse = new SimpleDateFormat("yyyyMMdd").parse(weekDate); String dateString = new SimpleDateFormat("yyyy-MM-dd").format(parse); Date parseb = new SimpleDateFormat("yyyyMMdd").parse(nowDate); String dateStringb = new SimpleDateFormat("yyyy-MM-dd").format(parseb); time = dateString.concat(" 至 ").concat(dateStringb); } //查询累计收入 String countIncome = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(OrderManageMapper.class).selectCountIncome(m); //查询总成本价 String predictIncome = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(OrderManageMapper.class).selectPredictIncome(m); //查询累计收入 List> mapList = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(OrderManageMapper.class).selectCountIncomeb(m); String wxzfbAmout = "0"; String czAmout = "0"; for (int i = 0; i < mapList.size(); i++) { Map map = mapList.get(i); String transType = map.get("transType"); if(transType.equals("00")){ //充值金额 czAmout = String.valueOf(map.get("amout")); } if(transType.equals("10")){ //支付金额 wxzfbAmout = String.valueOf(map.get("amout")); } } predictIncome = CommonUtil.subtract(countIncome,predictIncome); String zsrAmout = CommonUtil.add(czAmout,wxzfbAmout); //返回数据 res.set("countIncome", countIncome); res.set("predictIncome", predictIncome); res.set("czAmout", czAmout); res.set("zsrAmout", zsrAmout); res.set("time", time); return res; } /** * 总销售数量 * @param session * @return * @throws Exception */ @MINAction(value = SELECT_ALL_SALE) public MINActionResult selectAllSale ( MINSession session) throws Exception { MINActionResult res = new MINActionResult(); User user = session.getUser(); //总实际金额 String allSale = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(OrderManageMapper.class).selectAllSale(); //总商品成本 String allCost = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(OrderManageMapper.class).selectAllCost(); BigDecimal num1 = new BigDecimal(allSale); BigDecimal num2 = new BigDecimal(allCost); BigDecimal allProfit = num1.subtract(num2); //返回数据 res.set("allSale", allSale); res.set("allCost", allCost); res.set("allProfit", allProfit); return res; } /** * 销售数据 * @param page * @param limit * @param session * @return * @throws Exception */ @MINAction(value = SELECT_SALES_DATA) public MINActionResult selectSalesData ( @MINParam(key = "page", defaultValue = "1") int page, @MINParam(key = "limit", defaultValue = "7") int limit, @MINParam(key = "proName") String proName, MINSession session) throws Exception { MINActionResult res = new MINActionResult(); User user = session.getUser(); Map m = new HashMap(); m.put("proName", proName); MINRowBounds rows = new MINRowBounds(page, limit); List> detailList = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(OrderManageMapper.class).selectProductInfo(rows, m); detailList = Service.lookup(IFormatService.class).formatCurrency(detailList, "amount", "proNums"); //返回数据 res.set(IMINBusinessConstant.F_PAGING_LAY, detailList); res.set(IMINBusinessConstant.F_PAGING_COUNT, rows.getCount()); return res; } /** * 总收入统计 * @param session * @return * @throws Exception */ // @MINAction(value = SELECT_ALL_INCOME) // public MINActionResult selectAllIncome ( // MINSession session) throws Exception { // MINActionResult res = new MINActionResult(); // User user = session.getUser(); // //查询订单数 // String orderNum = Service.lookup(IMINDataBaseService.class) // .getMybatisMapper(OrderManageMapper.class).selectCountOrderNum(); // //查询累计收入 // String countIncome = Service.lookup(IMINDataBaseService.class) // .getMybatisMapper(OrderManageMapper.class).selectCountIncome(); // //查询总机台数 // String countDevice = Service.lookup(IMINDataBaseService.class) // .getMybatisMapper(OrderManageMapper.class).selectCountDevice(); // //返回数据 // res.set("orderNum", orderNum); // res.set("countIncome", countIncome); // res.set("countDevice", countDevice); // return res; // } /** * 收入统计 * @param page * @param limit * @param session * @return * @throws Exception */ @MINAction(value = SELECT_INCOME_STATISTICS) public MINActionResult selectIncomeStatistics ( @MINParam(key = "page", defaultValue = "1") int page, @MINParam(key = "limit", defaultValue = "10") int limit, @MINParam(key = "equNum") String equNum, @MINParam(key = "datesTime") String datesTime, MINSession session) throws Exception { MINActionResult res = new MINActionResult(); User user = session.getUser(); String branchId = user.getBranchId(); MINRowBounds rows = new MINRowBounds(page, limit); //获取当前时间 Date currentTime = new Date(); String nowDate = DateUtil.format(currentTime,"yyyyMMdd"); Map m = new HashMap(); m.put("equNum", equNum); m.put("datesTime", datesTime); m.put("nowDate", nowDate); if(!"88888888".equals(branchId)) { m.put("branchId", branchId); } List> detailList = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(OrderManageMapper.class).selectIncomeDetail(rows, m); detailList = Service.lookup(IFormatService.class).formatDate(detailList, "sellTime"); detailList = Service.lookup(IFormatService.class).formatCurrency(detailList, "sellWxSum", "sellZfSum", "" + "sellMfSum", "allSell"); //返回数据 res.set(IMINBusinessConstant.F_PAGING_LAY, detailList); res.set(IMINBusinessConstant.F_PAGING_COUNT, rows.getCount()); return res; } /** * 取货记录 * @param machineNo * @param orderNo * @param pickUpDates * @param page * @param limit * @param session * @return * @throws Exception */ @MINAction(value = SELECT_PICKUP_RECORD) public MINActionResult selectPickupRecord ( @MINParam(key = "machineNo") String machineNo, @MINParam(key = "orderNo") String orderNo, @MINParam(key = "pickUpDates") String pickUpDates, @MINParam(key = "equrelId") String equrelId, @MINParam(key = "vciId") String vciId, @MINParam(key = "pickupNo") String pickupNo, @MINParam(key = "page", defaultValue = "1") int page, @MINParam(key = "limit", defaultValue = "3") int limit, MINSession session) throws Exception { MINActionResult res = new MINActionResult(); User user = session.getUser(); String branchId = user.getBranchId(); Map m = new HashMap(); m.put("machineNo", machineNo); m.put("orderNo", orderNo); m.put("pickUpDates", pickUpDates); m.put("equrelId", equrelId); m.put("vciId", vciId); m.put("pickupNo", pickupNo); if(!"88888888".equals(branchId)) { m.put("branchId", branchId); } MINRowBounds rows = new MINRowBounds(page, limit); List> detailList = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(OrderManageMapper.class).selectPickupRecord(m,rows); detailList = new MINCopyFormat("{stt:'sttDesc'}").format(detailList); detailList = Service.lookup(IFormatService.class).formatEnum(detailList,"{sttDesc:'PICKUP_STT'}"); detailList = Service.lookup(IFormatService.class).formatDateTime(detailList, "pickUpTime"); //返回数据 res.set(IMINBusinessConstant.F_PAGING_LAY, detailList); res.set(IMINBusinessConstant.F_PAGING_COUNT, rows.getCount()); return res; } /** * 查询订单详情 * @param machineNo * @param pickUpCode * @param creatdDtes * @param pickUpDates * @param pickUpState * @param page * @param limit * @param session * @return * @throws Exception */ @MINAction(value = SELECT_ORDER_DETAIL) public MINActionResult selectOrderDetail ( @MINParam(key = "machineNo") String machineNo, @MINParam(key = "pickUpCode") String pickUpCode, @MINParam(key = "equrelId") String equrelId, @MINParam(key = "creatdDtes") String creatdDtes, @MINParam(key = "pickUpDates") String pickUpDates, @MINParam(key = "pickUpState") String pickUpState, @MINParam(key = "page", defaultValue = "1") int page, @MINParam(key = "limit", defaultValue = "3") int limit, MINSession session) throws Exception { MINActionResult res = new MINActionResult(); User user = session.getUser(); String branchId = user.getBranchId(); Map m = new HashMap(); m.put("machineNo", machineNo); m.put("pickUpCode", pickUpCode); m.put("equrelId", equrelId); m.put("creatdDtes", creatdDtes); m.put("pickUpDates", pickUpDates); m.put("pickUpState", pickUpState); if(!"88888888".equals(branchId)) { m.put("branchId", branchId); } MINRowBounds rows = new MINRowBounds(page, limit); List> detailList = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(OrderManageMapper.class).selectOrderDetail(m,rows); // 格式化数据 detailList = Service.lookup(IFormatService.class).formatDateTime(detailList, "pickUpTime"); detailList = Service.lookup(IFormatService.class).formatDateTime(detailList, "createTime"); detailList = new MINCopyFormat("{stt:'sttDesc'}").format(detailList); detailList = Service.lookup(IFormatService.class).formatEnum(detailList,"{sttDesc:'ORDER_PICKUP_STT'}"); //返回数据 res.set(IMINBusinessConstant.F_PAGING_LAY, detailList); res.set(IMINBusinessConstant.F_PAGING_COUNT, rows.getMaxRows()); return res; } /** *卡卷管理、取货、作废 * @param orderNo * @param temp 操作0:作废,1:取货 * @param session * @return * @throws Exception */ @MINAction(value = UPDATE_ORDER_STT) public MINActionResult updateOrderStt( @MINParam ( key = "orderNo")String orderNo, @MINParam ( key = "temp")String temp, @MINParam ( key = "pickupNo")String pickupNo, @MINParam ( key = "detailsId")String detailsId, MINSession session) throws Exception{ MINActionResult res = new MINActionResult(); User user = session.getUser(); VmDeliveryInf vd = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmDeliveryInfMapper.class) .selectByPrimaryKey(pickupNo); if(vd == null || "2".equals(vd.getStatus()) || "6".equals(vd.getStatus())){ throw new MINBusinessException("提货编号已提货"); } String ordDetId = vd.getOrdDetId(); VmOrderDetails vmOrderDetails = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmOrderDetailsMapper.class) .selectByPrimaryKey(ordDetId); if(vmOrderDetails == null||"01".equals(vmOrderDetails.getIsDelivery())){ throw new MINBusinessException("提货编号已提货"); } String info = ""; if ("0".equals(temp)) { vd.setStatus("6"); info = "废止"; //修改提货表 Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmDeliveryInfMapper.class) .updateByPrimaryKeySelective(vd); //修改订单详情表 vmOrderDetails.setIsDelivery("01"); vmOrderDetails.setPickupTime(DateUtil.getCurrentDateTimeString()); Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmOrderDetailsMapper.class) .updateByPrimaryKeySelective(vmOrderDetails); }else if("1".equals(temp)) { String url = Service.lookup(IPropertiesService.class) .getSystemProperties().get("V01_SHOUHUO_NOTIFY_URL").getKey(); StringBuffer paramStr = new StringBuffer(); paramStr.append("MINView=JSON&"); paramStr.append("deliveryNo="); paramStr.append(pickupNo); url = url.concat("/DeliveryAction/makeDeliveryForMachineNoSession?"); String jsonObj = HttpPostUtil.sendPost(url, paramStr.toString()); if(CommonUtil.isEmpty(jsonObj)){ throw new MINBusinessException("操作失败!请重新操作"); } JSONObject js2 = JSONObject.fromObject(jsonObj); String mINStatus = js2.getString("MINStatus"); String mINErrorMessage = js2.getString("MINErrorMessage"); //{"msg":"没有提货信息!","code":1,"MINPage":{"charset":"UTF-8","cache":false,"view":"JSON","page":"","type":"","contentType":"text/html"},"MINLangLocale":"zh_CN","MINStatus":1,"MINTime":"2020-12-13 01:41:56","MINErrorMessage":"没有提货信息!"} if(!"0".equals(mINStatus)){ throw new MINBusinessException(mINErrorMessage); } //发送请求 info = "发货"; } //日志 String logInfo = user.getName()+"-更新提货单状态:" +info+ ",订单号"+pickupNo; Service.lookup(ILogService.class).logging(session, logInfo); return res; } }