| | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.baomidou.mybatisplus.plugins.Page; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.service.WrkMastService; |
| | | import com.zy.common.web.BaseController; |
| | | import com.core.annotations.ManagerAuth; |
| | | import com.core.common.BaseRes; |
| | | import com.core.common.Cools; |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.R; |
| | | import com.zy.asrs.entity.WrkDetl; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.service.WrkDetlService; |
| | | import com.zy.asrs.service.WrkMastService; |
| | | import com.zy.common.web.BaseController; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | |
| | | @Autowired |
| | | private WrkDetlService wrkDetlService; |
| | | |
| | | @RequestMapping(value = "/wrkMast/{id}/auth") |
| | | @ManagerAuth |
| | |
| | | @RequestParam(defaultValue = "10")Integer limit, |
| | | @RequestParam(required = false)String orderByField, |
| | | @RequestParam(required = false)String orderByType, |
| | | @RequestParam(required = false)String condition, |
| | | @RequestParam Map<String, Object> param){ |
| | | excludeTrash(param); |
| | | String detlMatnr = getAndRemove(param, "matnr"); |
| | | String detlMaktx = getAndRemove(param, "maktx"); |
| | | EntityWrapper<WrkMast> wrapper = new EntityWrapper<>(); |
| | | applyWrkDetlFilter(wrapper, detlMatnr, detlMaktx); |
| | | convert(param, wrapper); |
| | | allLike(WrkMast.class, param.keySet(), wrapper, condition); |
| | | if (!Cools.isEmpty(orderByField)){ |
| | | if (orderByField.endsWith("$")){ |
| | | orderByField = orderByField.substring(0, orderByField.length()-1); |
| | | } |
| | | wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType)); |
| | | }else { |
| | | wrapper.orderBy("io_time", false); |
| | | wrapper.orderBy("appe_time", false); |
| | | } |
| | | return R.ok(wrkMastService.selectPage(new Page<>(curr, limit), wrapper)); |
| | | Page<WrkMast> page = wrkMastService.selectPage(new Page<>(curr, limit), wrapper); |
| | | fillDetlSummary(page.getRecords()); |
| | | return R.ok(page); |
| | | } |
| | | |
| | | private void convert(Map<String, Object> map, EntityWrapper wrapper){ |
| | | private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){ |
| | | for (Map.Entry<String, Object> entry : map.entrySet()){ |
| | | if (entry.getKey().endsWith(">")) { |
| | | wrapper.ge(Cools.deleteChar(entry.getKey()), DateUtils.convert(String.valueOf(entry.getValue()))); |
| | | } else if (entry.getKey().endsWith("<")) { |
| | | wrapper.le(Cools.deleteChar(entry.getKey()), DateUtils.convert(String.valueOf(entry.getValue()))); |
| | | 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(), String.valueOf(entry.getValue())); |
| | | wrapper.eq(entry.getKey(), val); |
| | | } |
| | | } |
| | | } |
| | |
| | | List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class); |
| | | EntityWrapper<WrkMast> wrapper = new EntityWrapper<>(); |
| | | Map<String, Object> map = excludeTrash(param.getJSONObject("wrkMast")); |
| | | String detlMatnr = getAndRemove(map, "matnr"); |
| | | String detlMaktx = getAndRemove(map, "maktx"); |
| | | applyWrkDetlFilter(wrapper, detlMatnr, detlMaktx); |
| | | convert(map, wrapper); |
| | | List<WrkMast> list = wrkMastService.selectList(wrapper); |
| | | fillDetlSummary(list); |
| | | return R.ok(exportSupport(list, fields)); |
| | | } |
| | | |
| | | private String getAndRemove(Map<String, Object> map, String key) { |
| | | Object val = map.remove(key); |
| | | if (val == null) { |
| | | return null; |
| | | } |
| | | String str = String.valueOf(val).trim(); |
| | | if (Cools.isEmpty(str) || "null".equalsIgnoreCase(str)) { |
| | | return null; |
| | | } |
| | | return str; |
| | | } |
| | | |
| | | private void applyWrkDetlFilter(EntityWrapper<WrkMast> wrapper, String matnr, String maktx) { |
| | | if (Cools.isEmpty(matnr) && Cools.isEmpty(maktx)) { |
| | | return; |
| | | } |
| | | EntityWrapper<WrkDetl> detlWrapper = (EntityWrapper<WrkDetl>) new EntityWrapper<WrkDetl>().setSqlSelect("distinct wrk_no"); |
| | | if (!Cools.isEmpty(matnr)) { |
| | | detlWrapper.like("matnr", matnr); |
| | | } |
| | | if (!Cools.isEmpty(maktx)) { |
| | | detlWrapper.like("maktx", maktx); |
| | | } |
| | | List<WrkDetl> detls = wrkDetlService.selectList(detlWrapper); |
| | | if (detls.isEmpty()) { |
| | | wrapper.eq("wrk_no", -1); |
| | | return; |
| | | } |
| | | Set<Integer> wrkNos = new LinkedHashSet<>(); |
| | | for (WrkDetl detl : detls) { |
| | | if (detl != null && detl.getWrkNo() != null) { |
| | | wrkNos.add(detl.getWrkNo()); |
| | | } |
| | | } |
| | | if (wrkNos.isEmpty()) { |
| | | wrapper.eq("wrk_no", -1); |
| | | return; |
| | | } |
| | | wrapper.in("wrk_no", wrkNos); |
| | | } |
| | | |
| | | private void fillDetlSummary(List<WrkMast> masts) { |
| | | if (masts == null || masts.isEmpty()) { |
| | | return; |
| | | } |
| | | Set<Integer> wrkNos = new LinkedHashSet<>(); |
| | | for (WrkMast mast : masts) { |
| | | if (mast != null && mast.getWrkNo() != null) { |
| | | wrkNos.add(mast.getWrkNo()); |
| | | } |
| | | } |
| | | if (wrkNos.isEmpty()) { |
| | | return; |
| | | } |
| | | EntityWrapper<WrkDetl> wrapper = (EntityWrapper<WrkDetl>) new EntityWrapper<WrkDetl>() |
| | | .setSqlSelect("wrk_no, matnr, maktx") |
| | | .in("wrk_no", wrkNos); |
| | | List<WrkDetl> detls = wrkDetlService.selectList(wrapper); |
| | | |
| | | Map<Integer, LinkedHashSet<String>> matnrByWrkNo = new HashMap<>(); |
| | | Map<Integer, LinkedHashSet<String>> maktxByWrkNo = new HashMap<>(); |
| | | for (WrkDetl detl : detls) { |
| | | if (detl == null || detl.getWrkNo() == null) { |
| | | continue; |
| | | } |
| | | Integer wrkNo = detl.getWrkNo(); |
| | | if (!Cools.isEmpty(detl.getMatnr())) { |
| | | matnrByWrkNo.computeIfAbsent(wrkNo, k -> new LinkedHashSet<>()).add(detl.getMatnr()); |
| | | } |
| | | if (!Cools.isEmpty(detl.getMaktx())) { |
| | | maktxByWrkNo.computeIfAbsent(wrkNo, k -> new LinkedHashSet<>()).add(detl.getMaktx()); |
| | | } |
| | | } |
| | | |
| | | for (WrkMast mast : masts) { |
| | | if (mast == null || mast.getWrkNo() == null) { |
| | | continue; |
| | | } |
| | | LinkedHashSet<String> matnrs = matnrByWrkNo.get(mast.getWrkNo()); |
| | | if (matnrs != null && !matnrs.isEmpty()) { |
| | | mast.setMatnr(String.join(",", matnrs)); |
| | | } |
| | | LinkedHashSet<String> maktxs = maktxByWrkNo.get(mast.getWrkNo()); |
| | | if (maktxs != null && !maktxs.isEmpty()) { |
| | | mast.setMaktx(String.join(",", maktxs)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | @RequestMapping(value = "/wrkMastQuery/auth") |
| | | @ManagerAuth |
| | |
| | | @RequestMapping(value = "/wrkMast/add/pri/auth") |
| | | @ManagerAuth(memo = "工作档增加优先级") |
| | | public R addPri(@RequestBody List<WrkMast> list) { |
| | | if (list.isEmpty()) { |
| | | return R.error("请至少选择一行数据"); |
| | | } |
| | | for (WrkMast entity : list){ |
| | | entity.setIoPri(entity.getIoPri() + 1); |
| | | } |
| | |
| | | @RequestMapping(value = "/wrkMast/red/pri/auth") |
| | | @ManagerAuth(memo = "工作档降低优先级") |
| | | public R redPri(@RequestBody List<WrkMast> list) { |
| | | if (list.isEmpty()) { |
| | | return R.error("请至少选择一行数据"); |
| | | } |
| | | for (WrkMast entity : list){ |
| | | entity.setIoPri(entity.getIoPri() - 1); |
| | | } |