自动化立体仓库 - WMS系统
#
TQS
2023-01-11 c7b2dd66f2d9b6a1caf59f8fb5b3f8d5848602ff
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
package com.zy.asrs.task.handler;
 
import com.zy.asrs.entity.Mat;
import com.zy.asrs.entity.dto.MatnrCountDto;
import com.zy.asrs.service.MatService;
import com.zy.asrs.service.WrkDetlService;
import com.zy.asrs.service.WrkMastService;
import com.zy.asrs.task.AbstractHandler;
import com.zy.asrs.task.core.ReturnT;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
import java.util.Date;
import java.util.List;
import java.util.Map;
 
/**
 * Created by vincent on 2020/7/7
 */
@Slf4j
@Service
public class MatHandler extends AbstractHandler<String> {
 
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private MatService matService;
    @Autowired
    private WrkDetlService wrkDetlService;
    @Autowired
    private WrkMastService wrkMastService;
 
    @Transactional
    public ReturnT<String> start() {
        try {
            Date now = new Date();
            List<MatnrCountDto> matnrCountDtos = jdbcTemplate.queryForList("select\n" +
                    "matnr,\n" +
                    "count(1) as count\n" +
                    "from (\n" +
                    "\tselect\n" +
                    "\tdistinct awd.*\n" +
                    "\tfrom asr_wrk_mast_log awm\n" +
                    "\tleft join asr_wrk_detl_log awd on awm.wrk_no = awd.wrk_no\n" +
                    "\twhere 1=1\n" +
                    "\tand datediff(day, getdate(), awm.io_time) = 0 \n" +
                    "\tand io_type not in (103,104,107)\n" +
                    "\tand (manu_type is null or manu_type != '手动取消')\n" +
                    ") a\n" +
                    "group by matnr", MatnrCountDto.class);
            for (MatnrCountDto dto : matnrCountDtos) {
                if (dto.getCount() >= 3) {
                    Mat mat = matService.selectByMatnr(dto.getMatnr());
                    mat.setInoutEveryday(Boolean.TRUE);
                    mat.setUpdateTime(now);
                    if (!matService.updateById(mat)) {
                        log.error("{}商品修改为高频属性失败!", dto.getMatnr());
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return FAIL.setMsg(e.getMessage());
        }
        return SUCCESS;
    }
 
}