|
@ -1,11 +1,11 @@ |
|
|
package com.epmet.controller; |
|
|
package com.epmet.controller; |
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker; |
|
|
|
|
|
import com.epmet.commons.tools.annotation.MaskResponse; |
|
|
import com.epmet.commons.tools.annotation.MaskResponse; |
|
|
import com.epmet.commons.tools.aop.NoRepeatSubmit; |
|
|
import com.epmet.commons.tools.aop.NoRepeatSubmit; |
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
import com.epmet.commons.tools.enums.DictTypeEnum; |
|
|
import com.epmet.commons.tools.enums.DictTypeEnum; |
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.commons.tools.validator.AssertUtils; |
|
|
import com.epmet.commons.tools.validator.AssertUtils; |
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
@ -21,12 +21,11 @@ import com.epmet.service.PovertyCondoleAttrService; |
|
|
import com.epmet.service.PovertyCondoleService; |
|
|
import com.epmet.service.PovertyCondoleService; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.util.CollectionUtils; |
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
import org.springframework.util.StringUtils; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
import java.text.ParseException; |
|
|
import java.text.ParseException; |
|
|
import java.util.ArrayList; |
|
|
import java.util.*; |
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -63,11 +62,7 @@ public class PovertyCondoleController { |
|
|
PovertyCondoleDTO data = povertyCondoleService.get(id); |
|
|
PovertyCondoleDTO data = povertyCondoleService.get(id); |
|
|
List<PovertyCondoleAttrDTO> imgs = attrService.selectByPcId(id); |
|
|
List<PovertyCondoleAttrDTO> imgs = attrService.selectByPcId(id); |
|
|
if (!CollectionUtils.isEmpty(imgs)) { |
|
|
if (!CollectionUtils.isEmpty(imgs)) { |
|
|
List<String> imageList = new ArrayList<>(); |
|
|
data.setImgs(imgs); |
|
|
imgs.forEach(file -> { |
|
|
|
|
|
imageList.add(file.getUrl()); |
|
|
|
|
|
}); |
|
|
|
|
|
data.setImgs(imageList); |
|
|
|
|
|
} |
|
|
} |
|
|
return new Result<PovertyCondoleDTO>().ok(data); |
|
|
return new Result<PovertyCondoleDTO>().ok(data); |
|
|
} |
|
|
} |
|
@ -77,27 +72,41 @@ public class PovertyCondoleController { |
|
|
public Result save(@RequestBody PovertyCondoleFormDto dto) throws ParseException { |
|
|
public Result save(@RequestBody PovertyCondoleFormDto dto) throws ParseException { |
|
|
//效验数据
|
|
|
//效验数据
|
|
|
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); |
|
|
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); |
|
|
dto.setId(IdWorker.getIdStr()); |
|
|
|
|
|
if (!CollectionUtils.isEmpty(dto.getImgs())) { |
|
|
|
|
|
List<PovertyCondoleAttrEntity> imageList = new ArrayList<>(); |
|
|
|
|
|
buildImgs(imageList, dto.getImgs(), dto.getId()); |
|
|
|
|
|
attrService.insertBatch(imageList); |
|
|
|
|
|
} |
|
|
|
|
|
povertyCondoleService.save(dto); |
|
|
povertyCondoleService.save(dto); |
|
|
return new Result(); |
|
|
return new Result(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@NoRepeatSubmit |
|
|
@NoRepeatSubmit |
|
|
@PostMapping("update") |
|
|
@PostMapping("update") |
|
|
public Result update(@RequestBody PovertyCondoleFormDto dto) throws ParseException { |
|
|
public Result update(@RequestBody PovertyCondoleFormDto formDto) throws ParseException { |
|
|
//效验数据
|
|
|
//效验数据
|
|
|
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); |
|
|
ValidatorUtils.validateEntity(formDto, UpdateGroup.class, DefaultGroup.class); |
|
|
if (!CollectionUtils.isEmpty(dto.getImgs())) { |
|
|
List<PovertyCondoleAttrEntity> imageList = new ArrayList<>(); |
|
|
List<PovertyCondoleAttrEntity> imageList = new ArrayList<>(); |
|
|
Set<String> delList = new HashSet<>(); |
|
|
buildImgs(imageList, dto.getImgs(), dto.getId()); |
|
|
if (!CollectionUtils.isEmpty(formDto.getImgs())) { |
|
|
attrService.insertBatch(imageList); |
|
|
List<PovertyCondoleAttrDTO> imgs = attrService.selectByPcId(formDto.getId()); |
|
|
|
|
|
if (!CollectionUtils.isEmpty(imgs)) { |
|
|
|
|
|
for (PovertyCondoleAttrDTO img : formDto.getImgs()) { |
|
|
|
|
|
for (PovertyCondoleAttrDTO attr : imgs) { |
|
|
|
|
|
if (StringUtils.isEmpty(img.getId())) { //新增
|
|
|
|
|
|
buildImgs(imageList, Arrays.asList(img), formDto.getId()); |
|
|
|
|
|
}else if (!img.getId().equals(attr.getId())) {//删除
|
|
|
|
|
|
delList.add(attr.getId()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} else {//没有图片全部新增
|
|
|
|
|
|
buildImgs(imageList, formDto.getImgs(), formDto.getId()); |
|
|
|
|
|
attrService.saveOrUpdateBatch(imageList); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
povertyCondoleService.update(formDto); |
|
|
|
|
|
if (imageList.size() > 0) { |
|
|
|
|
|
attrService.saveOrUpdateBatch(imageList); |
|
|
|
|
|
} |
|
|
|
|
|
if (delList.size() > 0) { |
|
|
|
|
|
attrService.deleteBatchIds(delList); |
|
|
} |
|
|
} |
|
|
povertyCondoleService.update(dto); |
|
|
|
|
|
return new Result(); |
|
|
return new Result(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -131,14 +140,16 @@ public class PovertyCondoleController { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void buildImgs(List<PovertyCondoleAttrEntity> imgList, List<String> dtoImgs, String dtoId) { |
|
|
private void buildImgs(List<PovertyCondoleAttrEntity> imgList, List<PovertyCondoleAttrDTO> formImgs, String dtoId) { |
|
|
for (String url : dtoImgs) { |
|
|
for (PovertyCondoleAttrDTO attr : formImgs) { |
|
|
PovertyCondoleAttrEntity attr = new PovertyCondoleAttrEntity(); |
|
|
if (!imgList.contains(attr)) {//去重
|
|
|
attr.setPovertyCondoleId(dtoId); |
|
|
PovertyCondoleAttrEntity entity = ConvertUtils.sourceToTarget(attr, PovertyCondoleAttrEntity.class); |
|
|
attr.setAttachmentUrl(url); |
|
|
entity.setPovertyCondoleId(dtoId); |
|
|
attr.setAttachmentFormat(url.substring(url.lastIndexOf(".") + NumConstant.ONE).toLowerCase()); |
|
|
entity.setAttachmentUrl(attr.getUrl()); |
|
|
attr.setAttachmentType("image"); |
|
|
entity.setAttachmentFormat(attr.getUrl().substring(attr.getUrl().lastIndexOf(".") + NumConstant.ONE).toLowerCase()); |
|
|
imgList.add(attr); |
|
|
entity.setAttachmentType("image"); |
|
|
|
|
|
imgList.add(entity); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|