无关风月
2025-01-23 c3019597126f19e8508bd22e7da3a39058033510
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package com.jilongda.applet.controller;
 
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.jilongda.applet.model.TLineUp;
import com.jilongda.applet.service.TLineUpService;
import com.jilongda.applet.utils.LoginInfoUtil;
import com.jilongda.applet.vo.TLineUpVO;
import com.jilongda.common.basic.ApiResult;
import com.jilongda.common.constants.WarehousingConstant;
import com.jilongda.common.security.JwtTokenUtils;
import com.jilongda.common.utils.CodeGenerateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
 
/**
 * <p>
 * 排号管理 前端控制器
 * </p>
 *
 * @author 无关风月
 * @since 2024-12-09
 */
@Api(tags = "排号管理")
@RestController
@RequestMapping("/t-line-up")
public class TLineUpController {
 
    @Autowired
    private TLineUpService tLineUpService;
    @Autowired
    private LoginInfoUtil loginInfoUtil;
 
    @ApiOperation(value = "排号管理待验光人数")
    @GetMapping(value = "/getLineUpByStoreId")
    public ApiResult getLineUpByStoreId(@RequestParam Integer storeId) {
        return ApiResult.success(tLineUpService.count(Wrappers.lambdaQuery(TLineUp.class)
                .eq(TLineUp::getStoreId, storeId)
                .eq(TLineUp::getStatus, 1)
                .likeRight(TLineUp::getCreateTime, LocalDate.now())));
    }
 
    @ApiOperation(value = "添加排号管理")
    @PostMapping(value = "/add")
    public ApiResult add(@Validated @RequestBody TLineUp dto) {
        // 获取当天该门店的排号
        long count = tLineUpService.count(Wrappers.lambdaQuery(TLineUp.class)
                .likeRight(TLineUp::getCreateTime, LocalDate.now())
                .eq(TLineUp::getStoreId, dto.getStoreId()));
        dto.setStatus(1);
        dto.setUserId(loginInfoUtil.getUserId());
        dto.setCode(String.valueOf(count+1));
        tLineUpService.save(dto);
        return ApiResult.success();
    }
 
    @ApiOperation(value = "查询当前用户排号信息")
    @GetMapping(value = "/getUserLineUpByStoreId")
    public ApiResult getUserLineUpByStoreId(@RequestParam Integer storeId) {
        long userId = loginInfoUtil.getUserId();
        List<Integer> list = Arrays.asList(1, 2);
 
        TLineUp lineUp = tLineUpService.getOne(Wrappers.lambdaQuery(TLineUp.class)
                .eq(TLineUp::getUserId, userId)
                .eq(TLineUp::getStoreId, storeId)
                .in(TLineUp::getStatus, list)
                .orderByDesc(TLineUp::getCreateTime)
                .last("LIMIT 1"));
        TLineUpVO tLineUpVO = new TLineUpVO();
        if (lineUp!=null){
            BeanUtils.copyProperties(lineUp, tLineUpVO);
            long count = tLineUpService.count(Wrappers.lambdaQuery(TLineUp.class)
                    .eq(TLineUp::getStoreId, storeId)
                    .eq(TLineUp::getStatus, 1)
                    .lt(lineUp!=null,TLineUp::getCode, lineUp.getCode())
                    .likeRight(TLineUp::getCreateTime, LocalDate.now()));
            tLineUpVO.setLinUpCount(count);
 
        }else{
            long count = tLineUpService.count(Wrappers.lambdaQuery(TLineUp.class)
                    .eq(TLineUp::getStoreId, storeId)
                    .eq(TLineUp::getStatus, 1)
                    .likeRight(TLineUp::getCreateTime, LocalDate.now()));
            tLineUpVO.setLinUpCount(count);
        }
        return ApiResult.success(tLineUpVO);
    }
    @ApiOperation(value = "取消排号")
    @GetMapping(value = "/cancelLineUp")
    public ApiResult cancelLineUp(@RequestParam Integer id) {
        TLineUp lineUp = tLineUpService.getById(id);
        lineUp.setStatus(5);
        tLineUpService.updateById(lineUp);
        return ApiResult.success();
    }
 
}