张晓波
2023-09-19 164694c47c35d6654df69b533e8dbf8b5423efc5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
package com.thhy.materials.modules.biz.materials.service.impl;
 
import cn.hutool.core.io.IoUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.thhy.general.common.BasicResult;
import com.thhy.general.config.SysUserInfo;
import com.thhy.general.utils.UserInfoUtils;
import com.thhy.materials.modules.biz.concret.entity.SysSteel;
import com.thhy.materials.modules.biz.concret.entity.SysSteelRecord;
import com.thhy.materials.modules.biz.concret.entity.dto.SteelStatisticsDto;
import com.thhy.materials.modules.biz.concret.mapper.SysSteelMapper;
import com.thhy.materials.modules.biz.concret.mapper.SysSteelRecordMapper;
import com.thhy.materials.modules.biz.materials.entity.SysAssistCorrection;
import com.thhy.materials.modules.biz.materials.entity.SysAssistGood;
import com.thhy.materials.modules.biz.materials.entity.SysAssistRecord;
import com.thhy.materials.modules.biz.materials.entity.dto.*;
import com.thhy.materials.modules.biz.materials.mapper.SysAssistGoodMapper;
import com.thhy.materials.modules.biz.materials.mapper.SysAssistRecordMapper;
import com.thhy.materials.modules.biz.materials.service.SysAssistGoodService;
import com.thhy.materials.modules.biz.materials.service.SysAssistRecordService;
import com.thhy.materials.modules.biz.utils.ExcelUtil;
import org.apache.poi.ss.usermodel.DataValidation;
import org.apache.poi.ss.usermodel.DataValidationConstraint;
import org.apache.poi.ss.usermodel.DataValidationHelper;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.multipart.MultipartFile;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;
import java.util.Map;
 
@Service
public class SysAssistRecordServiceImpl implements SysAssistRecordService {
    @Resource
    private SysAssistRecordMapper assistRecordMapper;
    @Resource
    private SysSteelRecordMapper recordMapper;
    @Resource
    private SysAssistGoodMapper goodMapper;
 
    @Override
    @Transactional
    public BasicResult assistRecordInsert(HashMap<String, Object> values) {
 
        SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
        //辅材id
        String assistId = values.get("assistId").toString();
        Integer stockType = Integer.valueOf(values.get("stockType").toString());
 
        Integer changeStock = Integer.valueOf(values.get("changeStock").toString());
        Integer stock = assistRecordMapper.assistStock(assistId);
        if(stockType==1){
            Integer nums = (changeStock + stock);
            assistRecordMapper.assistStockUp(assistId,nums);
        }else {
            if (changeStock>stock){
                return BasicResult.faild("11111","出库量大于库存","出库量大于库存");
            }else {
                Integer nums = (stock - changeStock);
                assistRecordMapper.assistStockUp(assistId,nums);
            }
        }
        values.put("id","");
        values.put("createUser",sysUserInfo.getUserId());
        values.put("companyId",sysUserInfo.getCompanyId());
        assistRecordMapper.assistRecordInsert(values);
        return BasicResult.success("添加成功");
    }
 
    @Override
    public BasicResult assistRecordList(Map<String, Object> values) {
        SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
        String companyId = sysUserInfo.getCompanyId();
        values.put("companyId",companyId);
 
        Integer pageSize = Integer.valueOf(values.get("pageSize").toString());
        Integer pageNum = Integer.valueOf(values.get("pageNum").toString());
        PageHelper.startPage(pageNum,pageSize);
        List<SysAssistRecord> sysAssistRecords = assistRecordMapper.assistRecordList(values);
        PageInfo<SysAssistRecord> sysAssistRecordPageInfo = new PageInfo<>(sysAssistRecords);
        return BasicResult.success(sysAssistRecordPageInfo);
    }
    @Override
    public BasicResult assistRecordOutList(Map<String, Object> values) {
        SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
        String companyId = sysUserInfo.getCompanyId();
        values.put("companyId",companyId);
 
        Integer pageSize = Integer.valueOf(values.get("pageSize").toString());
        Integer pageNum = Integer.valueOf(values.get("pageNum").toString());
        PageHelper.startPage(pageNum,pageSize);
        List<SysAssistRecord> sysAssistRecords = assistRecordMapper.assistRecordOutList(values);
        PageInfo<SysAssistRecord> sysAssistRecordPageInfo = new PageInfo<>(sysAssistRecords);
        return BasicResult.success(sysAssistRecordPageInfo);
    }
 
    @Override
    @Transactional
    public BasicResult assistCheck(Map<String, Object> values) {
        //校正后库存
        Integer correctionAfter = Integer.valueOf(values.get("correctionAfter").toString());
        //辅材id
        String assistId = values.get("assistId").toString();
        assistRecordMapper.assistStockUp(assistId,correctionAfter);
        SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
        values.put("createUser",sysUserInfo.getUserId());
        values.put("id","");
        assistRecordMapper.assistCheckInsert(values);
        return BasicResult.success("校正成功");
    }
 
    @Override
    public BasicResult assistCorrectionList(Map<String, Object> values) {
        SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
        String companyId = sysUserInfo.getCompanyId();
        values.put("companyId",companyId);
        Integer pageSize = Integer.valueOf(values.get("pageSize").toString());
        Integer pageNum = Integer.valueOf(values.get("pageNum").toString());
        PageHelper.startPage(pageNum,pageSize);
        List<SysAssistCorrection> sysAssistCorrections =  assistRecordMapper.assistCorrectionList(values);
        PageInfo<SysAssistCorrection> sysAssistCorrectionPageInfo = new PageInfo<>(sysAssistCorrections);
        return BasicResult.success(sysAssistCorrectionPageInfo);
    }
 
    @Override
    public void assistExport(Map<String, Object> values, HttpServletResponse response) {
        SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
        String companyId = sysUserInfo.getCompanyId();
        values.put("companyId",companyId);
 
        List<SysAssistRecord> sysAssistRecords = assistRecordMapper.assistRecordList(values);
//        if (sysAssistRecords.size()<=0){
//            response.setStatus(400);
//            return;
//        }
        List<AssistRecordDto> assistRecordDtos = new ArrayList<>();
        for (SysAssistRecord assistRecordDto:sysAssistRecords){
            AssistRecordDto ar = new AssistRecordDto();
            ar.setAssistName(assistRecordDto.getAssistName());
            ar.setAssistModel(assistRecordDto.getAssistModel());
            ar.setSupplierName(assistRecordDto.getSupplierName());
            ar.setChangeStock(assistRecordDto.getChangeStock());
            ar.setSinglePrice(assistRecordDto.getSinglePrice());
            ar.setAmount(assistRecordDto.getAmount());
            ar.setRealName(assistRecordDto.getRealName());
            ar.setCreateTime(assistRecordDto.getCreateTime());
            ar.setRemark(assistRecordDto.getRemark());
            assistRecordDtos.add(ar);
        }
        ExcelWriter excel = new ExcelWriter();//定义excel
        excel.addHeaderAlias("assistName", "物品名称");
        excel.addHeaderAlias("assistModel", "规格型号");
        excel.addHeaderAlias("supplierName", "供应商");
        excel.addHeaderAlias("changeStock", "入库数量");
        excel.addHeaderAlias("singlePrice", "单价");
        excel.addHeaderAlias("amount", "金额");
        excel.addHeaderAlias("realName","收料人");
        excel.addHeaderAlias("createTime", "入库时间");
        excel.addHeaderAlias("remark", "备注");
 
        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
        response.setHeader("Content-Disposition", "attachment;filename=test.xls");
        OutputStream out = null;
        try {
            out = response.getOutputStream();
            excel.write(assistRecordDtos);
            excel.flush(out, true);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            // 关闭writer,释放内存
            excel.close();
        }
        IoUtil.close(out);
 
    }
 
    @Override
    public void recordExportTemplate(HttpServletResponse response) {
        SysUserInfo sysUserInfo1 = UserInfoUtils.getInstance().getUserInfo();
        String companyId1 = sysUserInfo1.getCompanyId();
        List<String> supplierList = recordMapper.supplierPull(companyId1);
        String[] gys = supplierList.toArray(new String[supplierList.size()]);
 
        XSSFWorkbook book = new XSSFWorkbook();
        XSSFSheet sheet = book.createSheet();
        XSSFRow row = sheet.createRow(0);
        row.createCell(0).setCellValue("物品名称-规格型号");
        row.createCell(1).setCellValue("供应商");
        row.createCell(2).setCellValue("入库数量");
        row.createCell(3).setCellValue("单价");
        row.createCell(4).setCellValue("金额");
        row.createCell(5).setCellValue("备注");
        //row.createCell(6).setCellValue("计量单位");
        // row.createCell(6).setCellValue("入库人");
//
//        //供应商
        CellRangeAddressList regions = new CellRangeAddressList(1, 500, 1, 1);
        DataValidationHelper dataValidationHelper = sheet.getDataValidationHelper();
        DataValidationConstraint createExplicitListConstraint = dataValidationHelper.createExplicitListConstraint(gys);
        DataValidation createValidation = dataValidationHelper.createValidation(createExplicitListConstraint, regions);
        sheet.addValidationData(createValidation);
//
        Map<String, Object> values = new HashMap<>();
        SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
        String companyId = sysUserInfo.getCompanyId();
        values.put("companyId",companyId);
        List<SysAssistGood> assistGoods =  goodMapper.assistList(values);
        List<String> lx = new ArrayList<>();
        assistGoods.forEach(sysSteel -> {
            lx.add(sysSteel.getAssistName()+"-"+sysSteel.getAssistModel());
        });
        String[] gjlx = lx.toArray(new String[lx.size()]);
 
//        //物品名称-规格型号
        CellRangeAddressList regions1 = new CellRangeAddressList(1, 500, 0, 0);
        DataValidationHelper dataValidationHelper1 = sheet.getDataValidationHelper();
        DataValidationConstraint createExplicitListConstraint1 = dataValidationHelper1.createExplicitListConstraint(gjlx);
        DataValidation createValidation1 = dataValidationHelper.createValidation(createExplicitListConstraint1, regions1);
        sheet.addValidationData(createValidation1);
        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
        response.setHeader("Content-Disposition", "attachment;filename=test.xls");
        OutputStream out = null;
        try {
            out = response.getOutputStream();
            book.write(out);
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            IOUtils.closeQuietly(out);
        }
    }
 
    @Override
    public void assistOutExport(Map<String, Object> values, HttpServletResponse response) {
        SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
        String companyId = sysUserInfo.getCompanyId();
        values.put("companyId",companyId);
        List<SysAssistRecord> sysAssistRecords = assistRecordMapper.assistRecordOutList(values);
 
        List<AssistRecordOutExcelDto> assistRecordOutExcelDtos = new ArrayList<>();
        for (SysAssistRecord assistRecord:sysAssistRecords){
            AssistRecordOutExcelDto arod = new AssistRecordOutExcelDto();
            arod.setAssistName(assistRecord.getAssistName());
            arod.setAssistModel(assistRecord.getAssistModel());
            arod.setChangeStock(assistRecord.getChangeStock());
            arod.setSinglePrice(assistRecord.getSinglePrice());
            arod.setAmount(assistRecord.getAmount());
            arod.setRealName(assistRecord.getRealName());
            arod.setDepartName(assistRecord.getDepartName());
            arod.setCreateTime(assistRecord.getCreateTime());
            arod.setRemark(assistRecord.getRemark());
            assistRecordOutExcelDtos.add(arod);
        }
        ExcelWriter excel = new ExcelWriter();//定义excel
        excel.addHeaderAlias("assistName", "物品名称");
        excel.addHeaderAlias("assistModel", "规格型号");
        excel.addHeaderAlias("changeStock", "出库数量");
        excel.addHeaderAlias("singlePrice", "单价");
        excel.addHeaderAlias("amount", "金额");
        excel.addHeaderAlias("realName","发料人");
        excel.addHeaderAlias("departName", "领料部门");
        excel.addHeaderAlias("createTime", "出库时间");
        excel.addHeaderAlias("remark", "备注");
 
        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
        response.setHeader("Content-Disposition", "attachment;filename=test.xls");
        OutputStream out = null;
        try {
            out = response.getOutputStream();
            excel.write(assistRecordOutExcelDtos);
            excel.flush(out, true);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            // 关闭writer,释放内存
            excel.close();
        }
        IoUtil.close(out);
 
    }
 
    @Override
    @Transactional
    public BasicResult assistRecordDel(Map<String,Object> values) {
        String id = values.get("id").toString();
        Integer stockType = Integer.valueOf(values.get("stockType").toString());
        SysAssistRecord assistRecord= assistRecordMapper.assistIdSelect(id);
        //辅材id
        String assistId = assistRecord.getAssistId();
        Integer stock = assistRecordMapper.assistStock(assistId);
        if(stockType==1){
            Integer nums = (stock - assistRecord.getChangeStock());
            assistRecordMapper.assistStockUp(assistId,nums);
        }else {
            Integer nums = (stock + assistRecord.getChangeStock());
            assistRecordMapper.assistStockUp(assistId,nums);
        }
        assistRecordMapper.assistRecordDel(id);
        return BasicResult.success("删除成功");
    }
 
    @Override
    public BasicResult assistRecordInfo(String id) {
        SysAssistRecord assistRecord = assistRecordMapper.assistRecordInfo(id);
        return BasicResult.success(assistRecord);
    }
 
    @Override
    public BasicResult variateExcel(MultipartFile file, HttpServletRequest request) {
        List<List<Object>> lists = null;//去工具类处理,返回excel中的数据
        try {
            lists = ExcelUtil.getUserListByExcel(file.getInputStream(), file.getOriginalFilename());
        } catch (Exception e) {
            e.printStackTrace();
        }
        lists.remove(0);
        if (lists.size()>0){
            for (List<Object> list :lists){
                HashMap<String, Object> values = new HashMap<>();
                String lx = list.get(0).toString();
                String[] split = lx.split("-");
                String s = split[0];
                String s1 = split[1];
                String id =  goodMapper.assistNameAndType(s,s1);
                values.put("assistId",id);
                //供应商
                String supplierName = list.get(1).toString();
                String supplierId = recordMapper.supplierIdSelect(supplierName);
                values.put("supplierId",supplierId);
                values.put("stockType",1);
                //入库数量
                Integer changeStock = Integer.valueOf(list.get(2).toString());
                values.put("changeStock",changeStock);
                //单价
                String dj = list.get(3).toString();
                BigDecimal singlePrice = new BigDecimal(dj);
                values.put("singlePrice",singlePrice);
                //金额
                String je = list.get(4).toString();
                BigDecimal amount = new BigDecimal(je);
                values.put("amount",amount);
                //备注
                String remark = list.get(5).toString();
                values.put("remark",remark);
                //入库人
                SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
                String userId = sysUserInfo.getUserId();
                String companyId = sysUserInfo.getCompanyId();
                values.put("createUser",userId);
                values.put("companyId",companyId);
                //现有库存
                Integer stock = assistRecordMapper.assistStock(id);
                int num = (stock + changeStock);//添加后库存
                assistRecordMapper.assistStockUp(id,num);
                values.put("id","");
                System.out.println(values);
                assistRecordMapper.assistRecordInsert(values);
            }
            return BasicResult.success("导入成功");
        }else {
 
            return BasicResult.faild("11111","error","空文件");
        }
    }
 
    @Override
    public BasicResult assistStatistics(Map<String, Object> values) {
        SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
        String companyId = sysUserInfo.getCompanyId();
        values.put("companyId",companyId);
        String dateType = values.get("dateType").toString();
        String strTime = values.get("strTime").toString();
        String endTime = values.get("endTime").toString();
        List<AssistGoodPullDto> assistGoodPullDtos = assistRecordMapper.assistRecordPullS(values);
        if(dateType.equals("1")){
            //日
            List<String> betweenDate = getBetweenDate(strTime, endTime);
            if(assistGoodPullDtos.size()>0){
                for (AssistGoodPullDto a :assistGoodPullDtos){
                    values.put("assistId",a.getAssistId());
                    List<AssistStatisticsDto> assistStatisticsDtos = assistRecordMapper.assistStatisticsDay(values);
                    a.setAssistStatisticsDtos(assistStatisticsDtos);
                    a.setBetweenDate(betweenDate);
                }
            }
            return BasicResult.success(assistGoodPullDtos);
        }else if (dateType.equals("2")){//月
            if(assistGoodPullDtos.size()>0){
                List<String> monthBetweenDate = getMonthBetweenDate(strTime, endTime);
                for (AssistGoodPullDto a :assistGoodPullDtos){
                    values.put("assistId",a.getAssistId());
                    List<AssistStatisticsDto> assistStatisticsDtos = assistRecordMapper.assistStatisticsMonth(values);
                    a.setAssistStatisticsDtos(assistStatisticsDtos);
                    a.setBetweenDate(monthBetweenDate);
                }
            }
            return BasicResult.success(assistGoodPullDtos);
        }
        return BasicResult.faild("11111","类型错误","");
    }
 
    @Override
    public BasicResult assistStatisticsExcel(Map<String, Object> values,HttpServletResponse response) {
        SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
        String companyId = sysUserInfo.getCompanyId();
        values.put("companyId",companyId);
        String dateType = values.get("dateType").toString();
        List<AssistStatisticsExcel> assistStatisticsExcels = new ArrayList<>();
 
        if(dateType.equals("1")){
            //日
            List<AssistStatisticsDto> assistStatisticsDtos = assistRecordMapper.assistStatisticsDay(values);
            for (AssistStatisticsDto as :assistStatisticsDtos){
                AssistStatisticsExcel ase = new AssistStatisticsExcel();
                ase.setAssistName(as.getAssistName());
                ase.setAssistModel(as.getAssistModel());
                ase.setGetDate(as.getGetDate());
                ase.setChangeStock(as.getChangeStock());
                assistStatisticsExcels.add(ase);
            }
        }else if (dateType.equals("2")){//月
            List<AssistStatisticsDto> assistStatisticsDtos = assistRecordMapper.assistStatisticsMonth(values);
            for (AssistStatisticsDto as :assistStatisticsDtos){
                AssistStatisticsExcel ase = new AssistStatisticsExcel();
                ase.setAssistName(as.getAssistName());
                ase.setAssistModel(as.getAssistModel());
                ase.setGetDate(as.getGetDate());
                ase.setChangeStock(as.getChangeStock());
                assistStatisticsExcels.add(ase);
            }
        }
        ExcelWriter excel = new ExcelWriter();//定义excel
        excel.addHeaderAlias("assistName", "物品名称");
        excel.addHeaderAlias("assistModel", "规格型号");
        excel.addHeaderAlias("getDate", "日期");
        excel.addHeaderAlias("changeStock", "出库数量");
        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
        response.setHeader("Content-Disposition", "attachment;filename=test.xls");
        OutputStream out = null;
        try {
            out = response.getOutputStream();
            excel.write(assistStatisticsExcels);
            excel.flush(out, true);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            // 关闭writer,释放内存
            excel.close();
        }
        IoUtil.close(out);
        return BasicResult.success();
    }
 
    @Override
    public BasicResult assistRecordPull() {
        SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
        String companyId = sysUserInfo.getCompanyId();
        List<AssistGoodPullDto> assistGoodPullDtos = assistRecordMapper.assistRecordPull(companyId);
        return BasicResult.success(assistGoodPullDtos);
    }
 
    public static List<String> getBetweenDate(String startTime, String endTime){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        // 声明保存日期集合
        List<String> list = new ArrayList<String>();
        try {
            // 转化成日期类型
            Date startDate = sdf.parse(startTime);
            Date endDate = sdf.parse(endTime);
 
            //用Calendar 进行日期比较判断
            Calendar calendar = Calendar.getInstance();
            while (startDate.getTime()<=endDate.getTime()){
                // 把日期添加到集合
                list.add(sdf.format(startDate));
                // 设置日期
                calendar.setTime(startDate);
                //把日期增加一天
                calendar.add(Calendar.DATE, 1);
                // 获取增加后的日期
                startDate=calendar.getTime();
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return list;
    }
 
    /**
     * 获取两个日期之间的所有月份 (年月)
     *
     * @param startTime
     * @param endTime
     * @return:list
     */
    public static List<String> getMonthBetweenDate(String startTime, String endTime) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        // 声明保存日期集合
        List<String> list = new ArrayList<>();
        try {
            // 转化成日期类型
            Date startDate = sdf.parse(startTime);
            Date endDate = sdf.parse(endTime);
 
            //用Calendar 进行日期比较判断
            Calendar calendar = Calendar.getInstance();
            while (startDate.getTime() <= endDate.getTime()) {
 
                // 把日期添加到集合
                list.add(sdf.format(startDate));
 
                // 设置日期
                calendar.setTime(startDate);
 
                //把月数增加 1
                calendar.add(Calendar.MONTH, 1);
 
                // 获取增加后的日期
                startDate = calendar.getTime();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }
 
}