| | |
| | | import com.zy.acs.manager.common.domain.PageParam; |
| | | import com.zy.acs.manager.common.utils.ExcelUtil; |
| | | import com.zy.acs.manager.manager.controller.param.LocInitParam; |
| | | import com.zy.acs.manager.manager.entity.Code; |
| | | import com.zy.acs.manager.manager.entity.Loc; |
| | | import com.zy.acs.manager.manager.entity.LocSts; |
| | | import com.zy.acs.manager.manager.entity.LocType; |
| | | import com.zy.acs.manager.manager.entity.Zone; |
| | | import com.zy.acs.manager.manager.service.CodeService; |
| | | import com.zy.acs.manager.manager.service.LocService; |
| | | import com.zy.acs.manager.manager.service.LocStsService; |
| | | import com.zy.acs.manager.manager.service.LocTypeService; |
| | | import com.zy.acs.manager.manager.service.ZoneService; |
| | | import com.zy.acs.manager.manager.entity.*; |
| | | import com.zy.acs.manager.manager.enums.LocStsType; |
| | | import com.zy.acs.manager.manager.enums.StatusType; |
| | | import com.zy.acs.manager.manager.service.*; |
| | | import com.zy.acs.manager.system.controller.BaseController; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | |
| | | return R.ok().add(vos); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:loc:list')") |
| | | @PostMapping("/loc/export") |
| | | public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { |
| | | ExcelUtil.build(ExcelUtil.create(locService.list(), Loc.class), response); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:loc:save')") |
| | | @PostMapping("/loc/import") |
| | | public R importBatch(@RequestBody List<Map<String, Object>> rows) { |
| | | if (Cools.isEmpty(rows)) { |
| | | return R.ok(); |
| | | } |
| | | Date now = new Date(); |
| | | Long userId = getLoginUserId(); |
| | | for (Map<String, Object> row : rows) { |
| | | Zone zone = resolveZone(readCell(row, "zone")); |
| | | Integer rowNo = parseInteger(row.get("row"), "row", true); |
| | | Integer bayNo = parseInteger(row.get("bay"), "bay", true); |
| | | Integer levNo = parseInteger(row.get("lev"), "lev", true); |
| | | String locNo = buildLocNo(zone, rowNo, bayNo, levNo); |
| | | |
| | | Long locStsId = resolveLocStsId(readCell(row, "loc_sts")); |
| | | Long locTypeId = resolveLocTypeId(readCell(row, "loc_type")); |
| | | Long codeId = resolveCodeId(readCell(row, "code")); |
| | | Integer compDirect = parseInteger(row.get("comp_direct"), "comp_direct", false); |
| | | Double offset = parseDouble(row.get("offset"), "offset"); |
| | | |
| | | Loc loc = locService.selectByLocNo(locNo); |
| | | boolean exists = loc != null; |
| | | if (!exists) { |
| | | loc = new Loc(); |
| | | loc.setUuid(locNo); |
| | | loc.setLocNo(locNo); |
| | | loc.setName(locNo); |
| | | loc.setStatus(1); |
| | | loc.setDeleted(0); |
| | | loc.setCreateBy(userId); |
| | | loc.setCreateTime(now); |
| | | } |
| | | loc.setZoneId(zone.getId()); |
| | | loc.setRow(rowNo); |
| | | loc.setBay(bayNo); |
| | | loc.setLev(levNo); |
| | | loc.setLocSts(locStsId); |
| | | loc.setLocType(locTypeId); |
| | | loc.setCode(codeId); |
| | | loc.setCompDirect(compDirect); |
| | | loc.setOffset(offset); |
| | | loc.setUpdateBy(userId); |
| | | loc.setUpdateTime(now); |
| | | |
| | | if (!exists) { |
| | | if (!locService.save(loc)) { |
| | | throw new CoolException(locNo + " save fail !"); |
| | | } |
| | | } else { |
| | | if (!locService.updateById(loc)) { |
| | | throw new CoolException(locNo + " update fail !"); |
| | | } |
| | | } |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:loc:save')") |
| | | @OperationLog |
| | | @PostMapping("/loc/init") |
| | |
| | | return R.ok("initialize success"); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:loc:list')") |
| | | @PostMapping("/loc/export") |
| | | public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { |
| | | ExcelUtil.build(ExcelUtil.create(locService.list(), Loc.class), response); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:loc:save')") |
| | | @PostMapping("/loc/import") |
| | | public R importBatch(@RequestBody List<Map<String, Object>> rows) { |
| | | if (Cools.isEmpty(rows)) { |
| | | return R.ok(); |
| | | } |
| | | Date now = new Date(); |
| | | Long userId = getLoginUserId(); |
| | | for (Map<String, Object> row : rows) { |
| | | Zone zone = resolveZone(readCell(row, "zone")); |
| | | Integer rowNo = parseInteger(row.get("row"), "row", true); |
| | | Integer bayNo = parseInteger(row.get("bay"), "bay", true); |
| | | Integer levNo = parseInteger(row.get("lev"), "lev", true); |
| | | String locNo = buildLocNo(zone, rowNo, bayNo, levNo); |
| | | if (locService.selectByLocNo(locNo) != null) { |
| | | continue; |
| | | } |
| | | |
| | | Long locStsId = resolveLocStsId(readCell(row, "loc_sts")); |
| | | Long locTypeId = resolveLocTypeId(readCell(row, "loc_type")); |
| | | Long codeId = resolveCodeId(readCell(row, "code")); |
| | | Integer compDirect = parseInteger(row.get("comp_direct"), "comp_direct", false); |
| | | Double offset = parseDouble(row.get("offset"), "offset"); |
| | | |
| | | Loc loc = new Loc(); |
| | | loc.setZoneId(zone.getId()); |
| | | loc.setUuid(locNo); |
| | | loc.setLocNo(locNo); |
| | | loc.setRow(rowNo); |
| | | loc.setBay(bayNo); |
| | | loc.setLev(levNo); |
| | | |
| | | loc.setLocSts(locStsId); |
| | | loc.setLocType(locTypeId); |
| | | loc.setCode(codeId); |
| | | loc.setCompDirect(compDirect); |
| | | loc.setOffset(offset); |
| | | |
| | | loc.setStatus(StatusType.ENABLE.val); |
| | | loc.setCreateBy(userId); |
| | | loc.setCreateTime(now); |
| | | loc.setUpdateBy(userId); |
| | | loc.setUpdateTime(now); |
| | | |
| | | if (!locService.save(loc)) { |
| | | throw new CoolException(locNo + " save fail !"); |
| | | } |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | private Zone resolveZone(String identifier) { |
| | | if (Cools.isEmpty(identifier)) { |
| | | throw new CoolException("zone is required"); |
| | | } |
| | | Zone zone = zoneService.getOne(new LambdaQueryWrapper<Zone>().eq(Zone::getUuid, identifier), false); |
| | | if (zone == null) { |
| | | zone = zoneService.getOne(new LambdaQueryWrapper<Zone>().eq(Zone::getName, identifier), false); |
| | | } |
| | | if (zone == null) { |
| | | throw new CoolException("zone " + identifier + " not found"); |
| | | } |
| | | return zone; |
| | | return zoneService.selectByUuid(identifier); |
| | | } |
| | | |
| | | private Long resolveLocStsId(String identifier) { |
| | | if (Cools.isEmpty(identifier)) { |
| | | throw new CoolException("loc_sts is required"); |
| | | } |
| | | LocSts locSts = locStsService.getOne(new LambdaQueryWrapper<LocSts>().eq(LocSts::getUuid, identifier), false); |
| | | if (locSts == null) { |
| | | locSts = locStsService.getOne(new LambdaQueryWrapper<LocSts>().eq(LocSts::getName, identifier), false); |
| | | } |
| | | if (locSts == null) { |
| | | LocStsType locStsType = LocStsType.valueOf(identifier); |
| | | if (locStsType == null) { |
| | | throw new CoolException("loc_sts " + identifier + " not found"); |
| | | } |
| | | return locSts.getId(); |
| | | return locStsType.val(); |
| | | } |
| | | |
| | | private Long resolveLocTypeId(String identifier) { |
| | |
| | | return null; |
| | | } |
| | | LocType locType = locTypeService.getOne(new LambdaQueryWrapper<LocType>().eq(LocType::getUuid, identifier), false); |
| | | if (locType == null) { |
| | | locType = locTypeService.getOne(new LambdaQueryWrapper<LocType>().eq(LocType::getName, identifier), false); |
| | | } |
| | | if (locType == null) { |
| | | throw new CoolException("loc_type " + identifier + " not found"); |
| | | } |