| | |
| | | package com.zy.asrs.wms.asrs.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.fastjson.parser.Feature; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.zy.asrs.framework.common.Cools; |
| | | import com.zy.asrs.framework.common.R; |
| | | import com.zy.asrs.framework.exception.CoolException; |
| | | import com.zy.asrs.wms.asrs.entity.MatField; |
| | | import com.zy.asrs.wms.asrs.entity.MatFieldValue; |
| | | import com.zy.asrs.wms.asrs.entity.Tag; |
| | | import com.zy.asrs.wms.asrs.entity.template.MatTemplate; |
| | | import com.zy.asrs.wms.asrs.service.MatFieldService; |
| | | import com.zy.asrs.wms.asrs.service.MatFieldValueService; |
| | | import com.zy.asrs.wms.asrs.service.TagService; |
| | | import com.zy.asrs.wms.common.annotation.CacheData; |
| | | import com.zy.asrs.wms.common.annotation.OperationLog; |
| | | import com.zy.asrs.wms.common.domain.BaseParam; |
| | | import com.zy.asrs.wms.common.domain.KeyValVo; |
| | | import com.zy.asrs.wms.common.domain.PageParam; |
| | | import com.zy.asrs.wms.asrs.entity.Mat; |
| | | import com.zy.asrs.wms.asrs.service.MatService; |
| | | import com.zy.asrs.wms.system.controller.BaseController; |
| | | import com.zy.asrs.wms.utils.ExcelUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | 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.util.*; |
| | | |
| | | @RestController |
| | | @RequestMapping("/api") |
| | | public class MatController extends BaseController { |
| | | |
| | | @Autowired |
| | | private MatService matService; |
| | | @Autowired |
| | | private MatFieldService matFieldService; |
| | | @Autowired |
| | | private MatFieldValueService matFieldValueService; |
| | | @Autowired |
| | | private TagService tagService; |
| | | |
| | | @PreAuthorize("hasAuthority('asrs:mat:list')") |
| | | @PostMapping("/mat/page") |
| | | @CacheData(tableName = {"man_mat"}) |
| | | public R page(@RequestBody Map<String, Object> map) { |
| | | BaseParam baseParam = buildParam(map, BaseParam.class); |
| | | PageParam<Mat, BaseParam> pageParam = new PageParam<>(baseParam, Mat.class); |
| | | PageParam<Mat, BaseParam> page = matService.page(pageParam, pageParam.buildWrapper(true)); |
| | | |
| | | JSONObject data = JSON.parseObject(JSON.toJSONString(page)); |
| | | |
| | | List<Mat> records = page.getRecords(); |
| | | data.put("records", records); |
| | | for (Mat mat : records) { |
| | | List<MatFieldValue> list = matFieldValueService.list(new LambdaQueryWrapper<MatFieldValue>() |
| | | .eq(MatFieldValue::getMatId, mat.getId())); |
| | | mat.syncField(list); |
| | | } |
| | | |
| | | return R.ok().add(data); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('asrs:mat:list')") |
| | | @PostMapping("/mat/list") |
| | | @CacheData(tableName = {"man_mat"}) |
| | | public R list(@RequestBody Map<String, Object> map) { |
| | | return R.ok().add(matService.list()); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('asrs:mat:list')") |
| | | @GetMapping("/mat/{id}") |
| | | @CacheData(tableName = {"man_mat"}) |
| | | public R get(@PathVariable("id") Long id) { |
| | | return R.ok().add(matService.getById(id)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('asrs:mat:save')") |
| | | @OperationLog("添加商品档案") |
| | | @PostMapping("/mat/save") |
| | | public R save(@RequestBody HashMap<String,Object> param) { |
| | | Mat mat = JSON.parseObject(JSON.toJSONString(param), Mat.class, Feature.DisableCircularReferenceDetect); |
| | | if (!matService.save(mat)) { |
| | | return R.error("添加失败"); |
| | | } |
| | | //设置扩展字段 |
| | | setMatField(param, mat); |
| | | return R.ok("添加成功"); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('asrs:mat:update')") |
| | | @OperationLog("修改商品档案") |
| | | @PostMapping("/mat/update") |
| | | public R update(@RequestBody HashMap<String,Object> param) { |
| | | Mat mat = JSON.parseObject(JSON.toJSONString(param), Mat.class, Feature.DisableCircularReferenceDetect); |
| | | //设置扩展字段 |
| | | setMatField(param, mat); |
| | | |
| | | if (!matService.updateById(mat)) { |
| | | return R.error("修改失败"); |
| | | } |
| | | return R.ok("修改成功"); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('asrs:mat:remove')") |
| | | @OperationLog("删除商品档案") |
| | | @PostMapping("/mat/remove/{ids}") |
| | | public R remove(@PathVariable Long[] ids) { |
| | | if (!matService.removeByIds(Arrays.asList(ids))) { |
| | | return R.error("删除失败"); |
| | | } |
| | | return R.ok("删除成功"); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('asrs:mat:list')") |
| | | @PostMapping("/mat/query") |
| | | public R query(@RequestParam(required = false) String condition) { |
| | | List<KeyValVo> vos = new ArrayList<>(); |
| | | LambdaQueryWrapper<Mat> wrapper = new LambdaQueryWrapper<>(); |
| | | if (!Cools.isEmpty(condition)) { |
| | | wrapper.like(Mat::getId, condition); |
| | | } |
| | | matService.page(new Page<>(1, 30), wrapper).getRecords().forEach( |
| | | item -> vos.add(new KeyValVo(item.getId(), item.getId())) |
| | | ); |
| | | return R.ok().add(vos); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('asrs:mat:list')") |
| | | @PostMapping("/mat/export") |
| | | public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { |
| | | BaseParam baseParam = buildParam(map, BaseParam.class); |
| | | PageParam<Mat, BaseParam> pageParam = new PageParam<>(baseParam, Mat.class); |
| | | List<Mat> data = matService.list(pageParam.buildWrapper(true)); |
| | | |
| | | List<Mat> list = matService.parseMat(data); |
| | | List<MatField> matFields = matFieldService.getMatFields(); |
| | | ExcelUtil.build(ExcelUtil.create(list, Mat.class, matFields), response); |
| | | } |
| | | |
| | | private void setMatField(Map<String, Object> param, Mat mat) { |
| | | //获取扩展字段 |
| | | List<MatField> matFields = matFieldService.list(); |
| | | for (MatField matField : matFields) { |
| | | if (param.containsKey(matField.getName())) { |
| | | MatFieldValue fieldValue = matFieldValueService.getOne(new LambdaQueryWrapper<MatFieldValue>() |
| | | .eq(MatFieldValue::getMatId, mat.getId()) |
| | | .eq(MatFieldValue::getFieldId, matField.getId())); |
| | | Object valueObj = param.get(matField.getName()); |
| | | String value = ""; |
| | | if(valueObj != null) { |
| | | value = valueObj.toString(); |
| | | } |
| | | |
| | | if (fieldValue == null) { |
| | | fieldValue = new MatFieldValue(); |
| | | fieldValue.setMatId(mat.getId()); |
| | | fieldValue.setFieldId(matField.getId()); |
| | | fieldValue.setName(matField.getName()); |
| | | fieldValue.setValue(value); |
| | | matFieldValueService.save(fieldValue); |
| | | }else { |
| | | fieldValue.setValue(value); |
| | | matFieldValueService.updateById(fieldValue); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('asrs:mat:list')") |
| | | @PostMapping("/mat/exportTemplate") |
| | | public void exportTemplate(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { |
| | | ArrayList<MatTemplate> list = new ArrayList<>(); |
| | | List<MatField> matFields = matFieldService.getMatFields(); |
| | | ExcelUtil.build(ExcelUtil.create(list, MatTemplate.class, matFields), response); |
| | | } |
| | | |
| | | @PostMapping("/mat/upload") |
| | | @Transactional |
| | | public R upload(@RequestParam("file") MultipartFile file) { |
| | | List<MatTemplate> list = ExcelUtil.parseExcelFile(file, MatTemplate.class); |
| | | for (MatTemplate matTemplate : list) { |
| | | String firstTag = matTemplate.getFirstTag(); |
| | | String secondTag = matTemplate.getSecondTag(); |
| | | Tag tag1 = null; |
| | | Long tagId = null; |
| | | |
| | | if (!Cools.isEmpty(firstTag)) { |
| | | Tag tag = tagService.getOne(new LambdaQueryWrapper<Tag>().eq(Tag::getName, firstTag)); |
| | | if (tag == null) { |
| | | tag = new Tag(); |
| | | tag.setName(firstTag); |
| | | tag.setParentId(0L); |
| | | tagService.save(tag); |
| | | } |
| | | |
| | | tagId = tag.getId(); |
| | | tag1 = tag; |
| | | } |
| | | |
| | | if (!Cools.isEmpty(secondTag)) { |
| | | if (tag1 != null) { |
| | | Tag tag = tagService.getOne(new LambdaQueryWrapper<Tag>().eq(Tag::getName, secondTag).eq(Tag::getParentId, tag1.getId())); |
| | | if (tag == null) { |
| | | tag = new Tag(); |
| | | tag.setName(secondTag); |
| | | tag.setParentId(tag1.getId()); |
| | | tagService.save(tag); |
| | | } |
| | | |
| | | tagId = tag.getId(); |
| | | } |
| | | } |
| | | |
| | | |
| | | Mat mat = new Mat(); |
| | | mat.sync(matTemplate); |
| | | mat.setTagId(tagId); |
| | | if (!matService.save(mat)) { |
| | | throw new CoolException("创建商品失败"); |
| | | } |
| | | //设置扩展字段 |
| | | setMatField(matTemplate.getDynamicFields(), mat); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | } |
| | | package com.zy.asrs.wms.asrs.controller;
|
| | |
|
| | | import com.alibaba.fastjson.JSON;
|
| | | import com.alibaba.fastjson.JSONObject;
|
| | | import com.alibaba.fastjson.parser.Feature;
|
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
| | | import com.zy.asrs.framework.common.Cools;
|
| | | import com.zy.asrs.framework.common.R;
|
| | | import com.zy.asrs.framework.exception.CoolException;
|
| | | import com.zy.asrs.wms.asrs.entity.MatField;
|
| | | import com.zy.asrs.wms.asrs.entity.MatFieldValue;
|
| | | import com.zy.asrs.wms.asrs.entity.Tag;
|
| | | import com.zy.asrs.wms.asrs.entity.template.MatTemplate;
|
| | | import com.zy.asrs.wms.asrs.service.MatFieldService;
|
| | | import com.zy.asrs.wms.asrs.service.MatFieldValueService;
|
| | | import com.zy.asrs.wms.asrs.service.TagService;
|
| | | import com.zy.asrs.wms.common.annotation.CacheData;
|
| | | import com.zy.asrs.wms.common.annotation.OperationLog;
|
| | | import com.zy.asrs.wms.common.domain.BaseParam;
|
| | | import com.zy.asrs.wms.common.domain.KeyValVo;
|
| | | import com.zy.asrs.wms.common.domain.PageParam;
|
| | | import com.zy.asrs.wms.asrs.entity.Mat;
|
| | | import com.zy.asrs.wms.asrs.service.MatService;
|
| | | import com.zy.asrs.wms.system.controller.BaseController;
|
| | | import com.zy.asrs.wms.utils.ExcelUtil;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.security.access.prepost.PreAuthorize;
|
| | | 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.util.*;
|
| | |
|
| | | @RestController
|
| | | @RequestMapping("/api")
|
| | | public class MatController extends BaseController {
|
| | |
|
| | | @Autowired
|
| | | private MatService matService;
|
| | | @Autowired
|
| | | private MatFieldService matFieldService;
|
| | | @Autowired
|
| | | private MatFieldValueService matFieldValueService;
|
| | | @Autowired
|
| | | private TagService tagService;
|
| | |
|
| | | @PreAuthorize("hasAuthority('asrs:mat:list')")
|
| | | @PostMapping("/mat/page")
|
| | | @CacheData(tableName = {"man_mat"})
|
| | | public R page(@RequestBody Map<String, Object> map) {
|
| | | BaseParam baseParam = buildParam(map, BaseParam.class);
|
| | | PageParam<Mat, BaseParam> pageParam = new PageParam<>(baseParam, Mat.class);
|
| | | PageParam<Mat, BaseParam> page = matService.page(pageParam, pageParam.buildWrapper(true));
|
| | |
|
| | | JSONObject data = JSON.parseObject(JSON.toJSONString(page));
|
| | |
|
| | | List<Mat> records = page.getRecords();
|
| | | data.put("records", records);
|
| | | for (Mat mat : records) {
|
| | | List<MatFieldValue> list = matFieldValueService.list(new LambdaQueryWrapper<MatFieldValue>()
|
| | | .eq(MatFieldValue::getMatId, mat.getId()));
|
| | | mat.syncField(list);
|
| | | }
|
| | |
|
| | | return R.ok().add(data);
|
| | | }
|
| | |
|
| | | @PreAuthorize("hasAuthority('asrs:mat:list')")
|
| | | @PostMapping("/mat/list")
|
| | | @CacheData(tableName = {"man_mat"})
|
| | | public R list(@RequestBody Map<String, Object> map) {
|
| | | return R.ok().add(matService.list());
|
| | | }
|
| | |
|
| | | @PreAuthorize("hasAuthority('asrs:mat:list')")
|
| | | @GetMapping("/mat/{id}")
|
| | | @CacheData(tableName = {"man_mat"})
|
| | | public R get(@PathVariable("id") Long id) {
|
| | | return R.ok().add(matService.getById(id));
|
| | | }
|
| | |
|
| | | @PreAuthorize("hasAuthority('asrs:mat:save')")
|
| | | @OperationLog("添加商品档案")
|
| | | @PostMapping("/mat/save")
|
| | | public R save(@RequestBody HashMap<String,Object> param) {
|
| | | Mat mat = JSON.parseObject(JSON.toJSONString(param), Mat.class, Feature.DisableCircularReferenceDetect);
|
| | | if (!matService.save(mat)) {
|
| | | return R.error("添加失败");
|
| | | }
|
| | | //设置扩展字段
|
| | | setMatField(param, mat);
|
| | | return R.ok("添加成功");
|
| | | }
|
| | |
|
| | | @PreAuthorize("hasAuthority('asrs:mat:update')")
|
| | | @OperationLog("修改商品档案")
|
| | | @PostMapping("/mat/update")
|
| | | public R update(@RequestBody HashMap<String,Object> param) {
|
| | | Mat mat = JSON.parseObject(JSON.toJSONString(param), Mat.class, Feature.DisableCircularReferenceDetect);
|
| | | //设置扩展字段
|
| | | setMatField(param, mat);
|
| | |
|
| | | if (!matService.updateById(mat)) {
|
| | | return R.error("修改失败");
|
| | | }
|
| | | return R.ok("修改成功");
|
| | | }
|
| | |
|
| | | @PreAuthorize("hasAuthority('asrs:mat:remove')")
|
| | | @OperationLog("删除商品档案")
|
| | | @PostMapping("/mat/remove/{ids}")
|
| | | public R remove(@PathVariable Long[] ids) {
|
| | | if (!matService.removeByIds(Arrays.asList(ids))) {
|
| | | return R.error("删除失败");
|
| | | }
|
| | | return R.ok("删除成功");
|
| | | }
|
| | |
|
| | | @PreAuthorize("hasAuthority('asrs:mat:list')")
|
| | | @PostMapping("/mat/query")
|
| | | public R query(@RequestParam(required = false) String condition) {
|
| | | List<KeyValVo> vos = new ArrayList<>();
|
| | | LambdaQueryWrapper<Mat> wrapper = new LambdaQueryWrapper<>();
|
| | | if (!Cools.isEmpty(condition)) {
|
| | | wrapper.like(Mat::getId, condition);
|
| | | }
|
| | | matService.page(new Page<>(1, 30), wrapper).getRecords().forEach(
|
| | | item -> vos.add(new KeyValVo(item.getId(), item.getId()))
|
| | | );
|
| | | return R.ok().add(vos);
|
| | | }
|
| | |
|
| | | @PreAuthorize("hasAuthority('asrs:mat:list')")
|
| | | @PostMapping("/mat/export")
|
| | | public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception {
|
| | | BaseParam baseParam = buildParam(map, BaseParam.class);
|
| | | PageParam<Mat, BaseParam> pageParam = new PageParam<>(baseParam, Mat.class);
|
| | | List<Mat> data = matService.list(pageParam.buildWrapper(true));
|
| | |
|
| | | List<Mat> list = matService.parseMat(data);
|
| | | List<MatField> matFields = matFieldService.getMatFields();
|
| | | ExcelUtil.build(ExcelUtil.create(list, Mat.class, matFields), response);
|
| | | }
|
| | |
|
| | | private void setMatField(Map<String, Object> param, Mat mat) {
|
| | | //获取扩展字段
|
| | | List<MatField> matFields = matFieldService.list();
|
| | | for (MatField matField : matFields) {
|
| | | if (param.containsKey(matField.getName())) {
|
| | | MatFieldValue fieldValue = matFieldValueService.getOne(new LambdaQueryWrapper<MatFieldValue>()
|
| | | .eq(MatFieldValue::getMatId, mat.getId())
|
| | | .eq(MatFieldValue::getFieldId, matField.getId()));
|
| | | Object valueObj = param.get(matField.getName());
|
| | | String value = "";
|
| | | if(valueObj != null) {
|
| | | value = valueObj.toString();
|
| | | }
|
| | |
|
| | | if (fieldValue == null) {
|
| | | fieldValue = new MatFieldValue();
|
| | | fieldValue.setMatId(mat.getId());
|
| | | fieldValue.setFieldId(matField.getId());
|
| | | fieldValue.setName(matField.getName());
|
| | | fieldValue.setValue(value);
|
| | | matFieldValueService.save(fieldValue);
|
| | | }else {
|
| | | fieldValue.setValue(value);
|
| | | matFieldValueService.updateById(fieldValue);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | @PreAuthorize("hasAuthority('asrs:mat:list')")
|
| | | @PostMapping("/mat/exportTemplate")
|
| | | public void exportTemplate(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception {
|
| | | ArrayList<MatTemplate> list = new ArrayList<>();
|
| | | List<MatField> matFields = matFieldService.getMatFields();
|
| | | ExcelUtil.build(ExcelUtil.create(list, MatTemplate.class, matFields), response);
|
| | | }
|
| | |
|
| | | @PostMapping("/mat/upload")
|
| | | @Transactional
|
| | | public R upload(@RequestParam("file") MultipartFile file) {
|
| | | List<MatTemplate> list = ExcelUtil.parseExcelFile(file, MatTemplate.class);
|
| | | for (MatTemplate matTemplate : list) {
|
| | | String firstTag = matTemplate.getFirstTag();
|
| | | String secondTag = matTemplate.getSecondTag();
|
| | | Tag tag1 = null;
|
| | | Long tagId = null;
|
| | |
|
| | | if (!Cools.isEmpty(firstTag)) {
|
| | | Tag tag = tagService.getOne(new LambdaQueryWrapper<Tag>().eq(Tag::getName, firstTag));
|
| | | if (tag == null) {
|
| | | tag = new Tag();
|
| | | tag.setName(firstTag);
|
| | | tag.setParentId(0L);
|
| | | tagService.save(tag);
|
| | | }
|
| | |
|
| | | tagId = tag.getId();
|
| | | tag1 = tag;
|
| | | }
|
| | |
|
| | | if (!Cools.isEmpty(secondTag)) {
|
| | | if (tag1 != null) {
|
| | | Tag tag = tagService.getOne(new LambdaQueryWrapper<Tag>().eq(Tag::getName, secondTag).eq(Tag::getParentId, tag1.getId()));
|
| | | if (tag == null) {
|
| | | tag = new Tag();
|
| | | tag.setName(secondTag);
|
| | | tag.setParentId(tag1.getId());
|
| | | tagService.save(tag);
|
| | | }
|
| | |
|
| | | tagId = tag.getId();
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | Mat mat = new Mat();
|
| | | mat.sync(matTemplate);
|
| | | mat.setTagId(tagId);
|
| | | if (!matService.save(mat)) {
|
| | | throw new CoolException("创建商品失败");
|
| | | }
|
| | | //设置扩展字段
|
| | | setMatField(matTemplate.getDynamicFields(), mat);
|
| | | }
|
| | | return R.ok();
|
| | | }
|
| | |
|
| | | }
|