|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.zy.acs.common.utils.GsonUtils; | 
|---|
|  |  |  | import com.zy.acs.common.utils.Utils; | 
|---|
|  |  |  | import com.zy.acs.framework.common.Cools; | 
|---|
|  |  |  | import com.zy.acs.framework.common.R; | 
|---|
|  |  |  | import com.zy.acs.framework.exception.CoolException; | 
|---|
|  |  |  | import com.zy.acs.manager.common.utils.ExcelUtil; | 
|---|
|  |  |  | import com.zy.acs.manager.common.annotation.OperationLog; | 
|---|
|  |  |  | import com.zy.acs.manager.common.domain.BaseParam; | 
|---|
|  |  |  | import com.zy.acs.manager.common.domain.KeyValVo; | 
|---|
|  |  |  | import com.zy.acs.manager.common.domain.PageParam; | 
|---|
|  |  |  | import com.zy.acs.manager.manager.controller.param.LocInitParam; | 
|---|
|  |  |  | import com.zy.acs.manager.manager.entity.Loc; | 
|---|
|  |  |  | import com.zy.acs.manager.manager.entity.Zone; | 
|---|
|  |  |  | import com.zy.acs.manager.manager.enums.LocStsType; | 
|---|
|  |  |  | import com.zy.acs.manager.manager.service.LocService; | 
|---|
|  |  |  | import com.zy.acs.manager.manager.service.ZoneService; | 
|---|
|  |  |  | import com.zy.acs.manager.system.controller.BaseController; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.security.access.prepost.PreAuthorize; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.servlet.http.HttpServletResponse; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @RequestMapping("/api") | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LocService locService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ZoneService zoneService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('manager:loc:list')") | 
|---|
|  |  |  | @PostMapping("/loc/page") | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok("Update Success").add(loc); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('manager:loc:update')") | 
|---|
|  |  |  | @OperationLog("Update Loc") | 
|---|
|  |  |  | @PostMapping("/loc/update/many") | 
|---|
|  |  |  | public R updateMany(@RequestBody List<Loc> locList) { | 
|---|
|  |  |  | if (!Cools.isEmpty(locList)) { | 
|---|
|  |  |  | for (Loc loc : locList) { | 
|---|
|  |  |  | loc.setUpdateBy(getLoginUserId()); | 
|---|
|  |  |  | loc.setUpdateTime(new Date()); | 
|---|
|  |  |  | if (!locService.updateById(loc)) { | 
|---|
|  |  |  | return R.error("Update Fail"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok("Update Success").add(locList.stream().map(Loc::getId).collect(Collectors.toList())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('manager:loc:remove')") | 
|---|
|  |  |  | @OperationLog("Delete Loc") | 
|---|
|  |  |  | @PostMapping("/loc/remove/{ids}") | 
|---|
|  |  |  | 
|---|
|  |  |  | ExcelUtil.build(ExcelUtil.create(locService.list(), Loc.class), response); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('manager:loc:save')") | 
|---|
|  |  |  | @OperationLog | 
|---|
|  |  |  | @PostMapping("/loc/init") | 
|---|
|  |  |  | public R init(@RequestBody LocInitParam param) { | 
|---|
|  |  |  | if (param.getStartRow() > param.getEndRow()) { | 
|---|
|  |  |  | return R.error("the start row cannot be greater than the end row !"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (param.getStartBay() > param.getEndBay()) { | 
|---|
|  |  |  | return R.error("the start bay cannot be greater than the end bay !"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (param.getStartLev() > param.getEndLev()) { | 
|---|
|  |  |  | return R.error("the start lev cannot be greater than the end lev !"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Zone zone = zoneService.getById(param.getZoneId()); | 
|---|
|  |  |  | for (int r = param.getStartRow(); r <= param.getEndRow(); r++) { | 
|---|
|  |  |  | for (int b = param.getStartBay(); b <= param.getEndBay(); b++) { | 
|---|
|  |  |  | for (int l = param.getStartLev(); l <= param.getEndLev(); l++) { | 
|---|
|  |  |  | String locNo = Utils.zeroFill(zone.getUuid(), 2) + String.format("%03d", r) + String.format("%03d", b) + String.format("%02d", l); | 
|---|
|  |  |  | double offset = param.getBottom() + ((l-1) * param.getLevOffset()); | 
|---|
|  |  |  | Loc loc = new Loc( | 
|---|
|  |  |  | locNo,    // 编号 | 
|---|
|  |  |  | zone.getId(),    // 库区 | 
|---|
|  |  |  | locNo,    // 库位编号 | 
|---|
|  |  |  | null,    // 名称 | 
|---|
|  |  |  | null,    // 条码 | 
|---|
|  |  |  | param.getLocSts(),    // 库位状态 | 
|---|
|  |  |  | offset,    // 偏移量 | 
|---|
|  |  |  | r,    // 排 | 
|---|
|  |  |  | b,    // 列 | 
|---|
|  |  |  | l,    // 层 | 
|---|
|  |  |  | null,    // 托盘码 | 
|---|
|  |  |  | param.getLocType(),    // 库位类型 | 
|---|
|  |  |  | null,    // 状态[非空] | 
|---|
|  |  |  | null,    // 是否删除[非空] | 
|---|
|  |  |  | null,    // 租户 | 
|---|
|  |  |  | getLoginUserId(),    // 添加人员 | 
|---|
|  |  |  | null,    // 添加时间[非空] | 
|---|
|  |  |  | getLoginUserId(),    // 修改人员 | 
|---|
|  |  |  | null,    // 修改时间 | 
|---|
|  |  |  | null    // 备注 | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | loc.setCompDirect(param.getCompDirect()); | 
|---|
|  |  |  | if (locService.count(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, locNo)) > 0) { | 
|---|
|  |  |  | throw new CoolException(locNo + " location has exist !"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!locService.save(loc)) { | 
|---|
|  |  |  | throw new CoolException(locNo + "location save fail !"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok("initialize success"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|