搬单查询小工具总结

搬单查询小工具总结

  • 需求:页面输入团单号,从数据库中查询搬单错误的数据,以excel形式导出。


前端页面放在ts-settle-tools-web项目中,后端查询数据库的部分写在ts-tg-settle中,以API形式提供给ts-settle-tools使用,其实是通过webservice调用的。



java
public interface TSSettleService {
    /**
    * 查询搬单错误数据
    * @param dealGroupIds
    * @return
    */
   public List<TSSettleDetailDTO> getSettleDetailByDealGroupIds(List<Integer> dealGroupIds);
}



java
public class TSSettleServiceObject implements TSSettleService {
   @Override
   public List<TSSettleDetailDTO> getSettleDetailByDealGroupIds(List<Integer> dealGroupIds){
       if(dealGroupIds == null || dealGroupIds.size() == 0){
           return null;
       }
       List<TSSettleDetailData> list = tsSettleDetailDao.getSettleDetailByDealGroupIds(dealGroupIds);
       if(list == null || list.size() == 0){
           return null;
       }
       List<TSSettleDetailDTO> tsSettleDetailDTOs = new ArrayList<TSSettleDetailDTO>();
       for(TSSettleDetailData tsSettleDetailData: list){
           TSSettleDetailDTO tsSettleDetailDTO = new TSSettleDetailDTO();
           tsSettleDetailDTO.setAddTime(tsSettleDetailData.getAddTime());
           tsSettleDetailDTO.setAccountId(tsSettleDetailData.getAccountId());
           tsSettleDetailDTO.setCustomerId(tsSettleDetailData.getCustomerId());
           tsSettleDetailDTO.setDealCost(tsSettleDetailData.getDealCost());
           tsSettleDetailDTO.setDealGroupId(tsSettleDetailData.getDealGroupId());
           tsSettleDetailDTO.setDealPrice(tsSettleDetailData.getDealPrice());
           tsSettleDetailDTO.setDealId(tsSettleDetailData.getDealId());
           tsSettleDetailDTO.setDetailId(tsSettleDetailData.getDetailId());
           tsSettleDetailDTO.setGroupId(tsSettleDetailData.getGroupId());
           tsSettleDetailDTO.setIsDeleted(tsSettleDetailData.getIsDeleted());
           tsSettleDetailDTO.setIsOrderId(tsSettleDetailData.getIsOrderId());
           tsSettleDetailDTO.setQuantity(tsSettleDetailData.getQuantity());
           tsSettleDetailDTO.setSequence(tsSettleDetailData.getSequence());
           tsSettleDetailDTO.setSettleLevel(tsSettleDetailData.getSettleLevel());
           tsSettleDetailDTO.setSettleStatus(tsSettleDetailData.getSettleStatus());
           tsSettleDetailDTO.setSettleTime(tsSettleDetailData.getSettleTime());
           tsSettleDetailDTO.setSettleType(tsSettleDetailData.getSettleType());
           tsSettleDetailDTO.setShopId(tsSettleDetailData.getShopId());
           tsSettleDetailDTOs.add(tsSettleDetailDTO);
       }
       return tsSettleDetailDTOs;
   }
}



java
public interface TSSettleDetailDao extends GenericDao {
   @DAOAction(action = DAOActionType.QUERY)
   List<TSSettleDetailData> getSettleDetailByDealGroupIds(@DAOParam("dealGroupIds") List<Integer> dealGroupIds);
}



xml
<select id="getSettleDetailByDealGroupIds" resultClass="tsSettleDetail" parameterClass="map">
   <include refid="sql_select"/>
   WHERE DealGroupID IN
   <iterate property="dealGroupIds" open="(" close=")" conjunction=",">
       #dealGroupIds[]#
   </iterate>
   <![CDATA[
   AND UpdateTime>‘2015-12-01‘ ORDER BY id ;
    ]]>
</select>
以上是调用TSSettleService接口的部分代码。TSSettleService中的服务需要发布,配置如下xml
<bean id="tsSettleSystemService" class="com.dianping.dpsf.spring.ServiceRegistry" init-method="init" lazy-init="false">
   <property name="port" value="${ts-tg-settle-service.tsSettleService.port}"/>
   <property name="services">
       <map>
           <entry key="http://service.dianping.com/ts/tg/tsSettleService/TSSettleService_1.0.0" value-ref="tsTGSettleService"/>
       </map>
   </property>
</bean>
ts-settle-tools中接收页面请求,并且调用TSSettleService的服务。页面效果如下:页面代码如下:

`html
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="utf-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta name="viewport" content="width=device-width, initial-scale=1">
   <link href="/css/bootstrap.min.css" rel="stylesheet">
   <title>搬单错误查询页面</title>
</head>
<body>
<div class="panel panel-primary">
   <div class="panel-heading">
       <div class="panel-title">搬单错误数据查询</div>
   </div>
   <div class="panel-body">
       <div class="row">
           <div class="col-md-12">
               <form class="form-horizontal" action="/settle/querySettleDetailDataAction" onsubmit="return check()" method="post">
                   <div class="form-group">
                       <label class="col-md-2 control-label">团单号</label>
                       <div class="col-md-10">
                           <textarea rows="3" class="form-control" id="dealGroupIds" name="dealGroupIds"  placeholder="使用英文逗号分隔"></textarea>
                       </div>
                   </div>
                   <div class="form-group">
                       <div class="col-md-offset-2 col-md-10">
                           <button class="btn btn-primary" type="submit">查询</button>
                       </div>
                   </div>
               </form>
           </div>
       </div>
   </div>
</div>
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/layer/layer.js"></script>

<script type="text/javascript">
   $(document).ready(function(){

});

function check(){
    if($("#dealGroupIds").val() == "" || $("#dealGroupIds").val() == ","){
        layer.tips(‘请输入正确的团单号,多个团单号用英文逗号分隔‘, ‘#dealGroupIds‘);
        return false;
    }
}

</script>
</body>
</html>页面使用了JQuery和layer以及bootstrap。controller部分如下:java
@RequestMapping("/settle")
@Controller
public class SettleController {

@Autowired
private SettleService settleService;

@RequestMapping("/querySettleDetailData")
public String querySettleDetailData(){

    return "querySettleDetailData";
}

@RequestMapping("/querySettleDetailDataAction")
public void querySettleDetailDataAction(@RequestParam String dealGroupIds, HttpServletRequest request, HttpServletResponse response){
    List<QuerySettleDetailData> list = settleService.loadTsSettleDetail(dealGroupIds);
    ExportExcel<QuerySettleDetailData> ex = new ExportExcel<QuerySettleDetailData>();
    String[] headers = { "团单号", "套餐号", "验券门店", "结算价", "售价", "验券时间", "券号", "打款状态"};
    try {
        HSSFWorkbook workbook = ex.exportExcel(headers, list);
        String filename = "result.xls";
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment;filename=" + filename);
        OutputStream ouputStream = response.getOutputStream();
        workbook.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

}

}

service部分如下:java
public class SettleServiceImpl implements SettleService {

private AvatarLogger monitorLogger = AvatarLoggerFactory.getLogger(this.getClass());
@Autowired
private TSSettleService tsSettleService;
@Autowired
private TSSettleInfoQueryService tsSettleInfoQueryService;
@Autowired
private DistributionBaseService distributionBaseService;
@Autowired
private PayPlanBaseService payPlanBaseService;

public List<QuerySettleDetailData> loadTsSettleDetail(String dealGroupIds){
    if(dealGroupIds == null || dealGroupIds.equals("")){
        return null;
    }
    String[] strs=dealGroupIds.split(",");
    List<Integer> dealGroupIdList = new ArrayList<Integer>();
    for(int i = 0; i < strs.length; i++){
        try {
            dealGroupIdList.add(Integer.valueOf(strs[i]));
        }catch (Exception e) {
            monitorLogger.error("Number format error", e);
        }
    }
    List<TSSettleDetailDTO> tsSettleDetailDTOs = tsSettleService.getSettleDetailByDealGroupIds(dealGroupIdList);
    if(tsSettleDetailDTOs == null){
        return null;
    }
    List<QuerySettleDetailData> querySettleDetailDatas = new ArrayList<QuerySettleDetailData>();
    for (TSSettleDetailDTO o: tsSettleDetailDTOs){
        //调用tsSettleInfoQueryService服务
        String sn = tsSettleInfoQueryService.loadSnByGroupId(o.getGroupId());
        QuerySettleDetailData querySettleDetailData = new QuerySettleDetailData();
        querySettleDetailData.setDealGroupId(o.getDealGroupId());
        querySettleDetailData.setDealId(o.getDealId());
        querySettleDetailData.setShopId(o.getShopId());
        querySettleDetailData.setDealCost(o.getDealCost());
        querySettleDetailData.setDealPrice(o.getDealPrice());
        querySettleDetailData.setSettleTime(o.getSettleTime());
        querySettleDetailData.setDetailId(o.getDetailId());
        int payPlanId = 0;
        //调用distribution服务
        List<DistributionDetailDTO> distributionDetailDTOs = distributionBaseService.queryDistributeDetail(sn);
        for(DistributionDetailDTO distributionDetailDTO: distributionDetailDTOs){
            if(distributionDetailDTO.getPayPlanId() != 0){
                payPlanId = distributionDetailDTO.getPayPlanId();
                break;
            }
        }
        int status = 0;
        //调用payPlan服务
        PayPlanDTO payPlanDTO = payPlanBaseService.loadPayPlanData(payPlanId);
        if(payPlanDTO != null){
            if(payPlanDTO.getStatus() == 5){
                status = 1;//payPlan的status=5  已打款
            }else{//其他都为未打款
                status = 0;
            }
        }
        querySettleDetailData.setStatus(status);
        querySettleDetailDatas.add(querySettleDetailData);
    }
    return querySettleDetailDatas;
}

}

`
至此就得到了需要查询的数据,controllrt拿到查询到的数据之后需要将数据以excel形式返回给浏览器。生成excel的代码如下:

`java
public class ExportExcel<T> {
   private AvatarLogger monitorLogger = AvatarLoggerFactory.getLogger(this.getClass());
   public HSSFWorkbook exportExcel(Collection<T> dataset) {
       return exportExcel("导出结果", null, dataset);
   }

public HSSFWorkbook exportExcel(String[] headers, Collection<T> dataset) {
    return exportExcel("导出结果", headers, dataset);
}

@SuppressWarnings("unchecked")
public HSSFWorkbook exportExcel(String title, String[] headers,
                        Collection<T> dataset) {
    // 声明一个工作薄
    HSSFWorkbook workbook = new HSSFWorkbook();
    // 生成一个表格
    HSSFSheet sheet = workbook.createSheet(title);
    // 设置表格默认列宽度为18个字节
    sheet.setDefaultColumnWidth((short) 18);
    // 生成一个样式
    HSSFCellStyle style = workbook.createCellStyle();
    // 设置这些样式
    style.setFillForegroundColor(HSSFColor.WHITE.index);
    style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
    style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    // 生成一个字体
    HSSFFont font = workbook.createFont();

//        font.setColor(HSSFColor.VIOLET.index);
       font.setFontHeightInPoints((short) 12);
       font.setBoldweight(HSSFFont.BOLDWEIGHTBOLD);
       // 把字体应用到当前的样式
       style.setFont(font);
       // 生成并设置另一个样式
       HSSFCellStyle style2 = workbook.createCellStyle();
       style2.setFillForegroundColor(HSSFColor.WHITE.index);
       style2.setFillPattern(HSSFCellStyle.SOLID
FOREGROUND);
       style2.setBorderBottom(HSSFCellStyle.BORDERTHIN);
       style2.setBorderLeft(HSSFCellStyle.BORDER
THIN);
       style2.setBorderRight(HSSFCellStyle.BORDERTHIN);
       style2.setBorderTop(HSSFCellStyle.BORDER
THIN);
       style2.setAlignment(HSSFCellStyle.ALIGNCENTER);
       style2.setVerticalAlignment(HSSFCellStyle.VERTICAL
CENTER);
       // 生成另一个字体
       HSSFFont font2 = workbook.createFont();
       font2.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
       // 把字体应用到当前的样式
       style2.setFont(font2);

    // 产生表格标题行
    HSSFRow row = sheet.createRow(0);
    for (short i = 0; i < headers.length; i++) {
        HSSFCell cell = row.createCell(i);
        cell.setCellStyle(style);
        HSSFRichTextString text = new HSSFRichTextString(headers[i]);
        cell.setCellValue(text);
    }
    //没有查询到数据
    if (dataset == null || dataset.size() == 0) {
        sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, headers.length - 1));
        HSSFRow row1 = sheet.createRow(1);
        HSSFCell cell = row1.createCell(0);
        cell.setCellValue("没有查询到数据");
    }else{
        // 遍历集合数据,产生数据行
        Iterator<T> it = dataset.iterator();
        int index = 0;
        while (it.hasNext()) {
            index++;
            row = sheet.createRow(index);
            T t = (T) it.next();
            // 利用反射,根据javabean属性的先后顺序,动态调用getXxx()方法得到属性值
            Field[] fields = t.getClass().getDeclaredFields();
            int colNum = 0;
            for (short i = 0; i < fields.length; i++) {
                Field field = fields[i];
                String fieldName = field.getName();
                String getMethodName = "get"
                        + fieldName.substring(0, 1).toUpperCase()
                        + fieldName.substring(1);
                if (fieldName.equals("dealGroupId") || fieldName.equals("dealId") || fieldName.equals("shopId") || fieldName.equals("dealCost") || fieldName.equals("dealPrice") || fieldName.equals("settleTime") || fieldName.equals("detailId") || fieldName.equals("status")) {
                    //只导出这几个字段
                } else {
                    continue;
                }
                HSSFCell cell = row.createCell(colNum);
                cell.setCellStyle(style2);
                try {
                    Class tCls = t.getClass();
                    Method getMethod = tCls.getMethod(getMethodName,
                            new Class[]{});
                    Object value = getMethod.invoke(t, new Object[]{});
                    // 判断值的类型后进行强制类型转换
                    if (fieldName.equals("dealCost") || fieldName.equals("dealPrice")) {
                        cell.setCellValue(Double.parseDouble(value.toString()));
                    } else if (fieldName.equals("status")) {
                        cell.setCellValue(TSTGSettleStatusEnum.getByCode(Integer.valueOf(value.toString())).getMessage());
                    } else if (value instanceof Date) {
                        Date date = (Date) value;
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        cell.setCellValue(sdf.format(date));
                    } else if (fieldName.equals("dealGroupId") || fieldName.equals("dealId") || fieldName.equals("shopId") || fieldName.equals("detailId")) {
                        cell.setCellValue(value.toString());
                    }
                    colNum++;
                } catch (Exception e) {
                    monitorLogger.error(e);
                } finally {
                    // 清理资源
                }
            }
        }
    }
   return workbook;
}

}

`

ts-settle-tools使用服务时,需要添加对应的pom依赖,并且配置服务的地址:`xml
<bean id="tsSettleService" class="com.dianping.dpsf.spring.ProxyBeanFactory" init-method="init">
   <property name="serviceName" value="http://service.dianping.com/ts/tg/tsSettleService/TSSettleService_1.0.0"/>
   <property name="iface" value="com.dianping.ts.tg.settle.api.TSSettleService"/>
   <property name="serialize" value="hessian"/>
   <property name="callMethod" value="sync"/>
   <property name="timeout" value="5000"/>
</bean>

<bean id="tsSettleInfoQueryService" class="com.dianping.dpsf.spring.ProxyBeanFactory" init-method="init">
   <property name="serviceName" value="http://service.dianping.com/ts/tg/tsSettleService/TSSettleInfoQueryService_1.0.0"/>
   <property name="iface" value="com.dianping.ts.tg.settle.api.TSSettleInfoQueryService"/>
   <property name="serialize" value="hessian"/>
   <property name="callMethod" value="sync"/>
   <property name="timeout" value="5000"/>
</bean>

<bean id="distributionBaseService" class="com.dianping.dpsf.spring.ProxyBeanFactory" init-method="init">
   <property name="serviceName" value="http://service.dianping.com/tsDistributionService/DistributionBaseService_1.0.0"/>
   <property name="iface" value="com.dianping.ts.account.distribution.api.service.DistributionBaseService"/>
   <property name="serialize" value="hessian"/>
   <property name="callMethod" value="sync"/>
   <property name="timeout" value="5000"/>
</bean>

<bean id="payPlanBaseService" class="com.dianping.dpsf.spring.ProxyBeanFactory" init-method="init">
   <property name="serviceName" value="http://service.dianping.com/tsATMPayPlanBaseService/PayPlanBaseService_1.0.0"/>
   <property name="iface" value="com.dianping.ts.atm.payplan.api.PayPlanBaseService"/>
   <property name="serialize" value="hessian"/>
   <property name="callMethod" value="sync"/>
   <property name="timeout" value="5000"/>
</bean>`

时间: 2024-07-30 10:12:18

搬单查询小工具总结的相关文章

HTA+VBS实现的话单核查小工具

今天用HTA+VBS实现了一个话单核查小工具,代码行数185行. 主要作用是快速解析话单的所有字段,避免每次取下话单后还需要查看规范文档,然后到UE里去数位数才能确定数据. 使用这个工具可以节约不少时间. 界面效果如下图所示: 主要难点 1.话单格式配置需要设计,最初是想做成xml格式,但后面想想不方便维护,所以做成了txt格式 2.VBS控制HTML展示效果,需要逐步修正才能达到满意的效果 小技巧汇总 1.HTA窗口启动位置和大小控制 1 2 3 4 5 6     Sub Window_On

Python3中级玩家:爬虫-广东财经大学成绩查询小工具

2016.6.28软件重新迁移到 http://yun.baidu.com/s/1pL2BAfL#path=%252F 源码Github:https://github.com/hunterhug/gdufesearch 代码讲解待写... # GDUFE绩点/考试查询工具一个广东财经大学查询成绩/考试信息的自助系统.支持导出Excel和计算绩点. # How to use1.运行run.bat即可或者exe中后缀为exe的可执行文件2.隐藏功能:在exe文件夹中jinhan.pyd每行写一个学号

搬单小工具总结

需求:页面输入团单号,从数据库中查询搬单错误的数据,以excel形式导出. 前端页面放在ts-settle-tools-web项目中,后端查询数据库的部分写在ts-tg-settle中,以API形式提供给ts-settle-tools使用,其实是通过webservice调用的. public interface TSSettleService {      /**      * 查询搬单错误数据      * @param dealGroupIds      * @return      */

web day19 Service层处理事务(利用ThreadLocal),TxQueryRunner小工具,单表练习(增删改查操作),分页

Service事务 DAO中不是处理事务的地方,因为DAO中的每个方法都是对数据库的一次操作 在Service中不应该出现Connection,它应该只在DAO中出现, 因为它是JDBC的东西,JDBC的东西是用来连接数据库的 修改JdbcUtils 我们把对事务的开启和关闭放到JdbcUtils中,在Service中调用JdbcUtils的方法来完成事务的处理, 但在Service中就不会再出现Connection这一"禁忌"了. 代码 public class JdbcUtils

小工具:火车票查询

今天又到了抢火车票的时候,反正是每次抢票都是傻眼.于是写个小工具帮助自己查询火车票,如果有票的话给自己发个邮件提示购买. 一.准备工作 利用firebug等工具,我们可以获取到当我们单击查询时调用的Get请求. 请求地址: https://kyfw.12306.cn/otn/leftTicket/query?leftTicketDTO.train_date=2017-09-01&leftTicketDTO.from_station=TJP&leftTicketDTO.to_station=

spring MVC +freemarker + easyui 实现sql查询和执行小工具总结

项目中,有时候线下不能方便的连接项目中的数据源时刻,大部分的问题定位和处理都会存在难度,有时候,一个小工具就能实时的查询和执行当前对应的数据源的库.下面,就本人在项目中实际开发使用的小工具,实时的介绍开发使用过程.首先看图:大概的操作界面,基本使用easyui组件实现,欢迎大家吐槽: 界面包含了基本的sql查询 和 sql执行的小功能,把查询和执行分开,也是为了后台实现的需要,以及权限控制的考虑,毕竟执行的操作,会影响到系统的数据问题.查询和执行的菜单,是用easyui的手风琴式的菜单处理的.两

SQL查询条件生成小工具

最近运维数据,经常遇到需要在sql条件中个In('',''....)个字符串的情况,于是在网上找了个小工具改造一下,先用着: 效果如图: 1 using System; 2 using System.Collections.Generic; 3 using System.IO; 4 using System.Linq; 5 using System.Text; 6 using System.Threading.Tasks; 7 using Newtonsoft.Json.Serializatio

用cefsharp写了一个保存网页为单文件html的小工具

折腾了两天,用cefsharp写成了一个保存网页为单文件html的小工具. 主要功能嘛 就是把自己感觉有用的网页保存下来,保存为一个单独的html文件. 特点嘛就是可以在保存前做一些裁剪. 见下图: 热键F11 裁剪到选中部分(也就是只保留选中部分,其它的全删除掉), 热键F12 删除掉选中部分. 文件被自动保存到C盘下的一个目录: 如果不想要图片,可以一键把页面上的图片删除掉.如下图: 查看源文件,可以发现其中的图片都是使用base64字符串方式保存的. 工具栏上[清理]的功能是删除掉 scr

关于小工具对数据库进行分页查询

需求:关于第三方数据库的数据抽取,数据每2个小时会有增量数据. 要求:每天凌晨12:05对T-1日数据进行统一处理. 于是利用1周时间开发了个小工具,主要对接第三方oracle,pg,mysql数据库的数据. 采用技术: 1.多线程,线程池 2.jdbc,连接池 3.数据库分页 遇到问题 1.Javaswing页面设计难度大 解决方案:采用成熟的eclipse插件WindowBuilder 2.分页过程中,不断有新数据插入则会影响数据丢失或重复抽取 解决方案:order by或temp表 3.数