|
|
@@ -72,6 +72,8 @@ public class ChecklistController extends BladeController {
|
|
|
private final IUserLogService userLogService;
|
|
|
private final IDictService dictService;
|
|
|
|
|
|
+ private final String pattern = "yyyy-MM-dd";
|
|
|
+
|
|
|
/**
|
|
|
* 详情
|
|
|
*/
|
|
|
@@ -116,7 +118,7 @@ public class ChecklistController extends BladeController {
|
|
|
}
|
|
|
|
|
|
/*if (new Integer(2).equals(checklist.getDataType())){
|
|
|
- String[] dateRange = getDateRange();
|
|
|
+ String[] dateRange = getWeekRange();
|
|
|
checklist.setBeginDate(dateRange[0]);
|
|
|
checklist.setEndDate(dateRange[1]);
|
|
|
}*/
|
|
|
@@ -240,7 +242,7 @@ public class ChecklistController extends BladeController {
|
|
|
List<ChecklistVO> mlist0 = checklistService.getDataList(checklist);
|
|
|
|
|
|
checklist.setCycle("week");
|
|
|
- /*String[] dateRange = getDateRange();
|
|
|
+ /*String[] dateRange = getWeekRange();
|
|
|
checklist.setBeginDate(dateRange[0]);
|
|
|
checklist.setEndDate(dateRange[1]);*/
|
|
|
checklist.setIsChecked(1);
|
|
|
@@ -267,60 +269,155 @@ public class ChecklistController extends BladeController {
|
|
|
public R getReport(ChecklistVO checklist) {
|
|
|
|
|
|
List<Map> list = new ArrayList<>();
|
|
|
-
|
|
|
- Dept dept = deptService.getById(AuthUtil.getDeptId());
|
|
|
List<Dict> check_category = dictService.getList("check_category");
|
|
|
List<Dict> check_item = dictService.getList("check_item");
|
|
|
+ Dept dept = deptService.getById(AuthUtil.getDeptId());
|
|
|
|
|
|
if (checklist.getCycle() == null){
|
|
|
checklist.setCycle("day");
|
|
|
}
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(checklist.getDate_begin()) && StringUtils.isNotBlank(checklist.getDate_end())){
|
|
|
+ // 延长一天,是为了sql可以查询出最后一天的记录
|
|
|
+// checklist.setDate_end(getNextDay(checklist.getDate_end()));
|
|
|
+ }else{
|
|
|
+ // 默认是当天
|
|
|
+ String today = DateUtil.format(DateUtil.now(), pattern);
|
|
|
+ checklist.setDate_begin(today);
|
|
|
+ checklist.setDate_end(today);
|
|
|
+ }
|
|
|
+
|
|
|
+ String dateBegin = checklist.getDate_begin();
|
|
|
+ String dateEnd = checklist.getDate_end();
|
|
|
+ long days = getInterval(dateBegin, dateEnd);
|
|
|
+
|
|
|
String dataType = checklist.getCycle();
|
|
|
+ if (dataType.equals("day")){
|
|
|
+ for (int i = 0; i <= days; i++) {
|
|
|
+ String theDay = getDay(dateBegin, i);
|
|
|
+ // 延长一天,是为了sql可以查询出最后一天的记录
|
|
|
+ String nextDay = getDay(dateBegin, i + 1);
|
|
|
+ checklist.setDate_begin(theDay);
|
|
|
+ checklist.setDate_end(nextDay);
|
|
|
+
|
|
|
+ List<Map> reportData = getReportData(checklist, dataType, theDay, dept.getOrgNo(), check_category, check_item);
|
|
|
+ list.addAll(reportData);
|
|
|
+ }
|
|
|
+ }else if (dataType.equals("week")){
|
|
|
+ String[] weekRange = getWeekRange(checklist.getDate_begin());
|
|
|
+ checklist.setDate_begin(weekRange[0]);
|
|
|
+ checklist.setDate_end(weekRange[1]);
|
|
|
+
|
|
|
+ List<Map> reportData = getReportData(checklist, dataType, null, dept.getOrgNo(), check_category, check_item);
|
|
|
+ list.addAll(reportData);
|
|
|
+ }else {
|
|
|
+ String[] monthRange = getMonthRange(checklist.getDate_begin());
|
|
|
+ checklist.setDate_begin(monthRange[0]);
|
|
|
+ checklist.setDate_end(monthRange[1]);
|
|
|
+ List<Map> reportData = getReportData(checklist, dataType, null, dept.getOrgNo(), check_category, check_item);
|
|
|
+ list.addAll(reportData);
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.data(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Map> getReportData(ChecklistVO checklist, String dataType, String theDay, String orgNo, List<Dict> check_category, List<Dict> check_item){
|
|
|
+ List<Map> list = new ArrayList<>();
|
|
|
+
|
|
|
check_category.forEach(category -> {
|
|
|
check_item.forEach(item -> {
|
|
|
- if (category.getDictKey().contains(dataType) && item.getDictKey().contains(dataType)){
|
|
|
+ if (category.getDictKey().contains(dataType) && item.getDictKey().contains(dataType) && item.getDictKey().contains(category.getDictKey())){
|
|
|
Map row = new HashMap();
|
|
|
- row.put("orgNo", dept.getOrgNo());
|
|
|
+ row.put("orgNo", orgNo);
|
|
|
row.put("type", category.getDictKey());
|
|
|
row.put("item", item.getDictKey());
|
|
|
-// checklist.setCycle(dataType);
|
|
|
+ if (dataType.equals("day")){
|
|
|
+ row.put("checkDate", theDay);
|
|
|
+ }
|
|
|
+
|
|
|
checklist.setType(category.getDictKey());
|
|
|
checklist.setItem(item.getDictKey());
|
|
|
- checklist.setOrgNo(dept.getOrgNo());
|
|
|
- checklist.setIsChecked(1);
|
|
|
- List<ChecklistVO> dlist1 = checklistService.getDataList(checklist);
|
|
|
- checklist.setIsChecked(0);
|
|
|
- List<ChecklistVO> dlist0 = checklistService.getDataList(checklist);
|
|
|
+ checklist.setOrgNo(orgNo);
|
|
|
+// checklist.setIsChecked(1);
|
|
|
+ List<ChecklistVO> dataList = checklistService.getDataList(checklist);
|
|
|
+ int checkedCount = dataList.size();
|
|
|
+ int nocheckCount = checkedCount > 0 ? 0 : 1;
|
|
|
+ if (checkedCount > 0){
|
|
|
+ Checklist one = dataList.get(0);
|
|
|
+ row.put("checkDate", DateUtil.format(one.getCheckDate(), pattern));
|
|
|
+ }
|
|
|
|
|
|
List<ChecklistVO> dlistOver = checklistService.getOverList(checklist);
|
|
|
|
|
|
- row.put("checked", dlist1.size());
|
|
|
- row.put("nocheck", dlist0.size());
|
|
|
+ row.put("checked", checkedCount);
|
|
|
+ row.put("nocheck", nocheckCount);
|
|
|
row.put("over", dlistOver.size());
|
|
|
list.add(row);
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- return R.data(list);
|
|
|
+ return list;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取传入时间的第二天
|
|
|
+ * @param today
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getNextDay(String today){
|
|
|
+ Calendar cd = Calendar.getInstance();
|
|
|
+ cd.setTime(DateUtil.parse(today, pattern));
|
|
|
+ cd.add(Calendar.DATE, 1);
|
|
|
+ String nextDay = DateUtil.format(cd.getTime(), pattern);
|
|
|
+ return nextDay;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算传入时间的相对位移时间,后几天或者前几天
|
|
|
+ * @param theDay
|
|
|
+ * @param interval
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getDay(String theDay, int interval){
|
|
|
+ Calendar cd = Calendar.getInstance();
|
|
|
+ cd.setTime(DateUtil.parse(theDay, pattern));
|
|
|
+ cd.add(Calendar.DATE, interval);
|
|
|
+ String ThatDay = DateUtil.format(cd.getTime(), pattern);
|
|
|
+ return ThatDay;
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 计算两个日期相差天数
|
|
|
+ * @param beginDate
|
|
|
+ * @param endDate
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private long getInterval(String beginDate, String endDate){
|
|
|
+ Date begin = DateUtil.parse(beginDate, pattern);
|
|
|
+ Date end = DateUtil.parse(endDate, pattern);
|
|
|
+ return (end.getTime() - begin.getTime()) / (24 * 60 * 60 * 1000);
|
|
|
+ }
|
|
|
|
|
|
- private String[] getDateRange(){
|
|
|
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ /**
|
|
|
+ * 根据传入时间,算出这周开始日期和结束日期
|
|
|
+ * @param theDay
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String[] getWeekRange(String theDay){
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat(pattern);
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
- cal.setTime(new Date());
|
|
|
+ cal.setTime(DateUtil.parse(theDay, pattern));
|
|
|
int w = cal.get(Calendar.DAY_OF_WEEK) - 1; // 指示一个星期中的某天。
|
|
|
int[] weekDays = { 7, 1, 2, 3, 4, 5, 6 };
|
|
|
int today = weekDays[w];
|
|
|
- int begin = today - 1;
|
|
|
- int end = 6 - today;
|
|
|
+ int begin = today == 7 ? 0 : -today;
|
|
|
+ int end = today == 7 ? 6 : 6 - today;
|
|
|
|
|
|
Calendar beginDate = Calendar.getInstance();
|
|
|
- beginDate.setTime(new Date());
|
|
|
+ beginDate.setTime(DateUtil.parse(theDay, pattern));
|
|
|
Calendar endDate = Calendar.getInstance();
|
|
|
- endDate.setTime(new Date());
|
|
|
+ endDate.setTime(DateUtil.parse(theDay, pattern));
|
|
|
beginDate.add(Calendar.DAY_OF_MONTH, begin);
|
|
|
endDate.add(Calendar.DAY_OF_MONTH, end);
|
|
|
|
|
|
@@ -329,4 +426,22 @@ public class ChecklistController extends BladeController {
|
|
|
return new String[]{beginDateStr, endDateStr};
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据传入时间,算出这个月的开始日期和结束日期
|
|
|
+ * @param theDay
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String[] getMonthRange(String theDay){
|
|
|
+ String[] split = theDay.split("-");
|
|
|
+ String beginDateStr = split[0] + "-" + split[1] + "-" + "01";
|
|
|
+
|
|
|
+ Calendar endDate = Calendar.getInstance();
|
|
|
+ endDate.setTime(DateUtil.parse(theDay, pattern));
|
|
|
+ endDate.add(Calendar.MONTH, 1);
|
|
|
+ endDate.add(Calendar.DATE, -1);
|
|
|
+ String endDateStr = DateUtil.format(endDate.getTime(), pattern);
|
|
|
+
|
|
|
+ return new String[]{beginDateStr, endDateStr};
|
|
|
+ }
|
|
|
+
|
|
|
}
|