| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.fastjson.parser.Feature; |
| | | import com.alibaba.fastjson.serializer.SerializerFeature; |
| | | 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.OperationLog; |
| | | import com.zy.asrs.wms.common.domain.BaseParam; |
| | | import com.zy.asrs.wms.common.domain.KeyValVo; |
| | |
| | | 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.*; |
| | |
| | | private MatFieldService matFieldService; |
| | | @Autowired |
| | | private MatFieldValueService matFieldValueService; |
| | | @Autowired |
| | | private TagService tagService; |
| | | |
| | | @PreAuthorize("hasAuthority('asrs:mat:list')") |
| | | @PostMapping("/mat/page") |
| | |
| | | ExcelUtil.build(ExcelUtil.create(list, Mat.class, matFields), response); |
| | | } |
| | | |
| | | private void setMatField(HashMap<String, Object> param, Mat mat) { |
| | | private void setMatField(Map<String, Object> param, Mat mat) { |
| | | //获取扩展字段 |
| | | List<MatField> matFields = matFieldService.list(); |
| | | for (MatField matField : matFields) { |
| | |
| | | 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(param.get(matField.getName()).toString()); |
| | | fieldValue.setValue(value); |
| | | matFieldValueService.save(fieldValue); |
| | | }else { |
| | | fieldValue.setValue(param.get(matField.getName()).toString()); |
| | | 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(); |
| | | } |
| | | |
| | | } |