Commit 76567c40 by chamberone

Merge branch 'develop' of https://zhangguoping@gitlab.dituhui.com/bsh/project/pr…

…oject.git into develop
2 parents 038fa185 b9ee0b92
Showing with 974 additions and 597 deletions
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;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
......@@ -21,11 +20,11 @@ import java.util.Objects;
* @date 2023/10/24
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/pea-order")
public class MsgController {
private final MsgService msgService;
@Autowired
private MsgService msgService;
/**
* 消息列表
......@@ -38,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())) {
......@@ -57,16 +56,51 @@ public class MsgController {
/**
* 删除消息
*
* @param userId 用户标识
* @param deleteDto
* @param userId 用户标识
* @param dto
* @return {@link Result }<{@link Boolean }>
* @author RenPing
* @date 2023/10/24
*/
@RequestMapping(value = "/msg/delete", method = RequestMethod.POST)
public Result<Boolean> delete(@RequestHeader(name = "userId", required = true) String userId, @RequestBody @Valid MsgDTO.DeleteDto deleteDto) {
@PostMapping("/msg/delete")
public Result<Boolean> delete(@RequestHeader(name = "userId", required = true) String userId, @RequestBody @Valid IdDTO dto) {
AssertUtil.isNotEmpty(userId, "用户ID不能为空");
msgService.delete(deleteDto.getId(), userId);
AssertUtil.isNotNull(dto.getId(), "消息ID不能为空");
msgService.delete(dto.getId(), userId);
return Result.success(true);
}
/**
* 设置消息已读
*
* @param userId 用户标识
* @param dto
* @return {@link Result }<{@link Boolean }>
* @author RenPing
* @date 2023/10/24
*/
@PostMapping("/msg/read")
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);
}
/**
* 新增消息
*
* @param dto 参数
* @return {@link Result }<{@link Boolean }>
* @author RenPing
* @date 2023/10/25
*/
@PostMapping("/msg/add")
public Result<Boolean> add(@RequestBody @Valid MsgDTO dto) {
CommonUtil.setNullValue(dto);
AssertUtil.checkArgument(StrUtil.isNotEmpty(dto.getClusterId())
|| StrUtil.isNotEmpty(dto.getBranchId())
|| StrUtil.isNotEmpty(dto.getGroupId()), "大区Id、分部Id、分组Id不能同时为空");
msgService.add(dto);
return Result.success(true);
}
......
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;
......@@ -15,7 +13,7 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
public interface MsgDao extends JpaRepository<MsgEntity, Long> {
public interface MsgDao extends JpaRepository<MsgEntity, Integer> {
@Query(value = "select t.cluster_id,t.branch_id,t.group_id" +
" from (" +
" select tt.cluster_id,tt.branch_id,tt.group_id,min(tt.create_time) create_time,min(r.is_read) is_read" +
......@@ -23,6 +21,7 @@ public interface MsgDao extends JpaRepository<MsgEntity, Long> {
" 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,14 +31,16 @@ public interface MsgDao extends JpaRepository<MsgEntity, Long> {
" 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" +
@Query(value = "select t.* from (select tt.*,r.is_read," +
" (select group_concat(u.nickname) from zzz_msg_receiver rr join sys_user u on u.id=rr.user_id where rr.msg_id=tt.id) receivers"+
" from zzz_msg tt join zzz_msg_receiver r on r.msg_id=tt.id and r.user_id=:#{#req.userId}" +
" where IF(:#{#msgGroupResp.clusterId} is not null, tt.cluster_id=:#{#msgGroupResp.clusterId}, tt.cluster_id is null)" +
" and IF(:#{#msgGroupResp.branchId} is not null, tt.branch_id=:#{#msgGroupResp.branchId}, tt.branch_id is null)" +
......@@ -50,6 +51,30 @@ public interface MsgDao extends JpaRepository<MsgEntity, Long> {
") 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);
/**
* 根据小组或分部或大区获取角色为“分站派工”的用户
*
* @param clusterId 大区
* @param branchId 分部
* @param groupId 小组
* @return {@link List }<{@link String }>
* @author RenPing
* @date 2023/10/25
*/
@Query(value = "SELECT distinct u.id" +
" from sys_user u" +
" join sys_user_org uo on u.id=uo.user_id" +
" join sys_user_role ur on ur.user_id=u.id" +
" join sys_role r on r.id=ur.role_id and r.name='分站派工'" +
" and IF(:groupId is not null, uo.org_id=:groupId and uo.org_level=2, 1=1)" +
" and IF(:groupId is null and :branchId is not null, uo.org_id=:branchId and uo.org_level=1, 1=1)" +
" and IF(:groupId is null and :branchId is null and :clusterId is not null, uo.org_id=:clusterId and uo.org_level=0, 1=1)"
, nativeQuery = true // 开启原生sql
)
List<String> getDispatchUserList(@Param("clusterId") String clusterId,
@Param("branchId") String branchId,
@Param("groupId") String groupId);
}
......@@ -4,10 +4,12 @@ import com.dituhui.pea.order.entity.MsgReceiverEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
public interface MsgReceiverDao extends JpaRepository<MsgReceiverEntity, Long> {
import java.util.List;
public interface MsgReceiverDao extends JpaRepository<MsgReceiverEntity, Integer> {
@Modifying
@Query("delete from MsgReceiverEntity a where a.msgId=?1 and a.userId=?2")
void delete(Integer msgId, String userId);
@Query(value = "update zzz_msg_receiver set is_read=1 where msg_id in (:msgIds) and user_id=:userId", nativeQuery = true)
void read(@Param("msgIds") List<Integer> msgIds, @Param("userId") String userId);
}
......@@ -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.NotNull;
import java.time.LocalDate;
import java.util.Date;
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 addDto {
/**
* 大区ID
*/
private String clusterId;
/**
* 分部ID
*/
private String branchId;
/**
* 小组ID
*/
private String groupId;
/**
* 消息类型,0:派工类,1:服务类,2:容量类
*/
private Integer type;
/**
* 消息内容
*/
private String content;
/**
* 单号集合,以顿号连接
*/
private String orderIds;
/**
* 标签类型,0:紧急,1:正常
*/
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
......@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
@Data
......@@ -70,5 +71,10 @@ public class MsgResp {
*/
private Integer isRead;
/**
* 接收人
*/
private String receivers;
}
......@@ -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;
......
package com.dituhui.pea.order.entity;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.persistence.*;
import java.time.LocalDateTime;
......@@ -16,6 +17,7 @@ import java.util.Date;
@Entity
@Data
@Table(name = "zzz_msg")
@Accessors(chain = true)
public class MsgEntity {
@Id
......
......@@ -21,7 +21,7 @@ import java.util.Date;
public class MsgReceiverEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private Integer id;
/**
......
......@@ -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";
......
......@@ -16,7 +16,7 @@ public class OrderCancel {
/**
* 取消原因
*/
private String cancellationReason;
private Reason cancellationReason;
/**
* 取消备注
*/
......
package com.dituhui.pea.order.feign.bean;
import lombok.Getter;
import lombok.Setter;
@Setter
@Getter
public class Reason {
/**
* 一级原因
*/
private String oneLevel;
/**
* 二级原因
*/
private String twoLevel;
/**
* 三级原因
*/
private String threeLevel;
}
......@@ -22,7 +22,7 @@ public class Rescheduled {
/**
* 改约原因
*/
private String reasonForRescheduling;
private Reason reasonForRescheduling;
/**
* 改约备注
*/
......@@ -50,5 +50,26 @@ public class Rescheduled {
* 审批人工号
*/
private String approver;
/**
* 改派后工程师工号 reassignment 为true必填
*/
private String executorWorkNo;
/**
* 改派辅助工程师工号 没有辅助工程师传null
*/
private String assistantWorkNo;
/**
* 工程师部门id reassignment 为true必填
*/
private String orgUnitId;
/**
* 辅助工程师部门id 没有辅助工程师传null
*/
private String assOrgUnitId;
}
......@@ -22,7 +22,7 @@ public class ServiceOrg {
/**
* 状态;1正常、0注销
*/
private int status;
private Integer status;
/**
* 服务商类型
*/
......
......@@ -3,6 +3,10 @@ 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;
public interface MsgService {
......@@ -14,7 +18,7 @@ public interface MsgService {
* @author RenPing
* @date 2023/10/23
*/
PageResult<MsgGroupResp> list(MsgDTO.Request request);
PageResult<MsgGroupResp> list(MsgQuery request);
/**
* 删除
......@@ -25,4 +29,24 @@ public interface MsgService {
* @date 2023/10/24
*/
void delete(Integer msgId, String userId);
/**
* 设置消息已读
*
* @param msgIds 消息标识
* @param userId 用户标识
* @author RenPing
* @date 2023/10/25
*/
@Transactional(rollbackFor = Exception.class)
void readMsg(List<Integer> msgIds, String userId);
/**
* 新增消息
*
* @param dto 参数
* @author RenPing
* @date 2023/10/25
*/
void add(MsgDTO dto);
}
......@@ -100,23 +100,29 @@ public class BeanRemoteServiceImpl {
Rescheduled rescheduled = new Rescheduled();
rescheduled.setRisId("1000000302");
rescheduled.setRisId("1000002220");
rescheduled.setRescheduledDate(System.currentTimeMillis());
rescheduled.setReasonForRescheduling("reason");
Reason reason = new Reason();
reason.setOneLevel("reason1");
reason.setTwoLevel("reason2");
reason.setThreeLevel("reason3");
rescheduled.setReasonForRescheduling(reason);
rescheduled.setRemarksForRescheduling("remark");
rescheduled.setReassignment(Boolean.TRUE);
rescheduled.setReassignment(Boolean.FALSE);
rescheduled.setRequireApprove(Boolean.FALSE);
rescheduled.setInitiatorOfRescheduling("11111");
log.info("-----请求参数:{}", JsonUtil.toJson(rescheduled));
BeanR<?> beanRq = beanRemoteService.orderRescheduled(accessToken, rescheduled);
log.info("[服务工单改约]【/api/openapi/task/rescheduled 】返回值-------------------->{}", JsonUtil.toJson(beanRq));
OrderCancel orderCancel = new OrderCancel();
orderCancel.setRisId("S20230615000001");
orderCancel.setCancellationReason("example_reason");
orderCancel.setRisId("1000002248");
orderCancel.setCancellationReason(reason);
orderCancel.setCancelNote("example_note");
orderCancel.setCancelStartTime(1678594800000L);
orderCancel.setCancelStartTime(System.currentTimeMillis());
orderCancel.setCancelInitiator("example_initiator");
log.info("-----请求参数:{}", JsonUtil.toJson(orderCancel));
BeanR<?> beanR1 = beanRemoteService.orderTaskCancel(accessToken, orderCancel);
log.info("[服务工单取消]【/api/openapi/task/cancel】返回值-------------------->{}", JsonUtil.toJson(beanR1));
......@@ -135,6 +141,11 @@ public class BeanRemoteServiceImpl {
}
/**
* 处理全部机构
*
* @return
*/
public Result allDepartment() {
//获取token
final String accessToken = getAccessToken();
......@@ -143,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);
......@@ -201,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();
}
......@@ -217,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();
}
}
package com.dituhui.pea.order.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
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;
import com.dituhui.pea.order.entity.OrgBranchEntity;
import com.dituhui.pea.order.entity.OrgGroupEntity;
import com.dituhui.pea.order.enums.MsgTagEnum;
import com.dituhui.pea.order.enums.MsgTypeEnum;
import com.dituhui.pea.order.service.MsgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
......@@ -45,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);
......@@ -84,6 +87,47 @@ public class MsgServiceImpl implements MsgService {
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Integer msgId, String userId) {
msgReceiverDao.delete(msgId, userId);
List<MsgReceiverEntity> list = msgReceiverDao.findAll(Example.of(new MsgReceiverEntity().setMsgId(msgId).setUserId(userId)));
list.forEach(msgReceiverEntity -> {
msgReceiverDao.deleteById(msgReceiverEntity.getId());
});
}
@Override
@Transactional(rollbackFor = Exception.class)
public void readMsg(List<Integer> msgIds, String userId) {
msgReceiverDao.read(msgIds, userId);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void add(MsgDTO dto) {
if (Objects.nonNull(dto.getGroupId())) {
OrgGroupEntity group = groupDao.getByGroupId(dto.getGroupId());
dto.setBranchId(group.getBranchId());
dto.setClusterId(group.getClusterId());
} else if (Objects.nonNull(dto.getBranchId())) {
OrgBranchEntity branch = branchDao.getByBranchId(dto.getBranchId());
dto.setClusterId(branch.getClusterId());
} else if (Objects.nonNull(dto.getClusterId())) {
OrgBranchEntity branch = branchDao.getByBranchId(dto.getBranchId());
dto.setClusterId(branch.getClusterId());
}
List<String> userList = msgDao.getDispatchUserList(dto.getClusterId(), dto.getBranchId(), dto.getGroupId());
MsgEntity msgEntity = new MsgEntity();
BeanUtil.copyProperties(dto, msgEntity);
msgEntity.setCreateTime(new Date()).setUpdateTime(new Date());
msgDao.save(msgEntity);
userList.forEach(userId -> {
MsgReceiverEntity msgReceiverEntity = new MsgReceiverEntity()
.setMsgId(msgEntity.getId())
.setUserId(userId)
.setIsRead(0)
.setCreateTime(new Date())
.setUpdateTime(new Date());
msgReceiverDao.save(msgReceiverEntity);
});
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!