Commit 236ac225 authored by lining's avatar lining

feat: 订单列表接口控制权限

parent befc7fe1
......@@ -80,8 +80,8 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
throw new ServiceException(BizCodeEnum.SERVICE_ORDER_CANNOT_VALUATION);
}
ServiceValuator serviceValuator = serviceValuatorMapper.selectByPrimaryKey(dto.getHostId());
if (Objects.isNull(serviceValuator)) {
User valuatorUser = userMapper.selectByPrimaryKey(dto.getHostId());
if (Objects.isNull(valuatorUser)) {
throw new ServiceException(BizCodeEnum.SERVICE_VALUATOR_NOT_EXIST);
}
......@@ -89,13 +89,14 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
serviceOrder.setOrderStatus(ServiceOrderStatusEnum.VALUATION.getStatus());
serviceOrder.setModifyBy(userId);
serviceOrder.setValuatorId(valuatorUser.getId());
int result = this.updateByPrimaryKeySelective(serviceOrder);
if (result == 1) {
String description = String.format(ServiceOrderStatusEnum.VALUATION.getMsg(), user.getUserName(), serviceValuator.getName());
String description = String.format(ServiceOrderStatusEnum.VALUATION.getMsg(), user.getUserName(), valuatorUser.getUserName());
recordComponent.recordProcess(serviceOrder.getId(), ServiceOrderStatusEnum.VALUATION.getStatus(), description,
sourceEnum, serviceValuator.getId(), dto.getRemark(), dto.getExpectArrivalTime());
sourceEnum, valuatorUser.getId(), dto.getRemark(), dto.getExpectArrivalTime());
}
return result;
......@@ -112,19 +113,22 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
throw new ServiceException(BizCodeEnum.SERVICE_ORDER_CANNOT_REVALUATION);
}
ServiceValuator serviceValuator = serviceValuatorMapper.selectByPrimaryKey(dto.getHostId());
if (Objects.isNull(serviceValuator)) {
User valuatorUser = userMapper.selectByPrimaryKey(dto.getHostId());
if (Objects.isNull(valuatorUser)) {
throw new ServiceException(BizCodeEnum.SERVICE_VALUATOR_NOT_EXIST);
}
disableServiceValuatorAssign(serviceOrder, userId, false);
int result = serviceValuatorAssignMapper.insertSelective(buildServiceValuatorAssign(dto, userId));
serviceValuatorAssignMapper.insertSelective(buildServiceValuatorAssign(dto, userId));
serviceOrder.setValuatorId(dto.getHostId());
int result = this.updateByPrimaryKeySelective(serviceOrder);
if (result == 1) {
String description = String.format(ServiceOrderStatusEnum.REVALUATION.getMsg(), user.getUserName(), serviceValuator.getName());
String description = String.format(ServiceOrderStatusEnum.REVALUATION.getMsg(), user.getUserName(), valuatorUser.getUserName());
recordComponent.recordProcess(serviceOrder.getId(), ServiceOrderStatusEnum.REVALUATION.getStatus(), description,
sourceEnum, serviceValuator.getId(), dto.getRemark(), dto.getExpectArrivalTime());
sourceEnum, valuatorUser.getId(), dto.getRemark(), dto.getExpectArrivalTime());
}
return result;
......
......@@ -7,6 +7,7 @@ public class BizConstants {
public static class UserConstants {
public static final String ACCOUNT_NO = "accountNo";
public static final String ROLE_TYPE = "roleType";
}
public static class OrderConstants {
......
......@@ -8,6 +8,6 @@ import java.util.List;
public interface ServiceOrderMapper extends Mapper<ServiceOrder> {
List<ServiceOrder> selectServiceOrderPage(@Param("orderStatus") Integer orderStatus, String month, String keyWord);
List<ServiceOrder> selectServiceOrderPage(@Param("orderStatus") Integer orderStatus, String month, String keyWord, Integer roleType, Long userId);
}
\ No newline at end of file
......@@ -2,7 +2,13 @@ package com.onsiteservice.dao.mapper.user;
import com.onsiteservice.dao.common.Mapper;
import com.onsiteservice.entity.service.ServiceValuator;
import com.onsiteservice.entity.user.User;
import java.util.List;
public interface UserMapper extends Mapper<User> {
List<User> selectByNameLike(String name);
}
\ No newline at end of file
......@@ -10,6 +10,18 @@
<if test="orderStatus != 0">
and order_status = #{orderStatus,jdbcType=INTEGER}
</if>
<choose>
<when test="roleType == 0"> <!-- 普通用户 -->
account_no = #{userId}
</when>
<when test="roleType == 1"> <!-- 客服 -->
</when>
<otherwise> <!-- 估价员 -->
valuator_id = #{userId}
</otherwise>
</choose>
<if test="month != null and month != ''">
and date_format(create_time,'%Y%m') = #{month}
</if>
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.onsiteservice.dao.mapper.user.UserMapper">
<select id="selectByNameLike" resultType="com.onsiteservice.entity.user.User">
select * from user where user_name like '%${name}%' order by create_time asc
</select>
</mapper>
\ No newline at end of file
......@@ -141,6 +141,10 @@ public class ServiceOrder implements Serializable {
@ApiModelProperty("修改人")
private Long modifyBy;
@Column(name = "valuator_id")
@ApiModelProperty("估价员id")
private Long valuatorId;
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
......@@ -21,7 +21,7 @@ public class ServiceValuatorVO {
@ApiModelProperty(value = "估价员id")
private Long id;
@ApiModelProperty(value = "估价员id")
@ApiModelProperty(value = "估价员姓名")
private String name;
@ApiModelProperty(value = "估价员手机号")
......
......@@ -7,6 +7,7 @@ import com.onsiteservice.constant.constant.BizConstants;
import com.onsiteservice.constant.enums.BizCodeEnum;
import com.onsiteservice.constant.enums.ServiceOrderOpSourceEnum;
import com.onsiteservice.constant.enums.ServiceOrderStatusEnum;
import com.onsiteservice.constant.enums.ServiceUserTypeEnum;
import com.onsiteservice.core.exception.ServiceException;
import com.onsiteservice.core.result.Result;
import com.onsiteservice.core.result.ResultGenerator;
......@@ -14,12 +15,14 @@ import com.onsiteservice.dao.common.AbstractMapper;
import com.onsiteservice.dao.common.page.PageInfoVO;
import com.onsiteservice.dao.component.RecordComponent;
import com.onsiteservice.dao.mapper.service.*;
import com.onsiteservice.dao.mapper.user.UserMapper;
import com.onsiteservice.entity.address.ServiceAddress;
import com.onsiteservice.entity.category.ServiceCategory;
import com.onsiteservice.entity.category.ServiceSubclass;
import com.onsiteservice.entity.order.ServiceOrder;
import com.onsiteservice.entity.service.ServiceOrderImg;
import com.onsiteservice.entity.service.ServiceOrderLog;
import com.onsiteservice.entity.user.User;
import com.onsiteservice.miniapp.controller.order.dto.CancelServiceOrderDTO;
import com.onsiteservice.miniapp.controller.order.dto.PageServiceOrderDTO;
import com.onsiteservice.miniapp.controller.order.dto.PayServiceOrderDTO;
......@@ -76,6 +79,9 @@ public class ServiceOrderBizService extends AbstractMapper<ServiceOrder> {
@Resource
private ServiceCategoryMapper serviceCategoryMapper;
@Resource
private UserMapper userMapper;
@Autowired
private RecordComponent recordComponent;
......@@ -118,7 +124,13 @@ public class ServiceOrderBizService extends AbstractMapper<ServiceOrder> {
log.info("order getPage dto: {}, userId: {}", dto, userId);
PageHelper.startPage(dto.getPage(), dto.getSize());
List<ServiceOrder> serviceOrderList = serviceOrderMapper.selectServiceOrderPage(dto.getOrderStatus(), dto.getMonth(), dto.getKeyWord());
User user = userMapper.selectByPrimaryKey(userId);
if (Objects.isNull(user) || !checkRoleType(user)) {
throw new ServiceException(BizCodeEnum.NO_AUTH);
}
List<ServiceOrder> serviceOrderList = serviceOrderMapper.selectServiceOrderPage(dto.getOrderStatus(), dto.getMonth(), dto.getKeyWord(), user.getRoleType(), userId);
return ResultGenerator.success(new PageInfoVO<>(buildServiceOrderVO(serviceOrderList)));
}
......@@ -262,4 +274,15 @@ public class ServiceOrderBizService extends AbstractMapper<ServiceOrder> {
}
private boolean checkRoleType(User user) {
for (ServiceUserTypeEnum userTypeEnum : ServiceUserTypeEnum.values()) {
if (user.getRoleType().equals(userTypeEnum.getId())) {
return true;
}
}
return false;
}
}
package com.onsiteservice.miniapp.service.worker;
import com.google.common.collect.Lists;
import com.onsiteservice.constant.constant.BizConstants;
import com.onsiteservice.dao.common.AbstractMapper;
import com.onsiteservice.dao.mapper.service.ServiceValuatorAssignMapper;
import com.onsiteservice.dao.mapper.service.ServiceValuatorMapper;
import com.onsiteservice.dao.mapper.user.UserMapper;
import com.onsiteservice.entity.service.ServiceValuator;
import com.onsiteservice.entity.service.ServiceValuatorAssign;
import com.onsiteservice.entity.user.User;
import com.onsiteservice.miniapp.controller.worker.vo.ServiceValuatorVO;
import com.onsiteservice.miniapp.mapper.service.ServiceValuatorBizMapper;
import com.onsiteservice.util.AttrCopyUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -22,9 +22,8 @@ import java.util.Map;
import java.util.stream.Collectors;
/**
* @author 潘维吉
* @author lining
* @date 2022-07-11 16:07
* @description ServiceValuatorService服务类
*/
@Service
@Slf4j
......@@ -36,38 +35,45 @@ public class ServiceValuatorService extends AbstractMapper<ServiceValuator> {
private ServiceValuatorAssignMapper serviceValuatorAssignMapper;
@Resource
private ServiceValuatorBizMapper serviceValuatorBizMapper;
private UserMapper userMapper;
public List<ServiceValuatorVO> all() {
List<ServiceValuator> serviceValuatorList = this.selectAll();
return handle(serviceValuatorList);
Condition c = new Condition(User.class);
c.createCriteria().andEqualTo(BizConstants.UserConstants.ROLE_TYPE);
List<User> userList = userMapper.selectByCondition(c);
return handle(userList);
}
public List<ServiceValuatorVO> selectByName(String name) {
log.info("valuator selectByName name: {}", name);
List<ServiceValuator> serviceValuatorList = serviceValuatorBizMapper.selectByNameLike(name);
return handle(serviceValuatorList);
List<User> userList = userMapper.selectByNameLike(name);
return handle(userList);
}
private List<ServiceValuatorVO> handle(List<ServiceValuator> serviceValuatorList){
if (CollectionUtils.isEmpty(serviceValuatorList)) {
private List<ServiceValuatorVO> handle(List<User> userList) {
if (CollectionUtils.isEmpty(userList)) {
return Lists.newArrayList();
}
// 估价员id列表
List<Long> valuatorIds = serviceValuatorList.parallelStream().map(ServiceValuator::getId).collect(Collectors.toList());
List<Long> valuatorIds = userList.parallelStream().map(User::getId).collect(Collectors.toList());
// 已被指派的时间
List<ServiceValuatorAssign> serviceValuatorAssignList = serviceValuatorAssignMapper.selectByDeletedAndIdListAndAssignTime(valuatorIds);
Map<Long, List<ServiceValuatorAssign>> serviceValuatorAssignMap =
serviceValuatorAssignList.parallelStream()
.collect(Collectors.groupingBy(ServiceValuatorAssign::getValuatorId));
return serviceValuatorList.parallelStream().map(e1 -> {
ServiceValuatorVO serviceValuatorVO = AttrCopyUtils.copy(e1, new ServiceValuatorVO());
return userList.parallelStream().map(e1 -> {
ServiceValuatorVO serviceValuatorVO = new ServiceValuatorVO();
serviceValuatorVO.setId(e1.getId());
serviceValuatorVO.setName(e1.getUserName());
serviceValuatorVO.setPhone(e1.getPhone());
// 估价员已经被指派的时间
List<ServiceValuatorAssign> assigns = serviceValuatorAssignMap.getOrDefault(e1.getId(), Lists.newArrayList());
List<Date> assignTimes = assigns.parallelStream().map(ServiceValuatorAssign::getAssignTime).collect(Collectors.toList());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment