| | |
| | | package com.zy.asrs.task.handler; |
| | | |
| | | import com.core.common.Cools; |
| | | 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> { |
| | | |
| | |
| | | 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<Map<String, Object>> list = 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"); |
| | | if (!Cools.isEmpty(list)) { |
| | | for (Map<String, Object> map : list) { |
| | | MatnrCountDto dto = Cools.conver(map, MatnrCountDto.class); |
| | | 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(); |