Commit 025f1c3c by 刘鑫

Merge remote-tracking branch 'origin/develop' into develop

2 parents 1132e3da 76567c40
Showing with 804 additions and 633 deletions
......@@ -84,45 +84,44 @@ public class BatchServiceImpl implements BatchService {
batchDay = optional.get().getBatchDate();
}
// FIXME 因为系统暂时没有订单,每次固定拉取2023-08-13号订单数据生成新订单
LocalDate localDt = LocalDate.parse(batchDay, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
List<OrderInfo> orders = orderInfoRepository.findByOrgGroupIdAndDt(groupId, localDt);
if (CollectionUtils.isEmpty(orders)) {
String tempDay = "2023-08-13";
String createOrder = "INSERT INTO order_info (\r\n" + " order_id,\r\n" + " dt,\r\n" + " sub_id,\r\n"
+ " NAME,\r\n" + " phone,\r\n" + " province,\r\n" + " city,\r\n" + " county,\r\n"
+ " address,\r\n" + " X,\r\n" + " Y,\r\n" + " bean_brand,\r\n" + " brand,\r\n" + " TYPE,\r\n"
+ " skill,\r\n" + " take_time,\r\n" + " is_workshop,\r\n" + " fault_describe,\r\n"
+ " apply_note,\r\n" + " expect_time_begin,\r\n" + " expect_time_end,\r\n"
+ " expect_time_desc,\r\n" + " source,\r\n" + " bean_priority,\r\n" + " bean_tags,\r\n"
+ " bean_status,\r\n" + " bean_sub_status,\r\n" + " area_id,\r\n" + " org_cluster_id,\r\n"
+ " org_branch_id,\r\n" + " org_group_id,\r\n" + " org_team_id,\r\n" + " priority,\r\n"
+ " tags,\r\n" + " appointment_method,\r\n" + " appointment_status,\r\n" + " dispatcher,\r\n"
+ " order_status,\r\n" + " service_status,\r\n" + " engineer_code,\r\n" + " engineer_name,\r\n"
+ " engineer_phone,\r\n" + " engineer_code_sub,\r\n" + " plan_start_time,\r\n"
+ " plan_end_time,\r\n" + " arrive_elapsed,\r\n" + " arrive_distance,\r\n"
+ " actual_start_time,\r\n" + " actual_end_time,\r\n" + " description,\r\n" + " extra_info,\r\n"
+ " create_time,\r\n" + " update_time\r\n" + ") \r\n" + "SELECT \r\n" + " CONCAT(order_id,'" + batchDay + "') order_id,\r\n" + " '"
+ batchDay + "',\r\n" + " sub_id,\r\n" + " NAME,\r\n" + " phone,\r\n" + " province,\r\n"
+ " city,\r\n" + " county,\r\n" + " address,\r\n" + " X,\r\n" + " Y,\r\n" + " bean_brand,\r\n"
+ " brand,\r\n" + " TYPE,\r\n" + " skill,\r\n" + " take_time,\r\n" + " is_workshop,\r\n"
+ " fault_describe,\r\n" + " apply_note,\r\n" + " expect_time_begin,\r\n"
+ " expect_time_end,\r\n" + " expect_time_desc,\r\n" + " source,\r\n" + " bean_priority,\r\n"
+ " bean_tags,\r\n" + " bean_status,\r\n" + " bean_sub_status,\r\n" + " area_id,\r\n"
+ " org_cluster_id,\r\n" + " org_branch_id,\r\n" + " org_group_id,\r\n" + " org_team_id,\r\n"
+ " priority,\r\n" + " tags,\r\n" + " appointment_method,\r\n" + " appointment_status,\r\n"
+ " dispatcher,\r\n" + " order_status,\r\n" + " service_status,\r\n" + " engineer_code,\r\n"
+ " engineer_name,\r\n" + " engineer_phone,\r\n" + " engineer_code_sub,\r\n"
+ " plan_start_time,\r\n" + " plan_end_time,\r\n" + " arrive_elapsed,\r\n"
+ " arrive_distance,\r\n" + " actual_start_time,\r\n" + " actual_end_time,\r\n"
+ " description,\r\n" + " extra_info,\r\n" + " create_time,\r\n" + " update_time \r\n"
+ "FROM\r\n" + " order_info a \r\n" + "WHERE a.org_group_id = 'gsuzhou' \r\n" + " AND a.dt = '"
+ tempDay + "' \r\n" + " AND bean_status = 'OPEN' \r\n"
+ " AND appointment_method LIKE 'AUTO%' \r\n"
+ " AND a.appointment_status IN ('INIT', 'PRE') \r\n" + " AND order_status = 'NORMAL' \r\n"
+ " AND service_status = 'INIT' \r\n" + "";
int createCount = jdbcTemplate.update(createOrder);
}
// LocalDate localDt = LocalDate.parse(batchDay, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
// List<OrderInfo> orders = orderInfoRepository.findByOrgGroupIdAndDt(groupId, localDt);
// if (CollectionUtils.isEmpty(orders)) {
// String tempDay = "2023-08-13";
// String createOrder = "INSERT INTO order_info (\r\n" + " order_id,\r\n" + " dt,\r\n" + " sub_id,\r\n"
// + " NAME,\r\n" + " phone,\r\n" + " province,\r\n" + " city,\r\n" + " county,\r\n"
// + " address,\r\n" + " X,\r\n" + " Y,\r\n" + " bean_brand,\r\n" + " brand,\r\n" + " TYPE,\r\n"
// + " skill,\r\n" + " take_time,\r\n" + " is_workshop,\r\n" + " fault_describe,\r\n"
// + " apply_note,\r\n" + " expect_time_begin,\r\n" + " expect_time_end,\r\n"
// + " expect_time_desc,\r\n" + " source,\r\n" + " bean_priority,\r\n" + " bean_tags,\r\n"
// + " bean_status,\r\n" + " bean_sub_status,\r\n" + " area_id,\r\n" + " org_cluster_id,\r\n"
// + " org_branch_id,\r\n" + " org_group_id,\r\n" + " org_team_id,\r\n" + " priority,\r\n"
// + " tags,\r\n" + " appointment_method,\r\n" + " appointment_status,\r\n" + " dispatcher,\r\n"
// + " order_status,\r\n" + " service_status,\r\n" + " engineer_code,\r\n" + " engineer_name,\r\n"
// + " engineer_phone,\r\n" + " engineer_code_sub,\r\n" + " plan_start_time,\r\n"
// + " plan_end_time,\r\n" + " arrive_elapsed,\r\n" + " arrive_distance,\r\n"
// + " actual_start_time,\r\n" + " actual_end_time,\r\n" + " description,\r\n" + " extra_info,\r\n"
// + " create_time,\r\n" + " update_time\r\n" + ") \r\n" + "SELECT \r\n" + " CONCAT(order_id,'" + batchDay + "') order_id,\r\n" + " '"
// + batchDay + "',\r\n" + " sub_id,\r\n" + " NAME,\r\n" + " phone,\r\n" + " province,\r\n"
// + " city,\r\n" + " county,\r\n" + " address,\r\n" + " X,\r\n" + " Y,\r\n" + " bean_brand,\r\n"
// + " brand,\r\n" + " TYPE,\r\n" + " skill,\r\n" + " take_time,\r\n" + " is_workshop,\r\n"
// + " fault_describe,\r\n" + " apply_note,\r\n" + " '" + batchDay + " 08:00:00' expect_time_begin,\r\n"
// + " '" + batchDay + " 18:00:00' expect_time_end,\r\n" + " expect_time_desc,\r\n" + " source,\r\n" + " bean_priority,\r\n"
// + " bean_tags,\r\n" + " bean_status,\r\n" + " bean_sub_status,\r\n" + " area_id,\r\n"
// + " org_cluster_id,\r\n" + " org_branch_id,\r\n" + " org_group_id,\r\n" + " org_team_id,\r\n"
// + " priority,\r\n" + " tags,\r\n" + " appointment_method,\r\n" + " appointment_status,\r\n"
// + " dispatcher,\r\n" + " order_status,\r\n" + " service_status,\r\n" + " null engineer_code,\r\n"
// + " null engineer_name,\r\n" + " null engineer_phone,\r\n" + " null engineer_code_sub,\r\n"
// + " null plan_start_time,\r\n" + " null plan_end_time,\r\n" + " arrive_elapsed,\r\n"
// + " arrive_distance,\r\n" + " actual_start_time,\r\n" + " actual_end_time,\r\n"
// + " description,\r\n" + " extra_info,\r\n" + " create_time,\r\n" + " update_time \r\n"
// + "FROM\r\n" + " order_info a \r\n" + "WHERE a.org_group_id = 'gsuzhou' \r\n" + " AND a.dt = '"
// + tempDay + "' \r\n" + " AND bean_status = 'OPEN' \r\n"
// + " AND appointment_method LIKE 'AUTO%' \r\n"
// + " AND a.appointment_status IN ('INIT', 'PRE') \r\n" + " AND order_status = 'NORMAL' \r\n"
// + " AND service_status = 'INIT' \r\n" + "";
// int createCount = jdbcTemplate.update(createOrder);
// }
log.info("清理原批次数据, groupId:{}, day:{}, batchNo:{}", groupId, batchDay, batchNo);
jdbcTemplate.update("delete from dispatch_engineer where group_id=? and batch_no=?", groupId, batchNo);
......
......@@ -3,9 +3,7 @@ package com.dituhui.pea.order.controller;
import cn.hutool.core.util.StrUtil;
import com.dituhui.pea.common.PageResult;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.dto.MsgDTO;
import com.dituhui.pea.order.dto.MsgGroupResp;
import com.dituhui.pea.order.dto.MsgResp;
import com.dituhui.pea.order.dto.*;
import com.dituhui.pea.order.service.MsgService;
import com.dituhui.pea.order.utils.AssertUtil;
import com.dituhui.pea.order.utils.CommonUtil;
......@@ -39,7 +37,7 @@ public class MsgController {
*/
@GetMapping("/msg/list")
public Result<PageResult<MsgGroupResp>> list(@RequestHeader(name = "userId", required = true) String userId,
MsgDTO.Request request) {
MsgQuery request) {
CommonUtil.setNullValue(request);
request.setUserId(userId);
if (!"is_read".equalsIgnoreCase(request.getSort())) {
......@@ -65,8 +63,9 @@ public class MsgController {
* @date 2023/10/24
*/
@PostMapping("/msg/delete")
public Result<Boolean> delete(@RequestHeader(name = "userId", required = true) String userId, @RequestBody @Valid MsgDTO.DeleteDto dto) {
public Result<Boolean> delete(@RequestHeader(name = "userId", required = true) String userId, @RequestBody @Valid IdDTO dto) {
AssertUtil.isNotEmpty(userId, "用户ID不能为空");
AssertUtil.isNotNull(dto.getId(), "消息ID不能为空");
msgService.delete(dto.getId(), userId);
return Result.success(true);
}
......@@ -81,7 +80,7 @@ public class MsgController {
* @date 2023/10/24
*/
@PostMapping("/msg/read")
public Result<Boolean> read(@RequestHeader(name = "userId", required = true) String userId, @RequestBody @Valid MsgDTO.ReadDto dto) {
public Result<Boolean> read(@RequestHeader(name = "userId", required = true) String userId, @RequestBody @Valid IdsDTO dto) {
AssertUtil.isNotEmpty(userId, "用户ID不能为空");
msgService.readMsg(dto.getIds(), userId);
return Result.success(true);
......@@ -96,7 +95,7 @@ public class MsgController {
* @date 2023/10/25
*/
@PostMapping("/msg/add")
public Result<Boolean> add(@RequestBody @Valid MsgDTO.addDto dto) {
public Result<Boolean> add(@RequestBody @Valid MsgDTO dto) {
CommonUtil.setNullValue(dto);
AssertUtil.checkArgument(StrUtil.isNotEmpty(dto.getClusterId())
|| StrUtil.isNotEmpty(dto.getBranchId())
......
package com.dituhui.pea.order.dao;
import com.dituhui.pea.order.dto.MsgDTO;
import com.dituhui.pea.order.dto.MsgGroupResp;
import com.dituhui.pea.order.dto.MsgResp;
import com.dituhui.pea.order.dto.MsgQuery;
import com.dituhui.pea.order.entity.MsgEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
......@@ -23,6 +21,7 @@ public interface MsgDao extends JpaRepository<MsgEntity, Integer> {
" where IF(:#{#req.startDate} is not null, tt.create_time>=:#{#req.startDate}, 1=1)" +
" and IF(:#{#req.endDate} is not null, tt.create_time<:#{#req.endDate}, 1=1)" +
" and IF(:#{#req.keyWord} is not null, tt.content like concat('%',:#{#req.keyWord},'%'), 1=1)" +
" and IF(:#{#req.orgTreeValue} is not null, (tt.cluster_id=:#{#req.orgTreeValue} or tt.branch_id=:#{#req.orgTreeValue} or tt.group_id=:#{#req.orgTreeValue}), 1=1)" +
"group by tt.cluster_id,tt.branch_id,tt.group_id" +
") t",
countQuery = "select count(t.cluster_id)" +
......@@ -32,11 +31,12 @@ public interface MsgDao extends JpaRepository<MsgEntity, Integer> {
" where IF(:#{#req.startDate} is not null, tt.create_time>=:#{#req.startDate}, 1=1)" +
" and IF(:#{#req.endDate} is not null, tt.create_time<:#{#req.endDate}, 1=1)" +
" and IF(:#{#req.keyWord} is not null, tt.content like concat('%',:#{#req.keyWord},'%'), 1=1)" +
" and IF(:#{#req.orgTreeValue} is not null, (tt.cluster_id=:#{#req.orgTreeValue} or tt.branch_id=:#{#req.orgTreeValue} or tt.group_id=:#{#req.orgTreeValue}), 1=1)" +
"group by tt.cluster_id,tt.branch_id,tt.group_id" +
") t"
, nativeQuery = true // 开启原生sql
)
Page<Map<String, Objects>> getGroupList(@Param("req") MsgDTO.Request req, Pageable pageable);
Page<Map<String, Objects>> getGroupList(@Param("req") MsgQuery req, Pageable pageable);
@Query(value = "select t.* from (select tt.*,r.is_read," +
......@@ -51,7 +51,7 @@ public interface MsgDao extends JpaRepository<MsgEntity, Integer> {
") t"
, nativeQuery = true // 开启原生sql
)
List<Map<String, Objects>> getList(@Param("req") MsgDTO.Request req
List<Map<String, Objects>> getList(@Param("req") MsgQuery req
, @Param("msgGroupResp") MsgGroupResp msgGroupResp, Pageable pageable);
/**
......
......@@ -26,6 +26,10 @@ public class BusinessTeamAddDTO {
* 开放工作日
*/
private List<String> workdays;
private String workOn;
private String workOff;
}
......
......@@ -33,5 +33,9 @@ public class BusinessTeamUpdateDTO {
* 开放工作日
*/
private List<String> workdays;
private String workOn;
private String workOff;
}
}
......@@ -26,5 +26,10 @@ public class EngineerInfoListResp {
private List<String> tags;
private List<String> credentials;
private String grade;
/**
* 工作地址
*/
private String workAddress;
}
}
package com.dituhui.pea.order.dto;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* 公共 id类
*
* @author RenPing
* @date 2023/10/26
*/
@Data
public class IdDTO {
@NotNull(message = "ID不能为空")
private Integer id;
}
package com.dituhui.pea.order.dto;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import java.util.List;
/**
* 公共 id集合类,用于批量操作
*
* @author RenPing
* @date 2023/10/26
*/
@Data
public class IdsDTO {
@NotEmpty(message = "Id集合不能为空")
private List<Integer> ids;
}
package com.dituhui.pea.order.dto;
import com.dituhui.pea.pojo.PageRequest;
import org.springframework.format.annotation.DateTimeFormat;
import lombok.Data;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
import static com.dituhui.pea.order.config.OrderConfig.DEFAULT_PAGE_SIZE;
@Data
public class MsgDTO {
@lombok.Data
public static class Request {
/**
* 每页大小
*/
private Integer size = DEFAULT_PAGE_SIZE;
/**
* 页码
*/
private Integer page = 1;
/**
* 当前用户Id,前端将userId放在header中
*/
private String userId;
/**
* 排序字段:create_time、is_read
*/
private String sort;
/**
* 排序类型:asc、desc
*/
private String sortType;
/**
* 开始日期
*/
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date startDate;
/**
* 结束日期
*/
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date endDate;
/**
* 关键词模糊查询
*/
private String keyWord;
}
@lombok.Data
public static class DeleteDto {
@NotNull(message = "消息ID不能为空")
private Integer id;
}
@lombok.Data
public static class ReadDto {
/**
* 消息Id集合
*/
@NotEmpty(message = "消息Id集合不能为空")
private List<Integer> ids;
}
@lombok.Data
public static class addDto {
/**
* 大区ID(大区Id、分部Id、分组Id只需传一个)
*/
private String clusterId;
/**
* 分部ID
*/
private String branchId;
/**
* 小组ID
*/
private String groupId;
/**
* 消息类型,0:派工类,1:服务类,2:容量类
*/
@NotNull(message = "消息类型不能为空")
@Min(value = 0, message = "消息类型格式不对")
@Max(value = 2, message = "消息类型格式不对")
private Integer type;
/**
* 消息内容
*/
@NotNull(message = "消息内容不能为空")
private String content;
/**
* 单号集合,以“、”连接
*/
private String orderIds;
/**
* 标签类型,0:紧急,1:正常
*/
@NotNull(message = "标签类型不能为空")
@Min(value = 0, message = "标签类型格式不对")
@Max(value = 1, message = "标签类型格式不对")
private Integer tag;
}
/**
* 大区ID(大区Id、分部Id、分组Id只需传一个)
*/
private String clusterId;
/**
* 分部ID
*/
private String branchId;
/**
* 小组ID
*/
private String groupId;
/**
* 消息类型,0:派工类,1:服务类,2:容量类
*/
@NotNull(message = "消息类型不能为空")
@Min(value = 0, message = "消息类型格式不对")
@Max(value = 2, message = "消息类型格式不对")
private Integer type;
/**
* 消息内容
*/
@NotNull(message = "消息内容不能为空")
private String content;
/**
* 单号集合,以“、”连接
*/
private String orderIds;
/**
* 标签类型,0:紧急,1:正常
*/
@NotNull(message = "标签类型不能为空")
@Min(value = 0, message = "标签类型格式不对")
@Max(value = 1, message = "标签类型格式不对")
private Integer tag;
}
\ No newline at end of file
package com.dituhui.pea.order.dto;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.util.Date;
import static com.dituhui.pea.order.config.OrderConfig.DEFAULT_PAGE_SIZE;
@lombok.Data
public class MsgQuery {
/**
* 每页大小
*/
private Integer size = DEFAULT_PAGE_SIZE;
/**
* 页码
*/
private Integer page = 1;
/**
* 当前用户Id,前端将userId放在header中
*/
private String userId;
/**
* 排序字段:create_time、is_read
*/
private String sort;
/**
* 排序类型:asc、desc
*/
private String sortType;
/**
* 开始日期
*/
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date startDate;
/**
* 结束日期
*/
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date endDate;
/**
* 关键词模糊查询
*/
private String keyWord;
/**
* 大区ID、部门ID、小组ID
*/
private String orgTreeValue;
}
\ No newline at end of file
......@@ -58,8 +58,11 @@ public class EngineerBusinessEntity implements Serializable {
@Column(name = "priority", nullable = false, columnDefinition = "tinyint(4) default '1'")
private int priority;
@Column(name = "departure", nullable = false, columnDefinition = "tinyint(4) default '0'")
private int departure;
/**
* 常规出发地,1配件仓,2家庭住址,3工作地址 默认工作地址
*/
@Column(name = "departure", nullable = false, columnDefinition = "tinyint(4) default '3'")
private int departure = 3;
@Column(name = "dispatch_strategy", nullable = false, length = 32, columnDefinition = "varchar(32) default 'CENTER'")
private String dispatchStrategy;
......
......@@ -58,6 +58,11 @@ public class EngineerInfoEntity {
private String address;
/**
* 工作地址
*/
private String workAddress;
/**
* 类型(1全职 2兼职)
*/
private Integer kind;
......
......@@ -31,7 +31,7 @@ public class OrgClusterEntity {
private String cityName;
private Integer status;
private Integer status = 1;
private String updateUser;
......
......@@ -88,5 +88,37 @@ public class OrgGroupEntity {
*/
private LocalDateTime updateTime = LocalDateTime.now();
public OrgGroupEntity() {}
public OrgGroupEntity() {
}
/**
* 管理城市列表
*/
private String citycodeList;
/**
* 部门缩写
*/
private String abbreviation;
/**
* 部门编号
*/
private String code;
/**
* 部门负责人联系方式
*/
private String phone;
/**
* 是否启用外围仓 0未启用 1启用
*/
private Integer warehouseEnabled = 0;
/**
* 最长配件保留时长(天)
*/
private Integer reserveTimeMax = 0;
/**
* 帐号状态(0无效 1有效)
*/
private Integer status = 1;
}
......@@ -49,9 +49,15 @@ public class OrgTeamEntity {
@Column(name = "update_time", nullable = false, columnDefinition = "timestamp default current_timestamp on update current_timestamp")
private LocalDateTime updateTime;
/**
* 工作起始时间
*/
@Column(name = "work_on", nullable = false, columnDefinition = "varchar(5) default '08:00'")
private String workOn = "08:00";
/**
* 工作截止时间
*/
@Column(name = "work_off", nullable = false, columnDefinition = "varchar(5) default '18:00'")
private String workOff = "18:00";
......
......@@ -22,7 +22,7 @@ public class ServiceOrg {
/**
* 状态;1正常、0注销
*/
private int status;
private Integer status;
/**
* 服务商类型
*/
......
......@@ -3,6 +3,7 @@ package com.dituhui.pea.order.service;
import com.dituhui.pea.common.PageResult;
import com.dituhui.pea.order.dto.MsgDTO;
import com.dituhui.pea.order.dto.MsgGroupResp;
import com.dituhui.pea.order.dto.MsgQuery;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
......@@ -17,7 +18,7 @@ public interface MsgService {
* @author RenPing
* @date 2023/10/23
*/
PageResult<MsgGroupResp> list(MsgDTO.Request request);
PageResult<MsgGroupResp> list(MsgQuery request);
/**
* 删除
......@@ -47,5 +48,5 @@ public interface MsgService {
* @author RenPing
* @date 2023/10/25
*/
void add(MsgDTO.addDto dto);
void add(MsgDTO dto);
}
......@@ -141,6 +141,11 @@ public class BeanRemoteServiceImpl {
}
/**
* 处理全部机构
*
* @return
*/
public Result allDepartment() {
//获取token
final String accessToken = getAccessToken();
......@@ -149,13 +154,20 @@ public class BeanRemoteServiceImpl {
return Result.failed(beanR.getMessage());
}
for (Department department : beanR.getData()) {
log.info("处理部门详情---->{}" + department.getBsDeptId());
log.info("处理部门详情---->{}", department.getBsDeptId());
Result result = this.departmentDetail(accessToken, department.getBsDeptId());
log.info("处理部门详情,id:{},结果---->{}" + department.getBsDeptId(), result.getCode());
log.info("处理部门详情,id:{},结果---->{}", department.getBsDeptId(), result.getCode());
}
return Result.success();
}
/**
* 处理单极机构,包含大区,分部,分站
*
* @param token
* @param orgId
* @return
*/
public Result departmentDetail(String token, String orgId) {
//获取token
BeanR<Department> departmentBeanR = beanRemoteService.departmentDetail(token, orgId);
......@@ -207,14 +219,33 @@ public class BeanRemoteServiceImpl {
groupEntity = new OrgGroupEntity();
}
groupEntity.setGroupName(data.getTagName());
//groupEntity.setAbbreviation(data.getAbbreviation());
//groupEntity.setStatus(data.getEnable());
//groupEntity.setCitycodeList(CollectionUtils.isEmpty(data.getManageCityList()) ? "" : JSONObject.toJSONString(data.getManageCityList()));
//groupEntity.setMemo(data.getDesc());
//groupEntity.setCode(data.getCode());
//groupEntity.setPhone(data.getPhone());
//groupEntity.setWarehouseEnabled(data.getPeripheralWarehouseEnabled());
//groupEntity.setReserveTimeMax(data.getPartReserveTimeMax());
groupEntity.setAbbreviation(data.getAbbreviation());
groupEntity.setStatus(data.getEnable());
groupEntity.setCitycodeList(CollectionUtils.isEmpty(data.getManageCityList()) ? "" : JSONObject.toJSONString(data.getManageCityList()));
groupEntity.setMemo(data.getDesc());
groupEntity.setCode(data.getCode());
groupEntity.setPhone(data.getPhone());
groupEntity.setWarehouseEnabled(data.getPeripheralWarehouseEnabled());
groupEntity.setReserveTimeMax(data.getPartReserveTimeMax());
//处理clusterId和branchId
OrgBranchEntity branchEntity = branchMap.get(data.getParentId());
if (ObjUtil.isNull(branchEntity)) {
branchEntity = orgBranchDao.getByBranchId(data.getParentId());
if (ObjUtil.isNull(branchEntity)) {
return Result.failed();
}
branchMap.put(data.getParentId(), branchEntity);
}
groupEntity.setBranchId(data.getParentId());
groupEntity.setClusterId(branchEntity.getClusterId());
//处理分站外围
if (data.getDeptType().equals(BeanOrgLevelEnum.PERIPHERY.getCode())) {
groupEntity.setKind(2);
}
if (data.getDeptType().equals(BeanOrgLevelEnum.STATION.getCode())) {
groupEntity.setKind(1);
}
groupEntity.setCategory(1);
orgGroupDao.save(groupEntity);
return Result.success();
}
......@@ -223,6 +254,53 @@ public class BeanRemoteServiceImpl {
/**
* 处理全部网点
*
* @return
*/
public Result serviceOrgList() {
//获取token
final String accessToken = getAccessToken();
BeanR<List<ServiceOrg>> listBeanR = beanRemoteService.serviceOrgList(accessToken, 1);
log.info("[查询网点/车队列表]【/api/openapi/department/queryServiceOrgList】返回值-------------------->{}", JsonUtil.toJson(listBeanR));
if (!listBeanR.getSuccess() || ObjUtil.isNull(listBeanR.getData())) {
return Result.failed(listBeanR.getMessage());
}
for (ServiceOrg serviceOrg : listBeanR.getData()) {
log.info("处理网点部门详情---->{}", serviceOrg.getServiceOrgId());
Result result = this.serviceOrgDetail(accessToken, serviceOrg);
log.info("处理网点部门详情,id:{},结果---->{}", serviceOrg.getServiceOrgId(), result.getCode());
}
return Result.success();
}
private Result serviceOrgDetail(String accessToken, ServiceOrg serviceOrg) {
BeanR<ServiceOrgDetail> beanR = beanRemoteService.serviceOrgDetail(accessToken, serviceOrg.getServiceOrgId());
log.info("[查询网点/车队列表]【/api/openapi/department/queryServiceOrgList】返回值-------------------->{}", JsonUtil.toJson(beanR));
if (!beanR.getSuccess() || ObjUtil.isNull(beanR.getData())) {
return Result.failed(beanR.getMessage());
}
ServiceOrgDetail data = beanR.getData();
OrgGroupEntity groupEntity = orgGroupDao.getByGroupId(data.getServiceOrgId());
if (ObjUtil.isNull(groupEntity)) {
groupEntity = new OrgGroupEntity();
}
groupEntity.setGroupName(data.getName());
groupEntity.setStatus(data.getStatus());
groupEntity.setCitycodeList(CollectionUtils.isEmpty(data.getServiceRange()) ? "" : JSONObject.toJSONString(data.getServiceRange()));
groupEntity.setPhone(data.getContactPhone());
groupEntity.setBranchId(data.getBelongBranch().getBsDeptId());
groupEntity.setClusterId(data.getBelongRegion().getBsDeptId());
//处理分站外围
groupEntity.setKind(4);
groupEntity.setCategory(2);
groupEntity.setAddress(data.getBusinessAddress().getAddress());
orgGroupDao.save(groupEntity);
return Result.success();
}
/**
* 获取bean token
*
* @return
......
......@@ -131,6 +131,8 @@ public class BusinessTeamServiceImpl implements BusinessTeamService {
.setTeamName(req.getTeamName())
.setTeamType(TEAMTYPE_PEA)
.setWarehouseId(req.getWarehouseId())
.setWorkOn(req.getWorkOn())
.setWorkOff(req.getWorkOff())
.setCreateTime(LocalDateTime.now())
.setUpdateTime(LocalDateTime.now());
if (req.getWorkdays() != null) {
......@@ -177,6 +179,12 @@ public class BusinessTeamServiceImpl implements BusinessTeamService {
if (StringUtils.isNotBlank(req.getGroupId())) {
entity.setGroupId(req.getGroupId());
}
if (StringUtils.isNotBlank(req.getWorkOn())) {
entity.setWorkOn(req.getWorkOn());
}
if (StringUtils.isNotBlank(req.getWorkOff())) {
entity.setWorkOff(req.getWorkOff());
}
entity.setUpdateTime(LocalDateTime.now());
orgTeamDao.save(entity);
......
......@@ -42,334 +42,335 @@ import java.util.stream.Collectors;
@Service
public class EngineerServiceImpl implements EngineerService {
@Autowired
private EngineerInfoDao engineerInfoDao;
@Autowired
private EngineerSkillGroupDao engineerSkillGroupDao;
@Autowired
private OrgGroupDao orgGroupDao;
@Autowired
private EngineerBusinessDao engineerBusinessDao;
@Autowired
private EntityManager entityManager;
@Transactional
@Override
public Result<?> getEngineerInfoList(String levelType, String levelValue, int page, int size, String kind, String key) {
// 查询工程师信息
Page<EngineerInfoEntity> pg = this.queryEngineerInfoIPage(levelType, levelValue, page, size, kind, key);
List<EngineerInfoEntity> records = pg.getContent();
// 获取groupIds
List<String> groupIds = records.stream().map(EngineerInfoEntity::getGroupId).collect(Collectors.toList());
// 获取Map<groupId, groupName>
HashMap<String, String> groupNames = this.queryGroupNames(groupIds);
// 设置返回值
EngineerInfoListResp res = new EngineerInfoListResp();
res.setContent(this.packEngineerInfos(records, groupNames));
res.setTotal(pg.getTotalElements());
res.setPages(pg.getTotalPages());
res.setPageCurrent(pg.getNumber() + 1);
res.setPageSize(pg.getSize());
return Result.success(res);
}
@Override
public Result<?> getEngineerInfoDetail(String engineerCode) throws BusinessException {
// 获取技术员基础信息详情
// 获取技术员列表
EngineerInfoEntity engineer = engineerInfoDao.getByEngineerCode(engineerCode);
if (engineer == null) {
throw new BusinessException("技术员不存在");
}
String groupId = engineer.getGroupId();
HashMap<String, String> groupNames = this.queryGroupNames(List.of(groupId));
List<EngineerInfoListResp.EngineerInfo> items = this.packEngineerInfos(List.of(engineer), groupNames);
if (items.isEmpty()) {
throw new BusinessException("技术员不存在");
}
return Result.success(items.get(0));
}
@Transactional
@Override
public Result<?> getEngineerSkillList(String levelType, String levelValue, int page, int size, String kind, String key) {
// 获取技术员技能列表
Page<EngineerInfoEntity> pg = this.queryEngineerInfoIPage(levelType, levelValue, page, size, kind, key);
List<EngineerInfoEntity> engineers = pg.getContent();
EngineerSkillListResp res = new EngineerSkillListResp();
res.setTotal(pg.getTotalElements());
res.setPages(pg.getTotalPages());
res.setPageCurrent(pg.getNumber() + 1);
res.setPageSize(pg.getSize());
res.setContent(this.packEngineerSkills(engineers));
return Result.success(res);
}
@Override
public Result<?> getEngineerSkillDetail(String engineerCode) throws BusinessException {
// 获取工程师技能详情
EngineerInfoEntity engineer = engineerInfoDao.getByEngineerCode(engineerCode);
if (engineer == null) {
throw new BusinessException("技术员不存在");
}
List<EngineerSkillListResp.EngineerSkill> items = this.packEngineerSkills(List.of(engineer));
if (items.isEmpty()) {
throw new BusinessException("技术员不存在");
}
return Result.success(items.get(0));
}
@Transactional
@Override
public Result<?> engineerSkillUpdate(String engineerCode, List<String> skillGroupIds) {
// 更新技术员技能
// 先将所有技能更新为0-不可用状态
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaUpdate<EngineerSkillGroupEntity> update = cb.createCriteriaUpdate(EngineerSkillGroupEntity.class);
Root<EngineerSkillGroupEntity> root = update.from(EngineerSkillGroupEntity.class);
update.set(root.get("status"), 0);
update.where(cb.equal(root.get("engineerCode"), engineerCode));
entityManager.createQuery(update).executeUpdate();
if (skillGroupIds.isEmpty()) {
return null;
}
// 更新categoryIds状态为1
CriteriaBuilder cb1 = entityManager.getCriteriaBuilder();
CriteriaUpdate<EngineerSkillGroupEntity> update1 = cb.createCriteriaUpdate(EngineerSkillGroupEntity.class);
Root<EngineerSkillGroupEntity> root1 = update1.from(EngineerSkillGroupEntity.class);
update1.set(root1.get("status"), 1);
update1.where(
cb1.equal(root1.get("engineerCode"), engineerCode),
root1.get("skillGroupCode").in(skillGroupIds)
);
int n = entityManager.createQuery(update1).executeUpdate();
if (skillGroupIds.size() == n) {
// 更新记录条数等于提交记录条数
return null;
}
// 可能存在engineerSkill表不存在的记录,需要补充录入
List<Boolean> statuses = new ArrayList<Boolean>(Arrays.asList(true, false));
List<String> engineerCodes = new ArrayList<>(Collections.singletonList(engineerCode));
HashMap<String, List<String>> engineerSkills = this.queryEngineerSkills(engineerCodes, statuses);
Set<String> sInput = new HashSet<>(skillGroupIds);
Set<String> sDB = new HashSet<>(engineerSkills.getOrDefault(engineerCode, new ArrayList<>()));
sInput.removeAll(sDB);
for (String skillGroupId : sInput) {
EngineerSkillGroupEntity e = new EngineerSkillGroupEntity();
e.setEngineerCode(engineerCode);
e.setSkillGroupCode(skillGroupId);
e.setBeanStatus(Boolean.TRUE);
e.setDescription("");
e.setStatus(true);
e.setMemo("");
e.setCreateTime(LocalDateTime.now());
e.setUpdateTime(LocalDateTime.now());
entityManager.persist(e);
}
return null;
}
@Transactional
@Override
public Result<?> getEngineerBusinessList(String levelType, String levelValue, int page, int size, String kind, String key) {
// 技术员业务属性配置列表
// 查询技术员列表
Page<EngineerInfoEntity> pg = this.queryEngineerInfoIPage(levelType, levelValue, page, size, kind, key);
List<EngineerInfoEntity> engineers = pg.getContent();
// 查询技术员业务属性
EngineerBusinessListResp res = new EngineerBusinessListResp();
res.setTotal(pg.getTotalElements());
res.setPages(pg.getTotalPages());
res.setPageCurrent(pg.getNumber() + 1);
res.setPageSize(pg.getSize());
res.setContent(this.packEngineerBusinesses(engineers));
return Result.success(res);
}
@Override
public Result<?> getEngineerBusinessDetail(String engineerCode) {
// 获取技术员业务熟悉详情
EngineerInfoEntity engineer = engineerInfoDao.getByEngineerCode(engineerCode);
if (engineer == null) {
throw new BusinessException("技术员不存在");
}
List<?> items = this.packEngineerBusinesses(List.of(engineer));
if (items.isEmpty()) {
throw new BusinessException("技术员不存在");
}
return Result.success(items.get(0));
}
@Transactional
@Override
public Result<?> engineerBusinessUpdate(String engineerCode, Integer maxNum, Integer departure, Integer priority,
String workOn, String workOff, String transportMode) {
// 计算时间差
int minute = this.getMinuteDiff(TimeUtils.time2LocalTime(workOn), TimeUtils.time2LocalTime(workOff));
// 技术员业务属性配置修改
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaUpdate<EngineerBusinessEntity> update = cb.createCriteriaUpdate(EngineerBusinessEntity.class);
Root<EngineerBusinessEntity> root = update.from(EngineerBusinessEntity.class);
update.set(root.get("maxNum"), maxNum);
update.set(root.get("departure"), departure);
update.set(root.get("priority"), priority);
update.set(root.get("workOn"), workOn);
update.set(root.get("workOff"), workOff);
update.set(root.get("maxMinute"), minute);
update.set(root.get("vehicle"), transportMode);
update.where(cb.equal(root.get("engineerCode"), engineerCode));
entityManager.createQuery(update).executeUpdate();
return Result.success(null);
}
private Page<EngineerInfoEntity> queryEngineerInfoIPage(String levelType, String levelValue, int page, int size, String kind, String key) {
// 分页查询工程师基础信息
// 查询技术员所在的groupIds
List<OrgGroupEntity> groups = new ArrayList<>();
if (levelType.equals("cluster")) {
groups = orgGroupDao.findAllByClusterId(levelValue);
} else if (levelType.equals("branch")) {
groups = orgGroupDao.findAllByBranchId(levelValue);
} else if (levelType.equals("group")) {
groups = orgGroupDao.findAllByGroupId(levelValue);
}
List<String> groupIds = groups.stream().map(OrgGroupEntity::getGroupId).collect(Collectors.toList());
Pageable pageable = PageRequest.of(page, size);
Specification<EngineerInfoEntity> spec = (root, query, cb) -> {
List<Predicate> predicates = new ArrayList<>();
if (groupIds != null && !groupIds.isEmpty()) {
predicates.add(root.get("groupId").in(groupIds));
}
if (StringUtils.hasText(kind)) {
int kindValue = kind.equals("fullJob") ? 1 : 2;
predicates.add(cb.equal(root.get("kind"), kindValue));
}
if (StringUtils.hasText(key)) {
String likeKey = "%" + key + "%";
predicates.add(cb.or(
cb.like(root.get("phone"), likeKey),
cb.like(root.get("name"), likeKey),
cb.like(root.get("engineerCode"), likeKey)
));
}
return cb.and(predicates.toArray(new Predicate[0]));
};
return engineerInfoDao.findAll(spec, pageable);
}
private HashMap<String, String> queryGroupNames(List<String> groupIds) {
//查询小组名称映射关系
HashMap<String, String> map = new HashMap<>();
if (groupIds.isEmpty()) {
return map;
}
List<OrgGroupEntity> groups = orgGroupDao.findByGroupIdIn(groupIds);
for (OrgGroupEntity g : groups) {
map.put(g.getGroupId(), g.getGroupName());
}
return map;
}
private HashMap<String, List<String>> queryEngineerSkills(List<String> engineerCodes, List<Boolean> statuses) {
// 获取engineerCode对应的技能表, HashMap<engineerCode, List<skillId>>
HashMap<String, List<String>> map = new HashMap<>();
if (engineerCodes.isEmpty()) {
return map;
}
List<EngineerSkillGroupEntity> records = engineerSkillGroupDao.findByEngineerCodeInAndStatusIn(engineerCodes, statuses);
if (ListUtils.isEmpty(records)) {
return map;
}
Comparator<EngineerSkillGroupEntity> ec = Comparator.comparing(EngineerSkillGroupEntity::getEngineerCode, String.CASE_INSENSITIVE_ORDER);
List<EngineerSkillGroupEntity> results = records.stream().sorted(ec).collect(Collectors.toList());
// 根据engineerCode分组
Map<String, List<EngineerSkillGroupEntity>> g = results.stream().collect(Collectors.groupingBy(EngineerSkillGroupEntity::getEngineerCode));
for (String engineerCode : g.keySet()) {
// 技术员技能ID列表
List<String> skillGroupIds = g.get(engineerCode).stream().map(EngineerSkillGroupEntity::getSkillGroupCode).collect(Collectors.toList());
map.put(engineerCode, skillGroupIds);
}
return map;
}
private HashMap<String, EngineerBusinessEntity> queryEngineerBusiness(List<String> engineerCodes) {
HashMap<String, EngineerBusinessEntity> map = new HashMap<>();
if (engineerCodes.isEmpty()) {
return map;
}
List<EngineerBusinessEntity> records = engineerBusinessDao.findByEngineerCodeIn(engineerCodes);
for (EngineerBusinessEntity r : records) {
map.put(r.getEngineerCode(), r);
}
return map;
}
private List<EngineerInfoListResp.EngineerInfo> packEngineerInfos(List<EngineerInfoEntity> engineers, HashMap<String, String> groups) {
String groupName, age, kind;
List<EngineerInfoListResp.EngineerInfo> items = new ArrayList<>();
for (EngineerInfoEntity e : engineers) {
EngineerInfoListResp.EngineerInfo item = new EngineerInfoListResp.EngineerInfo();
item.setEngineerCode(e.getEngineerCode());
item.setNumber(e.getEngineerCode());
item.setName(e.getName());
item.setSex(e.getGender());
item.setPhone(e.getPhone());
item.setAddress(e.getAddress());
item.setGrade(e.getGrade());
// group name
groupName = groups.getOrDefault(e.getGroupId(), "");
item.setGroupName(groupName);
// 年龄
age = this.getEngineerAge(e.getBirth());
item.setAge(age);
// 工作类型:全职/兼职
kind = (e.getKind() == 1) ? "fullJob" : "partJob";
item.setKind(kind);
if (e.getCredentials() != null) {
item.setCredentials(Arrays.asList(e.getCredentials().split("、")));
} else {
item.setCredentials(new ArrayList<String>());
}
// 标签
@Autowired
private EngineerInfoDao engineerInfoDao;
@Autowired
private EngineerSkillGroupDao engineerSkillGroupDao;
@Autowired
private OrgGroupDao orgGroupDao;
@Autowired
private EngineerBusinessDao engineerBusinessDao;
@Autowired
private EntityManager entityManager;
@Transactional
@Override
public Result<?> getEngineerInfoList(String levelType, String levelValue, int page, int size, String kind, String key) {
// 查询工程师信息
Page<EngineerInfoEntity> pg = this.queryEngineerInfoIPage(levelType, levelValue, page, size, kind, key);
List<EngineerInfoEntity> records = pg.getContent();
// 获取groupIds
List<String> groupIds = records.stream().map(EngineerInfoEntity::getGroupId).collect(Collectors.toList());
// 获取Map<groupId, groupName>
HashMap<String, String> groupNames = this.queryGroupNames(groupIds);
// 设置返回值
EngineerInfoListResp res = new EngineerInfoListResp();
res.setContent(this.packEngineerInfos(records, groupNames));
res.setTotal(pg.getTotalElements());
res.setPages(pg.getTotalPages());
res.setPageCurrent(pg.getNumber() + 1);
res.setPageSize(pg.getSize());
return Result.success(res);
}
@Override
public Result<?> getEngineerInfoDetail(String engineerCode) throws BusinessException {
// 获取技术员基础信息详情
// 获取技术员列表
EngineerInfoEntity engineer = engineerInfoDao.getByEngineerCode(engineerCode);
if (engineer == null) {
throw new BusinessException("技术员不存在");
}
String groupId = engineer.getGroupId();
HashMap<String, String> groupNames = this.queryGroupNames(List.of(groupId));
List<EngineerInfoListResp.EngineerInfo> items = this.packEngineerInfos(List.of(engineer), groupNames);
if (items.isEmpty()) {
throw new BusinessException("技术员不存在");
}
return Result.success(items.get(0));
}
@Transactional
@Override
public Result<?> getEngineerSkillList(String levelType, String levelValue, int page, int size, String kind, String key) {
// 获取技术员技能列表
Page<EngineerInfoEntity> pg = this.queryEngineerInfoIPage(levelType, levelValue, page, size, kind, key);
List<EngineerInfoEntity> engineers = pg.getContent();
EngineerSkillListResp res = new EngineerSkillListResp();
res.setTotal(pg.getTotalElements());
res.setPages(pg.getTotalPages());
res.setPageCurrent(pg.getNumber() + 1);
res.setPageSize(pg.getSize());
res.setContent(this.packEngineerSkills(engineers));
return Result.success(res);
}
@Override
public Result<?> getEngineerSkillDetail(String engineerCode) throws BusinessException {
// 获取工程师技能详情
EngineerInfoEntity engineer = engineerInfoDao.getByEngineerCode(engineerCode);
if (engineer == null) {
throw new BusinessException("技术员不存在");
}
List<EngineerSkillListResp.EngineerSkill> items = this.packEngineerSkills(List.of(engineer));
if (items.isEmpty()) {
throw new BusinessException("技术员不存在");
}
return Result.success(items.get(0));
}
@Transactional
@Override
public Result<?> engineerSkillUpdate(String engineerCode, List<String> skillGroupIds) {
// 更新技术员技能
// 先将所有技能更新为0-不可用状态
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaUpdate<EngineerSkillGroupEntity> update = cb.createCriteriaUpdate(EngineerSkillGroupEntity.class);
Root<EngineerSkillGroupEntity> root = update.from(EngineerSkillGroupEntity.class);
update.set(root.get("status"), 0);
update.where(cb.equal(root.get("engineerCode"), engineerCode));
entityManager.createQuery(update).executeUpdate();
if (skillGroupIds.isEmpty()) {
return null;
}
// 更新categoryIds状态为1
CriteriaBuilder cb1 = entityManager.getCriteriaBuilder();
CriteriaUpdate<EngineerSkillGroupEntity> update1 = cb.createCriteriaUpdate(EngineerSkillGroupEntity.class);
Root<EngineerSkillGroupEntity> root1 = update1.from(EngineerSkillGroupEntity.class);
update1.set(root1.get("status"), 1);
update1.where(
cb1.equal(root1.get("engineerCode"), engineerCode),
root1.get("skillGroupCode").in(skillGroupIds)
);
int n = entityManager.createQuery(update1).executeUpdate();
if (skillGroupIds.size() == n) {
// 更新记录条数等于提交记录条数
return null;
}
// 可能存在engineerSkill表不存在的记录,需要补充录入
List<Boolean> statuses = new ArrayList<Boolean>(Arrays.asList(true, false));
List<String> engineerCodes = new ArrayList<>(Collections.singletonList(engineerCode));
HashMap<String, List<String>> engineerSkills = this.queryEngineerSkills(engineerCodes, statuses);
Set<String> sInput = new HashSet<>(skillGroupIds);
Set<String> sDB = new HashSet<>(engineerSkills.getOrDefault(engineerCode, new ArrayList<>()));
sInput.removeAll(sDB);
for (String skillGroupId : sInput) {
EngineerSkillGroupEntity e = new EngineerSkillGroupEntity();
e.setEngineerCode(engineerCode);
e.setSkillGroupCode(skillGroupId);
e.setBeanStatus(Boolean.TRUE);
e.setDescription("");
e.setStatus(true);
e.setMemo("");
e.setCreateTime(LocalDateTime.now());
e.setUpdateTime(LocalDateTime.now());
entityManager.persist(e);
}
return null;
}
@Transactional
@Override
public Result<?> getEngineerBusinessList(String levelType, String levelValue, int page, int size, String kind, String key) {
// 技术员业务属性配置列表
// 查询技术员列表
Page<EngineerInfoEntity> pg = this.queryEngineerInfoIPage(levelType, levelValue, page, size, kind, key);
List<EngineerInfoEntity> engineers = pg.getContent();
// 查询技术员业务属性
EngineerBusinessListResp res = new EngineerBusinessListResp();
res.setTotal(pg.getTotalElements());
res.setPages(pg.getTotalPages());
res.setPageCurrent(pg.getNumber() + 1);
res.setPageSize(pg.getSize());
res.setContent(this.packEngineerBusinesses(engineers));
return Result.success(res);
}
@Override
public Result<?> getEngineerBusinessDetail(String engineerCode) {
// 获取技术员业务熟悉详情
EngineerInfoEntity engineer = engineerInfoDao.getByEngineerCode(engineerCode);
if (engineer == null) {
throw new BusinessException("技术员不存在");
}
List<?> items = this.packEngineerBusinesses(List.of(engineer));
if (items.isEmpty()) {
throw new BusinessException("技术员不存在");
}
return Result.success(items.get(0));
}
@Transactional
@Override
public Result<?> engineerBusinessUpdate(String engineerCode, Integer maxNum, Integer departure, Integer priority,
String workOn, String workOff, String transportMode) {
// 计算时间差
int minute = this.getMinuteDiff(TimeUtils.time2LocalTime(workOn), TimeUtils.time2LocalTime(workOff));
// 技术员业务属性配置修改
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaUpdate<EngineerBusinessEntity> update = cb.createCriteriaUpdate(EngineerBusinessEntity.class);
Root<EngineerBusinessEntity> root = update.from(EngineerBusinessEntity.class);
update.set(root.get("maxNum"), maxNum);
update.set(root.get("departure"), departure);
update.set(root.get("priority"), priority);
update.set(root.get("workOn"), workOn);
update.set(root.get("workOff"), workOff);
update.set(root.get("maxMinute"), minute);
update.set(root.get("vehicle"), transportMode);
update.where(cb.equal(root.get("engineerCode"), engineerCode));
entityManager.createQuery(update).executeUpdate();
return Result.success(null);
}
private Page<EngineerInfoEntity> queryEngineerInfoIPage(String levelType, String levelValue, int page, int size, String kind, String key) {
// 分页查询工程师基础信息
// 查询技术员所在的groupIds
List<OrgGroupEntity> groups = new ArrayList<>();
if (levelType.equals("cluster")) {
groups = orgGroupDao.findAllByClusterId(levelValue);
} else if (levelType.equals("branch")) {
groups = orgGroupDao.findAllByBranchId(levelValue);
} else if (levelType.equals("group")) {
groups = orgGroupDao.findAllByGroupId(levelValue);
}
List<String> groupIds = groups.stream().map(OrgGroupEntity::getGroupId).collect(Collectors.toList());
Pageable pageable = PageRequest.of(page, size);
Specification<EngineerInfoEntity> spec = (root, query, cb) -> {
List<Predicate> predicates = new ArrayList<>();
if (groupIds != null && !groupIds.isEmpty()) {
predicates.add(root.get("groupId").in(groupIds));
}
if (StringUtils.hasText(kind)) {
int kindValue = kind.equals("fullJob") ? 1 : 2;
predicates.add(cb.equal(root.get("kind"), kindValue));
}
if (StringUtils.hasText(key)) {
String likeKey = "%" + key + "%";
predicates.add(cb.or(
cb.like(root.get("phone"), likeKey),
cb.like(root.get("name"), likeKey),
cb.like(root.get("engineerCode"), likeKey)
));
}
return cb.and(predicates.toArray(new Predicate[0]));
};
return engineerInfoDao.findAll(spec, pageable);
}
private HashMap<String, String> queryGroupNames(List<String> groupIds) {
//查询小组名称映射关系
HashMap<String, String> map = new HashMap<>();
if (groupIds.isEmpty()) {
return map;
}
List<OrgGroupEntity> groups = orgGroupDao.findByGroupIdIn(groupIds);
for (OrgGroupEntity g : groups) {
map.put(g.getGroupId(), g.getGroupName());
}
return map;
}
private HashMap<String, List<String>> queryEngineerSkills(List<String> engineerCodes, List<Boolean> statuses) {
// 获取engineerCode对应的技能表, HashMap<engineerCode, List<skillId>>
HashMap<String, List<String>> map = new HashMap<>();
if (engineerCodes.isEmpty()) {
return map;
}
List<EngineerSkillGroupEntity> records = engineerSkillGroupDao.findByEngineerCodeInAndStatusIn(engineerCodes, statuses);
if (ListUtils.isEmpty(records)) {
return map;
}
Comparator<EngineerSkillGroupEntity> ec = Comparator.comparing(EngineerSkillGroupEntity::getEngineerCode, String.CASE_INSENSITIVE_ORDER);
List<EngineerSkillGroupEntity> results = records.stream().sorted(ec).collect(Collectors.toList());
// 根据engineerCode分组
Map<String, List<EngineerSkillGroupEntity>> g = results.stream().collect(Collectors.groupingBy(EngineerSkillGroupEntity::getEngineerCode));
for (String engineerCode : g.keySet()) {
// 技术员技能ID列表
List<String> skillGroupIds = g.get(engineerCode).stream().map(EngineerSkillGroupEntity::getSkillGroupCode).collect(Collectors.toList());
map.put(engineerCode, skillGroupIds);
}
return map;
}
private HashMap<String, EngineerBusinessEntity> queryEngineerBusiness(List<String> engineerCodes) {
HashMap<String, EngineerBusinessEntity> map = new HashMap<>();
if (engineerCodes.isEmpty()) {
return map;
}
List<EngineerBusinessEntity> records = engineerBusinessDao.findByEngineerCodeIn(engineerCodes);
for (EngineerBusinessEntity r : records) {
map.put(r.getEngineerCode(), r);
}
return map;
}
private List<EngineerInfoListResp.EngineerInfo> packEngineerInfos(List<EngineerInfoEntity> engineers, HashMap<String, String> groups) {
String groupName, age, kind;
List<EngineerInfoListResp.EngineerInfo> items = new ArrayList<>();
for (EngineerInfoEntity e : engineers) {
EngineerInfoListResp.EngineerInfo item = new EngineerInfoListResp.EngineerInfo();
item.setEngineerCode(e.getEngineerCode());
item.setNumber(e.getEngineerCode());
item.setName(e.getName());
item.setSex(e.getGender());
item.setPhone(e.getPhone());
item.setAddress(e.getAddress());
item.setGrade(e.getGrade());
item.setWorkAddress(e.getWorkAddress());
// group name
groupName = groups.getOrDefault(e.getGroupId(), "");
item.setGroupName(groupName);
// 年龄
age = this.getEngineerAge(e.getBirth());
item.setAge(age);
// 工作类型:全职/兼职
kind = (e.getKind() == 1) ? "fullJob" : "partJob";
item.setKind(kind);
if (e.getCredentials() != null) {
item.setCredentials(Arrays.asList(e.getCredentials().split("、")));
} else {
item.setCredentials(new ArrayList<String>());
}
// 标签
/*
List<String> tags = new ArrayList<>();
if (e.getTags() != null && !e.getTags().isEmpty()) {
......@@ -380,121 +381,121 @@ public class EngineerServiceImpl implements EngineerService {
item.setTags(tags);
*/
items.add(item);
}
return items;
}
private List<EngineerSkillListResp.EngineerSkill> packEngineerSkills(List<EngineerInfoEntity> engineers) {
// 获取groupId类表
List<String> groupIds = engineers.stream().map(EngineerInfoEntity::getGroupId).collect(Collectors.toList());
HashMap<String, String> groupNames = this.queryGroupNames(groupIds);
// 获取技术员code列表
List<String> engineerCodes = engineers.stream().map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toList());
// 获取技术员的可用技能列表
List<Boolean> statuses = Collections.singletonList(true);
HashMap<String, List<String>> engineerSkillGroups = this.queryEngineerSkills(engineerCodes, statuses);
List<String> emptySkills = Collections.emptyList();
List<EngineerSkillListResp.EngineerSkill> items = new ArrayList<>();
for (EngineerInfoEntity e : engineers) {
EngineerSkillListResp.EngineerSkill skill = new EngineerSkillListResp.EngineerSkill();
skill.setEngineerCode(e.getEngineerCode());
skill.setEngineerName(e.getName());
skill.setGroupName(groupNames.getOrDefault(e.getGroupId(), ""));
skill.setUpdateTime(TimeUtils.IsoLocalDateTime2String(e.getUpdateTime()));
// 获取一个工程师的技能列表
skill.setSkillGroupIds(engineerSkillGroups.getOrDefault(e.getEngineerCode(), emptySkills));
items.add(skill);
}
return items;
}
private List<EngineerBusinessListResp.EngineerBusiness> packEngineerBusinesses(List<EngineerInfoEntity> engineers) {
// 获取技术员code列表
List<String> engineerCodes = engineers.stream().map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toList());
List<String> groupIds = engineers.stream().map(EngineerInfoEntity::getGroupId).collect(Collectors.toList());
HashMap<String, String> groupNames = this.queryGroupNames(groupIds);
HashMap<String, EngineerBusinessEntity> buss = this.queryEngineerBusiness(engineerCodes);
List<EngineerBusinessListResp.EngineerBusiness> items = new ArrayList<>();
for (EngineerInfoEntity e : engineers) {
EngineerBusinessListResp.EngineerBusiness item = new EngineerBusinessListResp.EngineerBusiness();
EngineerBusinessEntity b = buss.getOrDefault(e.getEngineerCode(), null);
if (b == null) {
// 若没有配置,则不返回, 由同步程序初始化
continue;
}
item.setEngineerCode(e.getEngineerCode());
item.setGroupName(groupNames.getOrDefault(e.getGroupId(), ""));
item.setEngineerName(e.getName());
item.setKind((e.getKind() == 1) ? "fullJob" : "partJob");
item.setAddress(b.getAddress());
item.setLocation(String.format("%s,%s", b.getX(), b.getY()));
item.setWorkOn(b.getWorkOn());
item.setWorkOff(b.getWorkOff());
item.setTransportMode(b.getVehicle());
item.setDeparture(b.getDeparture());
item.setMaxMinute(b.getMaxMinute());
item.setMaxNum(b.getMaxNum());
item.setPriority(b.getPriority());
items.add(item);
}
return items;
}
private HashMap<String, Integer> getEngineerSkillIds(List<String> skillIds, HashMap<String, Integer> engineerSkillIds) {
HashMap<String, Integer> map = new HashMap<>();
for (String skillId : skillIds) {
map.put(skillId, engineerSkillIds.getOrDefault(skillId, 0));
}
return map;
}
private String getEngineerAge(String birth) {
// 获取工程师年龄
if (birth.isEmpty()) {
return "";
}
int age;
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
try {
Date birthDate = dateFormat.parse(birth);
Calendar birthCalendar = Calendar.getInstance();
birthCalendar.setTime(birthDate);
Calendar nowCalendar = Calendar.getInstance();
age = nowCalendar.get(Calendar.YEAR) - birthCalendar.get(Calendar.YEAR);
if (nowCalendar.get(Calendar.DAY_OF_YEAR) < birthCalendar.get(Calendar.DAY_OF_YEAR)) {
age--;
}
} catch (Exception e) {
return "";
}
return (age <= 0) ? "" : Integer.toString(age);
}
private int getMinuteDiff(LocalTime tBegin, LocalTime tEnd) {
int r = tBegin.compareTo(tEnd);
if (r == 0) {
return 0;
}
LocalDateTime dtBegin = LocalDateTime.of(LocalDateTime.now().toLocalDate(), tBegin);
LocalDateTime dtEnd;
if (r < 0) {
dtEnd = LocalDateTime.of(LocalDateTime.now().toLocalDate(), tEnd);
} else {
dtEnd = LocalDateTime.of(LocalDateTime.now().plusDays(1).toLocalDate(), tEnd);
}
Duration duration = Duration.between(dtBegin, dtEnd);
return (int) duration.toMinutes();
}
items.add(item);
}
return items;
}
private List<EngineerSkillListResp.EngineerSkill> packEngineerSkills(List<EngineerInfoEntity> engineers) {
// 获取groupId类表
List<String> groupIds = engineers.stream().map(EngineerInfoEntity::getGroupId).collect(Collectors.toList());
HashMap<String, String> groupNames = this.queryGroupNames(groupIds);
// 获取技术员code列表
List<String> engineerCodes = engineers.stream().map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toList());
// 获取技术员的可用技能列表
List<Boolean> statuses = Collections.singletonList(true);
HashMap<String, List<String>> engineerSkillGroups = this.queryEngineerSkills(engineerCodes, statuses);
List<String> emptySkills = Collections.emptyList();
List<EngineerSkillListResp.EngineerSkill> items = new ArrayList<>();
for (EngineerInfoEntity e : engineers) {
EngineerSkillListResp.EngineerSkill skill = new EngineerSkillListResp.EngineerSkill();
skill.setEngineerCode(e.getEngineerCode());
skill.setEngineerName(e.getName());
skill.setGroupName(groupNames.getOrDefault(e.getGroupId(), ""));
skill.setUpdateTime(TimeUtils.IsoLocalDateTime2String(e.getUpdateTime()));
// 获取一个工程师的技能列表
skill.setSkillGroupIds(engineerSkillGroups.getOrDefault(e.getEngineerCode(), emptySkills));
items.add(skill);
}
return items;
}
private List<EngineerBusinessListResp.EngineerBusiness> packEngineerBusinesses(List<EngineerInfoEntity> engineers) {
// 获取技术员code列表
List<String> engineerCodes = engineers.stream().map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toList());
List<String> groupIds = engineers.stream().map(EngineerInfoEntity::getGroupId).collect(Collectors.toList());
HashMap<String, String> groupNames = this.queryGroupNames(groupIds);
HashMap<String, EngineerBusinessEntity> buss = this.queryEngineerBusiness(engineerCodes);
List<EngineerBusinessListResp.EngineerBusiness> items = new ArrayList<>();
for (EngineerInfoEntity e : engineers) {
EngineerBusinessListResp.EngineerBusiness item = new EngineerBusinessListResp.EngineerBusiness();
EngineerBusinessEntity b = buss.getOrDefault(e.getEngineerCode(), null);
if (b == null) {
// 若没有配置,则不返回, 由同步程序初始化
continue;
}
item.setEngineerCode(e.getEngineerCode());
item.setGroupName(groupNames.getOrDefault(e.getGroupId(), ""));
item.setEngineerName(e.getName());
item.setKind((e.getKind() == 1) ? "fullJob" : "partJob");
item.setAddress(b.getAddress());
item.setLocation(String.format("%s,%s", b.getX(), b.getY()));
item.setWorkOn(b.getWorkOn());
item.setWorkOff(b.getWorkOff());
item.setTransportMode(b.getVehicle());
item.setDeparture(b.getDeparture());
item.setMaxMinute(b.getMaxMinute());
item.setMaxNum(b.getMaxNum());
item.setPriority(b.getPriority());
items.add(item);
}
return items;
}
private HashMap<String, Integer> getEngineerSkillIds(List<String> skillIds, HashMap<String, Integer> engineerSkillIds) {
HashMap<String, Integer> map = new HashMap<>();
for (String skillId : skillIds) {
map.put(skillId, engineerSkillIds.getOrDefault(skillId, 0));
}
return map;
}
private String getEngineerAge(String birth) {
// 获取工程师年龄
if (birth.isEmpty()) {
return "";
}
int age;
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
try {
Date birthDate = dateFormat.parse(birth);
Calendar birthCalendar = Calendar.getInstance();
birthCalendar.setTime(birthDate);
Calendar nowCalendar = Calendar.getInstance();
age = nowCalendar.get(Calendar.YEAR) - birthCalendar.get(Calendar.YEAR);
if (nowCalendar.get(Calendar.DAY_OF_YEAR) < birthCalendar.get(Calendar.DAY_OF_YEAR)) {
age--;
}
} catch (Exception e) {
return "";
}
return (age <= 0) ? "" : Integer.toString(age);
}
private int getMinuteDiff(LocalTime tBegin, LocalTime tEnd) {
int r = tBegin.compareTo(tEnd);
if (r == 0) {
return 0;
}
LocalDateTime dtBegin = LocalDateTime.of(LocalDateTime.now().toLocalDate(), tBegin);
LocalDateTime dtEnd;
if (r < 0) {
dtEnd = LocalDateTime.of(LocalDateTime.now().toLocalDate(), tEnd);
} else {
dtEnd = LocalDateTime.of(LocalDateTime.now().plusDays(1).toLocalDate(), tEnd);
}
Duration duration = Duration.between(dtBegin, dtEnd);
return (int) duration.toMinutes();
}
}
......@@ -7,6 +7,7 @@ import com.dituhui.pea.common.PageResult;
import com.dituhui.pea.order.dao.*;
import com.dituhui.pea.order.dto.MsgDTO;
import com.dituhui.pea.order.dto.MsgGroupResp;
import com.dituhui.pea.order.dto.MsgQuery;
import com.dituhui.pea.order.dto.MsgResp;
import com.dituhui.pea.order.entity.MsgEntity;
import com.dituhui.pea.order.entity.MsgReceiverEntity;
......@@ -47,7 +48,7 @@ public class MsgServiceImpl implements MsgService {
private OrgGroupDao groupDao;
@Override
public PageResult<MsgGroupResp> list(MsgDTO.Request request) {
public PageResult<MsgGroupResp> list(MsgQuery request) {
Sort sort = Sort.by("asc".equalsIgnoreCase(request.getSortType()) ? Sort.Direction.ASC : Sort.Direction.DESC, request.getSort());
Pageable pageable = PageRequest.of(request.getPage() - 1, request.getSize(), sort);
Page<Map<String, Objects>> page = msgDao.getGroupList(request, pageable);
......@@ -100,7 +101,7 @@ public class MsgServiceImpl implements MsgService {
@Override
@Transactional(rollbackFor = Exception.class)
public void add(MsgDTO.addDto dto) {
public void add(MsgDTO dto) {
if (Objects.nonNull(dto.getGroupId())) {
OrgGroupEntity group = groupDao.getByGroupId(dto.getGroupId());
dto.setBranchId(group.getBranchId());
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!