|  |  |  | 
|---|
|  |  |  | package com.zy.asrs.wms.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.excel.EasyExcel; | 
|---|
|  |  |  | import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONArray; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.metadata.IPage; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.zy.asrs.common.domain.dto.SafeStoDo; | 
|---|
|  |  |  | import com.zy.asrs.common.domain.dto.SafeStoDto; | 
|---|
|  |  |  | import com.zy.asrs.common.domain.entity.LocInPrintMatExcel; | 
|---|
|  |  |  | import com.zy.asrs.common.domain.entity.MatExcel; | 
|---|
|  |  |  | import com.zy.asrs.common.domain.entity.SafeStoExcel; | 
|---|
|  |  |  | import com.zy.asrs.common.utils.MatExcelListener; | 
|---|
|  |  |  | import com.zy.asrs.common.utils.SafeStoExcelListener; | 
|---|
|  |  |  | import com.zy.asrs.common.wms.entity.Mat; | 
|---|
|  |  |  | import com.zy.asrs.common.wms.entity.Prior; | 
|---|
|  |  |  | import com.zy.asrs.common.wms.service.MatService; | 
|---|
|  |  |  | import com.zy.asrs.common.wms.service.PriorService; | 
|---|
|  |  |  | import com.zy.asrs.framework.annotations.ManagerAuth; | 
|---|
|  |  |  | import com.zy.asrs.framework.common.Cools; | 
|---|
|  |  |  | import com.zy.asrs.framework.common.R; | 
|---|
|  |  |  | import com.zy.asrs.framework.common.*; | 
|---|
|  |  |  | import com.zy.asrs.framework.domain.KeyValueVo; | 
|---|
|  |  |  | import com.zy.asrs.framework.common.DateUtils; | 
|---|
|  |  |  | import com.zy.asrs.common.web.BaseController; | 
|---|
|  |  |  | import com.zy.asrs.framework.exception.CoolException; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  | import org.springframework.web.multipart.MultipartFile; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.servlet.http.HttpServletResponse; | 
|---|
|  |  |  | import java.io.IOException; | 
|---|
|  |  |  | import java.net.URLEncoder; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private PriorService priorService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private MatService matService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SnowflakeIdWorker snowflakeIdWorker; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/prior/{id}/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | 
|---|
|  |  |  | if (hostId != null) { | 
|---|
|  |  |  | param.put("host_id", hostId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(priorService.getSafeQtyPage(curr, limit, param)); | 
|---|
|  |  |  | IPage<SafeStoDo> safeQtyPage = priorService.getSafeQtyPage(curr, limit, param); | 
|---|
|  |  |  | return R.ok(safeQtyPage); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/safeSto/add/auth") | 
|---|
|  |  |  | @ManagerAuth(memo = "添加安全库存") | 
|---|
|  |  |  | public R del(@RequestBody SafeStoDto dto){ | 
|---|
|  |  |  | if (Cools.isEmpty(dto.getMatId(), dto.getSafeQua())) { | 
|---|
|  |  |  | return R.parse(BaseRes.PARAM); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (dto.getSafeQua() <= 0.0D) { | 
|---|
|  |  |  | return R.error("安全库存量必须大于零"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Mat mat = matService.getOne(new LambdaQueryWrapper<Mat>().eq(Mat::getId, dto.getMatId()).eq(Mat::getHostId, getHostId())); | 
|---|
|  |  |  | if (mat != null) { | 
|---|
|  |  |  | Prior prior = new Prior(); | 
|---|
|  |  |  | prior.setHostId(getHostId()); | 
|---|
|  |  |  | prior.setUuid("SP" + snowflakeIdWorker.nextId()); | 
|---|
|  |  |  | prior.setMatId(mat.getId()); | 
|---|
|  |  |  | prior.setMatnr(mat.getMatnr()); | 
|---|
|  |  |  | prior.setMaktx(mat.getMaktx()); | 
|---|
|  |  |  | prior.setLocNo(dto.getLocNo()); | 
|---|
|  |  |  | prior.setSafeQua(dto.getSafeQua()); | 
|---|
|  |  |  | prior.setCreateBy(getUserId()); | 
|---|
|  |  |  | prior.setCreateTime(new Date()); | 
|---|
|  |  |  | prior.setUpdateBy(getUserId()); | 
|---|
|  |  |  | prior.setUpdateTime(new Date()); | 
|---|
|  |  |  | prior.setStatus(1); | 
|---|
|  |  |  | prior.setMemo(dto.getMemo()); | 
|---|
|  |  |  | if (!priorService.save(prior)) { | 
|---|
|  |  |  | throw new CoolException("数据保存失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | throw new CoolException("服务器内部错误"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/safeSto/delete/auth") | 
|---|
|  |  |  | @ManagerAuth(memo = "删除库存预警") | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public R del(@RequestBody List<SafeStoDto> dtos){ | 
|---|
|  |  |  | if (Cools.isEmpty(dtos)) { | 
|---|
|  |  |  | return R.parse(BaseRes.PARAM); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (SafeStoDto dto : dtos) { | 
|---|
|  |  |  | if (!priorService.remove(new LambdaQueryWrapper<Prior>().eq(Prior::getId, dto.getId()).eq(Prior::getHostId, getHostId()))) { | 
|---|
|  |  |  | throw new CoolException("删除安全库存失败,请重新尝试"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping(value = "/safeSto/excel/import/auth") | 
|---|
|  |  |  | @ManagerAuth(memo = "安全库存数据导入") | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public R matExcelImport(MultipartFile file) throws IOException { | 
|---|
|  |  |  | SafeStoExcelListener listener = new SafeStoExcelListener(getUserId(), getHostId()); | 
|---|
|  |  |  | EasyExcel.read(file.getInputStream(), SafeStoExcel.class, listener).sheet().doRead(); | 
|---|
|  |  |  | return R.ok("成功同步"+listener.getTotal()+"条安全库存数据"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * excel导入模板下载 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @RequestMapping(value = "/safeSto/excel/import/mould") | 
|---|
|  |  |  | public void matExcelImportMould(HttpServletResponse response) throws IOException { | 
|---|
|  |  |  | List<SafeStoExcel> excels = new ArrayList<>(); | 
|---|
|  |  |  | response.setContentType("application/vnd.ms-excel"); | 
|---|
|  |  |  | response.setCharacterEncoding("utf-8"); | 
|---|
|  |  |  | String fileName = URLEncoder.encode("安全库存Excel导入模板", "UTF-8"); | 
|---|
|  |  |  | response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); | 
|---|
|  |  |  | EasyExcel.write(response.getOutputStream(), SafeStoExcel.class) | 
|---|
|  |  |  | .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) | 
|---|
|  |  |  | .sheet("sheet1") | 
|---|
|  |  |  | .doWrite(excels); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|