| | |
| | | import com.core.common.R; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import zy.cloud.wms.common.CodeRes; |
| | | import zy.cloud.wms.common.config.AdminInterceptor; |
| | | import zy.cloud.wms.common.utils.BarcodeUtils; |
| | | import zy.cloud.wms.common.utils.QrCode; |
| | | import zy.cloud.wms.common.web.BaseController; |
| | | import zy.cloud.wms.manager.entity.Mat; |
| | | import zy.cloud.wms.manager.entity.MatPrint; |
| | | import zy.cloud.wms.manager.service.MatService; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import javax.imageio.ImageIO; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.awt.image.BufferedImage; |
| | | import java.io.IOException; |
| | | import java.util.*; |
| | | |
| | | @RestController |
| | | public class MatController extends BaseController { |
| | | |
| | | @Autowired |
| | | private MatService matService; |
| | | |
| | | @RequestMapping(value = "/mat/list/pda/auth") |
| | | @ManagerAuth |
| | | public R pdaList(@RequestParam(required = true)Long tagId){ |
| | | EntityWrapper<Mat> wrapper = new EntityWrapper<>(); |
| | | wrapper.eq("tag_id", tagId); |
| | | wrapper.orderBy("create_time", false); |
| | | List<Mat> mats = matService.selectList(wrapper); |
| | | return R.ok().add(mats); |
| | | } |
| | | |
| | | @RequestMapping(value = "/mat/search/pda/auth") |
| | | @ManagerAuth |
| | | public R pdaSearch(@RequestParam(required = false)String condition){ |
| | | EntityWrapper<Mat> wrapper = new EntityWrapper<>(); |
| | | if (!Cools.isEmpty(condition)) { |
| | | wrapper.like("matnr", condition).or().like("maktx", condition); |
| | | } |
| | | wrapper.orderBy("create_time", false); |
| | | List<Mat> mats = matService.selectList(wrapper); |
| | | return R.ok().add(mats); |
| | | } |
| | | |
| | | @RequestMapping(value = "/mat/{id}/auth") |
| | | @ManagerAuth |
| | |
| | | @RequestParam(required = false)String orderByField, |
| | | @RequestParam(required = false)String orderByType, |
| | | @RequestParam Map<String, Object> param){ |
| | | // EntityWrapper<Mat> wrapper = new EntityWrapper<>(); |
| | | // excludeTrash(param); |
| | | // convert(param, wrapper); |
| | | // if (!Cools.isEmpty(orderByField)){ |
| | | // wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType)); |
| | | // } |
| | | // Page<Mat> page = matService.selectPage(new Page<>(curr, limit), wrapper); |
| | | // |
| | | // return R.ok().add(page); |
| | | Object tagId = param.get("tag_id"); |
| | | if (Cools.isEmpty(tagId)) { |
| | | tagId = getOriginTag().getId(); |
| | | } |
| | | return R.ok(matService.getPage(new Page<>(curr, limit), String.valueOf(tagId))); |
| | | return R.ok(matService.getPage(new Page<>(curr, limit) |
| | | , String.valueOf(tagId) |
| | | , param.get("matnr") |
| | | , param.get("maktx")) |
| | | ); |
| | | |
| | | } |
| | | |
| | |
| | | @RequestMapping(value = "/mat/add/auth") |
| | | @ManagerAuth |
| | | public R add(Mat mat) { |
| | | mat.setCreateBy(getUserId()); |
| | | mat.setCreateTime(new Date()); |
| | | mat.setUpdateBy(getUserId()); |
| | | mat.setUpdateTime(new Date()); |
| | | matService.insert(mat); |
| | | return R.ok(); |
| | | } |
| | |
| | | if (Cools.isEmpty(mat) || null==mat.getId()){ |
| | | return R.error(); |
| | | } |
| | | mat.setUpdateBy(getUserId()); |
| | | mat.setUpdateTime(new Date()); |
| | | matService.updateById(mat); |
| | | return R.ok(); |
| | | } |
| | |
| | | @ManagerAuth |
| | | public R query(String condition) { |
| | | EntityWrapper<Mat> wrapper = new EntityWrapper<>(); |
| | | wrapper.like("id", condition); |
| | | wrapper.like("matnr", condition).or().like("maktx", condition); |
| | | Page<Mat> page = matService.selectPage(new Page<>(0, 10), wrapper); |
| | | List<Map<String, Object>> result = new ArrayList<>(); |
| | | for (Mat mat : page.getRecords()){ |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("id", mat.getId()); |
| | | map.put("value", mat.getId()); |
| | | map.put("value", mat.getMatnr() + "(" + mat.getMaktx() + ")"); |
| | | result.add(map); |
| | | } |
| | | return R.ok(result); |
| | |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/mac/code/auth") |
| | | // @ManagerAuth(memo = "物料编码条形码获取(type:1(条形码);2(二维码)") |
| | | public R matCodeBarcode(@RequestParam(defaultValue = "1") Integer type |
| | | , @RequestParam String param |
| | | , HttpServletResponse response) throws Exception { |
| | | AdminInterceptor.cors(response); |
| | | if (Cools.isEmpty(param)){ |
| | | return R.parse(BaseRes.EMPTY); |
| | | } |
| | | BufferedImage img; |
| | | if (type == 1) { |
| | | img = BarcodeUtils.encode(param); |
| | | } else { |
| | | img = QrCode.createImg(param); |
| | | } |
| | | if (!ImageIO.write(img, "jpg", response.getOutputStream())) { |
| | | throw new IOException("Could not write an image of format jpg"); |
| | | } |
| | | response.getOutputStream().flush(); |
| | | response.getOutputStream().close(); |
| | | return R.ok(); |
| | | } |
| | | |
| | | // 打印 |
| | | @RequestMapping(value = "/mat/print/auth") |
| | | @ManagerAuth(memo = "物料编码打印") |
| | | public R matCodePrint(@RequestParam(value = "param[]") String[] param) { |
| | | if(Cools.isEmpty(param)) { |
| | | return R.parse(CodeRes.EMPTY); |
| | | } |
| | | List<MatPrint> res = new ArrayList<>(); |
| | | for (String matnr : param){ |
| | | Mat mat = matService.selectByMatnr(matnr); |
| | | // 打印数据注入 |
| | | MatPrint print = new MatPrint(); |
| | | print.setMatnr(mat.getMatnr()); |
| | | print.setBarcode(mat.getBarcode()); |
| | | print.setMaktx(mat.getMaktx()); |
| | | print.setSpecs(mat.getSpecs()); |
| | | print.setUnit(mat.getUnit()); |
| | | res.add(print); |
| | | } |
| | | return R.ok().add(res); |
| | | } |
| | | |
| | | } |