|
@@ -0,0 +1,204 @@
|
|
|
+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>
|
|
|
+ * 前端控制器
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author Seyason
|
|
|
+ * @since 2022-04-08
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/business-trip")
|
|
|
+public class BusinessTripController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ UserMapper userMapper;
|
|
|
+ @Resource
|
|
|
+ BusinessTripService businessTripService;
|
|
|
+ @Resource
|
|
|
+ private HttpServletRequest request;
|
|
|
+ @Resource
|
|
|
+ private TimeTypeMapper timeTypeMapper;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @RequestMapping("/add")
|
|
|
+ public HttpRespMsg add(BusinessTrip sheet) {
|
|
|
+ return businessTripService.add(sheet);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/modifyProject")
|
|
|
+ public HttpRespMsg modifyProject(BusinessTrip sheet) {
|
|
|
+ return businessTripService.modifyProject(sheet);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @RequestMapping("/cancel")
|
|
|
+ public HttpRespMsg cancel(Integer id) {
|
|
|
+ String userId = request.getHeader("Token");
|
|
|
+ return businessTripService.cancel(id, userId);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @RequestMapping("/delete")
|
|
|
+ public HttpRespMsg delete(Integer id) {
|
|
|
+ return businessTripService.delete(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/list")
|
|
|
+ public HttpRespMsg list(BusinessTrip sheet, @RequestParam Integer pageIndex, @RequestParam Integer pageSize,@RequestParam(defaultValue = "0") Integer checkState) {
|
|
|
+ return businessTripService.queryList(sheet, pageIndex, pageSize,checkState);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/auditList")
|
|
|
+ public HttpRespMsg auditList(BusinessTrip sheet, @RequestParam Integer pageIndex, @RequestParam Integer pageSize, @RequestParam(defaultValue = "0") Integer checkState) {
|
|
|
+ return businessTripService.auditList(sheet, pageIndex, pageSize, checkState);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/approve")
|
|
|
+ public HttpRespMsg approve(Integer id) {
|
|
|
+ return businessTripService.approve(id);
|
|
|
+ }
|
|
|
+ @RequestMapping("/deny")
|
|
|
+ public HttpRespMsg deny(Integer id, String reason) {
|
|
|
+ return businessTripService.deny(id, reason);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param keyword 姓名(模糊匹配)
|
|
|
+ * @param startDate 开始日期
|
|
|
+ * @param endDate 结束日期
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping("/summaryData")
|
|
|
+ public HttpRespMsg summaryData(String keyword, String startDate, String endDate) {
|
|
|
+ String userId = request.getHeader("Token");
|
|
|
+ return businessTripService.summaryData(keyword, startDate, endDate, userId);
|
|
|
+
|
|
|
+ }
|
|
|
+ @RequestMapping("/exportData")
|
|
|
+ public HttpRespMsg exportData(BusinessTrip sheet,@RequestParam(defaultValue = "0") Integer keyword, String startDate, String endDate){
|
|
|
+ String userId = request.getHeader("Token");
|
|
|
+ return businessTripService.exportData(sheet,keyword, startDate, endDate, userId);
|
|
|
+ }
|
|
|
+ @RequestMapping("/syncData")
|
|
|
+ public HttpRespMsg syncData(BusinessTrip sheet,@RequestParam(defaultValue = "0") Integer keyword, 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;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|