Commit 2fc1b4b1 authored by shangtx's avatar shangtx

feat: 查询估价员接口

parent 30321953
......@@ -17,11 +17,9 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Positive;
import java.util.List;
import static com.onsiteservice.core.result.ResultGenerator.fail;
import static com.onsiteservice.core.result.ResultGenerator.success;
/**
......@@ -48,23 +46,4 @@ public class ServiceValuatorController {
}
@ApiOperation(value = "分页查询列表")
@PostMapping("page")
public Result<PageInfoVO<ServiceValuatorVO>> getPage(@RequestBody @NonNull @Validated PageServiceValuatorDTO dto) {
return serviceValuatorService.getPage(dto);
}
@ApiOperation(value = "根据id查询")
@GetMapping("get/{id}")
public Result<ServiceValuatorVO> getDetails(@ApiParam(name = "id", value = "估价员id") @PathVariable @Positive Long id) {
return success(serviceValuatorService.selectById(id));
}
@ApiOperation(value = "新增")
@PostMapping("save")
public Result save(@RequestBody @NonNull @Validated SaveServiceValuatorDTO dto, @CurrentUserId Long userId) {
return serviceValuatorService.save(dto, userId) == 1 ? success() : fail("新增失败");
}
}
......@@ -38,6 +38,6 @@ public class ServiceValuatorVO {
private Date modifyTime;
@ApiModelProperty(value = "估价员已被指派的时间")
private List<Date> assignTime;
private List<String> assignTime;
}
\ No newline at end of file
......@@ -7,6 +7,7 @@ import com.onsiteservice.admin.controller.service.dto.SaveServiceValuatorDTO;
import com.onsiteservice.admin.controller.service.dto.UpdateServiceValuatorDTO;
import com.onsiteservice.admin.controller.service.vo.ServiceValuatorVO;
import com.onsiteservice.admin.mapper.service.ServiceValuatorBizMapper;
import com.onsiteservice.constant.constant.BizConstants;
import com.onsiteservice.constant.enums.BizCodeEnum;
import com.onsiteservice.constant.enums.ServiceUserTypeEnum;
import com.onsiteservice.core.exception.ServiceException;
......@@ -21,7 +22,9 @@ import com.onsiteservice.entity.service.ServiceValuatorAssign;
import com.onsiteservice.entity.service.ServiceWorker;
import com.onsiteservice.entity.user.User;
import com.onsiteservice.util.AttrCopyUtils;
import com.onsiteservice.util.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
......@@ -51,77 +54,47 @@ public class ServiceValuatorService extends AbstractMapper<ServiceValuator> {
private UserMapper userMapper;
@Resource
private ServiceValuatorAssignMapper serviceValuatorAssignMapper;
;
/**
* 分页查询列表
*/
public Result<PageInfoVO<ServiceValuatorVO>> getPage(PageServiceValuatorDTO dto) {
PageHelper.startPage(dto.getPage(), dto.getSize());
List<ServiceValuator> serviceValuatorList = serviceValuatorBizMapper.selectServiceValuatorPage(dto);
List<ServiceValuatorVO> serviceValuatorVOList = serviceValuatorList.parallelStream().map(e -> AttrCopyUtils.copy(e, new ServiceValuatorVO())).collect(Collectors.toList());
return ResultGenerator.success(new PageInfoVO<>(serviceValuatorVOList));
}
public ServiceValuatorVO selectById(Long id) {
log.info("valuator selectById id: {}", id);
ServiceValuator serviceValuator = this.selectByPrimaryKey(id);
if (Objects.isNull(serviceValuator)) {
throw new ServiceException(BizCodeEnum.SERVICE_VALUATOR_NOT_EXIST);
}
return AttrCopyUtils.copy(serviceValuator, new ServiceValuatorVO());
}
public int save(SaveServiceValuatorDTO dto, Long userId) {
log.info("valuator save dto: {}, userId: {}", dto, userId);
// checkAuth(userId);
Condition c = new Condition(ServiceWorker.class);
c.createCriteria().andEqualTo("phone", dto.getPhone());
List<ServiceValuator> serviceValuatorList = this.selectByCondition(c);
if (!CollectionUtils.isEmpty(serviceValuatorList)) {
throw new ServiceException(BizCodeEnum.SERVICE_VALUATOR_HAS_EXIST);
}
return this.insertSelective(AttrCopyUtils.copy(dto, new ServiceValuator()));
}
;
public List<ServiceValuatorVO> selectByName(String name) {
log.info("valuator selectByName name: {}", name);
List<ServiceValuator> serviceValuatorList = serviceValuatorBizMapper.selectByNameLike(name);
return handle(serviceValuatorList);
List<User> userList;
if (StringUtils.isNotEmpty(name)) {
userList = userMapper.selectByNameLike(name);
} else {
Condition c = new Condition(User.class);
c.createCriteria().andEqualTo(BizConstants.UserConstants.ROLE_TYPE);
userList = userMapper.selectByCondition(c);
}
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());
String dateFormat = "yyyy-MM-dd HH:mm";
List<String> assignTimes = assigns.parallelStream()
.map(assign -> DateUtils.formatDate(assign.getAssignTime(), dateFormat)).collect(Collectors.toList());
serviceValuatorVO.setAssignTime(assignTimes);
......
package com.onsiteservice.admin.service.service;
import com.alibaba.fastjson.JSONObject;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import javax.annotation.Resource;
import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest
class ServiceValuatorServiceTest {
@Resource
private ServiceValuatorService serviceValuatorService;
@Test
void selectByName() {
System.out.println(JSONObject.toJSONString(serviceValuatorService.selectByName(null)));
System.out.println(JSONObject.toJSONString(serviceValuatorService.selectByName("宁")));
}
}
\ No newline at end of file
......@@ -3,7 +3,10 @@
<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 * from user
where user_name like '%${name}%'
and role_type = ${@com.onsiteservice.constant.enums.ServiceUserTypeEnum@VALUATOR.getId()}
order by create_time asc
</select>
</mapper>
\ No newline at end of file
......@@ -28,6 +28,6 @@ public class ServiceValuatorVO {
private String phone;
@ApiModelProperty(value = "估价员已被指派的时间")
private List<Date> assignTime;
private List<String> assignTime;
}
......@@ -9,6 +9,7 @@ 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.util.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -76,7 +77,9 @@ public class ServiceValuatorService extends AbstractMapper<ServiceValuator> {
// 估价员已经被指派的时间
List<ServiceValuatorAssign> assigns = serviceValuatorAssignMap.getOrDefault(e1.getId(), Lists.newArrayList());
List<Date> assignTimes = assigns.parallelStream().map(ServiceValuatorAssign::getAssignTime).collect(Collectors.toList());
String dateFormat = "yyyy-MM-dd HH:mm";
List<String> assignTimes = assigns.parallelStream()
.map(assign -> DateUtils.formatDate(assign.getAssignTime(), dateFormat)).collect(Collectors.toList());
serviceValuatorVO.setAssignTime(assignTimes);
......
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