|
@@ -349,6 +349,147 @@ public class WorkPersonSchedulingController {
|
|
|
return dataMap;
|
|
|
}
|
|
|
|
|
|
+ @ApiOperation(value="查询后勤人员排班")
|
|
|
+ @RequestMapping(value = "findHqScheduling",method = RequestMethod.POST)
|
|
|
+ public Map<String,Object> findHqScheduling(
|
|
|
+ @RequestParam(value="personName",defaultValue="") String personName,
|
|
|
+ @RequestParam(value="queryMonth",defaultValue="") String queryMonth,
|
|
|
+ @RequestParam(value="companyId",defaultValue="") String companyId,
|
|
|
+ @RequestParam(value="subordinate",defaultValue="false") Boolean subordinate,
|
|
|
+ @RequestParam(name="pageIndex",defaultValue = "1") int pageIndex,
|
|
|
+ @RequestParam(name="pageSize",defaultValue = "10") int pageSize,
|
|
|
+ @RequestAttribute String subject) throws Exception{
|
|
|
+
|
|
|
+ //当前用户ID
|
|
|
+ System.out.println(subject);
|
|
|
+ Map<String,Object> dataMap = new HashMap<>();
|
|
|
+ try{
|
|
|
+ Map<String,Object> searchParams = new HashMap<>();
|
|
|
+ if (StringUtils.isNotEmpty(personName)) {
|
|
|
+ searchParams.put("name","%" + personName + "%");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(queryMonth)) {
|
|
|
+ searchParams.put("queryMonth",queryMonth);
|
|
|
+ }else{
|
|
|
+ throw new Exception("请选择查询日期!");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(companyId)) {
|
|
|
+ if ("hq1".equals(companyId)) {
|
|
|
+ //外勤1
|
|
|
+ List<CompanyInfo> list1 = companyInfoService.findByClassify("1");
|
|
|
+ searchParams.put("companyInfos", list1);
|
|
|
+
|
|
|
+ searchParams.put("hqStatus", "1");
|
|
|
+ } else if ("hq2".equals(companyId)) {
|
|
|
+ //外勤2
|
|
|
+ List<CompanyInfo> list2 = companyInfoService.findByClassify("2");
|
|
|
+ searchParams.put("companyInfos", list2);
|
|
|
+
|
|
|
+ searchParams.put("hqStatus", "2");
|
|
|
+ } else {
|
|
|
+ CompanyInfo parentCompanyInfo = companyInfoService.get(companyId);
|
|
|
+ String parentCode = parentCompanyInfo.getCode();
|
|
|
+ if (subordinate) {
|
|
|
+ searchParams.put("attendanceCompanyCode", parentCode + "%");
|
|
|
+ } else {
|
|
|
+ searchParams.put("attendanceCompanyCode", parentCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ searchParams.put("hqStatus", parentCompanyInfo.getClassify());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ searchParams.put("querHq", "yes");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Sort> sortList = new ArrayList<>();
|
|
|
+ sortList.add(new Sort("b.sort_no","asc"));
|
|
|
+ sortList.add(new Sort("a.id_","asc"));
|
|
|
+ //用户左边列
|
|
|
+ Page<PersonInfo> personInfoPage = personInfoService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
|
|
|
+ //头部是月份
|
|
|
+ Date queryDate = new SimpleDateFormat("yyyy-MM-dd").parse(queryMonth + "-01");
|
|
|
+ Map<String,Object> returnMap = getDayByMonth(queryDate);
|
|
|
+ List<Integer> days = (List<Integer>)returnMap.get("days");
|
|
|
+ int year = Integer.parseInt(returnMap.get("year").toString());
|
|
|
+ int month = Integer.parseInt(returnMap.get("month").toString());
|
|
|
+
|
|
|
+ List<Map<String,Object>> personList = new ArrayList<>();
|
|
|
+ List<Map> dayMapList = new ArrayList<>();
|
|
|
+ for(int i=0;i<days.size();i++){
|
|
|
+ int day = days.get(i);
|
|
|
+ Map map = new HashMap();
|
|
|
+ map.put("id",i);
|
|
|
+ map.put("day",day);
|
|
|
+ dayMapList.add(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ for(PersonInfo personInfo : personInfoPage.getResult()){
|
|
|
+ List<WorkPersonScheduling> workDayList = workPersonSchedulingService.findByPersonIdYearMonth(personInfo.getId(),year,month);
|
|
|
+ Map<String,List> dayMap = new HashMap<>();
|
|
|
+
|
|
|
+
|
|
|
+ for(int i=0;i<days.size();i++){
|
|
|
+ int day = days.get(i);
|
|
|
+ List<String> numberList = new ArrayList<>();
|
|
|
+ numberList.add("无");
|
|
|
+ dayMap.put(String.valueOf(day),numberList);
|
|
|
+ }
|
|
|
+
|
|
|
+ for(WorkPersonScheduling wps : workDayList){
|
|
|
+ //dayMap.put(sdf.format(wps.getSchedulingDay()),wps);
|
|
|
+ String shiftNumbers = "";
|
|
|
+ String[] shiftIds = null ;
|
|
|
+ if(wps.getShiftIds() != null){
|
|
|
+ shiftIds = wps.getShiftIds().split(",");
|
|
|
+ for(int i=0;i<shiftIds.length;i++){
|
|
|
+ String shiftId = shiftIds[i];
|
|
|
+ String shiftNumber = (String)valueOperations.get("shift_number_" + shiftId);
|
|
|
+
|
|
|
+ if(StringUtils.isEmpty(shiftNumber)){
|
|
|
+ shiftNumber = workShiftInfoService.findNumberById(shiftId);
|
|
|
+ valueOperations.set("shift_number_" + shiftId, shiftNumber);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(i < shiftIds.length - 1) {
|
|
|
+ shiftNumbers += shiftNumber + ",";
|
|
|
+ }else{
|
|
|
+ shiftNumbers += shiftNumber;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> numberList = new ArrayList<>();
|
|
|
+ numberList.add(shiftNumbers);
|
|
|
+ dayMap.replace(wps.getDay().toString(),numberList);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Map<String,Object> mapPerson = new HashMap<>();
|
|
|
+
|
|
|
+ mapPerson.put("id",personInfo.getId());
|
|
|
+ mapPerson.put("name",personInfo.getName());
|
|
|
+ mapPerson.put("companyId",personInfo.getCompanyId());
|
|
|
+ mapPerson.put("companyName",personInfo.getCompanyName());
|
|
|
+ mapPerson.put("personNumberMap",dayMap);
|
|
|
+
|
|
|
+ personList.add(mapPerson);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ dataMap.put("recordsTotal", personInfoPage.getTotal());
|
|
|
+ dataMap.put("totalPage", personInfoPage.getPages());
|
|
|
+ dataMap.put("personList", personList);
|
|
|
+ dataMap.put("dayList", dayMapList);
|
|
|
+ }catch (Exception ex){
|
|
|
+ ex.printStackTrace();
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+ }
|
|
|
+
|
|
|
+ return dataMap;
|
|
|
+ }
|
|
|
+
|
|
|
public static Map<String,Object> getDayByMonth(Date queryMonth){
|
|
|
Map<String,Object> returnMap = new HashMap<>();
|
|
|
List list = new ArrayList();
|
|
@@ -479,6 +620,132 @@ public class WorkPersonSchedulingController {
|
|
|
return msgResult;
|
|
|
}
|
|
|
|
|
|
+ @ApiOperation(value="后勤排班班次")
|
|
|
+ @RequestMapping(value = "changeSchedulingHq",method = RequestMethod.POST)
|
|
|
+ public MessageResult<List> changeSchedulingHq(
|
|
|
+ @RequestParam(name="companyId",defaultValue = "") String companyId,
|
|
|
+ @RequestParam(name="personId",defaultValue = "") String personId,
|
|
|
+ String[] schedulingIds,
|
|
|
+ @DateTimeFormat(pattern = "yyyy-MM-dd") String startDate,
|
|
|
+ @DateTimeFormat(pattern = "yyyy-MM-dd") String endDate,
|
|
|
+ @RequestAttribute String subject,
|
|
|
+ HttpServletRequest request) throws Exception{
|
|
|
+ MessageResult<List> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ if(!valueOperations.setIfAbsent("changeScheduling_" + subject,true,3,TimeUnit.SECONDS)){
|
|
|
+ throw new Exception("操作过于频繁,请稍后再试!");
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String,Object> searchParams = new HashMap<>();
|
|
|
+ if (StringUtils.isNotEmpty(companyId)) {
|
|
|
+ if ("hq1".equals(companyId)) {
|
|
|
+ //外勤1
|
|
|
+ List<CompanyInfo> list1 = companyInfoService.findByClassify("1");
|
|
|
+ searchParams.put("companyInfos", list1);
|
|
|
+
|
|
|
+ searchParams.put("hqStatus", "1");
|
|
|
+ } else if ("hq2".equals(companyId)) {
|
|
|
+ //外勤2
|
|
|
+ List<CompanyInfo> list2 = companyInfoService.findByClassify("2");
|
|
|
+ searchParams.put("companyInfos", list2);
|
|
|
+
|
|
|
+ searchParams.put("hqStatus", "2");
|
|
|
+ } else {
|
|
|
+ CompanyInfo parentCompanyInfo = companyInfoService.get(companyId);
|
|
|
+ String parentCode = parentCompanyInfo.getCode();
|
|
|
+ searchParams.put("attendanceCompanyCode", parentCode);
|
|
|
+ searchParams.put("hqStatus", parentCompanyInfo.getClassify());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new Exception("请选择部门");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Sort> sortList = new ArrayList<>();
|
|
|
+ sortList.add(new Sort("b.sort_no","asc"));
|
|
|
+ sortList.add(new Sort("a.id_","asc"));
|
|
|
+ //查询部门下人员
|
|
|
+ Page<PersonInfo> personInfoPage = personInfoService.pageSearch(searchParams,0,10000,false,sortList);
|
|
|
+ List<PersonInfo> personInfoList = personInfoPage.getResult();
|
|
|
+ if(StringUtils.isNotEmpty(personId)){
|
|
|
+ personInfoList = new ArrayList<>();
|
|
|
+ String [] pIds = personId.split(",");
|
|
|
+ for(String pId : pIds) {
|
|
|
+ PersonInfo personInfo = personInfoService.get(Long.valueOf(pId));
|
|
|
+ personInfoList.add(personInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for(PersonInfo pi : personInfoList){
|
|
|
+ //查询需要排班的日期
|
|
|
+ List<Date> dateList = getDayByYear(startDate,endDate);
|
|
|
+ int num=0;
|
|
|
+ for(Date scheDate : dateList){
|
|
|
+ //如果num = 数组的长度
|
|
|
+ String shiftId = schedulingIds[num];
|
|
|
+ if(num == schedulingIds.length-1) {
|
|
|
+ num = 0;
|
|
|
+ }else{
|
|
|
+ num ++;
|
|
|
+ }
|
|
|
+ List<WorkShiftInfo> wsiList = null;
|
|
|
+ if(StringUtils.isNotEmpty(shiftId)) {
|
|
|
+ String[] shiftIds = shiftId.split(";");
|
|
|
+ //String sortShiftIds = Arrays.stream(shiftIds).sorted(Comparator.naturalOrder()).collect(Collectors.joining(","));
|
|
|
+ List<String> shiftIdsList = Arrays.asList(shiftIds);
|
|
|
+
|
|
|
+ List<String> sortShiftIdsList = workShiftInfoService.sortIdsByNumber(shiftIdsList);
|
|
|
+ //返回排序后参数
|
|
|
+
|
|
|
+ shiftId = StringUtils.join(sortShiftIdsList,",");
|
|
|
+ }
|
|
|
+
|
|
|
+ Calendar calendar = Calendar.getInstance(Locale.CHINA);
|
|
|
+ calendar.setTime(scheDate);
|
|
|
+ int year = calendar.get(Calendar.YEAR);//年份
|
|
|
+ int month = calendar.get(Calendar.MONTH) + 1;//月份
|
|
|
+ int day = calendar.get(Calendar.DAY_OF_MONTH);
|
|
|
+
|
|
|
+ //先假删除
|
|
|
+ workPersonSchedulingService.deleteByPersonIdSchedulingDay(year,month,day,pi.getId());
|
|
|
+
|
|
|
+ WorkPersonScheduling workPersonScheduling = workPersonSchedulingService.findByYearMonthDayPersonId(year,month,day,pi.getId());
|
|
|
+ if(workPersonScheduling == null){
|
|
|
+ workPersonScheduling = new WorkPersonScheduling();
|
|
|
+ workPersonScheduling.setId(UUID.randomUUID().toString());
|
|
|
+ workPersonScheduling.setDelFlag(false);
|
|
|
+ workPersonScheduling.setCreateBy(subject);
|
|
|
+ workPersonScheduling.setCreateTime(new Date());
|
|
|
+
|
|
|
+ workPersonScheduling.setPersonId(pi.getId());
|
|
|
+ workPersonScheduling.setYear(year);
|
|
|
+ workPersonScheduling.setMonth(month);
|
|
|
+ workPersonScheduling.setDay(day);
|
|
|
+ workPersonScheduling.setSchedulingDay(scheDate);
|
|
|
+ workPersonScheduling.setShiftIds(shiftId);
|
|
|
+ //workPersonScheduling.setShiftNumbers(shiftNumber);
|
|
|
+
|
|
|
+ workPersonSchedulingService.insert(workPersonScheduling);
|
|
|
+ }else{
|
|
|
+ workPersonScheduling.setUpdateBy(subject);
|
|
|
+ workPersonScheduling.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ workPersonScheduling.setPersonId(pi.getId());
|
|
|
+ workPersonScheduling.setYear(year);
|
|
|
+ workPersonScheduling.setMonth(month);
|
|
|
+ workPersonScheduling.setDay(day);
|
|
|
+ workPersonScheduling.setSchedulingDay(scheDate);
|
|
|
+ workPersonScheduling.setShiftIds(shiftId);
|
|
|
+ //workPersonScheduling.setShiftNumbers(shiftNumber);
|
|
|
+
|
|
|
+ workPersonSchedulingService.update(workPersonScheduling);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ msgResult.setResult(true);
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
@ApiOperation(value="根据年月日人查班次ID")
|
|
|
@RequestMapping(value = "findWPSByParameter",method = RequestMethod.POST)
|