fangq 4 vuotta sitten
vanhempi
commit
fc3f1223e2

+ 8 - 8
src/main/java/org/springblade/bank/autodata/controller/AutoDataController.java

@@ -62,7 +62,7 @@ public class AutoDataController extends BladeController {
 	}
 
 	/**
-	 * 分页 
+	 * 分页
 	 */
 	@GetMapping("/list")
 	@ApiOperationSupport(order = 2)
@@ -74,7 +74,7 @@ public class AutoDataController extends BladeController {
 
 
 	/**
-	 * 自定义分页 
+	 * 自定义分页
 	 */
 	@GetMapping("/page")
 	@ApiOperationSupport(order = 3)
@@ -85,7 +85,7 @@ public class AutoDataController extends BladeController {
 	}
 
 	/**
-	 * 新增 
+	 * 新增
 	 */
 	@PostMapping("/save")
 	@ApiOperationSupport(order = 4)
@@ -95,7 +95,7 @@ public class AutoDataController extends BladeController {
 	}
 
 	/**
-	 * 修改 
+	 * 修改
 	 */
 	@PostMapping("/update")
 	@ApiOperationSupport(order = 5)
@@ -105,7 +105,7 @@ public class AutoDataController extends BladeController {
 	}
 
 	/**
-	 * 新增或修改 
+	 * 新增或修改
 	 */
 	@PostMapping("/submit")
 	@ApiOperationSupport(order = 6)
@@ -114,9 +114,9 @@ public class AutoDataController extends BladeController {
 		return R.status(autoDataService.saveOrUpdate(autoData));
 	}
 
-	
+
 	/**
-	 * 删除 
+	 * 删除
 	 */
 	@PostMapping("/remove")
 	@ApiOperationSupport(order = 7)
@@ -125,5 +125,5 @@ public class AutoDataController extends BladeController {
 		return R.status(autoDataService.deleteLogic(Func.toLongList(ids)));
 	}
 
-	
+
 }

+ 18 - 1
src/main/java/org/springblade/bank/autodata/mapper/AutoDataMapper.xml

@@ -47,7 +47,24 @@
 
 
     <select id="selectAutoDataPage" resultMap="autoDataResultMap">
-        select * from zh_auto_data where is_deleted = 0
+        select * from zh_auto_data where is_deleted = 0 and table_id = #{autoData.tableId}
+        <if test="autoData!=null">
+            <if test="autoData.params1!=null">
+                AND params1 like '${autoData.params1}%'
+            </if>
+            <if test="autoData.params2!=null">
+                AND params2 like '${autoData.params2}%'
+            </if>
+            <if test="autoData.params3!=null">
+                AND params3 like '${autoData.params3}%'
+            </if>
+            <if test="autoData.params4!=null">
+                AND params4 like '${autoData.params4}%'
+            </if>
+            <if test="autoData.params5!=null">
+                AND params5 like '${autoData.params5}%'
+            </if>
+        </if>
     </select>
 
 </mapper>

+ 23 - 226
src/main/java/org/springblade/bank/checklist/controller/ChecklistController.java

@@ -17,18 +17,21 @@
 package org.springblade.bank.checklist.controller;
 
 import cn.hutool.json.JSONUtil;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
-import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import lombok.AllArgsConstructor;
-import javax.validation.Valid;
-
 import org.apache.commons.lang.StringUtils;
-import org.springblade.bank.keypwd.entity.KeyPwd;
-import org.springblade.bank.sealhandover.entity.SealHandover;
+import org.springblade.bank.checklist.entity.Checklist;
+import org.springblade.bank.checklist.service.IChecklistService;
+import org.springblade.bank.checklist.vo.ChecklistVO;
+import org.springblade.bank.checklist.wrapper.ChecklistWrapper;
 import org.springblade.bank.userlog.entity.UserLog;
 import org.springblade.bank.userlog.service.IUserLogService;
+import org.springblade.common.utils.CommonUtil;
+import org.springblade.core.boot.ctrl.BladeController;
 import org.springblade.core.mp.support.Condition;
 import org.springblade.core.mp.support.Query;
 import org.springblade.core.secure.BladeUser;
@@ -43,16 +46,11 @@ import org.springblade.modules.system.service.IDeptService;
 import org.springblade.modules.system.service.IDictService;
 import org.springblade.modules.system.service.IUserService;
 import org.springframework.web.bind.annotation.*;
-import org.springframework.web.bind.annotation.RequestParam;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import org.springblade.bank.checklist.entity.Checklist;
-import org.springblade.bank.checklist.vo.ChecklistVO;
-import org.springblade.bank.checklist.wrapper.ChecklistWrapper;
-import org.springblade.bank.checklist.service.IChecklistService;
-import org.springblade.core.boot.ctrl.BladeController;
 
-import java.text.SimpleDateFormat;
-import java.util.*;
+import javax.validation.Valid;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
 
 /**
  * 每日/週/月核對記錄表 控制器
@@ -72,8 +70,6 @@ public class ChecklistController extends BladeController {
 	private final IUserLogService userLogService;
 	private final IDictService dictService;
 
-	private final String pattern = "yyyy-MM-dd";
-
 	/**
 	 * 详情
 	 */
@@ -244,39 +240,39 @@ public class ChecklistController extends BladeController {
 //			checklist.setDate_end(getNextDay(checklist.getDate_end()));
 		}else{
 			// 默认是当天
-			String today = DateUtil.format(DateUtil.now(), pattern);
+			String today = DateUtil.format(DateUtil.now(), CommonUtil.pattern);
 			checklist.setDate_begin(today);
 			checklist.setDate_end(today);
 		}
 
 		String dateBegin = checklist.getDate_begin();
 		String dateEnd = checklist.getDate_end();
-		long days = getInterval(dateBegin, dateEnd);
+		long days = CommonUtil.getInterval(dateBegin, dateEnd);
 
 		String dataType = checklist.getCycle();
 		if (dataType.equals("day")){
 			for (int i = 0; i <= days; i++) {
-				String theDay = getDay(dateBegin, i);
+				String theDay = CommonUtil.getDay(dateBegin, i);
 				// 延长一天,是为了sql可以查询出最后一天的记录
-				String nextDay = getDay(dateBegin, i + 1);
+				String nextDay = CommonUtil.getDay(dateBegin, i + 1);
 				checklist.setDate_begin(theDay);
 				checklist.setDate_end(nextDay);
 
-				List<Map> reportData = getReportData(checklist, dataType, theDay, dept, check_category, check_item);
+				List<Map> reportData = checklistService.getReportData(checklist, dataType, theDay, dept, check_category, check_item);
 				list.addAll(reportData);
 			}
 		}else if (dataType.equals("week")){
-			String[] weekRange = getWeekRange(checklist.getDate_begin());
+			String[] weekRange = CommonUtil.getWeekRange(checklist.getDate_begin());
 			checklist.setDate_begin(weekRange[0]);
 			checklist.setDate_end(weekRange[1]);
 
-			List<Map> reportData = getReportData(checklist, dataType, null, dept, check_category, check_item);
+			List<Map> reportData = checklistService.getReportData(checklist, dataType, null, dept, check_category, check_item);
 			list.addAll(reportData);
 		}else {
-			String[] monthRange = getMonthRange(checklist.getDate_begin());
+			String[] monthRange = CommonUtil.getMonthRange(checklist.getDate_begin());
 			checklist.setDate_begin(monthRange[0]);
 			checklist.setDate_end(monthRange[1]);
-			List<Map> reportData = getReportData(checklist, dataType, null, dept, check_category, check_item);
+			List<Map> reportData = checklistService.getReportData(checklist, dataType, null, dept, check_category, check_item);
 			list.addAll(reportData);
 		}
 
@@ -290,124 +286,10 @@ public class ChecklistController extends BladeController {
 	@ApiOperation(value = "分页", notes = "传入checklist")
 	public R getReport(ChecklistVO checklist) {
 
-		List<Map> list = new ArrayList<>();
-		List<Dict> check_category = dictService.getList("check_category");
-		List<Dict> check_item = dictService.getList("check_item");
-		List<Long> deptChildIds = new ArrayList<>();
-		if (checklist.getOrgNo() == null){
-			Dept dept = deptService.getById(AuthUtil.getDeptId());
-			deptChildIds = deptService.getDeptChildIds(dept.getId());
-		}else {
-			Dept dept = deptService.getByOrgNo(checklist.getOrgNo());
-			deptChildIds.add(dept.getId());
-		}
-
-		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(theDay);
-
-				deptChildIds.forEach(deptId -> {
-					List<Map> reportData = getReportData(checklist, dataType, theDay, deptService.getById(deptId), 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]);
-
-
-			deptChildIds.forEach(deptId -> {
-				List<Map> reportData = getReportData(checklist, dataType, null, deptService.getById(deptId), check_category, check_item);
-				list.addAll(reportData);
-			});
-		}else {
-			String[] monthRange = getMonthRange(checklist.getDate_begin());
-			checklist.setDate_begin(monthRange[0]);
-			checklist.setDate_end(monthRange[1]);
-
-			deptChildIds.forEach(deptId -> {
-				List<Map> reportData = getReportData(checklist, dataType, null, deptService.getById(deptId), check_category, check_item);
-				list.addAll(reportData);
-			});
-
-		}
-
-		return R.data(list);
+		List<Map> reportList = checklistService.getReport(checklist);
+		return R.data(reportList);
 	}
 
-	private List<Map> getReportData(ChecklistVO checklist, String dataType, String theDay, Dept dept, List<Dict> check_category, List<Dict> check_item){
-		List<Map> list = new ArrayList<>();
-		check_category.forEach(category -> {
-			check_item.forEach(item -> {
-				if (category.getIsSealed().equals(0) && item.getIsSealed().equals(0)){
-					if (category.getDictKey().contains(dataType) && item.getDictKey().contains(dataType) && item.getDictKey().contains(category.getDictKey())){
-						if (!dept.getOrgNo().startsWith("999") && !dept.getOrgNo().equals("51614")){
-							Map row = new HashMap();
-							row.put("orgNo", dept.getOrgNo());
-							row.put("deptName", dept.getDeptName());
-							row.put("type", category.getDictKey());
-							row.put("item", item.getDictKey());
-
-							checklist.setType(category.getDictKey());
-							checklist.setItem(item.getDictKey());
-							checklist.setOrgNo(dept.getOrgNo());
-	//						checklist.setIsChecked(1);
-							List<ChecklistVO> dataList = checklistService.getDataList(checklist);
-							int checkedCount = dataList.size();
-							List<ChecklistVO> dlistOver = checklistService.getOverList(checklist);
-							int overCount = dlistOver.size();
-							int nocheckCount = (checkedCount > 0 || overCount > 0) ? 0 : 1;
-							if (checkedCount > 0){
-								Checklist one = dataList.get(0);
-								row.put("checkDate", DateUtil.format(one.getCheckDate(), pattern));
-							}
-							if (overCount > 0){
-								Checklist one = dlistOver.get(0);
-								row.put("checkDate", DateUtil.format(one.getCheckDate(), pattern));
-							}
-
-							if ("day".equals(dataType)){
-								row.put("needCheckDate", theDay);
-							}
-
-							row.put("checked", checkedCount);
-							row.put("nocheck", nocheckCount);
-							row.put("over", dlistOver.size());
-							list.add(row);
-						}
-					}
-				}
-			});
-		});
-
-		return list;
-	}
-
-
 	@GetMapping("/getList")
 	@ApiOperationSupport(order = 3)
 	@ApiOperation(value = "分页", notes = "传入checklist")
@@ -438,89 +320,4 @@ public class ChecklistController extends BladeController {
 		return R.data(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);
-	}
-
-	/**
-	 * 根据传入时间,算出这周开始日期和结束日期
-	 * @param theDay
-	 * @return
-	 */
-	private String[] getWeekRange(String theDay){
-		SimpleDateFormat format = new SimpleDateFormat(pattern);
-		Calendar cal = Calendar.getInstance();
-		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 == 7 ? 0 :  -today;
-		int end = today == 7 ? 6 : 6 - today;
-
-		Calendar beginDate = Calendar.getInstance();
-		beginDate.setTime(DateUtil.parse(theDay, pattern));
-		Calendar endDate = Calendar.getInstance();
-		endDate.setTime(DateUtil.parse(theDay, pattern));
-		beginDate.add(Calendar.DAY_OF_MONTH, begin);
-		endDate.add(Calendar.DAY_OF_MONTH, end);
-
-		String beginDateStr = format.format(beginDate.getTime());
-		String endDateStr = format.format(endDate.getTime());
-		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};
-	}
-
 }

+ 7 - 0
src/main/java/org/springblade/bank/checklist/service/IChecklistService.java

@@ -20,8 +20,11 @@ import org.springblade.bank.checklist.entity.Checklist;
 import org.springblade.bank.checklist.vo.ChecklistVO;
 import org.springblade.core.mp.base.BaseService;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.springblade.modules.system.entity.Dept;
+import org.springblade.modules.system.entity.Dict;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * 每日/週/月核對記錄表 服务类
@@ -47,4 +50,8 @@ public interface IChecklistService extends BaseService<Checklist> {
     List<ChecklistVO> getOverList(ChecklistVO checks);
 
     List<Checklist> getList(ChecklistVO checklist);
+
+    List<Map> getReport(ChecklistVO checklist);
+
+	List<Map> getReportData(ChecklistVO checklist, String dataType, String theDay, Dept dept, List<Dict> check_category, List<Dict> check_item);
 }

+ 135 - 0
src/main/java/org/springblade/bank/checklist/service/impl/ChecklistServiceImpl.java

@@ -17,16 +17,27 @@
 package org.springblade.bank.checklist.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import lombok.AllArgsConstructor;
+import org.apache.commons.lang.StringUtils;
 import org.springblade.bank.checklist.entity.Checklist;
 import org.springblade.bank.checklist.vo.ChecklistVO;
 import org.springblade.bank.checklist.mapper.ChecklistMapper;
 import org.springblade.bank.checklist.service.IChecklistService;
+import org.springblade.common.utils.CommonUtil;
 import org.springblade.core.mp.base.BaseServiceImpl;
 import org.springblade.core.secure.utils.AuthUtil;
+import org.springblade.core.tool.utils.DateUtil;
+import org.springblade.modules.system.entity.Dept;
+import org.springblade.modules.system.entity.Dict;
+import org.springblade.modules.system.service.IDeptService;
+import org.springblade.modules.system.service.IDictService;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 每日/週/月核對記錄表 服务实现类
@@ -35,8 +46,13 @@ import java.util.List;
  * @since 2021-08-13
  */
 @Service
+@AllArgsConstructor
 public class ChecklistServiceImpl extends BaseServiceImpl<ChecklistMapper, Checklist> implements IChecklistService {
 
+	private final String pattern = "yyyy-MM-dd";
+	private final IDictService dictService;
+	private final IDeptService deptService;
+
 	@Override
 	public IPage<ChecklistVO> selectChecklistPage(IPage<ChecklistVO> page, ChecklistVO checklist) {
 		return page.setRecords(baseMapper.selectChecklistPage(page, checklist));
@@ -63,4 +79,123 @@ public class ChecklistServiceImpl extends BaseServiceImpl<ChecklistMapper, Check
 		return baseMapper.selectChecklistPage(checklist);
 	}
 
+	@Override
+	public List<Map> getReport(ChecklistVO checklist) {
+		List<Map> list = new ArrayList<>();
+		List<Dict> check_category = dictService.getList("check_category");
+		List<Dict> check_item = dictService.getList("check_item");
+		List<Long> deptChildIds = new ArrayList<>();
+		if (checklist.getOrgNo() == null){
+			Dept dept = deptService.getById(AuthUtil.getDeptId());
+			deptChildIds = deptService.getDeptChildIds(dept.getId());
+		}else {
+			Dept dept = deptService.getByOrgNo(checklist.getOrgNo());
+			deptChildIds.add(dept.getId());
+		}
+
+		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 = CommonUtil.getInterval(dateBegin, dateEnd);
+
+		String dataType = checklist.getCycle();
+		if (dataType.equals("day")){
+			for (int i = 0; i <= days; i++) {
+				String theDay = CommonUtil.getDay(dateBegin, i);
+				// 延长一天,是为了sql可以查询出最后一天的记录
+//				String nextDay = getDay(dateBegin, i + 1);
+				checklist.setDate_begin(theDay);
+				checklist.setDate_end(theDay);
+
+				deptChildIds.forEach(deptId -> {
+					List<Map> reportData = getReportData(checklist, dataType, theDay, deptService.getById(deptId), check_category, check_item);
+					list.addAll(reportData);
+				});
+			}
+		}else if (dataType.equals("week")){
+			String[] weekRange = CommonUtil.getWeekRange(checklist.getDate_begin());
+			checklist.setDate_begin(weekRange[0]);
+			checklist.setDate_end(weekRange[1]);
+
+
+			deptChildIds.forEach(deptId -> {
+				List<Map> reportData = getReportData(checklist, dataType, null, deptService.getById(deptId), check_category, check_item);
+				list.addAll(reportData);
+			});
+		}else {
+			String[] monthRange = CommonUtil.getMonthRange(checklist.getDate_begin());
+			checklist.setDate_begin(monthRange[0]);
+			checklist.setDate_end(monthRange[1]);
+
+			deptChildIds.forEach(deptId -> {
+				List<Map> reportData = getReportData(checklist, dataType, null, deptService.getById(deptId), check_category, check_item);
+				list.addAll(reportData);
+			});
+
+		}
+		return list;
+	}
+
+	@Override
+	public List<Map> getReportData(ChecklistVO checklist, String dataType, String theDay, Dept dept, List<Dict> check_category, List<Dict> check_item){
+		List<Map> list = new ArrayList<>();
+		check_category.forEach(category -> {
+			check_item.forEach(item -> {
+				if (category.getIsSealed().equals(0) && item.getIsSealed().equals(0)){
+					if (category.getDictKey().contains(dataType) && item.getDictKey().contains(dataType) && item.getDictKey().contains(category.getDictKey())){
+						if (!dept.getOrgNo().startsWith("999") && !dept.getOrgNo().equals("51614")){
+							Map row = new HashMap();
+							row.put("orgNo", dept.getOrgNo());
+							row.put("deptName", dept.getDeptName());
+							row.put("type", category.getDictKey());
+							row.put("item", item.getDictKey());
+
+							checklist.setType(category.getDictKey());
+							checklist.setItem(item.getDictKey());
+							checklist.setOrgNo(dept.getOrgNo());
+							//						checklist.setIsChecked(1);
+							List<ChecklistVO> dataList = this.getDataList(checklist);
+							int checkedCount = dataList.size();
+							List<ChecklistVO> dlistOver = this.getOverList(checklist);
+							int overCount = dlistOver.size();
+							int nocheckCount = (checkedCount > 0 || overCount > 0) ? 0 : 1;
+							if (checkedCount > 0){
+								Checklist one = dataList.get(0);
+								row.put("checkDate", DateUtil.format(one.getCheckDate(), pattern));
+							}
+							if (overCount > 0){
+								Checklist one = dlistOver.get(0);
+								row.put("checkDate", DateUtil.format(one.getCheckDate(), pattern));
+							}
+
+							if ("day".equals(dataType)){
+								row.put("needCheckDate", theDay);
+							}
+
+							row.put("checked", checkedCount);
+							row.put("nocheck", nocheckCount);
+							row.put("over", dlistOver.size());
+							list.add(row);
+						}
+					}
+				}
+			});
+		});
+
+		return list;
+	}
+
 }

+ 116 - 0
src/main/java/org/springblade/common/utils/CommonUtil.java

@@ -16,6 +16,12 @@
  */
 package org.springblade.common.utils;
 
+import org.springblade.core.tool.utils.DateUtil;
+
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+
 /**
  * 通用工具类
  *
@@ -23,4 +29,114 @@ package org.springblade.common.utils;
  */
 public class CommonUtil {
 
+	public static final String pattern = "yyyy-MM-dd";
+
+	/**
+	 * 获取传入时间的第二天
+	 * @param today
+	 * @return
+	 */
+	public static 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
+	 */
+	public static 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
+	 */
+	public static 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);
+	}
+
+	/**
+	 * 判断日期是否为周五
+	 * @param theDay
+	 * @return
+	 */
+	public static boolean isWeekLastDay(String theDay){
+		Calendar cal = Calendar.getInstance();
+		cal.setTime(DateUtil.parse(theDay, pattern));
+		int w = cal.get(Calendar.DAY_OF_WEEK) - 1; // 指示一个星期中的某天。
+		int[] weekDays = { 7, 1, 2, 3, 4, 5, 6 };
+		return weekDays[w] == 5;
+	}
+
+	/**
+	 * 根据传入时间,算出这周开始日期和结束日期
+	 * @param theDay
+	 * @return
+	 */
+	public static String[] getWeekRange(String theDay){
+		SimpleDateFormat format = new SimpleDateFormat(pattern);
+		Calendar cal = Calendar.getInstance();
+		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 == 7 ? 0 :  -today;
+		int end = today == 7 ? 6 : 6 - today;
+
+		Calendar beginDate = Calendar.getInstance();
+		beginDate.setTime(DateUtil.parse(theDay, pattern));
+		Calendar endDate = Calendar.getInstance();
+		endDate.setTime(DateUtil.parse(theDay, pattern));
+		beginDate.add(Calendar.DAY_OF_MONTH, begin);
+		endDate.add(Calendar.DAY_OF_MONTH, end);
+
+		String beginDateStr = format.format(beginDate.getTime());
+		String endDateStr = format.format(endDate.getTime());
+		return new String[]{beginDateStr, endDateStr};
+	}
+
+	/**
+	 * 根据传入时间,算出这个月的开始日期和结束日期
+	 * @param theDay
+	 * @return
+	 */
+	public static 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));
+		int actualMaximum = endDate.getActualMaximum(Calendar.DAY_OF_MONTH);
+		String endDateStr = split[0] + "-" + split[1] + "-" + actualMaximum;
+
+		return new String[]{beginDateStr, endDateStr};
+	}
+
+	/**
+	 * 判断日期是否为周五
+	 * @param theDay
+	 * @return
+	 */
+	public static boolean isMonthLastDay(String theDay){
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(DateUtil.parse(theDay, pattern));
+		return calendar.get(Calendar.DAY_OF_MONTH) == calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
+	}
+
+
 }

+ 3 - 2
src/main/java/org/springblade/modules/desk/service/INoticeService.java

@@ -24,11 +24,10 @@ import org.springblade.bank.message.entity.Message;
 import org.springblade.bank.postchange.entity.PostChange;
 import org.springblade.bank.returns.entity.Returns;
 import org.springblade.bank.sealhandover.entity.SealHandover;
-import org.springblade.core.datascope.annotation.DataAuth;
-import org.springblade.core.datascope.enums.DataScopeEnum;
 import org.springblade.core.mp.base.BaseService;
 import org.springblade.modules.desk.entity.Notice;
 import org.springblade.modules.desk.vo.NoticeVO;
+import org.springblade.modules.system.entity.Dept;
 
 import java.util.List;
 
@@ -66,4 +65,6 @@ public interface INoticeService extends BaseService<Notice> {
 	boolean sendPostChangeNotice(PostChange postChange, boolean isEdit);
 
 	boolean sendGoodsUseNotice(GoodsUse goodsUse, boolean isEdit);
+
+	boolean sendChecklistNotice(String cycle, Dept dept);
 }

+ 39 - 0
src/main/java/org/springblade/modules/desk/service/impl/NoticeServiceImpl.java

@@ -19,6 +19,7 @@ package org.springblade.modules.desk.service.impl;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import lombok.AllArgsConstructor;
 import org.springblade.bank.cardswallow.entity.CardSwallow;
+import org.springblade.bank.checklist.vo.ChecklistVO;
 import org.springblade.bank.goodsuse.entity.GoodsUse;
 import org.springblade.bank.keypwd.entity.KeyPwd;
 import org.springblade.bank.message.entity.Message;
@@ -37,9 +38,11 @@ import org.springblade.modules.desk.mapper.NoticeMapper;
 import org.springblade.modules.desk.service.INoticeService;
 import org.springblade.modules.desk.vo.NoticeVO;
 import org.springblade.modules.system.entity.Dept;
+import org.springblade.modules.system.entity.Role;
 import org.springblade.modules.system.entity.User;
 import org.springblade.modules.system.service.IDeptService;
 import org.springblade.modules.system.service.IDictService;
+import org.springblade.modules.system.service.IRoleService;
 import org.springblade.modules.system.service.IUserService;
 import org.springframework.stereotype.Service;
 
@@ -59,6 +62,7 @@ public class NoticeServiceImpl extends BaseServiceImpl<NoticeMapper, Notice> imp
 	private final IUserService userService;
 	private final IDictService dictService;
 	private final IDeptService deptService;
+	private final IRoleService roleService;
 
 	@Override
 	public IPage<NoticeVO> selectNoticePage(IPage<NoticeVO> page, NoticeVO notice) {
@@ -233,6 +237,41 @@ public class NoticeServiceImpl extends BaseServiceImpl<NoticeMapper, Notice> imp
 		return sendNotice(notice);
 	}
 
+	@Override
+	public boolean sendChecklistNotice(String cycle, Dept dept) {
+		List<String> deptIds = new ArrayList<>();
+		Dept parentDept = deptService.getById(dept.getParentId());
+		if (parentDept.getOrgNo().startsWith("999")){
+			deptIds.add(parentDept.getId() + "");
+		}
+		deptIds.add(dept.getId() + "");
+		List<Role> roleList = roleService.getRolesByAlias("manager");
+		List<String> roleIds = roleList.stream().map(role -> role.getId()+"").collect(Collectors.toList());
+		List<User> users = userService.getUsersByDeptIdsRoleIds(deptIds, roleIds);
+		List<String> userIds = users.stream().map(user -> user.getId() + "").collect(Collectors.toList());
+		List<String> userNames = users.stream().map(user -> user.getName() + "").collect(Collectors.toList());
+		if (users.size() > 0){
+			System.out.println(dept.getDeptName() + ":" + StringUtil.join(userNames));
+		}
+
+		String checkType = "每月";
+		if (cycle.equals("day")){
+			checkType = "每日";
+		}else if (cycle.equals("week")){
+			checkType = "每週";
+		}
+
+		String title = dept.getDeptName() + "尚未完成" + checkType + "核對工作";
+		/*Notice notice = new Notice();
+		notice.setTitle(title);
+		notice.setBusinessType("checklist");
+		notice.setDeptId(dept.getId() + "");
+		notice.setRoleId(StringUtil.join(roleIds));
+		notice.setTargetIds(StringUtil.join(userIds));
+		sendNotice(notice);*/
+		return true;
+	}
+
 	private String getCategoryName(KeyPwd keyPwd){
 		String category = keyPwd.getCategory();
 		String value = dictService.getValue("key_type", category);

+ 1 - 0
src/main/java/org/springblade/modules/system/service/IRoleService.java

@@ -102,4 +102,5 @@ public interface IRoleService extends IService<Role> {
 	List<RoleVO> search(String roleName, Long parentId);
 
 
+	List<Role> getRolesByAlias(String roleAlias);
 }

+ 5 - 0
src/main/java/org/springblade/modules/system/service/impl/RoleServiceImpl.java

@@ -17,6 +17,7 @@
 package org.springblade.modules.system.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -214,4 +215,8 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
 		return RoleWrapper.build().listNodeVO(roleList);
 	}
 
+	@Override
+	public List<Role> getRolesByAlias(String roleAlias) {
+		return baseMapper.selectList(new QueryWrapper<>(new Role()).lambda().eq(Role::getRoleAlias, roleAlias));
+	}
 }

+ 1 - 1
src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java

@@ -597,7 +597,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implement
 		roleIds.forEach(ids -> {
 			List<User> usersByRoleId = getUsersByRoleId(ids);
 			usersByRoleId.forEach(item -> {
-				if (!isUserInList(item.getId(), list)){
+				if (!isUserInList(item.getId(), list) && deptIds.contains(item.getDeptId())){
 					list.add(item);
 				}
 			});

+ 86 - 1
src/main/java/org/springblade/modules/timer/TimeTask.java

@@ -1,4 +1,89 @@
 package org.springblade.modules.timer;
 
-public class TimeTask {
+
+import lombok.AllArgsConstructor;
+import org.springblade.bank.checklist.service.IChecklistService;
+import org.springblade.bank.checklist.vo.ChecklistVO;
+import org.springblade.common.utils.CommonUtil;
+import org.springblade.core.boot.ctrl.BladeController;
+import org.springblade.core.tool.utils.DateUtil;
+import org.springblade.modules.desk.service.INoticeService;
+import org.springblade.modules.system.entity.Dept;
+import org.springblade.modules.system.service.IDeptService;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+import java.util.Map;
+
+
+@Configuration      //1.主要用于标记配置类,兼备Component的效果。
+@EnableScheduling   // 2.开启定时任务
+@RestController
+@AllArgsConstructor
+public class TimeTask extends BladeController {
+
+	private final IDeptService deptService;
+	private final IChecklistService checklistService;
+	private final INoticeService noticeService;
+
+	//3.添加定时任务
+	@Scheduled(cron = "0 0 11 * * ?")
+//	@Scheduled(cron = "0/10 * * * * ?")
+	//或直接指定时间间隔,例如:5秒
+	//@Scheduled(fixedRate=5000)
+	private void configureTasks() {
+		System.err.println("执行静态定时任务时间: " + DateUtil.format(DateUtil.now(), "yyyy-MM-dd HH:mm:ss"));
+
+		//1、每天
+		dayTask();
+
+		//2、每周
+		if (CommonUtil.isWeekLastDay(DateUtil.format(DateUtil.now(), CommonUtil.pattern))){
+			weekTask();
+		}
+		//3、每月
+		if (CommonUtil.isMonthLastDay(DateUtil.format(DateUtil.now(), CommonUtil.pattern))){
+			monthTask();
+		}
+
+	}
+
+	private void checklistTask(String cycle){
+		Dept yybDept = deptService.getByOrgNo("51614");
+		//1、每天
+		List<Long> deptChildIds = deptService.getDeptChildIds(yybDept.getId());
+		deptChildIds.forEach(deptId -> {
+			Dept dept = deptService.getById(deptId);
+			ChecklistVO checklist = new ChecklistVO();
+			checklist.setCycle(cycle);
+			checklist.setOrgNo(dept.getOrgNo());
+			List<Map> dayReport = checklistService.getReport(checklist);
+			boolean flag = false;
+			for (int i = 0; i < dayReport.size(); i++) {
+				Map map = dayReport.get(i);
+				int nocheck = Integer.parseInt(map.get("nocheck").toString());
+				flag = flag || nocheck >= 1;
+			}
+			if (flag){
+				//給支行管理層發送行信通知
+				noticeService.sendChecklistNotice(checklist.getCycle(), dept);
+			}
+		});
+
+	}
+
+	private void dayTask(){
+		checklistTask("day");
+	}
+
+	private void weekTask(){
+		checklistTask("week");
+	}
+
+	private void monthTask(){
+		checklistTask("month");
+	}
 }