Commit 89e937fd by 刘鑫

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

2 parents a3a53293 41d5dddd
......@@ -18,5 +18,7 @@ public interface OrderInfoRepository extends CrudRepository<OrderInfo, Long> {
List<OrderInfo> findByOrderId(String orderId);
List<OrderInfo> findByOrgTeamIdAndDt(String teamId, LocalDate dt);
List<OrderInfo> findByOrgGroupIdAndDt(String groupId, LocalDate dt);
}
package com.dituhui.pea.dispatch.service.impl;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Optional;
import javax.persistence.EntityManager;
......@@ -13,8 +15,11 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.dituhui.pea.dispatch.dao.DispatchBatchRepository;
import com.dituhui.pea.dispatch.dao.OrderInfoRepository;
import com.dituhui.pea.dispatch.entity.DispatchBatch;
import com.dituhui.pea.dispatch.entity.OrderInfo;
import com.dituhui.pea.dispatch.service.BatchService;
import lombok.extern.slf4j.Slf4j;
......@@ -31,6 +36,9 @@ public class BatchServiceImpl implements BatchService {
@Autowired
DispatchBatchRepository batchRepository;
@Autowired
OrderInfoRepository orderInfoRepository;
@Autowired
private EntityManager entityManager;
......@@ -76,9 +84,45 @@ public class BatchServiceImpl implements BatchService {
batchDay = optional.get().getBatchDate();
}
// int engCount = queryEnginerCount(groupId);
// int orderCount = queryOrderCount(groupId, batchDay);
// 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);
}
log.info("清理原批次数据, groupId:{}, day:{}, batchNo:{}", groupId, batchDay, batchNo);
jdbcTemplate.update("delete from dispatch_engineer where group_id=? and batch_no=?", groupId, batchNo);
......@@ -97,7 +141,7 @@ public class BatchServiceImpl implements BatchService {
// 未派过的工单(已派过PRE状态还可以再次派)
String sqlOrder = "INSERT INTO dispatch_order (group_id, batch_no, team_id, order_id , dt, x, y, \n" +
" expect_time_begin, expect_time_end, tags, priority , skills , take_time, status )\n" +
" select a.org_group_id, ?, a.org_team_id , a.order_id, a.dt, a.x, a.y , \n" +
" select a.org_group_id, ?, a.org_team_id , a.order_id, ?, a.x, a.y , \n" +
" a.expect_time_begin, a.expect_time_end, a.tags, a.priority , \n" +
" concat(a.brand, '-', a.type, '-', a.skill) skills , a.take_time , a.appointment_status\n" +
" from order_info a \n" +
......@@ -105,12 +149,7 @@ public class BatchServiceImpl implements BatchService {
" and appointment_method like 'AUTO%' and a.appointment_status in ('INIT', 'PRE')\n" +
" and order_status ='NORMAL' and service_status='INIT'\n" +
" order by a.expect_time_begin asc ";
String tempDay = "2023-08-13";
int orderCount = jdbcTemplate.update(sqlOrder, batchNo, groupId,
/**
* FIXME 因为系统暂时没有订单,每次固定拉取2023-08-13号数据tempDay,上线后改成batchDay
*/
tempDay);
int orderCount = jdbcTemplate.update(sqlOrder, batchNo, batchDay, groupId, batchDay);
// confirm的要做预占用,所以也加入进来
String sqlOrderConfirm = "INSERT INTO dispatch_order (group_id, batch_no, team_id, order_id , dt, x, y, \n" +
......
......@@ -102,6 +102,11 @@ public enum StatusCodeEnum {
*/
RESOURCE_ALREADY_EXISTS_ROLE("017","角色中已存在该资源,不能重复添加", false),
/**
* 用户状态异常或已被禁用
*/
USER_ISBAN_OR_ERROR("018","用户状态异常或已被禁用", false),
GIS_EXISTS("001", "已存在", false),
GIS_NOT_EXISTS("002", "不存在", false),
......
......@@ -86,7 +86,7 @@ public class UserInfo {
/**
* 组织ids
*/
private List<Integer> orgIds;
private List<String> orgIds;
/**
* 组织级别 0:大区 1:分部 2:站点
*/
......@@ -135,6 +135,6 @@ public class UserInfo {
/**
* 是否正常 0: 否 1:是 默认1
*/
private Integer status = 1;
private Integer status;
}
......@@ -122,4 +122,9 @@ public class UserInfoSearch extends PageRequest implements Serializable {
*/
private String notes;
/**
* 是否正常 0: 否 1:是 默认1
*/
private Integer status = 1;
}
......@@ -10,7 +10,7 @@ public class OrgInfo implements Serializable {
/**
* 机构id
*/
private Integer id;
private String id;
/**
* 机构名称
......
// package com.dituhui.pea.user;
//
// import com.dituhui.pea.common.Result;
// import com.dituhui.pea.pojo.RoleInfo;
// import org.springframework.cloud.openfeign.FeignClient;
// import org.springframework.web.bind.annotation.RequestBody;
// import org.springframework.web.bind.annotation.RequestMapping;
// import org.springframework.web.bind.annotation.RequestMethod;
//
// /**
// * 角色相关接口
// */
// @FeignClient(value = "project-user", contextId = "role2")
// public interface IRole2 {
//
// /**
// * 添加角色
// *
// * @param roleInfo 角色信息
// * @return
// */
// @RequestMapping(value = "/pea-user/role/add2", method = RequestMethod.POST)
// Result<RoleInfo> addRole(@RequestBody RoleInfo roleInfo);
//
// }
......@@ -17,7 +17,7 @@ public class EngineerTimelineController {
private EngineerTimelineService engineerTimelineService;
@GetMapping("/engineer/work/dynamics")
public Result<?> GetEngineerTimeline(@RequestParam String engineerCode, String date) {
public Result<?> GetEngineerTimeline(@RequestParam String engineerCode, @RequestParam String date) {
return engineerTimelineService.getEngineerTimelines(engineerCode, date);
}
}
......@@ -14,8 +14,8 @@ public interface OrderInfoDao extends JpaRepository<OrderInfoEntity, Long>, JpaS
List<OrderInfoEntity> findByOrderId(String orderId);
List<OrderInfoEntity> findByDtAndEngineerCodeIn(LocalDate date, List<String> engineerCodes);
List<OrderInfoEntity> findByDtAndEngineerCode(LocalDate date, String engineerCode);
@Query("SELECT o.orderId, s.skillCategory as skillCaption FROM OrderInfoEntity o JOIN SkillInfoEntity s on o.brand=s.brand and o.type=s.type and o.skill=s.skill WHERE o.orderId = :orderId")
OrderSkillProjection getOrderSkillCaptionByOrderId(String orderId);
@Query("SELECT o.orderId, s.skillCategory as skillCaption FROM OrderInfoEntity o JOIN SkillInfoEntity s on o.brand=s.brand and o.type=s.type and o.skill=s.skill WHERE o.orderId = :orderId and o.dt = :dt")
OrderSkillProjection getOrderSkillCaptionByOrderIdAndDt(String orderId, LocalDate dt);
List<OrderInfoEntity> findAllByOrderIdIn(List<String> orderIds);
List<OrderInfoEntity> findAllByDtAndOrderIdIn(LocalDate dt, List<String> orderIds);
List<OrderInfoEntity> findByEngineerCodeAndDtAndAppointmentStatusIn(String engineerCode, LocalDate dt, List<String> appointmentStatus);
......
......@@ -4,31 +4,38 @@ import lombok.Data;
@Data
public class OrderServiceList {
private String orderId;
private String type;
private String brand;
private String skill;
private String faultDescribe;
private String name;
private String phone;
private String address;
private String x;
private String y;
private Integer priority;
private Integer takeTime;
private String expectTimeBegin;
private String expectTimeEnd;
private String expectTimeDesc;
private String source;
private String description;
private String orgBranchName;
private Integer engineerNum;
private String engineerNames;
private String dispatcher;
private String appointmentTime;
private String appointmentType;
private String appointmentStatus;
private String orderStatus;
private String serviceStatus;
private String createTime;
private String orderId;
private String type;
private String brand;
private String skill;
private String faultDescribe;
private String name;
private String phone;
private String address;
private String x;
private String y;
private Integer priority;
private Integer takeTime;
private String expectTimeBegin;
private String expectTimeEnd;
private String expectTimeDesc;
private String source;
private String description;
private String orgBranchName;
private Integer engineerNum;
private String engineerNames;
private String dispatcher;
private String appointmentTime;
private String appointmentType;
private String appointmentStatus;
private String orderStatus;
private String serviceStatus;
private String createTime;
/**
* bean优先级,例如:紧急、正常
*/
private String beanPriority;
}
......@@ -53,7 +53,8 @@ public class EngineerGanttServiceImpl implements EngineerGanttService {
log.info("根据多条件,查询返回符合条件的技术员列表:{}", engineerCodes);
}
List<OrderInfoEntity> orders = orderInfoDao.findByDtAndEngineerCodeIn(LocalDate.parse(reqDTO.getDate()), engineerCodes);
LocalDate localDate = LocalDate.parse(reqDTO.getDate());
List<OrderInfoEntity> orders = orderInfoDao.findByDtAndEngineerCodeIn(localDate, engineerCodes);
HashMap<String, List<EngineersGanttDTO.Slot>> mapEngineers = new HashMap<>();
for (OrderInfoEntity order : orders) {
// 服务工单本体
......@@ -71,7 +72,7 @@ public class EngineerGanttServiceImpl implements EngineerGanttService {
slot.setEtime(getHourMinute(order.getExpectTimeEnd()));
}
slot.setTooltip(getOrderTips(order));
OrderSkillProjection orderSkill = orderInfoDao.getOrderSkillCaptionByOrderId(order.getOrderId());
OrderSkillProjection orderSkill = orderInfoDao.getOrderSkillCaptionByOrderIdAndDt(order.getOrderId(), localDate);
if (orderSkill != null) {
slot.setText(orderSkill.getSkillCaption());
}
......
......@@ -24,177 +24,179 @@ import java.util.stream.Collectors;
@Service
public class OrderServiceListServiceImpl implements OrderServiceListService {
@Autowired
private OrderInfoMPDao orderInfoMPDao;
@Autowired
private EngineerInfoDao engineerInfoDao;
@Autowired
private OrgBranchDao orgBranchDao;
@Transactional
@Override
public Result<OrderServiceListResp> getOrderServiceList(OrderServiceListReq reqDTO) throws BusinessException {
//分页
Page<OrderInfo> pg = new Page(reqDTO.getPage(), reqDTO.getSize());
LocalDate startDate = TimeUtils.IsoDate2LocalDate(reqDTO.getStartDate());
LocalDate endDate = TimeUtils.IsoDate2LocalDate(reqDTO.getEndDate());
LambdaQueryWrapper<OrderInfo> lqw = new LambdaQueryWrapper<>();
lqw.eq(reqDTO.getLevelType().equals("cluster"), OrderInfo::getOrgClusterId, reqDTO.getLevelValue());
lqw.eq(reqDTO.getLevelType().equals("branch"), OrderInfo::getOrgBranchId, reqDTO.getLevelValue());
lqw.eq(reqDTO.getLevelType().equals("group"), OrderInfo::getOrgGroupId, reqDTO.getLevelValue());
lqw.ge(OrderInfo::getDt, startDate); //预约开始日期
lqw.le(OrderInfo::getDt, endDate); //预约开始日期
//筛选项
lqw.eq(StringUtils.isNotEmpty(reqDTO.getPhone()), OrderInfo::getPhone, reqDTO.getPhone());
lqw.eq(StringUtils.isNotEmpty(reqDTO.getOrderId()), OrderInfo::getOrderId, reqDTO.getOrderId());
lqw.in(ListUtils.isNotEmpty(reqDTO.getBranchIds()), OrderInfo::getOrgBranchId, reqDTO.getBranchIds());
lqw.in(ListUtils.isNotEmpty(reqDTO.getGroupIds()), OrderInfo::getOrgGroupId, reqDTO.getGroupIds());
lqw.in(ListUtils.isNotEmpty(reqDTO.getTeamIds()), OrderInfo::getOrgTeamId, reqDTO.getTeamIds());
lqw.in(ListUtils.isNotEmpty(reqDTO.getAppointmentType()), OrderInfo::getAppointmentMethod, reqDTO.getAppointmentType());
lqw.in(ListUtils.isNotEmpty(reqDTO.getAppointmentStatus()), OrderInfo::getAppointmentStatus, reqDTO.getAppointmentStatus());
if (ListUtils.isNotEmpty(reqDTO.getPriorities())) {
List<Integer> p = reqDTO.getPriorities();
if (p.contains(0) && p.contains(1)) {
lqw.ge(OrderInfo::getPriority, 1);
} else if (p.contains(0) && !p.contains(1)) {
lqw.le(OrderInfo::getPriority, 1);
} else if (p.contains(1) && !p.contains(0)) {
lqw.ge(OrderInfo::getPriority, 5);
}
}
if (ListUtils.isNotEmpty(reqDTO.getEngineerCodes())){
lqw.and(w ->
w.in(OrderInfo::getEngineerCode, reqDTO.getEngineerCodes())
.or()
.in(OrderInfo::getEngineerCodeSub, reqDTO.getEngineerCodes())
);
}
if (ListUtils.isNotEmpty(reqDTO.getTypeCategory())) {
String types = "'" + String.join("','", reqDTO.getTypeCategory()) + "'";
String sql = String.format("select 1 from skill_info sk where sk.brand = order_info.brand and sk.type = order_info.type and sk.skill = order_info.skill and type_category in (%s)", types);
lqw.exists(sql);
}
if (ListUtils.isNotEmpty(reqDTO.getSkillCategory())) {
String skills = "'" + String.join("','", reqDTO.getSkillCategory()) + "'";
String sql = String.format("select 1 from skill_info sk where sk.brand = order_info.brand and sk.type = order_info.type and sk.skill = order_info.skill and skill_category in (%s)", skills);
lqw.exists(sql);
}
if (ListUtils.isNotEmpty(reqDTO.getGroupCategory())) {
String groupCategory = reqDTO.getGroupCategory().stream().map(Object::toString).collect(Collectors.joining(","));
String sql = String.format("select 1 from org_group g where g.group_id = order_info.org_group_id and g.category in (%s)", groupCategory);
lqw.exists(sql);
}
// 查询工单表列表
orderInfoMPDao.selectPage(pg, lqw);
List<OrderInfo> orders = pg.getRecords();
// 获取技术员姓名
Map<String, String> engineerNames = this.getEngineerNames(orders);
// 获取branch
Map<String, String> branchNames = this.getBranchNames(orders);
// 获取工程师工号列表
List<OrderServiceList> content = new ArrayList<>();
for (OrderInfo o : orders) {
OrderServiceList record = new OrderServiceList();
record.setOrderId(o.getOrderId());
record.setType(o.getType());
record.setBrand(o.getBrand());
record.setSkill(o.getSkill());
record.setTakeTime(o.getTakeTime());
record.setFaultDescribe(o.getFaultDescribe());
record.setName(o.getName());
record.setPhone(o.getPhone());
record.setAddress(String.format("%s-%s-%s", o.getCity(), o.getCounty(), o.getAddress()));
record.setX(o.getX());
record.setY(o.getY());
record.setSource(o.getSource());
record.setDescription(o.getDescription());
record.setPriority(o.getPriority());
record.setOrgBranchName(branchNames.getOrDefault(o.getOrgBranchId(), ""));
// 获取工程师信息
List<String> names = this.getOrderEngineerNames(o.getEngineerCode(), o.getEngineerCodeSub(), engineerNames);
record.setEngineerNum(names.size()); //工程师数量
record.setEngineerNames(String.join("、", names)); //工程师姓名列表
record.setExpectTimeBegin(TimeUtils.IsoTimestamp2DateTime(o.getExpectTimeBegin()));
record.setExpectTimeEnd(TimeUtils.IsoTimestamp2DateTime(o.getExpectTimeEnd()));
record.setExpectTimeDesc(o.getExpectTimeDesc());
record.setAppointmentType(o.getAppointmentMethod());
record.setAppointmentStatus(o.getAppointmentStatus());
record.setOrderStatus(o.getOrderStatus());
record.setServiceStatus(o.getServiceStatus());
record.setDispatcher(o.getDispatcher());
record.setCreateTime(TimeUtils.IsoTimestamp2DateTime(o.getCreateTime()));
content.add(record);
}
// 组装
OrderServiceListResp res = new OrderServiceListResp();
res.setTotal(pg.getTotal());
res.setPages(pg.getPages());
res.setPageCurrent(pg.getCurrent());
res.setPageSize(pg.getSize());
res.setContent(content);
return Result.success(res);
}
private Map<String, String> getEngineerNames(List<OrderInfo> orders) {
// 获取技术员姓名
Set<String> engineerCodes = new HashSet<>();
for(OrderInfo r: orders){
if(StringUtils.isNotEmpty(r.getEngineerCode())){
engineerCodes.add(r.getEngineerCode());
}
if(StringUtils.isNotEmpty(r.getEngineerCodeSub())){
engineerCodes.add(r.getEngineerCodeSub());
}
}
if(engineerCodes.isEmpty()){
return new HashMap<>();
}
List<EngineerInfoEntity> engineers = engineerInfoDao.findByEngineerCodeIn(new ArrayList<>(engineerCodes));
return engineers.stream().collect(Collectors.toMap(EngineerInfoEntity::getEngineerCode, EngineerInfoEntity::getName));
}
private Map<String, String> getBranchNames(List<OrderInfo> orders){
// 获取branch名称
Set<String> branches = new HashSet<>();
for(OrderInfo r: orders){
if(StringUtils.isNotEmpty(r.getOrgBranchId())){
branches.add(r.getOrgBranchId());
}
}
if(branches.isEmpty()){
return new HashMap<>();
}
List<OrgBranchEntity> records = orgBranchDao.findByBranchIdIn(new ArrayList<>(branches));
return records.stream().collect(Collectors.toMap(OrgBranchEntity::getBranchId, OrgBranchEntity::getBranchName));
}
private List<String> getOrderEngineerNames(String engineerCode, String engineerCodeSub, Map<String,String> engineerNames){
// 获取订单技术员姓名信息
List<String> names = new ArrayList<>();
for(String code: List.of(engineerCode, engineerCodeSub)){
String name = engineerNames.getOrDefault(code, "");
if(StringUtils.isNotEmpty(name)){
names.add(name);
}
}
return names;
}
@Autowired
private OrderInfoMPDao orderInfoMPDao;
@Autowired
private EngineerInfoDao engineerInfoDao;
@Autowired
private OrgBranchDao orgBranchDao;
@Transactional
@Override
public Result<OrderServiceListResp> getOrderServiceList(OrderServiceListReq reqDTO) throws BusinessException {
//分页
Page<OrderInfo> pg = new Page(reqDTO.getPage(), reqDTO.getSize());
LocalDate startDate = TimeUtils.IsoDate2LocalDate(reqDTO.getStartDate());
LocalDate endDate = TimeUtils.IsoDate2LocalDate(reqDTO.getEndDate());
LambdaQueryWrapper<OrderInfo> lqw = new LambdaQueryWrapper<>();
lqw.eq(reqDTO.getLevelType().equals("cluster"), OrderInfo::getOrgClusterId, reqDTO.getLevelValue());
lqw.eq(reqDTO.getLevelType().equals("branch"), OrderInfo::getOrgBranchId, reqDTO.getLevelValue());
lqw.eq(reqDTO.getLevelType().equals("group"), OrderInfo::getOrgGroupId, reqDTO.getLevelValue());
lqw.ge(OrderInfo::getDt, startDate); //预约开始日期
lqw.le(OrderInfo::getDt, endDate); //预约开始日期
//筛选项
lqw.eq(StringUtils.isNotEmpty(reqDTO.getPhone()), OrderInfo::getPhone, reqDTO.getPhone());
lqw.eq(StringUtils.isNotEmpty(reqDTO.getOrderId()), OrderInfo::getOrderId, reqDTO.getOrderId());
lqw.in(ListUtils.isNotEmpty(reqDTO.getBranchIds()), OrderInfo::getOrgBranchId, reqDTO.getBranchIds());
lqw.in(ListUtils.isNotEmpty(reqDTO.getGroupIds()), OrderInfo::getOrgGroupId, reqDTO.getGroupIds());
lqw.in(ListUtils.isNotEmpty(reqDTO.getTeamIds()), OrderInfo::getOrgTeamId, reqDTO.getTeamIds());
lqw.in(ListUtils.isNotEmpty(reqDTO.getAppointmentType()), OrderInfo::getAppointmentMethod, reqDTO.getAppointmentType());
lqw.in(ListUtils.isNotEmpty(reqDTO.getAppointmentStatus()), OrderInfo::getAppointmentStatus, reqDTO.getAppointmentStatus());
if (ListUtils.isNotEmpty(reqDTO.getPriorities())) {
List<Integer> p = reqDTO.getPriorities();
if (p.contains(0) && p.contains(1)) {
lqw.ge(OrderInfo::getPriority, 1);
} else if (p.contains(0) && !p.contains(1)) {
lqw.le(OrderInfo::getPriority, 1);
} else if (p.contains(1) && !p.contains(0)) {
lqw.ge(OrderInfo::getPriority, 5);
}
}
if (ListUtils.isNotEmpty(reqDTO.getEngineerCodes())) {
lqw.and(w ->
w.in(OrderInfo::getEngineerCode, reqDTO.getEngineerCodes())
.or()
.in(OrderInfo::getEngineerCodeSub, reqDTO.getEngineerCodes())
);
}
if (ListUtils.isNotEmpty(reqDTO.getTypeCategory())) {
String types = "'" + String.join("','", reqDTO.getTypeCategory()) + "'";
String sql = String.format("select 1 from skill_info sk where sk.brand = order_info.brand and sk.type = order_info.type and sk.skill = order_info.skill and type_category in (%s)", types);
lqw.exists(sql);
}
if (ListUtils.isNotEmpty(reqDTO.getSkillCategory())) {
String skills = "'" + String.join("','", reqDTO.getSkillCategory()) + "'";
String sql = String.format("select 1 from skill_info sk where sk.brand = order_info.brand and sk.type = order_info.type and sk.skill = order_info.skill and skill_category in (%s)", skills);
lqw.exists(sql);
}
if (ListUtils.isNotEmpty(reqDTO.getGroupCategory())) {
String groupCategory = reqDTO.getGroupCategory().stream().map(Object::toString).collect(Collectors.joining(","));
String sql = String.format("select 1 from org_group g where g.group_id = order_info.org_group_id and g.category in (%s)", groupCategory);
lqw.exists(sql);
}
// 查询工单表列表
orderInfoMPDao.selectPage(pg, lqw);
List<OrderInfo> orders = pg.getRecords();
// 获取技术员姓名
Map<String, String> engineerNames = this.getEngineerNames(orders);
// 获取branch
Map<String, String> branchNames = this.getBranchNames(orders);
// 获取工程师工号列表
List<OrderServiceList> content = new ArrayList<>();
for (OrderInfo o : orders) {
OrderServiceList record = new OrderServiceList();
record.setOrderId(o.getOrderId());
record.setType(o.getType());
record.setBrand(o.getBrand());
record.setSkill(o.getSkill());
record.setTakeTime(o.getTakeTime());
record.setFaultDescribe(o.getFaultDescribe());
record.setName(o.getName());
record.setPhone(o.getPhone());
record.setAddress(String.format("%s-%s-%s", o.getCity(), o.getCounty(), o.getAddress()));
record.setX(o.getX());
record.setY(o.getY());
record.setSource(o.getSource());
record.setDescription(o.getDescription());
record.setPriority(o.getPriority());
record.setOrgBranchName(branchNames.getOrDefault(o.getOrgBranchId(), ""));
// 获取工程师信息
List<String> names = this.getOrderEngineerNames(o.getEngineerCode(), o.getEngineerCodeSub(), engineerNames);
record.setEngineerNum(names.size()); //工程师数量
record.setEngineerNames(String.join("、", names)); //工程师姓名列表
record.setExpectTimeBegin(TimeUtils.IsoTimestamp2DateTime(o.getExpectTimeBegin()));
record.setExpectTimeEnd(TimeUtils.IsoTimestamp2DateTime(o.getExpectTimeEnd()));
record.setExpectTimeDesc(o.getExpectTimeDesc());
record.setAppointmentType(o.getAppointmentMethod());
record.setAppointmentStatus(o.getAppointmentStatus());
record.setOrderStatus(o.getOrderStatus());
record.setServiceStatus(o.getServiceStatus());
record.setDispatcher(o.getDispatcher());
record.setCreateTime(TimeUtils.IsoTimestamp2DateTime(o.getCreateTime()));
record.setBeanPriority(o.getBeanPriority());
content.add(record);
}
// 组装
OrderServiceListResp res = new OrderServiceListResp();
res.setTotal(pg.getTotal());
res.setPages(pg.getPages());
res.setPageCurrent(pg.getCurrent());
res.setPageSize(pg.getSize());
res.setContent(content);
return Result.success(res);
}
private Map<String, String> getEngineerNames(List<OrderInfo> orders) {
// 获取技术员姓名
Set<String> engineerCodes = new HashSet<>();
for (OrderInfo r : orders) {
if (StringUtils.isNotEmpty(r.getEngineerCode())) {
engineerCodes.add(r.getEngineerCode());
}
if (StringUtils.isNotEmpty(r.getEngineerCodeSub())) {
engineerCodes.add(r.getEngineerCodeSub());
}
}
if (engineerCodes.isEmpty()) {
return new HashMap<>();
}
List<EngineerInfoEntity> engineers = engineerInfoDao.findByEngineerCodeIn(new ArrayList<>(engineerCodes));
return engineers.stream().collect(Collectors.toMap(EngineerInfoEntity::getEngineerCode, EngineerInfoEntity::getName));
}
private Map<String, String> getBranchNames(List<OrderInfo> orders) {
// 获取branch名称
Set<String> branches = new HashSet<>();
for (OrderInfo r : orders) {
if (StringUtils.isNotEmpty(r.getOrgBranchId())) {
branches.add(r.getOrgBranchId());
}
}
if (branches.isEmpty()) {
return new HashMap<>();
}
List<OrgBranchEntity> records = orgBranchDao.findByBranchIdIn(new ArrayList<>(branches));
return records.stream().collect(Collectors.toMap(OrgBranchEntity::getBranchId, OrgBranchEntity::getBranchName));
}
private List<String> getOrderEngineerNames(String engineerCode, String engineerCodeSub, Map<String, String> engineerNames) {
// 获取订单技术员姓名信息
List<String> names = new ArrayList<>();
for (String code : List.of(engineerCode, engineerCodeSub)) {
String name = engineerNames.getOrDefault(code, "");
if (StringUtils.isNotEmpty(name)) {
names.add(name);
}
}
return names;
}
}
// package com.dituhui.pea.user.controller2;
//
// import com.dituhui.pea.common.PageResult;
// import com.dituhui.pea.common.Result;
// import com.dituhui.pea.enums.StatusCodeEnum;
// import com.dituhui.pea.pojo.PageRequest;
// import com.dituhui.pea.pojo.ResourceInfo;
// import com.dituhui.pea.pojo.RoleInfo;
// import com.dituhui.pea.pojo.WebResult;
// import com.dituhui.pea.user.IRole;
// import com.dituhui.pea.user.IRole2;
// import com.dituhui.pea.user.service.RoleService;
// import com.dituhui.pea.user.service.RoleService2;
// import org.apache.commons.lang.StringUtils;
// import org.springframework.beans.factory.annotation.Autowired;
// import org.springframework.cloud.context.config.annotation.RefreshScope;
// import org.springframework.validation.annotation.Validated;
// import org.springframework.web.bind.annotation.RequestBody;
// import org.springframework.web.bind.annotation.RequestMapping;
// import org.springframework.web.bind.annotation.RequestMethod;
// import org.springframework.web.bind.annotation.RestController;
//
// import java.util.List;
//
// /**
// * 角色控制层
// */
// @RestController
// @RefreshScope
// public class RoleController2 implements IRole2 {
//
//
// @Autowired
// RoleService2 roleService;
//
// /**
// * 添加角色
// *
// * @param roleInfo 角色信息
// * @return
// */
// @RequestMapping(value = "/pea-user/role/add2", method = RequestMethod.POST)
// public Result<RoleInfo> addRole(@RequestBody RoleInfo roleInfo) {
// return roleService.addRole(roleInfo);
// }
//
// }
// package com.dituhui.pea.user.dao;
//
//
// import com.dituhui.pea.user.entity.RoleEntity2;
// import org.springframework.data.jpa.repository.JpaRepository;
// import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
// import org.springframework.data.repository.CrudRepository;
//
// /**
// * 角色表(Role)表数据库访问层
// *
// */
// public interface RoleDao2 extends JpaRepository<RoleEntity2, String>,
// JpaSpecificationExecutor<RoleEntity2>, CrudRepository<RoleEntity2, String> {
//
// }
// package com.dituhui.pea.user.entity;
//
// import lombok.Data;
// import org.hibernate.annotations.GenericGenerator;
// import org.springframework.data.annotation.CreatedDate;
// import org.springframework.data.annotation.LastModifiedDate;
// import org.springframework.data.jpa.domain.support.AuditingEntityListener;
//
// import javax.persistence.*;
// import javax.validation.constraints.NotBlank;
// import java.io.Serializable;
// import java.util.Date;
//
// /**
// * 角色表(RoleEntity)实体类
// *
// */
// @Data
// @Entity
// @Table(name ="sys_role")
// @EntityListeners(AuditingEntityListener.class)
// public class RoleEntity2 implements Serializable {
// private static final long serialVersionUID = -71423293716769828L;
// /**
// * 主键
// */
// @Id
// @GeneratedValue(generator = "uuid")
// @GenericGenerator(name = "uuid", strategy = "uuid")
// @Column(name = "ID", unique = true, nullable = false, length = 60)
// private String id;
// /**
// * 名称
// */
// @Column(name = "name")
// @NotBlank(message = "角色名称不能为空!")
// private String name;
// /**
// * 角色组id
// */
// @Column(name = "group_id")
// private String groupId;
// /**
// * 角色自定义条件
// */
// @Column(name = "extra")
// @NotBlank(message = "角色自定义条件不能为空!")
// private String extra;
// /**
// * 创建人
// */
// @Column(name = "CREATED_BY")
// private String createdBy;
// /**
// * 创建时间
// */
// @Column(name = "CREATED_TIME")
// @CreatedDate
// private Date createdTime;
// /**
// * 更新人
// */
// @Column(name = "UPDATED_BY")
// private String updatedBy;
// /**
// * 更新时间
// */
// @Column(name = "UPDATED_TIME")
// @LastModifiedDate
// private Date updatedTime;
//
// /**
// * 备注
// */
// @Column(name = "notes")
// private String notes;
//
// }
......@@ -2,35 +2,63 @@ package com.dituhui.pea.user.entity;
import lombok.Data;
import lombok.experimental.Accessors;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.Date;
@Entity
@Table(name = "sys_user_org")
@Data
@Accessors(chain = true)
// @Accessors(chain = true)
@EntityListeners(AuditingEntityListener.class)
public class UserOrgEntity {
private static final long serialVersionUID = 595672847439664430L;
/**
* 主键
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid")
@Column(name = "ID", unique = true, nullable = false, length = 32)
private String id;
@Column(name = "user_id", nullable = false, unique = true)
// @Column(name = "user_id", nullable = false, unique = true)
@Column(name = "user_id", nullable = false)
private String userId;
@Column(name = "org_id", nullable = false)
private Integer orgId;
private String orgId;
/**
* 组织级别 0:大区 1:分部 2:站点
*/
@Column(name = "org_level", nullable = false)
private Integer orgLevel;
@Column(name = "create_time", nullable = false, updatable = false, columnDefinition = "timestamp default current_timestamp")
private LocalDateTime createTime;
@Column(name = "update_time", nullable = false, columnDefinition = "timestamp default current_timestamp on update current_timestamp")
private LocalDateTime updateTime;
/**
* 创建人
*/
@Column(name = "CREATED_BY")
private String createdBy;
/**
* 创建时间
*/
@Column(name = "create_time")
@CreatedDate
private Date createdTime;
/**
* 更新人
*/
@Column(name = "UPDATED_BY")
private String updatedBy;
/**
* 更新时间
*/
@Column(name = "update_time")
@LastModifiedDate
private Date updatedTime;
}
// package com.dituhui.pea.user.service;
//
// import cn.hutool.core.bean.BeanUtil;
// import com.alibaba.fastjson.JSONObject;
// import com.dituhui.pea.common.Result;
// import com.dituhui.pea.pojo.RoleInfo;
// import com.dituhui.pea.pojo.role.RoleResourceInfo;
// import com.dituhui.pea.user.dao.RoleDao;
// import com.dituhui.pea.user.dao.RoleDao2;
// import com.dituhui.pea.user.dao.RoleResourceDao;
// import com.dituhui.pea.user.entity.RoleEntity;
// import com.dituhui.pea.user.entity.RoleEntity2;
// import com.dituhui.pea.user.entity.RoleResourceEntity;
// import lombok.extern.slf4j.Slf4j;
// import org.apache.commons.collections.CollectionUtils;
// import org.springframework.beans.factory.annotation.Autowired;
// import org.springframework.stereotype.Service;
// import org.springframework.transaction.annotation.Transactional;
//
// import java.util.List;
//
// @Service
// @Slf4j
// public class RoleService2 {
//
// @Autowired
// RoleDao2 roleDao;
// @Autowired
// RoleResourceDao roleResourceDao;
//
// @Transactional
// public Result<RoleInfo> addRole(RoleInfo roleInfo) {
// RoleEntity2 roleEntity = BeanUtil.copyProperties(roleInfo, RoleEntity2.class);
// // RoleEntity roleEntity = assembleRole(roleInfo);
// log.info("新增角色入参:" + JSONObject.toJSONString(roleEntity));
// roleEntity = roleDao.save(roleEntity);
// // roleInfo = BeanUtil.copyProperties(roleEntity, RoleInfo.class);
// roleInfo.setId(roleEntity.getId());
// List<RoleResourceInfo> resourceInfos = roleInfo.getResourceInfos();
// if (CollectionUtils.isNotEmpty(resourceInfos)) {
// for (RoleResourceInfo resourceInfo : resourceInfos) {
// RoleResourceEntity roleResourceEntity = assembleRoleResource(roleInfo.getId(), resourceInfo.getResourceId());
// roleResourceDao.save(roleResourceEntity);
// }
// }
// log.info("新增角色信息:" + JSONObject.toJSONString(roleInfo));
// return Result.success(roleInfo);
// }
//
//
// private RoleResourceEntity assembleRoleResource(String roleId, String resourceId) {
// RoleResourceEntity roleResourceEntity = new RoleResourceEntity();
// roleResourceEntity.setRoleId(roleId);
// roleResourceEntity.setResourceId(resourceId);
// return roleResourceEntity;
// }
//
//
// }
......@@ -102,17 +102,20 @@ public class UserService {
public Result<UserLoginDTO> userLogin(String account, String password) {
UserEntity user = userDao.findByAccountAndPassword(account, SecureUtil.md5(password));
log.info("{}/{} login", account, password);
if (null != user) {
UserLoginDTO userDTO = convertToUserLoginDTO(user);
// 生成token
String token = IdUtil.simpleUUID();
userDTO.setToken(token);
long timestamp = System.currentTimeMillis() + LIVE_TIME_MILLIS;
redisService.set(RedisKeyGroup.authToken + ":" + token, gson.toJson(userDTO), timestamp / 1000);
return Result.success(userDTO);
} else {
if (null == user) {
return Result.failure("鉴权失败");
}
//判断用户禁用/异常情况
if (user.getBan() == 1 || user.getStatus() == 0) {
return Result.failed(StatusCodeEnum.USER_ISBAN_OR_ERROR, null);
}
UserLoginDTO userDTO = convertToUserLoginDTO(user);
// 生成token
String token = IdUtil.simpleUUID();
userDTO.setToken(token);
long timestamp = System.currentTimeMillis() + LIVE_TIME_MILLIS;
redisService.set(RedisKeyGroup.authToken + ":" + token, gson.toJson(userDTO), timestamp / 1000);
return Result.success(userDTO);
}
private UserLoginDTO convertToUserLoginDTO(UserEntity user) {
......@@ -157,7 +160,7 @@ public class UserService {
ResourceInfo res = BeanUtil.copyProperties(r, ResourceInfo.class);
splitMenuExtra(res);
return res;
}).sorted(Comparator.comparing(ResourceInfo::getOrder)).collect(Collectors.toList());
}).collect(Collectors.toList());
resourceInfo.setChildren(levelTowResourceInfo);
}
levelOne = levelOne.stream().sorted(Comparator.comparing(ResourceInfo::getOrder))
......@@ -193,6 +196,9 @@ public class UserService {
}
private void splitMenuExtra(ResourceInfo resourceInfo) {
if (StringUtils.isBlank(resourceInfo.getExtra())) {
return;
}
String[] temp = resourceInfo.getExtra().split(",");
resourceInfo.setCode(temp[0]);
resourceInfo.setOrder(Integer.parseInt(temp[1]));
......@@ -445,6 +451,7 @@ public class UserService {
}
assembleUpdateUserInfo(userInfo, userEntity);
userEntity = userDao.save(userEntity);
userInfo.setCreatedBy(userEntity.getCreatedBy());
savaUserRoleAndOrgInfo(userInfo);
userInfo = BeanUtil.copyProperties(userEntity, UserInfo.class);
userInfo.setPassword(null);
......@@ -469,6 +476,7 @@ public class UserService {
UserRoleEntity userRoleEntity = new UserRoleEntity();
userRoleEntity.setUserId(userInfo.getId());
userRoleEntity.setRoleId(roleId);
userRoleEntity.setCreatedBy(userInfo.getCreatedBy());
userRoleDao.save(userRoleEntity);
}
}
......@@ -482,10 +490,11 @@ public class UserService {
//处理用户机构关联信息
if (CollectionUtils.isNotEmpty(userInfo.getOrgIds()) && null != userInfo.getOrgIds()) {
userOrgDao.deleteByUserId(userInfo.getId());
for (Integer orgId : userInfo.getOrgIds()) {
for (String orgId : userInfo.getOrgIds()) {
UserOrgEntity userOrgEntity = new UserOrgEntity();
userOrgEntity.setUserId(userInfo.getId());
userOrgEntity.setOrgId(orgId);
userOrgEntity.setCreatedBy(userInfo.getCreatedBy());
userOrgEntity.setOrgLevel(userInfo.getOrgLevel());
userOrgDao.save(userOrgEntity);
}
......@@ -653,6 +662,24 @@ public class UserService {
if (StringUtils.isNotBlank(formUserInfo.getRegion())) {
toUserEntity.setRegion(formUserInfo.getRegion());
}
if (ObjectUtil.isNotNull(formUserInfo.getStatus())) {
toUserEntity.setStatus(formUserInfo.getStatus());
}
if (ObjectUtil.isNotNull(formUserInfo.getSource())) {
toUserEntity.setSource(formUserInfo.getSource());
}
if (StringUtils.isNotBlank(formUserInfo.getNotes())) {
toUserEntity.setNotes(formUserInfo.getNotes());
}
if (StringUtils.isNotBlank(formUserInfo.getEngineerCode())) {
toUserEntity.setEngineerCode(formUserInfo.getEngineerCode());
}
if (ObjectUtil.isNotNull(formUserInfo.getBan())) {
toUserEntity.setBan(formUserInfo.getBan());
}
if (StringUtils.isNotBlank(formUserInfo.getUpdatedBy())) {
toUserEntity.setUpdatedBy(formUserInfo.getUpdatedBy());
}
toUserEntity.setSex(formUserInfo.getSex());
}
......@@ -694,7 +721,7 @@ public class UserService {
entityManager.clear();
PageResult<UserInfoSearch> pageResult = new PageResult<>();
String count = "select count(*) ";
String select = "SELECT su.*,sr.name roleName ";
String select = "SELECT su.*,sr.name roleName ,sr.id roleId ";
String limit = " ORDER BY su.CREATED_TIME DESC limit " + (search.getPage() - 1) * search.getSize() + "," + search.getSize();
StringBuffer querySql = new StringBuffer("from sys_user su left join sys_user_role sur on su.id =sur.user_id left JOIN sys_role sr on sr.id =sur.role_id left join sys_user_org suo on su.id=suo.user_id where 1=1 ");
if (StringUtils.isNotBlank(search.getRoleId())) {
......@@ -746,10 +773,12 @@ public class UserService {
search.setNickname(map.containsKey("nickname") && ObjectUtil.isNotEmpty(map.get("nickname")) ? map.get("nickname").toString() : null);
search.setBan(map.containsKey("ban") && ObjectUtil.isNotEmpty(map.get("ban")) ? Integer.parseInt(map.get("ban").toString()) : null);
search.setSource(map.containsKey("source") && ObjectUtil.isNotEmpty(map.get("source")) ? Integer.parseInt(map.get("source").toString()) : null);
search.setStatus(map.containsKey("status") && ObjectUtil.isNotEmpty(map.get("status")) ? Integer.parseInt(map.get("status").toString()) : null);
search.setEmail(map.containsKey("email") && ObjectUtil.isNotEmpty(map.get("email")) ? map.get("email").toString() : null);
search.setPhone(map.containsKey("phone") && ObjectUtil.isNotEmpty(map.get("phone")) ? map.get("phone").toString() : null);
search.setEngineerCode(map.containsKey("engineer_code") && ObjectUtil.isNotEmpty(map.get("engineer_code")) ? map.get("engineer_code").toString() : null);
search.setRoleName(map.containsKey("roleName") && ObjectUtil.isNotEmpty(map.get("roleName")) ? map.get("roleName").toString() : null);
search.setRoleId(map.containsKey("roleId") && ObjectUtil.isNotEmpty(map.get("roleId")) ? map.get("roleId").toString() : null);
search.setBan(map.containsKey("ban") && ObjectUtil.isNotEmpty(map.get("ban")) ? Integer.parseInt(map.get("ban").toString()) : null);
search.setCreatedBy(map.containsKey("CREATED_BY") && ObjectUtil.isNotEmpty(map.get("CREATED_BY")) ? map.get("CREATED_BY").toString() : null);
search.setUpdatedBy(map.containsKey("UPDATED_BY") && ObjectUtil.isNotEmpty(map.get("UPDATED_BY")) ? map.get("UPDATED_BY").toString() : null);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!