feat:mapstruct

feat:mapstruct expression

feat:mapstruct

feat:some mapstruct

feat:clear code
This commit is contained in:
wangcheng 2020-03-17 17:29:16 +08:00 committed by wangcheng
parent 7937ea5a9b
commit 14a3852e92
32 changed files with 940 additions and 616 deletions

13
pom.xml
View File

@ -33,6 +33,7 @@
<springboot.version>2.2.5.RELEASE</springboot.version>
<tensorflow.version>1.12.0</tensorflow.version>
<es.version>7.6.1</es.version>
<mapstruct.version>1.3.1.Final</mapstruct.version>
</properties>
@ -243,6 +244,18 @@
<artifactId>tensorflow</artifactId>
<version>${tensorflow.version}</version>
</dependency>
<!-- MapStruct START -->
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
<version>${mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</dependency>
<!-- MapStruct end -->
</dependencies>
</dependencyManagement>

View File

@ -1,7 +1,5 @@
package com.pgmmers.radar.util;
import com.pgmmers.radar.dal.util.JsonUtils;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;

View File

@ -51,6 +51,17 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>

View File

@ -1,13 +0,0 @@
package com.pgmmers;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}

View File

@ -1,26 +1,59 @@
package com.pgmmers.radar.dal.util;
package com.pgmmers.radar.util;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonParser.Feature;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
/**
* json对象转换
*
* @author xushuai
*/
public class JsonUtils {
private static Logger logger = LoggerFactory.getLogger(JsonUtils.class);
public static ObjectMapper objectMapper = new ObjectMapper();
public static JsonNode getJsonNode(String str) {
try {
if (StringUtils.isEmpty(str)) {
return null;
}
return objectMapper.readTree(str);
} catch (JsonProcessingException e) {
logger.error("getJsonNode error{}", str, e);
return null;
}
}
public static String jsonNodeToString(JsonNode jsonNode) {
try {
if (jsonNode == null) {
return null;
}
return objectMapper.writeValueAsString(jsonNode);
} catch (JsonProcessingException e) {
logger.error("jsonNodeToString error{}", jsonNode.asText(), e);
return null;
}
}
public JsonUtils() {
}
public static String toJson(Object object) {
try {
return (new ObjectMapper()).setSerializationInclusion(Include.NON_NULL).writeValueAsString(object);
return (new ObjectMapper()).setSerializationInclusion(Include.NON_NULL)
.writeValueAsString(object);
} catch (JsonProcessingException var2) {
throw new RuntimeException(var2);
}
@ -28,14 +61,17 @@ public class JsonUtils {
public static <E> E fromJson(String json, Class<E> type) {
try {
return (new ObjectMapper()).configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).readValue(json, type);
return (new ObjectMapper())
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.readValue(json, type);
} catch (IOException var3) {
throw new RuntimeException(var3);
}
}
public static JavaType getCollectionType(Class<?> collectionClass, Class<?>... elementClasses) {
return (new ObjectMapper()).getTypeFactory().constructParametricType(collectionClass, elementClasses);
return (new ObjectMapper()).getTypeFactory()
.constructParametricType(collectionClass, elementClasses);
}
public static String toJsonString(Object object) {
@ -53,7 +89,7 @@ public class JsonUtils {
Map map = null;
try {
map = (Map)mapper.readValue(json, Map.class);
map = (Map) mapper.readValue(json, Map.class);
return map;
} catch (IOException var4) {
throw new RuntimeException(var4);

View File

@ -27,7 +27,16 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<!-- MapStruct START -->
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
</dependency>
<!-- MapStruct end -->
</dependencies>

View File

@ -1,19 +1,18 @@
package com.pgmmers.radar.dal.data.impl;
import java.util.ArrayList;
import java.util.List;
import com.github.pagehelper.PageHelper;
import com.pgmmers.radar.dal.data.MobileInfoDal;
import com.pgmmers.radar.dal.util.POVOUtils;
import com.pgmmers.radar.mapper.MobileInfoMapper;
import com.pgmmers.radar.mapstruct.MobileInfoMapping;
import com.pgmmers.radar.model.MobileInfoPO;
import com.pgmmers.radar.vo.data.MobileInfoVO;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import com.github.pagehelper.PageHelper;
import tk.mybatis.mapper.entity.Example;
@Service
@ -21,19 +20,18 @@ public class MobileInfoDalImpl implements MobileInfoDal {
@Autowired
private MobileInfoMapper mobileMapper;
@Resource
private MobileInfoMapping mobileInfoVOMapping;
@Override
public List<MobileInfoVO> listMobileInfo(int pageNum, int pageSize) {
Example example = new Example(MobileInfoPO.class);
PageHelper.startPage(pageNum, pageSize);
List<MobileInfoPO> poList = mobileMapper.selectByExample(example);
List<MobileInfoVO> voList = new ArrayList<MobileInfoVO>();
MobileInfoVO vo;
for (MobileInfoPO po : poList) {
vo = POVOUtils.copyFromMobileInfPO(po);
voList.add(vo);
if (CollectionUtils.isEmpty(poList)) {
return new ArrayList<>();
}
return voList;
return mobileInfoVOMapping.sourceToTarget(poList);
}
@Override
@ -49,37 +47,38 @@ public class MobileInfoDalImpl implements MobileInfoDal {
example.createCriteria().andEqualTo("mobile", mobile);
List<MobileInfoPO> list = mobileMapper.selectByExample(example);
if (list != null && list.size() > 0) {
return POVOUtils.copyFromMobileInfPO(list.get(0));
return mobileInfoVOMapping.sourceToTarget(list.get(0));
}
return null;
}
@Override
public List<MobileInfoVO> listMobileInfo(String province, String city, int pageNum, int pageSize) {
public List<MobileInfoVO> listMobileInfo(String province, String city, int pageNum,
int pageSize) {
Example example = new Example(MobileInfoPO.class);
PageHelper.startPage(pageNum, pageSize);
Example.Criteria criteria = example.createCriteria();
if (!StringUtils.isEmpty(province)) {
criteria.andEqualTo("province", province);
}
if (!StringUtils.isEmpty(city)) {
criteria.andEqualTo("city", city);
}
List<MobileInfoPO> poList = mobileMapper.selectByExample(example);
List<MobileInfoVO> voList = new ArrayList<MobileInfoVO>();
MobileInfoVO vo;
for (MobileInfoPO po : poList) {
vo = POVOUtils.copyFromMobileInfPO(po);
voList.add(vo);
List<MobileInfoVO> voList;
if (CollectionUtils.isEmpty(poList)) {
voList = new ArrayList<>();
} else {
voList=mobileInfoVOMapping.sourceToTarget(poList);
}
return voList;
}
@Override
public int save(MobileInfoVO info) {
MobileInfoPO po = POVOUtils.copyFromMobileInfoVO(info);
MobileInfoPO po = mobileInfoVOMapping.targetToSource(info);
return mobileMapper.insertSelective(po);
}

View File

@ -1,27 +1,26 @@
package com.pgmmers.radar.dal.model.impl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.pgmmers.radar.dal.bean.AbstractionQuery;
import com.pgmmers.radar.dal.bean.PageResult;
import com.pgmmers.radar.dal.model.AbstractionDal;
import com.pgmmers.radar.mapper.AbstractionMapper;
import com.pgmmers.radar.mapstruct.AbstractionMapping;
import com.pgmmers.radar.model.AbstractionPO;
import com.pgmmers.radar.util.BaseUtils;
import com.pgmmers.radar.vo.model.AbstractionVO;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import com.pgmmers.radar.dal.bean.AbstractionQuery;
import com.pgmmers.radar.dal.bean.PageResult;
import com.pgmmers.radar.dal.model.AbstractionDal;
import com.pgmmers.radar.dal.util.POVOUtils;
import com.pgmmers.radar.mapper.AbstractionMapper;
import com.pgmmers.radar.model.AbstractionPO;
import com.pgmmers.radar.util.BaseUtils;
import com.pgmmers.radar.vo.model.AbstractionVO;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import tk.mybatis.mapper.entity.Example;
@ -32,14 +31,14 @@ public class AbstractionDalImpl implements AbstractionDal {
@Autowired
private AbstractionMapper abstractionMapper;
@Resource
private AbstractionMapping abstractionMapping;
@Override
public AbstractionVO get(Long id) {
AbstractionPO abstraction = abstractionMapper.selectByPrimaryKey(id);
if (abstraction != null) {
AbstractionVO abstractionVO = new AbstractionVO();
BeanUtils.copyProperties(abstraction, abstractionVO);
return abstractionVO;
return abstractionMapping.sourceToTarget(abstraction);
}
return null;
}
@ -50,14 +49,10 @@ public class AbstractionDalImpl implements AbstractionDal {
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("modelId", modelId);
List<AbstractionPO> list = abstractionMapper.selectByExample(example);
List<AbstractionVO> listVO = new ArrayList<AbstractionVO>();
for (AbstractionPO abstractionPO : list) {
AbstractionVO abstractionVO = new AbstractionVO();
BeanUtils.copyProperties(abstractionPO, abstractionVO);
listVO.add(abstractionVO);
if (CollectionUtils.isEmpty(list)) {
return new ArrayList<>();
}
return listVO;
return abstractionMapping.sourceToTarget(list);
}
@Override
@ -80,28 +75,21 @@ public class AbstractionDalImpl implements AbstractionDal {
List<AbstractionPO> list = abstractionMapper.selectByExample(example);
Page<AbstractionPO> page = (Page<AbstractionPO>) list;
List<AbstractionVO> listVO = new ArrayList<AbstractionVO>();
for (AbstractionPO abstractionPO : page.getResult()) {
AbstractionVO abstractionVO = new AbstractionVO();
abstractionVO = POVOUtils.copyFromAbstractPO(abstractionPO);
listVO.add(abstractionVO);
List<AbstractionVO> listVO;
if (CollectionUtils.isEmpty(list)) {
listVO = new ArrayList<>();
} else {
listVO = abstractionMapping.sourceToTarget(list);
}
// for (AbstractionPO abstractionPO : page.getResult()) {
// AbstractionVO abstractionVO = new AbstractionVO();
// BeanUtils.copyProperties(abstractionPO, abstractionVO);
// listVO.add(abstractionVO);
// }
PageResult<AbstractionVO> pageResult = new PageResult<AbstractionVO>(page.getPageNum(), page.getPageSize(),
PageResult<AbstractionVO> pageResult = new PageResult<>(page.getPageNum(),
page.getPageSize(),
(int) page.getTotal(), listVO);
return pageResult;
}
@Override
public int save(AbstractionVO abstraction) {
AbstractionPO abstractionPO = POVOUtils.copyFromAbstractVO(abstraction);
AbstractionPO abstractionPO = abstractionMapping.targetToSource(abstraction);
Date sysDate = new Date();
int count = 0;
if (abstraction.getId() == null) {

View File

@ -1,26 +1,26 @@
package com.pgmmers.radar.dal.model.impl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.pgmmers.radar.dal.bean.ActivationQuery;
import com.pgmmers.radar.dal.bean.PageResult;
import com.pgmmers.radar.dal.model.ActivationDal;
import com.pgmmers.radar.mapper.ActivationMapper;
import com.pgmmers.radar.mapstruct.ActivationMapping;
import com.pgmmers.radar.model.ActivationPO;
import com.pgmmers.radar.util.BaseUtils;
import com.pgmmers.radar.vo.model.ActivationVO;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import tk.mybatis.mapper.entity.Example;
@ -31,14 +31,13 @@ public class ActivationDalImpl implements ActivationDal {
@Autowired
private ActivationMapper activationMapper;
@Resource
private ActivationMapping activationMapping;
@Override
public ActivationVO get(Long id) {
ActivationPO activation = activationMapper.selectByPrimaryKey(id);
if (activation != null) {
ActivationVO activationVO = new ActivationVO();
BeanUtils.copyProperties(activation, activationVO);
return activationVO;
return activationMapping.sourceToTarget(activation);
}
return null;
}
@ -58,23 +57,20 @@ public class ActivationDalImpl implements ActivationDal {
}
List<ActivationPO> list = activationMapper.selectByExample(example);
Page<ActivationPO> page = (Page<ActivationPO>) list;
List<ActivationVO> listVO = new ArrayList<>();
for (ActivationPO activationPO : page.getResult()) {
ActivationVO activationVO = new ActivationVO();
BeanUtils.copyProperties(activationPO, activationVO);
listVO.add(activationVO);
List<ActivationVO> listVO ;
if (CollectionUtils.isEmpty(list)){
listVO =new ArrayList<>();
}else {
listVO=activationMapping.sourceToTarget(list);
}
PageResult<ActivationVO> pageResult = new PageResult<ActivationVO>(page.getPageNum(), page.getPageSize(),
PageResult<ActivationVO> pageResult = new PageResult<>(page.getPageNum(), page.getPageSize(),
(int) page.getTotal(), listVO);
return pageResult;
}
@Override
public int save(ActivationVO activation) {
ActivationPO activationPO = new ActivationPO();
BeanUtils.copyProperties(activation, activationPO);
ActivationPO activationPO = activationMapping.targetToSource(activation);
Date sysDate = new Date();
int count = 0;
if (activation.getId() == null) {

View File

@ -1,10 +1,7 @@
package com.pgmmers.radar.dal.model.impl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.pgmmers.radar.dal.bean.DataListQuery;
import com.pgmmers.radar.dal.bean.DataListRecordQuery;
import com.pgmmers.radar.dal.bean.PageResult;
@ -12,6 +9,9 @@ import com.pgmmers.radar.dal.model.DataListDal;
import com.pgmmers.radar.mapper.DataListMetaMapper;
import com.pgmmers.radar.mapper.DataListRecordMapper;
import com.pgmmers.radar.mapper.DataListsMapper;
import com.pgmmers.radar.mapstruct.DataListMetaMapping;
import com.pgmmers.radar.mapstruct.DataListRecordMapping;
import com.pgmmers.radar.mapstruct.DataListsMapping;
import com.pgmmers.radar.model.DataListMetaPO;
import com.pgmmers.radar.model.DataListRecordPO;
import com.pgmmers.radar.model.DataListsPO;
@ -19,15 +19,17 @@ import com.pgmmers.radar.util.BaseUtils;
import com.pgmmers.radar.vo.model.DataListMetaVO;
import com.pgmmers.radar.vo.model.DataListRecordVO;
import com.pgmmers.radar.vo.model.DataListsVO;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import tk.mybatis.mapper.entity.Example;
@ -38,44 +40,39 @@ public class DataListDalImpl implements DataListDal {
@Autowired
private DataListsMapper dataListMapper;
@Resource
private DataListsMapping dataListsMapping;
@Autowired
private DataListRecordMapper dataListRecordMapper;
@Resource
private DataListRecordMapping dataListRecordMapping;
@Autowired
private DataListMetaMapper dataListMetaMapper;
@Resource
private DataListMetaMapping dataListMetaMapping;
@Override
public List<DataListMetaVO> listDataMeta(Long dataListId) {
logger.info("listDataRecord,{}", dataListId);
List<DataListMetaVO> volist = new ArrayList<>();
Example example = new Example(DataListMetaPO.class);
example.createCriteria().andEqualTo("dataListId", dataListId);
DataListMetaVO vo;
List<DataListMetaPO> list = dataListMetaMapper.selectByExample(example);
for (DataListMetaPO po : list) {
vo = new DataListMetaVO();
BeanUtils.copyProperties(po, vo);
volist.add(vo);
if (CollectionUtils.isEmpty(list)) {
return new ArrayList<>();
}
return volist;
return dataListMetaMapping.sourceToTarget(list);
}
@Override
public List<DataListRecordVO> listDataRecord(Long dataListId) {
logger.info("listDataRecord,{}", dataListId);
List<DataListRecordVO> voList = new ArrayList<>();
Example example = new Example(DataListRecordPO.class);
example.createCriteria().andEqualTo("dataListId", dataListId);
List<DataListRecordPO> list = dataListRecordMapper.selectByExample(example);
DataListRecordVO vo;
for (DataListRecordPO po : list) {
vo = new DataListRecordVO();
BeanUtils.copyProperties(po, vo);
voList.add(vo);
if (CollectionUtils.isEmpty(list)) {
return new ArrayList<>();
}
return voList;
return dataListRecordMapping.sourceToTarget(list);
}
@Override
@ -87,33 +84,23 @@ public class DataListDalImpl implements DataListDal {
@Override
public List<DataListsVO> listDataLists(Long modelId, Integer status) {
logger.info("listDataLists,{},{}", modelId, status);
List<DataListsVO> dataLists = new ArrayList<>();
Example example = new Example(DataListsPO.class);
Example.Criteria cri = example.createCriteria();
if (status != null) {
cri.andEqualTo("status", status);
}
List<DataListsPO> list = dataListMapper.selectByExample(example);
DataListsVO vo;
if (list == null || list.size() == 0) {
return null;
} else {
for (DataListsPO po : list) {
vo = new DataListsVO();
BeanUtils.copyProperties(po, vo);
dataLists.add(vo);
}
if (CollectionUtils.isEmpty(list)) {
return new ArrayList<>();
}
return dataLists;
return dataListsMapping.sourceToTarget(list);
}
@Override
public DataListsVO get(Long id) {
DataListsPO dataListsPO = dataListMapper.selectByPrimaryKey(id);
if (dataListsPO != null) {
DataListsVO dataListsVO = new DataListsVO();
BeanUtils.copyProperties(dataListsPO, dataListsVO);
return dataListsVO;
return dataListsMapping.sourceToTarget(dataListsPO);
}
return null;
}
@ -124,14 +111,10 @@ public class DataListDalImpl implements DataListDal {
Example.Criteria criteria = example.createCriteria();
criteria.andIn("modelId", Arrays.asList(modelId, 0L));
List<DataListsPO> list = dataListMapper.selectByExample(example);
List<DataListsVO> listVO = new ArrayList<>();
for (DataListsPO dataListsPO : list) {
DataListsVO dataListsVO = new DataListsVO();
BeanUtils.copyProperties(dataListsPO, dataListsVO);
listVO.add(dataListsVO);
if (CollectionUtils.isEmpty(list)) {
return new ArrayList<>();
}
return listVO;
return dataListsMapping.sourceToTarget(list);
}
@Override
@ -152,14 +135,12 @@ public class DataListDalImpl implements DataListDal {
}
List<DataListsPO> list = dataListMapper.selectByExample(example);
Page<DataListsPO> page = (Page<DataListsPO>) list;
List<DataListsVO> listVO = new ArrayList<>();
for (DataListsPO dataListsPO : page.getResult()) {
DataListsVO dataListsVO = new DataListsVO();
BeanUtils.copyProperties(dataListsPO, dataListsVO);
listVO.add(dataListsVO);
List<DataListsVO> listVO;
if (CollectionUtils.isEmpty(list)) {
listVO = new ArrayList<>();
} else {
listVO = dataListsMapping.sourceToTarget(list);
}
PageResult<DataListsVO> pageResult = new PageResult<>(page.getPageNum(), page.getPageSize(),
(int) page.getTotal(), listVO);
return pageResult;
@ -167,8 +148,7 @@ public class DataListDalImpl implements DataListDal {
@Override
public int save(DataListsVO datalist) {
DataListsPO dataListsPO = new DataListsPO();
BeanUtils.copyProperties(datalist, dataListsPO);
DataListsPO dataListsPO = dataListsMapping.targetToSource(datalist);
Date sysDate = new Date();
int count = 0;
if (datalist.getId() == null) {
@ -196,17 +176,14 @@ public class DataListDalImpl implements DataListDal {
public DataListMetaVO getMeta(Long id) {
DataListMetaPO dataListMetaPO = dataListMetaMapper.selectByPrimaryKey(id);
if (dataListMetaPO != null) {
DataListMetaVO dataListMetaVO = new DataListMetaVO();
BeanUtils.copyProperties(dataListMetaPO, dataListMetaVO);
return dataListMetaVO;
return dataListMetaMapping.sourceToTarget(dataListMetaPO);
}
return null;
}
@Override
public int saveMeta(DataListMetaVO dataListMeta) {
DataListMetaPO dataListMetaPO = new DataListMetaPO();
BeanUtils.copyProperties(dataListMeta, dataListMetaPO);
DataListMetaPO dataListMetaPO = dataListMetaMapping.targetToSource(dataListMeta);
Date sysDate = new Date();
int count = 0;
if (dataListMetaPO.getId() == null) {
@ -234,9 +211,7 @@ public class DataListDalImpl implements DataListDal {
public DataListRecordVO getRecord(Long id) {
DataListRecordPO dataListRecordPO = dataListRecordMapper.selectByPrimaryKey(id);
if (dataListRecordPO != null) {
DataListRecordVO dataListRecordVO = new DataListRecordVO();
BeanUtils.copyProperties(dataListRecordPO, dataListRecordVO);
return dataListRecordVO;
return dataListRecordMapping.sourceToTarget(dataListRecordPO);
}
return null;
}
@ -249,14 +224,12 @@ public class DataListDalImpl implements DataListDal {
example.createCriteria().andEqualTo("dataListId", query.getDataListId());
List<DataListRecordPO> list = dataListRecordMapper.selectByExample(example);
Page<DataListRecordPO> page = (Page<DataListRecordPO>) list;
List<DataListRecordVO> listVO = new ArrayList<>();
for (DataListRecordPO dataListRecordPO : page.getResult()) {
DataListRecordVO dataListRecordVO = new DataListRecordVO();
BeanUtils.copyProperties(dataListRecordPO, dataListRecordVO);
listVO.add(dataListRecordVO);
List<DataListRecordVO> listVO ;
if (CollectionUtils.isEmpty(list)){
listVO = new ArrayList<>();
}else {
listVO=dataListRecordMapping.sourceToTarget(list);
}
PageResult<DataListRecordVO> pageResult = new PageResult<>(page.getPageNum(),
page.getPageSize(), (int) page.getTotal(), listVO);
return pageResult;
@ -264,8 +237,7 @@ public class DataListDalImpl implements DataListDal {
@Override
public int saveRecord(DataListRecordVO dataListRecord) {
DataListRecordPO dataListRecordPO = new DataListRecordPO();
BeanUtils.copyProperties(dataListRecord, dataListRecordPO);
DataListRecordPO dataListRecordPO = dataListRecordMapping.targetToSource(dataListRecord);
Date sysDate = new Date();
int count = 0;
if (dataListRecordPO.getId() == null) {

View File

@ -1,27 +1,26 @@
package com.pgmmers.radar.dal.model.impl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.pgmmers.radar.dal.bean.FieldQuery;
import com.pgmmers.radar.dal.bean.PageResult;
import com.pgmmers.radar.dal.model.FieldDal;
import com.pgmmers.radar.mapper.FieldMapper;
import com.pgmmers.radar.mapstruct.FieldMapping;
import com.pgmmers.radar.model.FieldPO;
import com.pgmmers.radar.util.BaseUtils;
import com.pgmmers.radar.vo.model.FieldVO;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import tk.mybatis.mapper.entity.Example;
@ -32,14 +31,14 @@ public class FieldDalImpl implements FieldDal {
@Autowired
private FieldMapper fieldMapper;
@Resource
private FieldMapping fieldMapping;
@Override
public FieldVO get(Long id) {
FieldPO field = fieldMapper.selectByPrimaryKey(id);
if (field != null) {
FieldVO fieldVO = new FieldVO();
BeanUtils.copyProperties(field, fieldVO);
return fieldVO;
return fieldMapping.sourceToTarget(field);
}
return null;
}
@ -59,23 +58,21 @@ public class FieldDalImpl implements FieldDal {
}
List<FieldPO> list = fieldMapper.selectByExample(example);
Page<FieldPO> page = (Page<FieldPO>) list;
List<FieldVO> listVO = new ArrayList<>();
for (FieldPO fieldPO : page.getResult()) {
FieldVO fieldVO = new FieldVO();
BeanUtils.copyProperties(fieldPO, fieldVO);
listVO.add(fieldVO);
List<FieldVO> listVO;
if (CollectionUtils.isEmpty(list)) {
listVO = new ArrayList<>();
} else {
listVO = fieldMapping.sourceToTarget(list);
}
PageResult<FieldVO> pageResult = new PageResult<FieldVO>(page.getPageNum(), page.getPageSize(),
PageResult<FieldVO> pageResult = new PageResult<>(page.getPageNum(),
page.getPageSize(),
(int) page.getTotal(), listVO);
return pageResult;
}
@Override
public int save(FieldVO field) {
FieldPO fieldPO = new FieldPO();
BeanUtils.copyProperties(field, fieldPO);
FieldPO fieldPO = fieldMapping.targetToSource(field);
Date sysDate = new Date();
int count = 0;
if (field.getId() == null) {

View File

@ -7,17 +7,17 @@ import com.pgmmers.radar.model.ModelConfPO;
import com.pgmmers.radar.model.ModelConfParamPO;
import com.pgmmers.radar.vo.model.ModelConfParamVO;
import com.pgmmers.radar.vo.model.ModelConfVO;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class ModelConfDalImpl implements ModelConfDal {
@Resource
private ModelConfMapper modelConfMapper;
@Resource
@ -62,8 +62,8 @@ public class ModelConfDalImpl implements ModelConfDal {
@Override
public ModelConfParamVO getParamById(Long id) {
ModelConfParamVO modelConfParamVO = new ModelConfParamVO();
ModelConfParamPO po = modelConfParamMapper.selectByPrimaryKey(id);
BeanUtils.copyProperties(po,modelConfParamVO);
ModelConfParamPO po = modelConfParamMapper.selectByPrimaryKey(id);
BeanUtils.copyProperties(po, modelConfParamVO);
return modelConfParamVO;
}

View File

@ -1,31 +1,55 @@
package com.pgmmers.radar.dal.model.impl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.pgmmers.radar.dal.bean.ModelQuery;
import com.pgmmers.radar.dal.bean.PageResult;
import com.pgmmers.radar.dal.model.ModelDal;
import com.pgmmers.radar.enums.StatusType;
import com.pgmmers.radar.mapper.AbstractionMapper;
import com.pgmmers.radar.mapper.ActivationMapper;
import com.pgmmers.radar.mapper.DataListMetaMapper;
import com.pgmmers.radar.mapper.DataListRecordMapper;
import com.pgmmers.radar.mapper.DataListsMapper;
import com.pgmmers.radar.mapper.FieldMapper;
import com.pgmmers.radar.mapper.ModelMapper;
import com.pgmmers.radar.mapper.PreItemMapper;
import com.pgmmers.radar.mapper.RuleMapper;
import com.pgmmers.radar.mapstruct.AbstractionMapping;
import com.pgmmers.radar.mapstruct.ActivationMapping;
import com.pgmmers.radar.mapstruct.FieldMapping;
import com.pgmmers.radar.mapstruct.ModelMapping;
import com.pgmmers.radar.mapstruct.PreItemMapping;
import com.pgmmers.radar.mapstruct.RuleMapping;
import com.pgmmers.radar.model.AbstractionPO;
import com.pgmmers.radar.model.ActivationPO;
import com.pgmmers.radar.model.DataListMetaPO;
import com.pgmmers.radar.model.DataListRecordPO;
import com.pgmmers.radar.model.DataListsPO;
import com.pgmmers.radar.model.FieldPO;
import com.pgmmers.radar.model.ModelPO;
import com.pgmmers.radar.model.PreItemPO;
import com.pgmmers.radar.model.RulePO;
import com.pgmmers.radar.util.BaseUtils;
import com.pgmmers.radar.vo.model.AbstractionVO;
import com.pgmmers.radar.vo.model.ActivationVO;
import com.pgmmers.radar.vo.model.FieldVO;
import com.pgmmers.radar.vo.model.ModelVO;
import com.pgmmers.radar.vo.model.PreItemVO;
import com.pgmmers.radar.vo.model.RuleVO;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import com.pgmmers.radar.dal.bean.ModelQuery;
import com.pgmmers.radar.dal.bean.PageResult;
import com.pgmmers.radar.dal.model.ModelDal;
import com.pgmmers.radar.dal.util.POVOUtils;
import com.pgmmers.radar.enums.StatusType;
import com.pgmmers.radar.mapper.*;
import com.pgmmers.radar.model.*;
import com.pgmmers.radar.util.BaseUtils;
import com.pgmmers.radar.vo.model.*;
import javax.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import tk.mybatis.mapper.entity.Example;
@ -48,10 +72,10 @@ public class ModelDalImpl implements ModelDal {
@Autowired
private DataListsMapper dataListMapper;
@Autowired
private DataListMetaMapper dataListMetaMapper;
@Autowired
private DataListRecordMapper dataListRecordMapper;
@ -60,13 +84,24 @@ public class ModelDalImpl implements ModelDal {
@Autowired
private PreItemMapper preItemMapper;
@Autowired
private PreItemMapping preItemMapping;
@Resource
private ModelMapping modelMapping;
@Resource
private FieldMapping fieldMapping;
@Resource
private RuleMapping ruleMapping;
@Resource
private AbstractionMapping abstractionMapping;
@Resource
private ActivationMapping activationMapping;
@Cacheable(value = "models", key = "#guid")
@Override
public ModelVO getModelByGuid(String guid) {
logger.info("getModelByGuid,{}", guid);
ModelPO po = null;
ModelVO vo = new ModelVO();
Example example = new Example(ModelPO.class);
example.createCriteria().andEqualTo("guid", guid);
List<ModelPO> models = modelMapper.selectByExample(example);
@ -75,19 +110,16 @@ public class ModelDalImpl implements ModelDal {
} else {
po = models.get(0);
}
BeanUtils.copyProperties(po, vo);
return vo;
return modelMapping.sourceToTarget(po);
}
//@Cacheable(value = "models", key = "#modelId")
@Override
public ModelVO getModelById(Long modelId) {
logger.info("getModelById,{}", modelId);
ModelVO vo = new ModelVO();
ModelPO model = modelMapper.selectByPrimaryKey(modelId);
if (model != null) {
BeanUtils.copyProperties(model, vo);
return vo;
return modelMapping.sourceToTarget(model);
}
return null;
}
@ -107,72 +139,56 @@ public class ModelDalImpl implements ModelDal {
@Override
public List<FieldVO> listField(Long modelId) {
logger.info("listField,{}", modelId);
List<FieldVO> fieldList = new ArrayList<>();
Example example = new Example(FieldPO.class);
example.createCriteria().andEqualTo("modelId", modelId);
List<FieldPO> list = fieldMapper.selectByExample(example);
FieldVO vo;
if (list == null || list.size() == 0) {
return null;
if (CollectionUtils.isEmpty(list)) {
return new ArrayList<>();
} else {
for (FieldPO po : list) {
vo = new FieldVO();
BeanUtils.copyProperties(po, vo);
fieldList.add(vo);
}
return fieldMapping.sourceToTarget(list);
}
return fieldList;
}
@Override
public List<ModelVO> listModel(String merchantCode, Integer status) {
logger.info("listAbstraction,merchantCode:{},status:{}",merchantCode, status);
public List<ModelVO> listModel(String merchantCode, Integer status) {
logger.info("listAbstraction,merchantCode:{},status:{}", merchantCode, status);
return listModel(merchantCode, status, null);
}
}
@Override
@Override
public List<ModelVO> listModel(Integer status) {
logger.info("listAbstraction,status:{}", status);
List<ModelVO> modelList = new ArrayList<>();
Example example = new Example(ModelPO.class);
if (status != null) {
example.createCriteria().andEqualTo("status", status);
}
List<ModelPO> list = modelMapper.selectByExample(example);
for (ModelPO po : list) {
modelList.add(POVOUtils.copyFromModelPO(po));
if (CollectionUtils.isEmpty(list)) {
return new ArrayList<>();
}
return modelList;
return modelMapping.sourceToTarget(list);
}
@Override
public List<AbstractionVO> listAbstraction(Long modelId, Integer status) {
logger.info("listAbstraction,{}", modelId);
List<AbstractionVO> absList = new ArrayList<AbstractionVO>();
Example example = new Example(AbstractionPO.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("modelId", modelId);
if (status != null) {
criteria.andEqualTo("status",status);
criteria.andEqualTo("status", status);
}
List<AbstractionPO> list = abstractionMapper.selectByExample(example);
AbstractionVO vo;
if (list == null || list.size() == 0) {
return null;
} else {
for (AbstractionPO po : list) {
vo = new AbstractionVO();
BeanUtils.copyProperties(po, vo);
absList.add(vo);
}
if (CollectionUtils.isEmpty(list)) {
return new ArrayList<>();
}
return absList;
return abstractionMapping.sourceToTarget(list);
}
@Override
public List<ActivationVO> listActivation(Long modelId, Integer status) {
logger.info("listActivation,{}", modelId);
List<ActivationVO> activationList = new ArrayList<ActivationVO>();
Example example = new Example(ActivationPO.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("modelId", modelId);
@ -180,24 +196,16 @@ public class ModelDalImpl implements ModelDal {
criteria.andEqualTo("status", status);
}
List<ActivationPO> list = activationMapper.selectByExample(example);
ActivationVO vo;
if (list == null || list.size() == 0) {
return null;
} else {
for (ActivationPO po : list) {
vo = new ActivationVO();
BeanUtils.copyProperties(po, vo);
activationList.add(vo);
}
if (CollectionUtils.isEmpty(list)) {
return new ArrayList<>();
}
return activationList;
return activationMapping.sourceToTarget(list);
}
@Override
public List<RuleVO> listRules(Long modelId, Long activationId, Integer status) {
logger.info("listRules:{},{},{}", modelId, activationId, status);
List<RuleVO> ruleList = new ArrayList<>();
Example example = new Example(RulePO.class);
Example.Criteria criteria = example.createCriteria();
if (modelId != null) {
@ -209,20 +217,17 @@ public class ModelDalImpl implements ModelDal {
if (status != null) {
criteria.andEqualTo("status", status);
}
RuleVO vo;
List<RulePO> rulePoList = ruleMapper.selectByExample(example);
for (RulePO po : rulePoList) {
vo = new RuleVO();
BeanUtils.copyProperties(po, vo);
ruleList.add(vo);
if (CollectionUtils.isEmpty(rulePoList)) {
return new ArrayList<>();
}
return ruleList;
return ruleMapping.sourceToTarget(rulePoList);
}
@Override
public List<PreItemVO> listPreItem(Long modelId, Integer status) {
logger.info("listRules:{},{}", modelId, status);
List<PreItemVO> itemList = new ArrayList<>();
Example example = new Example(PreItemPO.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("modelId", modelId);
@ -230,73 +235,66 @@ public class ModelDalImpl implements ModelDal {
criteria.andEqualTo("status", status);
}
List<PreItemPO> itemPOList = preItemMapper.selectByExample(example);
PreItemVO vo = null;
for (PreItemPO po : itemPOList) {
vo = new PreItemVO();
vo = POVOUtils.copyFromPreItemPO(po);
itemList.add(vo);
if (CollectionUtils.isEmpty(itemPOList)){
return new ArrayList<>();
}
return itemList;
return preItemMapping.sourceToTarget(itemPOList);
}
@Override
public PageResult<ModelVO> query(ModelQuery query) {
PageHelper.startPage(query.getPageNo(), query.getPageSize());
@Override
public PageResult<ModelVO> query(ModelQuery query) {
PageHelper.startPage(query.getPageNo(), query.getPageSize());
Example example = new Example(ModelPO.class);
Example.Criteria criteria = example.createCriteria();
if (!StringUtils.isEmpty(query.getModelName())) {
criteria.andLike("modelName", BaseUtils.buildLike(query.getModelName()));
}
Example example = new Example(ModelPO.class);
Example.Criteria criteria = example.createCriteria();
if (!StringUtils.isEmpty(query.getModelName())) {
criteria.andLike("modelName", BaseUtils.buildLike(query.getModelName()));
}
if (!StringUtils.isEmpty(query.getLabel())) {
criteria.andLike("label", BaseUtils.buildLike(query.getLabel()));
}
if (query.getStatus() != null) {
criteria.andEqualTo("status", query.getStatus());
}
if (!StringUtils.isEmpty(query.getMerchantCode())) {
criteria.andEqualTo("code", query.getMerchantCode());
}
List<ModelPO> list = modelMapper.selectByExample(example);
Page<ModelPO> page = (Page<ModelPO>) list;
List<ModelVO> listVO = new ArrayList<>();
for (ModelPO modelPO : page.getResult()) {
ModelVO modelVO = new ModelVO();
BeanUtils.copyProperties(modelPO, modelVO);
listVO.add(modelVO);
}
PageResult<ModelVO> pageResult = new PageResult<>(page.getPageNum(), page.getPageSize(),
(int) page.getTotal(), listVO);
return pageResult;
}
if (query.getStatus() != null) {
criteria.andEqualTo("status", query.getStatus());
}
if (!StringUtils.isEmpty(query.getMerchantCode())) {
criteria.andEqualTo("code", query.getMerchantCode());
}
List<ModelPO> list = modelMapper.selectByExample(example);
Page<ModelPO> page = (Page<ModelPO>) list;
List<ModelVO> listVO;
if (CollectionUtils.isEmpty(list)) {
listVO = new ArrayList<>();
} else {
listVO = modelMapping.sourceToTarget(list);
}
return new PageResult<>(page.getPageNum(), page.getPageSize(),
(int) page.getTotal(), listVO);
}
//@CachePut(value = "models", key = "#model.id")
@Override
public int save(ModelVO model) {
ModelPO modelPO = new ModelPO();
BeanUtils.copyProperties(model, modelPO);
Date sysDate = new Date();
int count = 0;
if (model.getId() == null) {
modelPO.setCreateTime(sysDate);
modelPO.setUpdateTime(sysDate);
count = modelMapper.insertSelective(modelPO);
model.setId(modelPO.getId());//返回id
} else {
modelPO.setUpdateTime(sysDate);
count = modelMapper.updateByPrimaryKeySelective(modelPO);
}
return count;
}
public int save(ModelVO model) {
ModelPO modelPO = modelMapping.targetToSource(model);
Date sysDate = new Date();
int count = 0;
if (model.getId() == null) {
modelPO.setCreateTime(sysDate);
modelPO.setUpdateTime(sysDate);
count = modelMapper.insertSelective(modelPO);
model.setId(modelPO.getId());//返回id
} else {
modelPO.setUpdateTime(sysDate);
count = modelMapper.updateByPrimaryKeySelective(modelPO);
}
return count;
}
@Override
public int delete(Long[] id) {
Example example = new Example(ModelPO.class);
example.createCriteria().andIn("id", Arrays.asList(id));
int count = modelMapper.deleteByExample(example);
// 删除关联子表
@Override
public int delete(Long[] id) {
Example example = new Example(ModelPO.class);
example.createCriteria().andIn("id", Arrays.asList(id));
int count = modelMapper.deleteByExample(example);
// 删除关联子表
example = new Example(FieldPO.class);
example.createCriteria().andIn("modelId", Arrays.asList(id));
fieldMapper.deleteByExample(example);
@ -321,150 +319,150 @@ public class ModelDalImpl implements ModelDal {
example.createCriteria().andIn("modelId", Arrays.asList(id));
ruleMapper.deleteByExample(example);
return count;
}
@Override
public int copy(ModelVO model){
Long oldId=model.getId();
model.setId(null);
model.setStatus(StatusType.INIT.getKey());
}
@Override
public int copy(ModelVO model) {
Long oldId = model.getId();
model.setId(null);
model.setStatus(StatusType.INIT.getKey());
model.setGuid(UUID.randomUUID().toString().toUpperCase());
model.setTemplate(false);
int count=this.save(model);
Long newId=model.getId();
Date sysDate = new Date();
//复制field
Example fieldExample = new Example(FieldPO.class);
fieldExample.createCriteria().andEqualTo("modelId", oldId);
int count = this.save(model);
Long newId = model.getId();
Date sysDate = new Date();
//复制field
Example fieldExample = new Example(FieldPO.class);
fieldExample.createCriteria().andEqualTo("modelId", oldId);
List<FieldPO> fieldList = fieldMapper.selectByExample(fieldExample);
for(FieldPO po:fieldList){
po.setModelId(newId);
po.setId(null);
po.setCreateTime(sysDate);
for (FieldPO po : fieldList) {
po.setModelId(newId);
po.setId(null);
po.setCreateTime(sysDate);
po.setUpdateTime(sysDate);
fieldMapper.insertSelective(po);
}
//复制preItem
Example preItemExample = new Example(PreItemPO.class);
preItemExample.createCriteria().andEqualTo("modelId", oldId);
List<PreItemPO> preItemList = preItemMapper.selectByExample(preItemExample);
for(PreItemPO po:preItemList){
po.setModelId(newId);
po.setId(null);
po.setCreateTime(sysDate);
for (PreItemPO po : preItemList) {
po.setModelId(newId);
po.setId(null);
po.setCreateTime(sysDate);
po.setUpdateTime(sysDate);
preItemMapper.insertSelective(po);
}
//复制dataList
Example dataListsExample = new Example(DataListsPO.class);
dataListsExample.createCriteria().andEqualTo("modelId", oldId);
List<DataListsPO> dataListsList=dataListMapper.selectByExample(dataListsExample);
for(DataListsPO po:dataListsList){
Long oldDataListId=po.getId();
po.setModelId(newId);
po.setId(null);
po.setCreateTime(sysDate);
List<DataListsPO> dataListsList = dataListMapper.selectByExample(dataListsExample);
for (DataListsPO po : dataListsList) {
Long oldDataListId = po.getId();
po.setModelId(newId);
po.setId(null);
po.setCreateTime(sysDate);
po.setUpdateTime(sysDate);
dataListMapper.insertSelective(po);
Long newDataListId=po.getId();
Long newDataListId = po.getId();
//复制dataListMeta
Example dataListMetaExample = new Example(DataListMetaPO.class);
dataListMetaExample.createCriteria().andEqualTo("dataListId", oldDataListId);
List<DataListMetaPO> dataListMetaList=dataListMetaMapper.selectByExample(dataListMetaExample);
for(DataListMetaPO metaPO:dataListMetaList){
metaPO.setDataListId(newDataListId);
metaPO.setId(null);
metaPO.setCreateTime(sysDate);
metaPO.setUpdateTime(sysDate);
dataListMetaMapper.insertSelective(metaPO);
List<DataListMetaPO> dataListMetaList = dataListMetaMapper
.selectByExample(dataListMetaExample);
for (DataListMetaPO metaPO : dataListMetaList) {
metaPO.setDataListId(newDataListId);
metaPO.setId(null);
metaPO.setCreateTime(sysDate);
metaPO.setUpdateTime(sysDate);
dataListMetaMapper.insertSelective(metaPO);
}
//复制dataListRecord
Example dataListRecordExample = new Example(DataListRecordPO.class);
dataListRecordExample.createCriteria().andEqualTo("dataListId", oldDataListId);
List<DataListRecordPO> dataListRecordList=dataListRecordMapper.selectByExample(dataListRecordExample);
for(DataListRecordPO recordPO:dataListRecordList){
recordPO.setDataListId(newDataListId);
recordPO.setId(null);
recordPO.setCreateTime(sysDate);
recordPO.setUpdateTime(sysDate);
dataListRecordMapper.insertSelective(recordPO);
List<DataListRecordPO> dataListRecordList = dataListRecordMapper
.selectByExample(dataListRecordExample);
for (DataListRecordPO recordPO : dataListRecordList) {
recordPO.setDataListId(newDataListId);
recordPO.setId(null);
recordPO.setCreateTime(sysDate);
recordPO.setUpdateTime(sysDate);
dataListRecordMapper.insertSelective(recordPO);
}
}
//复制abstraction
Example abstractionExample = new Example(AbstractionPO.class);
abstractionExample.createCriteria().andEqualTo("modelId", oldId);
List<AbstractionPO> abstractionList = abstractionMapper.selectByExample(abstractionExample);
for(AbstractionPO po:abstractionList){
po.setModelId(newId);
po.setId(null);
po.setCreateTime(sysDate);
for (AbstractionPO po : abstractionList) {
po.setModelId(newId);
po.setId(null);
po.setCreateTime(sysDate);
po.setUpdateTime(sysDate);
abstractionMapper.insertSelective(po);
}
//复制activation
Example activationExample = new Example(ActivationPO.class);
activationExample.createCriteria().andEqualTo("modelId", oldId);
List<ActivationPO> activationList = activationMapper.selectByExample(activationExample);
for(ActivationPO po:activationList){
Long oldActivationID=po.getId();
po.setModelId(newId);
po.setId(null);
po.setCreateTime(sysDate);
for (ActivationPO po : activationList) {
Long oldActivationID = po.getId();
po.setModelId(newId);
po.setId(null);
po.setCreateTime(sysDate);
po.setUpdateTime(sysDate);
activationMapper.insertSelective(po);
Long newActivationID=po.getId();
Long newActivationID = po.getId();
//复制rule
Example ruleExample = new Example(RulePO.class);
ruleExample.createCriteria().andEqualTo("activationId", oldActivationID);
List<RulePO> ruleList = ruleMapper.selectByExample(ruleExample);
for(RulePO rulePO:ruleList){
rulePO.setModelId(newId);
rulePO.setActivationId(newActivationID);
rulePO.setId(null);
rulePO.setCreateTime(sysDate);
rulePO.setUpdateTime(sysDate);
ruleMapper.insertSelective(rulePO);
for (RulePO rulePO : ruleList) {
rulePO.setModelId(newId);
rulePO.setActivationId(newActivationID);
rulePO.setId(null);
rulePO.setCreateTime(sysDate);
rulePO.setUpdateTime(sysDate);
ruleMapper.insertSelective(rulePO);
}
}
return count;
}
return count;
}
@Override
public List<ModelVO> listModel(String merchantCode, Integer status,
Boolean isTemplate) {
List<ModelVO> modelList = new ArrayList<>();
Example example = new Example(ModelPO.class);
Example.Criteria criteria = example.createCriteria();
if (!StringUtils.isEmpty(merchantCode)){
if (!StringUtils.isEmpty(merchantCode)) {
criteria.andEqualTo("code", merchantCode);
}
if (status != null) {
criteria.andEqualTo("status",status);
criteria.andEqualTo("status", status);
}
if (isTemplate != null) {
criteria.andEqualTo("template", isTemplate);
}
List<ModelPO> list = modelMapper.selectByExample(example);
for (ModelPO po : list) {
modelList.add(POVOUtils.copyFromModelPO(po));
if (list == null) {
return new ArrayList<>();
}
return modelList;
return modelMapping.sourceToTarget(list);
}
}

View File

@ -5,22 +5,22 @@ import com.github.pagehelper.PageHelper;
import com.pgmmers.radar.dal.bean.PageResult;
import com.pgmmers.radar.dal.bean.PreItemQuery;
import com.pgmmers.radar.dal.model.PreItemDal;
import com.pgmmers.radar.dal.util.POVOUtils;
import com.pgmmers.radar.mapper.PreItemMapper;
import com.pgmmers.radar.mapstruct.PreItemMapping;
import com.pgmmers.radar.model.PreItemPO;
import com.pgmmers.radar.vo.model.PreItemVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;
@Service
public class PreItemDalImpl implements PreItemDal {
@ -29,15 +29,13 @@ public class PreItemDalImpl implements PreItemDal {
@Autowired
private PreItemMapper preItemMapper;
@Resource
private PreItemMapping preItemMapping;
@Override
public PreItemVO get(Long id) {
PreItemPO preItem = preItemMapper.selectByPrimaryKey(id);
if (preItem != null) {
PreItemVO preItemVO = new PreItemVO();
//BeanUtils.copyProperties(preItem, preItemVO);
preItemVO = POVOUtils.copyFromPreItemPO(preItem);
return preItemVO;
return preItemMapping.sourceToTarget(preItem);
}
return null;
}
@ -62,14 +60,12 @@ public class PreItemDalImpl implements PreItemDal {
List<PreItemPO> list = preItemMapper.selectByExample(example);
Page<PreItemPO> page = (Page<PreItemPO>) list;
List<PreItemVO> listVO = new ArrayList<PreItemVO>();
for (PreItemPO preItemPO : page.getResult()) {
PreItemVO preItemVO ;
preItemVO = POVOUtils.copyFromPreItemPO(preItemPO);
listVO.add(preItemVO);
List<PreItemVO> listVO;
if (CollectionUtils.isEmpty(list)){
listVO = new ArrayList<>();
}else {
listVO=preItemMapping.sourceToTarget(list);
}
PageResult<PreItemVO> pageResult = new PageResult<>(page.getPageNum(), page.getPageSize(),
(int) page.getTotal(), listVO);
return pageResult;
@ -78,7 +74,7 @@ public class PreItemDalImpl implements PreItemDal {
@Override
public int save(PreItemVO preItem) {
PreItemPO preItemPO ;
preItemPO = POVOUtils.copyFromPreItemVO(preItem);
preItemPO = preItemMapping.targetToSource(preItem);
Date sysDate = new Date();
int count = 0;
if (preItemPO.getId() == null) {

View File

@ -1,31 +1,31 @@
package com.pgmmers.radar.dal.model.impl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.pgmmers.radar.dal.bean.PageResult;
import com.pgmmers.radar.dal.bean.RuleHistoryQuery;
import com.pgmmers.radar.dal.bean.RuleQuery;
import com.pgmmers.radar.dal.model.RuleDal;
import com.pgmmers.radar.dal.util.POVOUtils;
import com.pgmmers.radar.mapper.RuleHistoryMapper;
import com.pgmmers.radar.mapper.RuleMapper;
import com.pgmmers.radar.mapstruct.RuleHistoryMapping;
import com.pgmmers.radar.mapstruct.RuleMapping;
import com.pgmmers.radar.model.RuleHistoryPO;
import com.pgmmers.radar.model.RulePO;
import com.pgmmers.radar.util.BaseUtils;
import com.pgmmers.radar.vo.model.RuleHistoryVO;
import com.pgmmers.radar.vo.model.RuleVO;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import tk.mybatis.mapper.entity.Example;
@ -36,16 +36,19 @@ public class RuleDalImpl implements RuleDal {
@Autowired
private RuleMapper ruleMapper;
@Autowired
private RuleHistoryMapper ruleHistoryMapper;
@Resource
private RuleHistoryMapping ruleHistoryMapping;
@Resource
private RuleMapping ruleMapping;
@Override
public RuleVO get(Long id) {
RulePO rule = ruleMapper.selectByPrimaryKey(id);
if (rule != null) {
RuleVO ruleVO = POVOUtils.copyFromRulePO(rule);
return ruleVO;
return ruleMapping.sourceToTarget(rule);
}
return null;
}
@ -61,36 +64,32 @@ public class RuleDalImpl implements RuleDal {
rule.setStatus(query.getStatus());
rule.setName(query.getName());
criteria.andEqualTo("activationId",query.getActivationId());
criteria.andEqualTo("activationId", query.getActivationId());
if (!StringUtils.isEmpty(query.getName())) {
criteria.andLike("name", BaseUtils.buildLike(query.getName()));
}
if (query.getStatus() != null) {
criteria.andEqualTo("status", query.getStatus());
criteria.andEqualTo("status", query.getStatus());
}
List<RulePO> list = ruleMapper.selectByExample(example);
Page<RulePO> page = (Page<RulePO>) list;
List<RuleVO> listVO = new ArrayList<RuleVO>();
for (RulePO rulePO : page.getResult()) {
// RuleVO ruleVO = new RuleVO();
// BeanUtils.copyProperties(rulePO, ruleVO);
RuleVO ruleVO = POVOUtils.copyFromRulePO(rulePO);
listVO.add(ruleVO);
List<RuleVO> listVO;
if (CollectionUtils.isEmpty(list)) {
listVO = new ArrayList<>();
} else {
listVO = ruleMapping.sourceToTarget(list);
}
PageResult<RuleVO> pageResult = new PageResult<RuleVO>(page.getPageNum(), page.getPageSize(),
PageResult<RuleVO> pageResult = new PageResult<>(page.getPageNum(), page.getPageSize(),
(int) page.getTotal(), listVO);
return pageResult;
}
@Override
public int save(RuleVO rule) {
RulePO rulePO = POVOUtils.copyFromRuleVO(rule);
RulePO rulePO = ruleMapping.targetToSource(rule);
Date sysDate = new Date();
int count = 0;
if (rule.getId() == null) {
@ -114,9 +113,9 @@ public class RuleDalImpl implements RuleDal {
return count;
}
@Override
public PageResult<RuleHistoryVO> queryHistory(RuleHistoryQuery query) {
PageHelper.startPage(query.getPageNo(), query.getPageSize());
@Override
public PageResult<RuleHistoryVO> queryHistory(RuleHistoryQuery query) {
PageHelper.startPage(query.getPageNo(), query.getPageSize());
Example example = new Example(RuleHistoryPO.class);
Example.Criteria criteria = example.createCriteria();
@ -124,28 +123,27 @@ public class RuleDalImpl implements RuleDal {
List<RuleHistoryPO> list = ruleHistoryMapper.selectByExample(example);
Page<RuleHistoryPO> page = (Page<RuleHistoryPO>) list;
List<RuleHistoryVO> listVO = new ArrayList<RuleHistoryVO>();
for (RuleHistoryPO ruleHistoryPO : page.getResult()) {
RuleHistoryVO ruleHistoryVO = new RuleHistoryVO();
BeanUtils.copyProperties(ruleHistoryPO, ruleHistoryVO);
listVO.add(ruleHistoryVO);
List<RuleHistoryVO> listVO;
if (CollectionUtils.isEmpty(list)) {
listVO = new ArrayList<>();
} else {
listVO = ruleHistoryMapping.sourceToTarget(list);
}
PageResult<RuleHistoryVO> pageResult = new PageResult<RuleHistoryVO>(page.getPageNum(), page.getPageSize(),
PageResult<RuleHistoryVO> pageResult = new PageResult<RuleHistoryVO>(page.getPageNum(),
page.getPageSize(),
(int) page.getTotal(), listVO);
return pageResult;
}
}
@Override
public int saveHistory(RuleHistoryVO ruleHistory) {
RuleHistoryPO ruleHistoryPO = new RuleHistoryPO();
BeanUtils.copyProperties(ruleHistory, ruleHistoryPO);
@Override
public int saveHistory(RuleHistoryVO ruleHistory) {
RuleHistoryPO ruleHistoryPO = ruleHistoryMapping.targetToSource(ruleHistory);
Date sysDate = new Date();
int count = 0;
ruleHistoryPO.setUpdateTime(sysDate);
count = ruleHistoryMapper.insertSelective(ruleHistoryPO);
ruleHistory.setId(ruleHistoryPO.getId());// 返回id
return count;
}
}
}

View File

@ -1,121 +0,0 @@
package com.pgmmers.radar.dal.util;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.util.JSONPObject;
import com.pgmmers.radar.model.*;
import com.pgmmers.radar.vo.data.MobileInfoVO;
import com.pgmmers.radar.vo.model.AbstractionVO;
import com.pgmmers.radar.vo.model.ModelVO;
import com.pgmmers.radar.vo.model.PreItemVO;
import com.pgmmers.radar.vo.model.RuleVO;
import jdk.nashorn.internal.parser.JSONParser;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import java.io.IOException;
public class POVOUtils {
public static ObjectMapper objectMapper = new ObjectMapper();
public static MobileInfoVO copyFromMobileInfPO(MobileInfoPO po) {
MobileInfoVO vo = new MobileInfoVO();
BeanUtils.copyProperties(po, vo);
return vo;
}
public static ModelVO copyFromModelPO(ModelPO po) {
ModelVO vo = new ModelVO();
BeanUtils.copyProperties(po, vo);
return vo;
}
public static MobileInfoPO copyFromMobileInfoVO(MobileInfoVO vo) {
MobileInfoPO po = new MobileInfoPO();
BeanUtils.copyProperties(vo, po);
return po;
}
public static AbstractionVO copyFromAbstractPO(AbstractionPO po) {
AbstractionVO vo = new AbstractionVO();
BeanUtils.copyProperties(po, vo);
JsonNode json = null;
try {
json = objectMapper.readTree(po.getRuleDefinition());
} catch (Exception e) {
e.printStackTrace();
}
vo.setRuleDefinition(json);
return vo;
}
public static AbstractionPO copyFromAbstractVO(AbstractionVO vo) {
AbstractionPO po = new AbstractionPO();
BeanUtils.copyProperties(vo, po);
try {
String str = objectMapper.writeValueAsString(vo.getRuleDefinition());
po.setRuleDefinition(str);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return po;
}
public static RuleVO copyFromRulePO(RulePO po) {
RuleVO vo = new RuleVO();
BeanUtils.copyProperties(po, vo);
JsonNode json = null;
try {
json = objectMapper.readTree(po.getRuleDefinition());
} catch (IOException e) {
e.printStackTrace();
}
vo.setRuleDefinition(json);
return vo;
}
public static RulePO copyFromRuleVO(RuleVO vo) {
RulePO po = new RulePO();
BeanUtils.copyProperties(vo, po);
try {
String str = objectMapper.writeValueAsString(vo.getRuleDefinition());
po.setRuleDefinition(str);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return po;
}
public static PreItemPO copyFromPreItemVO(PreItemVO vo) {
PreItemPO po = new PreItemPO();
BeanUtils.copyProperties(vo, po);
try {
if (vo.getConfigJson() != null) {
String str = objectMapper.writeValueAsString(vo.getConfigJson());
po.setConfigJson(str);
}
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return po;
}
public static PreItemVO copyFromPreItemPO(PreItemPO po) {
PreItemVO vo = new PreItemVO();
BeanUtils.copyProperties(po, vo);
JsonNode json = null;
try {
if (!StringUtils.isEmpty(po.getConfigJson())) {
json = objectMapper.readTree(po.getConfigJson());
}
} catch (IOException e) {
e.printStackTrace();
}
vo.setConfigJson(json);
return vo;
}
}

View File

@ -0,0 +1,20 @@
package com.pgmmers.radar.mapstruct;
import com.pgmmers.radar.model.AbstractionPO;
import com.pgmmers.radar.vo.model.AbstractionVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
@Mapper(componentModel = "spring")
public interface AbstractionMapping extends BaseMapping<AbstractionPO, AbstractionVO> {
@Mapping(target = "dataCollectionNames", source = "")
@Mapping(target = "ruleDefinition", expression = "java(com.pgmmers.radar.util.JsonUtils.getJsonNode(var1.getRuleDefinition()))")
@Override
AbstractionVO sourceToTarget(AbstractionPO var1);
@Mapping(target = "ruleDefinition", expression = "java(com.pgmmers.radar.util.JsonUtils.jsonNodeToString(var1.getRuleDefinition()))")
@Override
AbstractionPO targetToSource(AbstractionVO var1);
}

View File

@ -0,0 +1,10 @@
package com.pgmmers.radar.mapstruct;
import com.pgmmers.radar.model.ActivationPO;
import com.pgmmers.radar.vo.model.ActivationVO;
import org.mapstruct.Mapper;
@Mapper(componentModel = "spring")
public interface ActivationMapping extends BaseMapping<ActivationPO, ActivationVO> {
}

View File

@ -0,0 +1,44 @@
package com.pgmmers.radar.mapstruct;
import java.util.List;
import java.util.stream.Stream;
import org.mapstruct.InheritConfiguration;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.MapperConfig;
@MapperConfig
public interface BaseMapping<SOURCE, TARGET> {
/**
* 映射同名属性
*/
TARGET sourceToTarget(SOURCE var1);
/**
* 反向映射同名属性
*/
@InheritInverseConfiguration(name = "sourceToTarget")
SOURCE targetToSource(TARGET var1);
/**
* 映射同名属性集合形式
*/
@InheritConfiguration(name = "sourceToTarget")
List<TARGET> sourceToTarget(List<SOURCE> var1);
/**
* 反向映射同名属性集合形式
*/
@InheritConfiguration(name = "targetToSource")
List<SOURCE> targetToSource(List<TARGET> var1);
/**
* 映射同名属性集合流形式
*/
List<TARGET> sourceToTarget(Stream<SOURCE> stream);
/**
* 反向映射同名属性集合流形式
*/
List<SOURCE> targetToSource(Stream<TARGET> stream);
}

View File

@ -0,0 +1,10 @@
package com.pgmmers.radar.mapstruct;
import com.pgmmers.radar.model.DataListMetaPO;
import com.pgmmers.radar.vo.model.DataListMetaVO;
import org.mapstruct.Mapper;
@Mapper(componentModel = "spring")
public interface DataListMetaMapping extends BaseMapping<DataListMetaPO, DataListMetaVO> {
}

View File

@ -0,0 +1,10 @@
package com.pgmmers.radar.mapstruct;
import com.pgmmers.radar.model.DataListRecordPO;
import com.pgmmers.radar.vo.model.DataListRecordVO;
import org.mapstruct.Mapper;
@Mapper(componentModel = "spring")
public interface DataListRecordMapping extends BaseMapping<DataListRecordPO, DataListRecordVO> {
}

View File

@ -0,0 +1,10 @@
package com.pgmmers.radar.mapstruct;
import com.pgmmers.radar.model.DataListsPO;
import com.pgmmers.radar.vo.model.DataListsVO;
import org.mapstruct.Mapper;
@Mapper(componentModel = "spring")
public interface DataListsMapping extends BaseMapping<DataListsPO, DataListsVO> {
}

View File

@ -0,0 +1,11 @@
package com.pgmmers.radar.mapstruct;
import com.pgmmers.radar.model.FieldPO;
import com.pgmmers.radar.vo.model.FieldVO;
import org.mapstruct.Mapper;
@Mapper(componentModel = "spring")
public interface FieldMapping extends BaseMapping<FieldPO, FieldVO> {
}

View File

@ -0,0 +1,10 @@
package com.pgmmers.radar.mapstruct;
import com.pgmmers.radar.model.MobileInfoPO;
import com.pgmmers.radar.vo.data.MobileInfoVO;
import org.mapstruct.Mapper;
@Mapper(componentModel = "spring")
public interface MobileInfoMapping extends BaseMapping<MobileInfoPO, MobileInfoVO> {
}

View File

@ -0,0 +1,10 @@
package com.pgmmers.radar.mapstruct;
import com.pgmmers.radar.model.ModelPO;
import com.pgmmers.radar.vo.model.ModelVO;
import org.mapstruct.Mapper;
@Mapper(componentModel = "spring")
public interface ModelMapping extends BaseMapping<ModelPO, ModelVO> {
}

View File

@ -0,0 +1,20 @@
package com.pgmmers.radar.mapstruct;
import com.pgmmers.radar.model.PreItemPO;
import com.pgmmers.radar.vo.model.PreItemVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
@Mapper(componentModel = "spring")
public interface PreItemMapping extends BaseMapping<PreItemPO, PreItemVO> {
@Mapping(target = "configJson", expression = "java(com.pgmmers.radar.util.JsonUtils.getJsonNode(var1.getConfigJson()))")
@Override
PreItemVO sourceToTarget(PreItemPO var1);
@Mapping(target = "configJson", expression = "java(com.pgmmers.radar.util.JsonUtils.jsonNodeToString(var1.getConfigJson()))")
@Override
PreItemPO targetToSource(PreItemVO var1);
}

View File

@ -0,0 +1,10 @@
package com.pgmmers.radar.mapstruct;
import com.pgmmers.radar.model.RuleHistoryPO;
import com.pgmmers.radar.vo.model.RuleHistoryVO;
import org.mapstruct.Mapper;
@Mapper(componentModel = "spring")
public interface RuleHistoryMapping extends BaseMapping<RuleHistoryPO, RuleHistoryVO> {
}

View File

@ -0,0 +1,19 @@
package com.pgmmers.radar.mapstruct;
import com.pgmmers.radar.model.RulePO;
import com.pgmmers.radar.vo.model.RuleVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
@Mapper(componentModel = "spring")
public interface RuleMapping extends BaseMapping<RulePO, RuleVO> {
@Mapping(target = "ruleDefinition", expression = "java(com.pgmmers.radar.util.JsonUtils.getJsonNode(var1.getRuleDefinition()))")
@Override
RuleVO sourceToTarget(RulePO var1);
@Mapping(target = "ruleDefinition", expression = "java(com.pgmmers.radar.util.JsonUtils.jsonNodeToString(var1.getRuleDefinition()))")
@Override
RulePO targetToSource(RuleVO var1);
}

View File

@ -0,0 +1,10 @@
package com.pgmmers.radar.mapstruct;
import com.pgmmers.radar.model.UserPO;
import com.pgmmers.radar.vo.admin.UserVO;
import org.mapstruct.Mapper;
@Mapper(componentModel = "spring")
public interface UserMapping extends BaseMapping<UserPO, UserVO> {
}

View File

@ -0,0 +1,256 @@
package com.pgmmers.radar.dal;
import com.pgmmers.radar.EngineApplication;
import com.pgmmers.radar.mapper.AbstractionMapper;
import com.pgmmers.radar.mapper.ActivationMapper;
import com.pgmmers.radar.mapper.DataListMetaMapper;
import com.pgmmers.radar.mapper.DataListRecordMapper;
import com.pgmmers.radar.mapper.DataListsMapper;
import com.pgmmers.radar.mapper.FieldMapper;
import com.pgmmers.radar.mapper.MobileInfoMapper;
import com.pgmmers.radar.mapper.ModelMapper;
import com.pgmmers.radar.mapper.PreItemMapper;
import com.pgmmers.radar.mapper.RuleHistoryMapper;
import com.pgmmers.radar.mapper.RuleMapper;
import com.pgmmers.radar.mapper.UserMapper;
import com.pgmmers.radar.mapstruct.AbstractionMapping;
import com.pgmmers.radar.mapstruct.ActivationMapping;
import com.pgmmers.radar.mapstruct.DataListMetaMapping;
import com.pgmmers.radar.mapstruct.DataListRecordMapping;
import com.pgmmers.radar.mapstruct.DataListsMapping;
import com.pgmmers.radar.mapstruct.FieldMapping;
import com.pgmmers.radar.mapstruct.MobileInfoMapping;
import com.pgmmers.radar.mapstruct.ModelMapping;
import com.pgmmers.radar.mapstruct.PreItemMapping;
import com.pgmmers.radar.mapstruct.RuleHistoryMapping;
import com.pgmmers.radar.mapstruct.RuleMapping;
import com.pgmmers.radar.mapstruct.UserMapping;
import com.pgmmers.radar.model.AbstractionPO;
import com.pgmmers.radar.model.ActivationPO;
import com.pgmmers.radar.model.DataListMetaPO;
import com.pgmmers.radar.model.DataListRecordPO;
import com.pgmmers.radar.model.DataListsPO;
import com.pgmmers.radar.model.FieldPO;
import com.pgmmers.radar.model.MobileInfoPO;
import com.pgmmers.radar.model.ModelPO;
import com.pgmmers.radar.model.PreItemPO;
import com.pgmmers.radar.model.RuleHistoryPO;
import com.pgmmers.radar.model.RulePO;
import com.pgmmers.radar.model.UserPO;
import com.pgmmers.radar.vo.admin.UserVO;
import com.pgmmers.radar.vo.data.MobileInfoVO;
import com.pgmmers.radar.vo.model.AbstractionVO;
import com.pgmmers.radar.vo.model.ActivationVO;
import com.pgmmers.radar.vo.model.DataListMetaVO;
import com.pgmmers.radar.vo.model.DataListRecordVO;
import com.pgmmers.radar.vo.model.DataListsVO;
import com.pgmmers.radar.vo.model.FieldVO;
import com.pgmmers.radar.vo.model.ModelVO;
import com.pgmmers.radar.vo.model.PreItemVO;
import com.pgmmers.radar.vo.model.RuleHistoryVO;
import com.pgmmers.radar.vo.model.RuleVO;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/**
* author: wangcheng Date: 2020/3/17 Time: 下午5:19 Description:
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = EngineApplication.class)
public class MapStructTest {
@Autowired
private ModelMapper modelMapper;
@Autowired
private ModelMapping modelMapping;
@Resource
private AbstractionMapping abstractionMapping;
@Autowired
private AbstractionMapper abstractionMapper;
@Resource
private ActivationMapping activationMapping;
@Autowired
private ActivationMapper activationMapper;
@Resource
private FieldMapping fieldMapping;
@Autowired
private FieldMapper fieldMapper;
@Resource
private RuleMapping ruleMapping;
@Autowired
private RuleMapper ruleMapper;
@Test
public void modelTest() {
List<ModelPO> pos = modelMapper.selectAll();
Assert.assertNotNull(pos);
List<ModelVO> vos = modelMapping.sourceToTarget(pos);
Assert.assertNotNull(vos);
List<ModelPO> pos1 = modelMapping.targetToSource(vos);
Assert.assertNotNull(pos1);
}
@Test
public void abstractionTest() {
List<AbstractionPO> pos = abstractionMapper.selectAll();
Assert.assertNotNull(pos);
List<AbstractionVO> vos = abstractionMapping.sourceToTarget(pos);
Assert.assertNotNull(vos);
List<AbstractionPO> pos1 = abstractionMapping.targetToSource(vos);
Assert.assertNotNull(pos1);
}
@Test
public void activationTest() {
List<ActivationPO> pos = activationMapper.selectAll();
Assert.assertNotNull(pos);
List<ActivationVO> vos = activationMapping.sourceToTarget(pos);
Assert.assertNotNull(vos);
List<ActivationPO> pos1 = activationMapping.targetToSource(vos);
Assert.assertNotNull(pos1);
}
@Test
public void fieldTest() {
List<FieldPO> pos = fieldMapper.selectAll();
Assert.assertNotNull(pos);
List<FieldVO> vos = fieldMapping.sourceToTarget(pos);
Assert.assertNotNull(vos);
List<FieldPO> pos1 = fieldMapping.targetToSource(vos);
Assert.assertNotNull(pos1);
}
@Test
public void ruleTest() {
List<RulePO> pos = ruleMapper.selectAll();
Assert.assertNotNull(pos);
List<RuleVO> vos = ruleMapping.sourceToTarget(pos);
Assert.assertNotNull(vos);
List<RulePO> pos1 = ruleMapping.targetToSource(vos);
Assert.assertNotNull(pos1);
}
@Resource
DataListMetaMapping dataListMetaMapping;
@Autowired
DataListMetaMapper dataListMetaMapper;
@Test
public void datalistMetaTest() {
List<DataListMetaPO> pos = dataListMetaMapper.selectAll();
Assert.assertNotNull(pos);
List<DataListMetaVO> vos = dataListMetaMapping.sourceToTarget(pos);
Assert.assertNotNull(vos);
List<DataListMetaPO> pos1 = dataListMetaMapping.targetToSource(vos);
Assert.assertNotNull(pos1);
}
@Resource
private DataListRecordMapping dataListRecordMapping;
@Autowired
private DataListRecordMapper dataListRecordMapper;
@Test
public void dataListRecordTest() {
List<DataListRecordPO> pos = dataListRecordMapper.selectAll();
Assert.assertNotNull(pos);
List<DataListRecordVO> vos = dataListRecordMapping.sourceToTarget(pos);
Assert.assertNotNull(vos);
List<DataListRecordPO> pos1 = dataListRecordMapping.targetToSource(vos);
Assert.assertNotNull(pos1);
;
}
@Resource
private DataListsMapping dataListsMapping;
@Autowired
private DataListsMapper dataListsMapper;
@Test
public void dataListsTest() {
List<DataListsPO> pos = dataListsMapper.selectAll();
Assert.assertNotNull(pos);
List<DataListsVO> vos = dataListsMapping.sourceToTarget(pos);
Assert.assertNotNull(vos);
List<DataListsPO> pos1 = dataListsMapping.targetToSource(vos);
Assert.assertNotNull(pos1);
}
@Resource
private MobileInfoMapping mobileInfoMapping;
@Autowired
private MobileInfoMapper mobileInfoMapper;
@Test
public void mobileInfoTest() {
MobileInfoPO po = new MobileInfoPO();
po.setCity("hangzhou");
po.setCreateTime(new Date());
po.setId(1L);
po.setMobile("1234");
po.setProvince("zj");
po.setRegionCode("11");
po.setSupplier("1");
po.setUpdateTime(new Date());
MobileInfoVO vos = mobileInfoMapping.sourceToTarget(po);
Assert.assertNotNull(vos);
MobileInfoPO pos1 = mobileInfoMapping.targetToSource(vos);
Assert.assertNotNull(pos1);
}
@Resource
private PreItemMapping preItemMapping;
@Autowired
private PreItemMapper preItemMapper;
@Test
public void preItemTest() {
List<PreItemPO> pos = preItemMapper.selectAll();
Assert.assertNotNull(pos);
List<PreItemVO> vos = preItemMapping.sourceToTarget(pos);
Assert.assertNotNull(vos);
List<PreItemPO> pos1 = preItemMapping.targetToSource(vos);
Assert.assertNotNull(pos1);
}
@Resource
private RuleHistoryMapping ruleHistoryMapping;
@Autowired
private RuleHistoryMapper ruleHistoryMapper;
@Test
public void ruleHistoryTest() {
List<RuleHistoryPO> pos = ruleHistoryMapper.selectAll();
Assert.assertNotNull(pos);
List<RuleHistoryVO> vos = ruleHistoryMapping.sourceToTarget(pos);
Assert.assertNotNull(vos);
List<RuleHistoryPO> pos1 = ruleHistoryMapping.targetToSource(vos);
Assert.assertNotNull(pos1);
}
@Resource
private UserMapping userMapping;
@Autowired
private UserMapper userMapper;
@Test
public void userTest() {
List<UserPO> pos = userMapper.selectAll();
Assert.assertNotNull(pos);
List<UserVO> vos = userMapping.sourceToTarget(pos);
Assert.assertNotNull(vos);
List<UserPO> pos1 = userMapping.targetToSource(vos);
Assert.assertNotNull(pos1);
}
}

View File

@ -4,23 +4,25 @@ package com.pgmmers.radar.service.impl.admin;
import com.pgmmers.radar.dal.bean.PageResult;
import com.pgmmers.radar.dal.bean.UserQuery;
import com.pgmmers.radar.dal.model.UserDal;
import com.pgmmers.radar.mapstruct.UserMapping;
import com.pgmmers.radar.model.UserPO;
import com.pgmmers.radar.service.admin.UserService;
import com.pgmmers.radar.service.common.CommonResult;
import com.pgmmers.radar.vo.admin.UserVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserDal userDal;
@Resource
private UserMapping userMapping;
@Override
public CommonResult query(UserQuery query) {
@ -36,18 +38,13 @@ public class UserServiceImpl implements UserService {
@Override
public Optional<List<UserVO>> list(String userName, String passwd) {
List<UserPO> list = userDal.list(userName, passwd);
List<UserVO> users= list.stream().map(userPO -> {
UserVO vo = new UserVO();
BeanUtils.copyProperties(userPO, vo);
return vo;
}).collect(Collectors.toList());
List<UserVO> users = list.stream().map(userPO -> userMapping.sourceToTarget(userPO)).collect(Collectors.toList());
return Optional.ofNullable(users);
}
@Override
public Integer insert(UserVO userVO) {
UserPO userPO = new UserPO();
BeanUtils.copyProperties(userVO, userPO);
UserPO userPO = userMapping.targetToSource(userVO);
Integer integer = userDal.insert(userPO);
return integer;
}

View File

@ -69,7 +69,7 @@ public class ModelServiceImpl implements ModelService, SubscribeHandle {
@Override
public List<ModelVO> listModel(Integer status) {
if (modelList == null) {
modelList = modelDal.listModel(null);
modelList = modelDal.listModel(status);
}
return modelList;
}