|
@@ -1,6 +1,8 @@
|
|
|
package org.jeecg.modules.geke.userShift.controller;
|
|
|
|
|
|
+import java.lang.reflect.Field;
|
|
|
import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.io.IOException;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
@@ -11,7 +13,9 @@ import org.jeecg.common.api.vo.Result;
|
|
|
import org.jeecg.common.system.query.QueryGenerator;
|
|
|
import org.jeecg.common.aspect.annotation.AutoLog;
|
|
|
import org.jeecg.common.util.DateUtils;
|
|
|
+import org.jeecg.common.util.ImportExcelUtil;
|
|
|
import org.jeecg.common.util.oConvertUtils;
|
|
|
+import org.jeecg.modules.geke.statutoryleave.service.IStatutoryLeaveService;
|
|
|
import org.jeecg.modules.geke.userShift.entity.UserShift;
|
|
|
import org.jeecg.modules.geke.userShift.entity.UserShiftExcel;
|
|
|
import org.jeecg.modules.geke.userShift.entity.UserShiftVo;
|
|
@@ -27,6 +31,7 @@ import org.jeecgframework.poi.excel.entity.ExportParams;
|
|
|
import org.jeecgframework.poi.excel.entity.ImportParams;
|
|
|
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
|
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
@@ -49,6 +54,9 @@ import io.swagger.annotations.ApiOperation;
|
|
|
public class UserShiftController extends JeecgController<UserShift, IUserShiftService> {
|
|
|
@Autowired
|
|
|
private IUserShiftService userShiftService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IStatutoryLeaveService statutoryLeaveService;
|
|
|
|
|
|
/**
|
|
|
* 分页列表查询
|
|
@@ -175,34 +183,35 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
return super.exportXls(request, userShift, UserShift.class, "员工排班");
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 通过excel导入数据
|
|
|
- *
|
|
|
- * @param request
|
|
|
- * @param response
|
|
|
- * @return
|
|
|
- */
|
|
|
- @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
|
|
- public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
|
|
- MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
|
- Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
|
|
- for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
|
|
- MultipartFile file = entity.getValue();// 获取上传文件对象
|
|
|
- ImportParams params = new ImportParams();
|
|
|
- params.setTitleRows(2);
|
|
|
- params.setHeadRows(1);
|
|
|
- params.setNeedSave(true);
|
|
|
- try {
|
|
|
- List<UserShift>ls=new ArrayList<>();
|
|
|
- List<UserShiftExcel> list = ExcelImportUtil.importExcel(file.getInputStream(), UserShiftExcel.class, params);
|
|
|
- for(UserShiftExcel o:list){
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过excel导入数据
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
|
|
+ public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
|
+ Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
|
|
+ for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
|
|
+ MultipartFile file = entity.getValue();// 获取上传文件对象
|
|
|
+ ImportParams params = new ImportParams();
|
|
|
+ params.setTitleRows(2);
|
|
|
+ params.setHeadRows(1);
|
|
|
+ params.setNeedSave(true);
|
|
|
+ try {
|
|
|
+ List<UserShift>ls=new ArrayList<>();
|
|
|
+ List<UserShiftExcel> list = ExcelImportUtil.importExcel(file.getInputStream(), UserShiftExcel.class, params);
|
|
|
+ for(UserShiftExcel o:list){
|
|
|
if (oConvertUtils.isNotEmpty(o.getWorkNo())&&oConvertUtils.isNotEmpty(o.getMoth())){
|
|
|
- String userId = userShiftService.getUserId(o.getWorkNo());
|
|
|
- userShiftService.deleteUserShift(userId,o.getMoth()+"-01");
|
|
|
+ Map<String,Object> userId = userShiftService.getUserId(o.getWorkNo());
|
|
|
+ userShiftService.deleteUserShift(userId.get("id").toString(),o.getMoth()+"-01");
|
|
|
if (oConvertUtils.isNotEmpty(userId)) {
|
|
|
if (oConvertUtils.isNotEmpty(o.getA1())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-01","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA1());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA1().equals("休")) {
|
|
@@ -215,7 +224,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA2())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-02","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA2());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA2().equals("休")) {
|
|
@@ -228,7 +237,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA3())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-03","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA3());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA3().equals("休")) {
|
|
@@ -241,7 +250,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA4())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-04","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA4());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA4().equals("休")) {
|
|
@@ -254,7 +263,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA5())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-05","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA5());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA5().equals("休")) {
|
|
@@ -267,7 +276,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA6())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-06","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA6());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA6().equals("休")) {
|
|
@@ -280,7 +289,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA7())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-07","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA7());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA7().equals("休")) {
|
|
@@ -293,7 +302,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA8())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-08","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA8());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA8().equals("休")) {
|
|
@@ -306,7 +315,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA9())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-09","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA9());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA9().equals("休")) {
|
|
@@ -319,7 +328,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA10())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-10","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA10());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA10().equals("休")) {
|
|
@@ -332,7 +341,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA11())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-11","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA11());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA11().equals("休")) {
|
|
@@ -345,7 +354,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA12())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-12","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA12());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA12().equals("休")) {
|
|
@@ -358,7 +367,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA13())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-13","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA13());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA13().equals("休")) {
|
|
@@ -371,7 +380,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA14())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-14","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA14());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA14().equals("休")) {
|
|
@@ -384,7 +393,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA15())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-15","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA15());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA15().equals("休")) {
|
|
@@ -397,7 +406,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA16())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-16","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA16());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA16().equals("休")) {
|
|
@@ -410,7 +419,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA17())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-17","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA17());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA17().equals("休")) {
|
|
@@ -423,7 +432,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA18())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-18","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA18());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA18().equals("休")) {
|
|
@@ -436,7 +445,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA19())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-19","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA19());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA19().equals("休")) {
|
|
@@ -449,7 +458,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA20())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-20","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA20());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA20().equals("休")) {
|
|
@@ -462,7 +471,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA21())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-21","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA21());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA21().equals("休")) {
|
|
@@ -475,7 +484,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA22())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-22","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA22());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA22().equals("休")) {
|
|
@@ -488,7 +497,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA23())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-23","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA23());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA23().equals("休")) {
|
|
@@ -501,7 +510,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA23())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-23","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA23());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA23().equals("休")) {
|
|
@@ -514,7 +523,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA24())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-24","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA24());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA24().equals("休")) {
|
|
@@ -527,7 +536,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA25())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-25","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA25());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA25().equals("休")) {
|
|
@@ -540,7 +549,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA26())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-26","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA26());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA26().equals("休")) {
|
|
@@ -553,7 +562,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA27())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-27","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA27());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA27().equals("休")) {
|
|
@@ -566,7 +575,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA28())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-28","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA28());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA28().equals("休")) {
|
|
@@ -579,7 +588,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA30())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-30","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA30());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA30().equals("休")) {
|
|
@@ -592,7 +601,7 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
ls.add(u);
|
|
|
}if (oConvertUtils.isNotEmpty(o.getA31())) {
|
|
|
UserShift u = new UserShift();
|
|
|
- u.setUserId(userId);
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
u.setShiftDate(DateUtils.parseDate(o.getMoth()+"-31","yyyy-MM-dd"));
|
|
|
String shiftId = userShiftService.getShiftId(o.getA31());
|
|
|
if (oConvertUtils.isNotEmpty(shiftId)&&!o.getA31().equals("休")) {
|
|
@@ -606,17 +615,193 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
+ if (ls.size()>0){
|
|
|
+ userShiftService.saveBatch(ls);
|
|
|
+ }
|
|
|
+ //update-begin-author:taoyan date:20190528 for:批量插入数据
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ //400条 saveBatch消耗时间1592毫秒 循环插入消耗时间1947毫秒
|
|
|
+ //1200条 saveBatch消耗时间3687毫秒 循环插入消耗时间5212毫秒
|
|
|
+ log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
|
|
|
+ //update-end-author:taoyan date:20190528 for:批量插入数据
|
|
|
+ return Result.ok("文件导入成功!数据行数:" + ls.size());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ return Result.error("文件导入失败:" + e.getMessage());
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ file.getInputStream().close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result.error("文件导入失败!");
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 通过excel导入数据
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ /* @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
|
|
+ public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
+ MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
|
+ Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
|
|
+ int index=0;
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
|
|
|
+ SimpleDateFormat sd = new SimpleDateFormat("dd");
|
|
|
+ List<UserShift>ls=new ArrayList<>();
|
|
|
+ List<String>errs=new ArrayList<>();
|
|
|
+ List<String>us=new ArrayList<>();
|
|
|
+ for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
|
|
+ MultipartFile file = entity.getValue();// 获取上传文件对象
|
|
|
+ ImportParams params = new ImportParams();
|
|
|
+ params.setTitleRows(2);
|
|
|
+ params.setHeadRows(1);
|
|
|
+ params.setNeedSave(true);
|
|
|
+ try {
|
|
|
+ List<UserShiftExcel> list = ExcelImportUtil.importExcel(file.getInputStream(), UserShiftExcel.class, params);
|
|
|
+ for(UserShiftExcel o:list){
|
|
|
+ index++;
|
|
|
+ if (oConvertUtils.isNotEmpty(o.getWorkNo())&&oConvertUtils.isNotEmpty(o.getMoth())){
|
|
|
+ Map<String,Object> userId = userShiftService.getUserId(o.getWorkNo());
|
|
|
+ if (userId.size()>0) {
|
|
|
+ us.add(userId.get("id").toString()+","+o.getMoth() + "-01");
|
|
|
+ Map<String, Object> dataMap = objectToMap(o);
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(DateUtils.parseDate(o.getMoth() + "-01", "yyyy-MM-dd"));
|
|
|
+ int actualMaximum = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
|
|
|
+ for (int i = 1; i <= actualMaximum; i++) {//循环获取时间月份的总天数
|
|
|
+ List<String> lst = new ArrayList<>();
|
|
|
+ Integer sum = 0;
|
|
|
+ Integer xsum = 0;
|
|
|
+ int day = DateUtils.parseDate(o.getMoth() + "-" + i, "yyyy-MM-dd").getDay();
|
|
|
+ if (DateUtils.parseDate(o.getMoth() + "-" + i, "yyyy-MM-dd").getDay() == 1) {
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, 0));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, 1));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, 2));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, 3));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, 4));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, 5));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, 6));
|
|
|
+ } else if (DateUtils.parseDate(o.getMoth() + "-" + i, "yyyy-MM-dd").getDay() == 2) {
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, -1));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, 0));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, 1));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, 2));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, 3));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, 4));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, 5));
|
|
|
+
|
|
|
+ } else if (DateUtils.parseDate(o.getMoth() + "-" + i, "yyyy-MM-dd").getDay() == 3) {
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, -2));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, -1));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, 0));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, 1));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, 2));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, 3));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, 4));
|
|
|
+
|
|
|
+ } else if (DateUtils.parseDate(o.getMoth() + "-" + i, "yyyy-MM-dd").getDay() == 4) {
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, -3));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, -2));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, -1));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, 0));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, 1));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, 2));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, 3));
|
|
|
+ } else if (DateUtils.parseDate(o.getMoth() + "-" + i, "yyyy-MM-dd").getDay() == 5) {
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, -4));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, -3));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, -2));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, -1));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, 0));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, 1));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, 2));
|
|
|
+
|
|
|
+ } else if (DateUtils.parseDate(o.getMoth() + "-" + i, "yyyy-MM-dd").getDay() == 6) {
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, -5));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, -4));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, -3));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, -2));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, -1));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, 0));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, 1));
|
|
|
+
|
|
|
+ } else if (DateUtils.parseDate(o.getMoth() + "-" + i, "yyyy-MM-dd").getDay() == 0) {
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, -6));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, -5));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, -4));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, -3));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, -2));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, -1));
|
|
|
+ lst.add(this.getDay(o.getMoth() + "-" + i, 0));
|
|
|
+ }
|
|
|
+ List<String> dates = new ArrayList<>();
|
|
|
+ List<String> it = new ArrayList<>();
|
|
|
+ for (int is = 0; is < lst.size(); is++) {
|
|
|
+ if (!sdf.format(DateUtils.parseDate(lst.get(is), "yyyy-MM-dd")).equals(sdf.format(DateUtils.parseDate(o.getMoth() + "-" + i, "yyyy-MM-dd")))) {
|
|
|
+ dates.add(lst.get(is));
|
|
|
+ it.add(lst.get(is));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ lst.removeAll(it);
|
|
|
+ if (dates.size() > 0) {
|
|
|
+ Map<String, Integer> map = userShiftService.shiftCount(dates, userId.get("id").toString());
|
|
|
+ sum += map.get("count");
|
|
|
+ xsum += map.get("counts");
|
|
|
+ }
|
|
|
+ for (String s : lst) {
|
|
|
+ List<String> leavs = statutoryLeaveService.getList(s);
|
|
|
+ Object os = dataMap.get("a" + s.split("-")[1]);
|
|
|
+ if (os != null && os.equals("法") && leavs == null) {
|
|
|
+ errs.add("第" + index + "行,排班有误");
|
|
|
+ break;
|
|
|
+ } else if (os != null) {
|
|
|
+ if (!os.equals("休")) {
|
|
|
+ xsum++;
|
|
|
+ } else {
|
|
|
+ sum++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (userId.get("category").equals("106")) {
|
|
|
+ if (xsum > 6 || sum > 1) {
|
|
|
+ errs.add("第" + index + "行,排班有误");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (xsum > 5 || sum > 2) {
|
|
|
+ errs.add("第" + index + "行,排班有误");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (oConvertUtils.isNotEmpty(dataMap.get("a" + i))) {
|
|
|
+ UserShift u = new UserShift();
|
|
|
+ u.setUserId(userId.get("id").toString());
|
|
|
+ u.setShiftDate(DateUtils.parseDate(o.getMoth() + "-" + i, "yyyy-MM-dd"));
|
|
|
+ if (oConvertUtils.isNotEmpty(dataMap.get("a" + i)) && !dataMap.get("a" + i).equals("休") && !dataMap.get("a" + i).equals("法")) {
|
|
|
+ String shiftId = userShiftService.getShiftId(dataMap.get("a" + i).toString());
|
|
|
+ if (oConvertUtils.isNotEmpty(shiftId)) {
|
|
|
+ u.setShiftId(shiftId);
|
|
|
+ }
|
|
|
+ } else if (oConvertUtils.isNotEmpty(dataMap.get("a" + i)) && dataMap.get("a" + i).equals("法")) {
|
|
|
+ u.setShiftId("1");
|
|
|
+ } else if (oConvertUtils.isNotEmpty(dataMap.get("a" + i)) && dataMap.get("a" + i).equals("休")) {
|
|
|
+ u.setShiftId("0");
|
|
|
+ }
|
|
|
+ ls.add(u);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- if (ls.size()>0){
|
|
|
- userShiftService.saveBatch(ls);
|
|
|
- }
|
|
|
- //update-begin-author:taoyan date:20190528 for:批量插入数据
|
|
|
- long start = System.currentTimeMillis();
|
|
|
- //400条 saveBatch消耗时间1592毫秒 循环插入消耗时间1947毫秒
|
|
|
- //1200条 saveBatch消耗时间3687毫秒 循环插入消耗时间5212毫秒
|
|
|
- log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
|
|
|
- //update-end-author:taoyan date:20190528 for:批量插入数据
|
|
|
- return Result.ok("文件导入成功!数据行数:" + ls.size());
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
log.error(e.getMessage(), e);
|
|
|
return Result.error("文件导入失败:" + e.getMessage());
|
|
@@ -628,8 +813,17 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return Result.error("文件导入失败!");
|
|
|
- }
|
|
|
+
|
|
|
+ if (errs.size()<1){
|
|
|
+ if (us.size()>0) {
|
|
|
+ for (String u : us) {
|
|
|
+ userShiftService.deleteUserShift(u.split(",")[0], u.split(",")[1]);
|
|
|
+ }
|
|
|
+ userShiftService.saveBatch(ls);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result.error("文件导入失败");
|
|
|
+ }*/
|
|
|
|
|
|
|
|
|
@GetMapping(value = "/UserShiftType")
|
|
@@ -645,15 +839,28 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
|
|
|
}
|
|
|
|
|
|
|
|
|
- public String getDay(String date,Integer day){
|
|
|
- Date today = new Date(date);
|
|
|
+ public String getDay(String date,Integer day) throws ParseException {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
|
|
|
+ Date today = DateUtils.parseDate(date, "yyyy-MM-dd");
|
|
|
Long targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
|
|
|
today.setTime(targetday_milliseconds); //注意,这行是关键代码
|
|
|
- int tYear = today.getYear();
|
|
|
int tMonth = today.getMonth() + 1;
|
|
|
int tDate = today.getDate();
|
|
|
- return tYear + "-" + tMonth + "-" + tDate;
|
|
|
+ return sdf.format(today)+ "-" + tMonth + "-" + tDate;
|
|
|
}
|
|
|
|
|
|
+ public static Map<String, Object> objectToMap(Object object){
|
|
|
+ Map<String,Object> dataMap = new HashMap<>();
|
|
|
+ Class<?> clazz = object.getClass();
|
|
|
+ for (Field field : clazz.getDeclaredFields()) {
|
|
|
+ try {
|
|
|
+ field.setAccessible(true);
|
|
|
+ dataMap.put(field.getName(),field.get(object));
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return dataMap;
|
|
|
+ }
|
|
|
|
|
|
}
|