|
|
@@ -0,0 +1,258 @@
|
|
|
+package com.sckw.fleet.service;
|
|
|
+
|
|
|
+import com.sckw.core.exception.SystemException;
|
|
|
+import com.sckw.core.model.auth.context.LoginUserHolder;
|
|
|
+import com.sckw.core.model.constant.Global;
|
|
|
+import com.sckw.core.utils.BeanUtils;
|
|
|
+import com.sckw.core.utils.CollectionUtils;
|
|
|
+import com.sckw.core.utils.StringUtils;
|
|
|
+import com.sckw.core.web.constant.HttpStatus;
|
|
|
+import com.sckw.core.web.response.HttpResult;
|
|
|
+import com.sckw.fleet.dao.KwfDriverMapper;
|
|
|
+import com.sckw.fleet.dao.KwfTruckMapper;
|
|
|
+import com.sckw.fleet.dao.KwfTruckReportMapper;
|
|
|
+import com.sckw.fleet.model.KwfDriver;
|
|
|
+import com.sckw.fleet.model.KwfTruck;
|
|
|
+import com.sckw.fleet.model.KwfTruckEnt;
|
|
|
+import com.sckw.fleet.model.KwfTruckReport;
|
|
|
+import com.sckw.fleet.model.dto.*;
|
|
|
+import com.sckw.fleet.model.vo.KwfTableTopCount;
|
|
|
+import com.sckw.fleet.model.vo.KwfTruckReportVo;
|
|
|
+import com.sckw.system.api.RemoteSystemService;
|
|
|
+import com.sckw.system.api.model.dto.res.EntCacheResDto;
|
|
|
+import com.sckw.system.api.model.dto.res.UserCacheResDto;
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author zk
|
|
|
+ * @desc 车辆上报
|
|
|
+ * @date 2023/7/15 0006
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class KwfTruckReportService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ KwfTruckMapper truckDao;
|
|
|
+ @Autowired
|
|
|
+ KwfDriverMapper driverDao;
|
|
|
+ @Autowired
|
|
|
+ KwfTruckReportMapper truckReportDao;
|
|
|
+ @Autowired
|
|
|
+ KwfDriverService driverService;
|
|
|
+ @Autowired
|
|
|
+ KwfTruckService truckService;
|
|
|
+ @DubboReference(version = "2.0.0", group = "design", check = false)
|
|
|
+ private RemoteSystemService remoteSystemService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param key 主键id
|
|
|
+ * @desc 根据主键查询
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/15
|
|
|
+ **/
|
|
|
+ public KwfTruckReport selectByKey(Long key) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param params 参数
|
|
|
+ * @desc 统计
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/11
|
|
|
+ **/
|
|
|
+ public Map statistics(Map<String, Object> params) {
|
|
|
+ /**统计数据**/
|
|
|
+ List<KwfTableTopCount> counts = truckReportDao.statistics(params);
|
|
|
+ long tatol = 0;
|
|
|
+ for (KwfTableTopCount topCount:counts) {
|
|
|
+ tatol += topCount.getTotal();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**全部数据-处理**/
|
|
|
+ KwfTableTopCount allCount = new KwfTableTopCount();
|
|
|
+ allCount.setValue(String.valueOf(Global.NUMERICAL_ZERO));
|
|
|
+ allCount.setTotal(tatol);
|
|
|
+ counts.add(allCount);
|
|
|
+
|
|
|
+ /**数据组装**/
|
|
|
+ Map tableCount = new HashMap();
|
|
|
+ tableCount.put("tableTop", counts);
|
|
|
+ tableCount.put("tableBottom", tatol);
|
|
|
+ return tableCount;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param params 分页参数
|
|
|
+ * @desc 分页查询
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/15
|
|
|
+ **/
|
|
|
+ public List<KwfTruckReportVo> findPage(Map<String, Object> params) {
|
|
|
+ /**查询分页数据**/
|
|
|
+ List<KwfTruckReportVo> trucks = truckReportDao.findPage(params);
|
|
|
+ if (CollectionUtils.isEmpty(trucks)) {
|
|
|
+ return trucks;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**获取查询数据**/
|
|
|
+ List<Long> createBys = new ArrayList<>();
|
|
|
+ List<Long> entIds = new ArrayList<>();
|
|
|
+ for (KwfTruckReportVo truck:trucks) {
|
|
|
+ createBys.add(Long.parseLong(truck.getCreateBy()));
|
|
|
+ entIds.add(Long.parseLong(truck.getDriverEntId()));
|
|
|
+ entIds.add(Long.parseLong(truck.getTruckEntId()));
|
|
|
+ }
|
|
|
+ //用户数据集
|
|
|
+ createBys = createBys.stream().distinct().collect(Collectors.toList());
|
|
|
+ Map<Long, UserCacheResDto> users = remoteSystemService.queryUserCacheMapByIds(createBys);
|
|
|
+ //企业数据集
|
|
|
+ entIds = entIds.stream().distinct().collect(Collectors.toList());
|
|
|
+ Map<Long, EntCacheResDto> ents = remoteSystemService.queryEntCacheMapByIds(entIds);
|
|
|
+
|
|
|
+ /**数据组装**/
|
|
|
+ for (KwfTruckReportVo truck:trucks) {
|
|
|
+ UserCacheResDto user = users == null ? null : users.get(Long.parseLong(truck.getCreateBy()));
|
|
|
+ EntCacheResDto ent = ents == null ? null : ents.get(Long.parseLong(truck.getDriverEntId()));
|
|
|
+ truck.setCreateByName(user != null ? user.getName() : null);
|
|
|
+ truck.setDriverFirmName(ent != null ? ent.getFirmName() : null);
|
|
|
+ ent = ents == null ? null : ents.get(Long.parseLong(truck.getTruckEntId()));
|
|
|
+ truck.setTruckFirmName(ent != null ? ent.getFirmName() : null);
|
|
|
+ }
|
|
|
+ return trucks;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param {}
|
|
|
+ * @description 导出
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/07/11
|
|
|
+ **/
|
|
|
+ public HttpResult importExcel(MultipartFile file) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param params 参数
|
|
|
+ * @desc 新增车辆上报
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/15
|
|
|
+ **/
|
|
|
+ public HttpResult add(KwfTruckReportDto params) {
|
|
|
+ KwfTruckReport truckReport = new KwfTruckReport();
|
|
|
+ truckReport.setEntId(LoginUserHolder.getEntId());
|
|
|
+
|
|
|
+ /**车辆信息**/
|
|
|
+ //校验车辆档案是否存在
|
|
|
+ List<Map<String, Object>> trucks = truckDao.findList(new HashMap() {{
|
|
|
+ put("truckNo", params.getTruckNo());
|
|
|
+ }});
|
|
|
+ if (CollectionUtils.isEmpty(trucks)) {
|
|
|
+ //新增车辆档案
|
|
|
+ KwfTruckDto truckDto = new KwfTruckDto();
|
|
|
+ truckDto.setTruckNo(params.getTruckNo());
|
|
|
+ HttpResult result = truckService.add(truckDto);
|
|
|
+ if (result.getCode() != HttpStatus.SUCCESS_CODE) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //校验车辆是否已上报
|
|
|
+ Map<String, Object> truck = trucks.get(0);
|
|
|
+ Object truckId = truck.get("id");
|
|
|
+ List<Map<String, Object>> reports = truckReportDao.findList(new HashMap() {{
|
|
|
+ put("truckId", truckId);
|
|
|
+ put("entId", LoginUserHolder.getEntId());
|
|
|
+ }});
|
|
|
+ if (CollectionUtils.isEmpty(trucks)) {
|
|
|
+ //新增
|
|
|
+ truckReport.setTruckId(Long.parseLong(String.valueOf(truckId)));
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**档案信息**/
|
|
|
+ //校验司机档案是否存在
|
|
|
+ List<Map<String, Object>> drivers = driverDao.findList(new HashMap() {{
|
|
|
+ put("phone", params.getDriverPhone());
|
|
|
+ }});
|
|
|
+ if (CollectionUtils.isEmpty(drivers)) {
|
|
|
+ //新增司机档案
|
|
|
+ KwfDriverDto driverDto = new KwfDriverDto();
|
|
|
+ driverDto.setName(params.getDriverName());
|
|
|
+ driverDto.setPhone(params.getDriverPhone());
|
|
|
+ driverDto.setIdcard(params.getDriverIdcard());
|
|
|
+ HttpResult result = driverService.add(driverDto);
|
|
|
+ if (result.getCode() != HttpStatus.SUCCESS_CODE) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //校验司机是否已上报
|
|
|
+ Map<String, Object> driver = trucks.get(0);
|
|
|
+ Object driverId = driver.get("id");
|
|
|
+ List<Map<String, Object>> reports = truckReportDao.findList(new HashMap() {{
|
|
|
+ put("driverId", driverId);
|
|
|
+ put("entId", LoginUserHolder.getEntId());
|
|
|
+ }});
|
|
|
+ if (CollectionUtils.isEmpty(trucks)) {
|
|
|
+ if (true) {
|
|
|
+ truckReport.setDriverId(Long.parseLong(String.valueOf(driverId)));
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ truckReportDao.insert(truckReport);
|
|
|
+ return HttpResult.ok("车辆上报成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param params 参数
|
|
|
+ * @desc 车辆上报修改
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/15
|
|
|
+ **/
|
|
|
+ public HttpResult update(KwfTruckReportDto params) {
|
|
|
+ /**数据校验**/
|
|
|
+
|
|
|
+
|
|
|
+ /**车辆信息**/
|
|
|
+
|
|
|
+
|
|
|
+ return HttpResult.ok("车辆信息修改成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param {ids:主键ID(多个以逗号隔开)}
|
|
|
+ * @description 删除
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/15
|
|
|
+ **/
|
|
|
+ public HttpResult del(String ids) {
|
|
|
+ /**数据校验**/
|
|
|
+ if (StringUtils.isBlank(ids)) {
|
|
|
+ return HttpResult.error("请选择要删除的数据!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**数据组装**/
|
|
|
+ String[] idArray = ids.split(",");
|
|
|
+ for (String id : idArray) {
|
|
|
+ KwfTruckReport truckReport = truckReportDao.selectById(id);
|
|
|
+ if (truckReport != null) {
|
|
|
+ truckReport.setDelFlag(Global.YES);
|
|
|
+ if (truckReportDao.updateById(truckReport) <= 0) {
|
|
|
+ throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.DELETE_FAIL);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return HttpResult.ok("删除成功!");
|
|
|
+ }
|
|
|
+}
|