|
@@ -1,17 +1,30 @@
|
|
|
package com.management.platform.controller;
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.management.platform.entity.BusinessTrip;
|
|
|
import com.management.platform.entity.LeaveSheet;
|
|
|
+import com.management.platform.entity.TimeType;
|
|
|
+import com.management.platform.entity.User;
|
|
|
+import com.management.platform.mapper.TimeTypeMapper;
|
|
|
import com.management.platform.mapper.UserMapper;
|
|
|
import com.management.platform.service.BusinessTripService;
|
|
|
+import com.management.platform.util.DockWithMLD;
|
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -31,6 +44,8 @@ public class BusinessTripController {
|
|
|
BusinessTripService businessTripService;
|
|
|
@Resource
|
|
|
private HttpServletRequest request;
|
|
|
+ @Resource
|
|
|
+ private TimeTypeMapper timeTypeMapper;
|
|
|
|
|
|
|
|
|
|
|
@@ -97,5 +112,93 @@ public class BusinessTripController {
|
|
|
String userId = request.getHeader("Token");
|
|
|
return businessTripService.exportData(sheet,keyword, startDate, endDate, userId);
|
|
|
}
|
|
|
+ @RequestMapping("/syncData")
|
|
|
+ public HttpRespMsg syncData(String startDate, String endDate){
|
|
|
+ HttpRespMsg msg=new HttpRespMsg();
|
|
|
+ Integer companyId = userMapper.selectById(request.getHeader("token")).getCompanyId();
|
|
|
+ TimeType one = timeTypeMapper.selectOne(new QueryWrapper<TimeType>().eq("company_id", companyId).eq("sync_fanwei", 1));
|
|
|
+ if(one==null){
|
|
|
+ msg.setError("暂无请假数据待同步");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(startDate)) {
|
|
|
+ msg.setError("开始时间不能为空");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ //时间跨度不能超过1个月
|
|
|
+ if (StringUtils.isEmpty(endDate)) {
|
|
|
+ msg.setError("结束时间不能为空");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ DateTimeFormatter df=DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ LocalDate parse = LocalDate.parse(startDate, df);
|
|
|
+ LocalDate parse1 = LocalDate.parse(endDate, df);
|
|
|
+ long between = parse1.toEpochDay() - parse.toEpochDay();
|
|
|
+ if (between > 31) {
|
|
|
+ msg.setError("时间跨度不能超过1个月");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ JSONObject jsonObject=new JSONObject();
|
|
|
+ DateTimeFormatter dtf1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String date = startDate + " 00:00:00," + endDate + " 23:59:59";
|
|
|
+ jsonObject.put("gmtFinished",date);
|
|
|
+ String jsonString = jsonObject.toJSONString();
|
|
|
+ List<User> allUserList=userMapper.selectList(new QueryWrapper<User>().eq("company_id",companyId));
|
|
|
+ List<BusinessTrip> businessTripList=new ArrayList<>();
|
|
|
+ List<BusinessTrip> oldBusinessTripList = businessTripService.list(new QueryWrapper<BusinessTrip>().eq("company_id", companyId));
|
|
|
+ DockWithMLD dockWithMLD=new DockWithMLD();
|
|
|
+ HttpRespMsg travelRecordMsg = dockWithMLD.getResult("http://10.1.10.51:20175/api/cube/restful/interface/getModeDataPageList/getTravelRecord", jsonString);
|
|
|
+ List<Map<String,Object>> travelRecordList= (List<Map<String, Object>>) travelRecordMsg.data;
|
|
|
+ for (Map<String, Object> map : travelRecordList) {
|
|
|
+ Optional<User> optional=allUserList.stream().filter(al->al.getJobNumber()!=null&&al.getJobNumber().equals(map.get("rybh"))).findFirst();
|
|
|
+ if(!optional.isPresent()){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ User user=optional.get();
|
|
|
+ BusinessTrip businessTrip=new BusinessTrip();
|
|
|
+ businessTrip.setCompanyId(user.getCompanyId());
|
|
|
+ businessTrip.setOwnerId(user.getId());
|
|
|
+ businessTrip.setOwnerName(user.getName());
|
|
|
+ businessTrip.setStartDate(LocalDate.parse(String.valueOf(map.get("startDate")),dtf1));
|
|
|
+ businessTrip.setEndDate(LocalDate.parse(String.valueOf(map.get("endDate")),dtf1));
|
|
|
+ Integer way=null;
|
|
|
+ switch (String.valueOf(map.get("way"))){
|
|
|
+ case "飞机":way=0;
|
|
|
+ break;
|
|
|
+ case "高铁/火车":way=1;
|
|
|
+ break;
|
|
|
+ case "汽车":way=2;
|
|
|
+ break;
|
|
|
+ case "轮船":way=3;
|
|
|
+ break;
|
|
|
+ case "其他":way=4;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ businessTrip.setWay(way);
|
|
|
+ businessTrip.setCityFrom((String) map.get("cityFrom"));
|
|
|
+ businessTrip.setCityTo((String) map.get("cityTo"));
|
|
|
+ Integer goBack=null;
|
|
|
+ switch (String.valueOf(map.get("goBack"))){
|
|
|
+ case "单程":goBack=0;
|
|
|
+ break;
|
|
|
+ case "往返":goBack=1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ businessTrip.setGoBack(goBack);
|
|
|
+ Double dayCount =Double.valueOf(String.valueOf(map.get("dayCount")));
|
|
|
+ businessTrip.setDayCount(dayCount.intValue());
|
|
|
+ businessTrip.setProcinstId((String) map.get("id"));
|
|
|
+ businessTrip.setGmtFinished((String)map.get("gmtFinished"));
|
|
|
+ Optional<BusinessTrip> first = oldBusinessTripList.stream().filter(ol -> ol.getStartDate().isEqual(businessTrip.getStartDate())&&ol.getEndDate().isEqual(businessTrip.getEndDate())&& ol.getOwnerId().equals(businessTrip.getOwnerId())&&(ol.getProcinstId()!=null&& ol.getProcinstId().equals(businessTrip.getProcinstId()))).findFirst();
|
|
|
+ if(first.isPresent()){
|
|
|
+ businessTrip.setId(first.get().getId());
|
|
|
+ }
|
|
|
+ businessTripList.add(businessTrip);
|
|
|
+ }
|
|
|
+ if(businessTripList.size()>0){
|
|
|
+ businessTripService.saveOrUpdateBatch(businessTripList);
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
}
|
|
|
|