自动化立体仓库 - WMS系统
1
zhang
3 天以前 7af1ffdd5af44733dc86a3d03e1f8543e87462d8
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package com.zy.asrs.controller;
 
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.core.annotations.ManagerAuth;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.common.R;
import com.core.common.SnowflakeIdWorker;
import com.core.exception.CoolException;
import com.zy.asrs.entity.Review;
import com.zy.asrs.importexcle.ImportReviewDto;
import com.zy.asrs.importexcle.ImportReviewListener;
import com.zy.asrs.mapper.ReviewDetlMapper;
import com.zy.asrs.service.ReviewDetlService;
import com.zy.asrs.service.ReviewService;
import com.zy.common.web.BaseController;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
 
import javax.annotation.Resource;
import java.io.IOException;
import java.util.Date;
import java.util.Map;
 
@RestController
public class ReviewController extends BaseController {
 
    @Autowired
    private ReviewService reviewService;
    @Autowired
    private ReviewDetlService reviewDetlService;
    @Autowired
    private SnowflakeIdWorker snowflakeIdWorker;
 
    @Autowired
    private PlatformTransactionManager transactionManager;
 
    @Resource
    private ReviewDetlMapper reviewDetlMapper;
 
    @PostMapping("/importReview")
    @ManagerAuth(memo = "单据导入")
    @ApiOperation(value = "单据导入", produces = MediaType.APPLICATION_JSON_VALUE)
    public R importOrderData(@RequestParam("file") MultipartFile multipartFile) {
        try {
            importOrder(multipartFile);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(e.getMessage());
        }
        return R.ok("导入成功");
    }
 
    @Transactional(rollbackFor = Exception.class)
    public void importOrder(MultipartFile multipartFile) throws IOException {
        // 考核数据的判重使用order_id,check_type的组合唯一索引解决
        EasyExcel.read(multipartFile.getInputStream(), ImportReviewDto.class,
                new ImportReviewListener(transactionManager,reviewService, reviewDetlService, snowflakeIdWorker, getUserId())).sheet().doReadSync();
    }
 
 
    @RequestMapping(value = "/review/head/page/auth")
    @ManagerAuth
    public R head(@RequestParam(defaultValue = "1") Integer curr,
                  @RequestParam(defaultValue = "10") Integer limit,
                  @RequestParam(required = false) String orderByField,
                  @RequestParam(required = false) String orderByType,
                  @RequestParam Map<String, Object> param) {
        EntityWrapper<Review> wrapper = new EntityWrapper<>();
        excludeTrash(param);
        convert(param, wrapper);
        if (!Cools.isEmpty(orderByField)) {
            wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));
        } else {
            wrapper.orderBy("settle").orderBy("create_time", false);
        }
        wrapper.eq("status", 1);
        return R.ok(reviewService.selectPage(new Page<>(curr, limit), wrapper));
    }
 
    private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper) {
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            String val = String.valueOf(entry.getValue());
            if (val.contains(RANGE_TIME_LINK)) {
                String[] dates = val.split(RANGE_TIME_LINK);
                wrapper.ge(entry.getKey(), DateUtils.convert(dates[0]));
                wrapper.le(entry.getKey(), DateUtils.convert(dates[1]));
            } else {
                wrapper.like(entry.getKey(), val);
            }
        }
    }
 
    @RequestMapping(value = "/review/update/auth")
    @ManagerAuth
    public R update(Review review) {
        if (Cools.isEmpty(review) || null == review.getId()) {
            return R.error();
        }
        Review review2 = reviewService.selectById(review.getId());
        review2.setSettle(review.getSettle());
        review.setUpdateBy(getUserId());
        review.setUpdateTime(new Date());
        if (!reviewService.updateById(review)) {
            throw new CoolException("修改失败");
        }
        return R.ok();
    }
 
}