Commit 5ba53a6c authored by hanbing's avatar hanbing

[add] 策略管理-场景库接口

parent ade33711
package net.wanji.opt.controller.strategy;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.opt.dto.IntegerIdsDTO;
import net.wanji.opt.dto.strategy.AddOrUpdateSceneDTO;
import net.wanji.opt.dto.strategy.QuerySceneDTO;
import net.wanji.opt.service.strategy.impl.SceneServiceImpl;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.ws.rs.core.MediaType;
import java.util.List;
/**
* 策略管理-场景库
*
* @author Kent HAN
* @date 2023/2/27 9:25
*/
@Api(value = "SceneController", description = "策略管理-场景库")
@RequestMapping("/scene")
@RestController
public class SceneController {
private final SceneServiceImpl sceneService;
public SceneController(SceneServiceImpl sceneService) {
this.sceneService = sceneService;
}
@ApiOperation(value = "新增/修改场景", notes = "新增/修改场景", response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@PostMapping(value = "/addOrUpdateScene",
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = JsonViewObject.class),
})
public JsonViewObject addOrUpdateScene(@RequestBody AddOrUpdateSceneDTO addOrUpdateSceneDTO) {
sceneService.addOrUpdateScene(addOrUpdateSceneDTO);
JsonViewObject jsonViewObject = JsonViewObject.newInstance();
return jsonViewObject.success();
}
@ApiOperation(value = "删除场景", notes = "删除场景", response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@PostMapping(value = "/deleteScene",
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = JsonViewObject.class),
})
public JsonViewObject deleteScene(@RequestBody IntegerIdsDTO integerIdsDTO) {
sceneService.deleteScene(integerIdsDTO);
JsonViewObject jsonViewObject = JsonViewObject.newInstance();
return jsonViewObject.success();
}
@ApiOperation(value = "查询场景", notes = "查询场景", response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@PostMapping(value = "/queryScene",
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = AddOrUpdateSceneDTO.class),
})
public JsonViewObject queryScene(@RequestBody QuerySceneDTO querySceneDTO) {
List<AddOrUpdateSceneDTO> sceneList = sceneService.queryScene(querySceneDTO);
JsonViewObject jsonViewObject = JsonViewObject.newInstance();
return jsonViewObject.success(sceneList);
}
}
package net.wanji.opt.dao.mapper.strategy; package net.wanji.opt.dao.mapper.strategy;
import net.wanji.opt.dto.strategy.QueryIdeaDTO;
import net.wanji.opt.po.strategy.IdeaPO; import net.wanji.opt.po.strategy.IdeaPO;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
...@@ -19,5 +20,7 @@ public interface IdeaMapper { ...@@ -19,5 +20,7 @@ public interface IdeaMapper {
void deleteByIds(List<Integer> ids); void deleteByIds(List<Integer> ids);
List<IdeaPO> selectByIdeaName(String ideaName); List<IdeaPO> selectByIdeaNameAndIdeaTarget(QueryIdeaDTO queryIdeaDTO);
IdeaPO selectById(Integer ideaId);
} }
package net.wanji.opt.dao.mapper.strategy;
import net.wanji.opt.po.strategy.ScenePO;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @author Kent HAN
* @date 2023/2/27 9:33
*/
@Repository
public interface SceneMapper {
void insertOne(ScenePO scenePO);
void deleteByIds(List<Integer> ids);
void updateOne(ScenePO scenePO);
List<ScenePO> selectByNameAndTarget(String sceneName, Integer sceneTarget);
}
package net.wanji.opt.dao.mapper.strategy;
import net.wanji.opt.po.strategy.SceneStrategyIdeaPO;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @author Kent HAN
* @date 2023/2/27 9:33
*/
@Repository
public interface SceneStrategyIdeaMapper {
void insertOne(SceneStrategyIdeaPO sceneStrategyIdeaPO);
void deleteBySceneIds(List<Integer> ids);
List<SceneStrategyIdeaPO> selectBySceneIdAndStrategyId(Integer sceneId, Integer strategyId);
void deleteByIdeaIds(List<Integer> ids);
void deleteByStrategyIds(List<Integer> ids);
}
package net.wanji.opt.dao.mapper.strategy;
import net.wanji.opt.po.strategy.SceneStrategyPO;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @author Kent HAN
* @date 2023/2/27 9:33
*/
@Repository
public interface SceneStrategyMapper {
void insertOne(SceneStrategyPO sceneStrategyPO);
void deleteBySceneIds(List<Integer> ids);
List<SceneStrategyPO> selectBySceneId(Integer sceneId);
void deleteByStrategyIds(List<Integer> ids);
}
package net.wanji.opt.dao.mapper.strategy; package net.wanji.opt.dao.mapper.strategy;
import net.wanji.opt.dto.strategy.QueryStrategyDTO;
import net.wanji.opt.po.strategy.StrategyPO; import net.wanji.opt.po.strategy.StrategyPO;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
...@@ -19,5 +20,7 @@ public interface StrategyMapper { ...@@ -19,5 +20,7 @@ public interface StrategyMapper {
void deleteByIds(List<Integer> ids); void deleteByIds(List<Integer> ids);
List<StrategyPO> selectByStrategyName(String strategyName); List<StrategyPO> selectByStrategyNameAndTarget(QueryStrategyDTO queryStrategyDTO);
StrategyPO selectById(Integer strategyId);
} }
package net.wanji.opt.dto.strategy;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @author Kent HAN
* @date 2023/2/27 11:31
*/
@NoArgsConstructor
@Data
@ApiModel(value = "AddOrUpdateSceneDTO", description = "策略管理-场景库-新增/修改场景")
public class AddOrUpdateSceneDTO {
@ApiModelProperty(value = "场景ID(不传ID为新增,传ID为修改)",notes = "")
private Integer id;
@ApiModelProperty(value = "编号",required = true, notes = "")
private String sceneCode;
@ApiModelProperty(value = "场景名称",required = true, notes = "")
private String sceneName;
@ApiModelProperty(value = "应用对象 1路口;2干线;3区域",required = true,notes = "")
private Integer secneTarget;
@ApiModelProperty(value = "应用策略",required = true,notes = "")
private List<StrategyListElement> strategyList;
@NoArgsConstructor
@Data
public static class StrategyListElement {
@ApiModelProperty(value = "策略ID",required = true,notes = "")
private Integer strategyId;
@ApiModelProperty(value = "策略名称",required = true,notes = "")
private String strategyName;
@ApiModelProperty(value = "优先级",required = true,notes = "")
private Integer priority;
@ApiModelProperty(value = "优化方法",required = true,notes = "")
private List<IdeaListElement> ideaList;
}
@NoArgsConstructor
@Data
public static class IdeaListElement {
@ApiModelProperty(value = "方法ID",required = true,notes = "")
private Integer ideaId;
@ApiModelProperty(value = "方法名称",required = true,notes = "")
private String ideaName;
}
}
...@@ -13,4 +13,6 @@ import lombok.Data; ...@@ -13,4 +13,6 @@ import lombok.Data;
public class QueryIdeaDTO { public class QueryIdeaDTO {
@ApiModelProperty(value = "方法名称",notes = "") @ApiModelProperty(value = "方法名称",notes = "")
private String ideaName ; private String ideaName ;
@ApiModelProperty(value = "应用对象 1路口;2干线;3区域",notes = "")
private Integer ideaTarget;
} }
package net.wanji.opt.dto.strategy;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author Kent HAN
* @date 2023/2/27 9:39
*/
@Data
@ApiModel(value = "QuerySceneDTO", description = "策略管理-场景库-查询场景")
public class QuerySceneDTO {
@ApiModelProperty(value = "场景名称",notes = "")
private String sceneName ;
@ApiModelProperty(value = "应用对象 1路口;2干线;3区域",required = true,notes = "")
private Integer sceneTarget;
}
...@@ -13,4 +13,6 @@ import lombok.Data; ...@@ -13,4 +13,6 @@ import lombok.Data;
public class QueryStrategyDTO { public class QueryStrategyDTO {
@ApiModelProperty(value = "策略名称",notes = "") @ApiModelProperty(value = "策略名称",notes = "")
private String strategyName ; private String strategyName ;
@ApiModelProperty(value = "应用对象 1路口;2干线;3区域",notes = "")
private Integer strategyTarget;
} }
package net.wanji.opt.po.strategy;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @author hanbing
* @date 2023/1/10 16:36
*/
@Data
public class ScenePO {
@ApiModelProperty(value = "场景ID",notes = "")
private Integer id ;
@ApiModelProperty(value = "编号",notes = "")
private String sceneCode ;
@ApiModelProperty(value = "场景名称",notes = "")
private String sceneName ;
/** 应用对象 1路口;2干线;3区域 */
@ApiModelProperty(value = "应用对象 1路口;2干线;3区域",notes = "")
private Integer sceneTarget;
/** 创建时间 */
@ApiModelProperty(value = "创建时间",notes = "")
private Date gmtCreate ;
/** 修改时间 */
@ApiModelProperty(value = "修改时间",notes = "")
private Date gmtModified ;
}
package net.wanji.opt.po.strategy;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @author hanbing
* @date 2023/1/10 16:36
*/
@Data
public class SceneStrategyIdeaPO {
@ApiModelProperty(name = "ID",notes = "")
private Integer id ;
@ApiModelProperty(name = "场景ID",notes = "")
private Integer sceneId ;
@ApiModelProperty(name = "策略ID",notes = "")
private Integer strategyId ;
@ApiModelProperty(name = "方法ID",notes = "")
private Integer ideaId ;
@ApiModelProperty(name = "创建时间",notes = "")
private Date gmtCreate ;
@ApiModelProperty(name = "修改时间",notes = "")
private Date gmtModified ;
}
package net.wanji.opt.po.strategy;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @author hanbing
* @date 2023/1/10 16:36
*/
@Data
public class SceneStrategyPO {
/** ID */
@ApiModelProperty(name = "ID",notes = "")
private Integer id ;
/** 场景ID */
@ApiModelProperty(name = "场景ID",notes = "")
private Integer sceneId ;
/** 策略ID */
@ApiModelProperty(name = "策略ID",notes = "")
private Integer strategyId ;
@ApiModelProperty(name = "优先级",notes = "")
private Integer sceneStrategyPriority ;
/** 创建时间 */
@ApiModelProperty(name = "创建时间",notes = "")
private Date gmtCreate ;
/** 修改时间 */
@ApiModelProperty(name = "修改时间",notes = "")
private Date gmtModified ;
}
package net.wanji.opt.service.strategy;
import net.wanji.opt.dto.IntegerIdsDTO;
import net.wanji.opt.dto.strategy.AddOrUpdateSceneDTO;
import net.wanji.opt.dto.strategy.QuerySceneDTO;
import java.util.List;
/**
* @author hanbing
* @date 2023/1/12 15:12
* @desc 策略管理-场景库接口服务
*/
public interface SceneService {
void addOrUpdateScene(AddOrUpdateSceneDTO addOrUpdateSceneDTO);
void deleteScene(IntegerIdsDTO integerIdsDTO);
List<AddOrUpdateSceneDTO> queryScene(QuerySceneDTO querySceneDTO);
}
...@@ -2,6 +2,7 @@ package net.wanji.opt.service.strategy.impl; ...@@ -2,6 +2,7 @@ package net.wanji.opt.service.strategy.impl;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import net.wanji.opt.dao.mapper.strategy.IdeaMapper; import net.wanji.opt.dao.mapper.strategy.IdeaMapper;
import net.wanji.opt.dao.mapper.strategy.SceneStrategyIdeaMapper;
import net.wanji.opt.dto.IntegerIdsDTO; import net.wanji.opt.dto.IntegerIdsDTO;
import net.wanji.opt.dto.strategy.AddOrUpdateIdeaDTO; import net.wanji.opt.dto.strategy.AddOrUpdateIdeaDTO;
import net.wanji.opt.dto.strategy.QueryIdeaDTO; import net.wanji.opt.dto.strategy.QueryIdeaDTO;
...@@ -19,9 +20,11 @@ import java.util.List; ...@@ -19,9 +20,11 @@ import java.util.List;
@Service @Service
public class IdeaServiceImpl implements IdeaService { public class IdeaServiceImpl implements IdeaService {
private final IdeaMapper ideaMapper; private final IdeaMapper ideaMapper;
private final SceneStrategyIdeaMapper sceneStrategyIdeaMapper;
public IdeaServiceImpl(IdeaMapper ideaMapper) { public IdeaServiceImpl(IdeaMapper ideaMapper, SceneStrategyIdeaMapper sceneStrategyIdeaMapper) {
this.ideaMapper = ideaMapper; this.ideaMapper = ideaMapper;
this.sceneStrategyIdeaMapper = sceneStrategyIdeaMapper;
} }
@Override @Override
...@@ -52,13 +55,13 @@ public class IdeaServiceImpl implements IdeaService { ...@@ -52,13 +55,13 @@ public class IdeaServiceImpl implements IdeaService {
public void deleteIdea(IntegerIdsDTO integerIdsDTO) { public void deleteIdea(IntegerIdsDTO integerIdsDTO) {
List<Integer> ids = integerIdsDTO.getIds(); List<Integer> ids = integerIdsDTO.getIds();
ideaMapper.deleteByIds(ids); ideaMapper.deleteByIds(ids);
// todo 删除关系表数据 // 删除关系表数据
sceneStrategyIdeaMapper.deleteByIdeaIds(ids);
} }
@Override @Override
public List<IdeaPO> queryIdea(QueryIdeaDTO queryIdeaDTO) { public List<IdeaPO> queryIdea(QueryIdeaDTO queryIdeaDTO) {
String ideaName = queryIdeaDTO.getIdeaName(); List<IdeaPO> ideaPOList = ideaMapper.selectByIdeaNameAndIdeaTarget(queryIdeaDTO);
List<IdeaPO> ideaPOList = ideaMapper.selectByIdeaName(ideaName);
return ideaPOList; return ideaPOList;
} }
} }
package net.wanji.opt.service.strategy.impl;
import cn.hutool.core.util.ObjectUtil;
import net.wanji.opt.dao.mapper.strategy.IdeaMapper;
import net.wanji.opt.dao.mapper.strategy.SceneMapper;
import net.wanji.opt.dao.mapper.strategy.SceneStrategyIdeaMapper;
import net.wanji.opt.dao.mapper.strategy.SceneStrategyMapper;
import net.wanji.opt.dao.mapper.strategy.StrategyMapper;
import net.wanji.opt.dto.IntegerIdsDTO;
import net.wanji.opt.dto.strategy.AddOrUpdateSceneDTO;
import net.wanji.opt.dto.strategy.QuerySceneDTO;
import net.wanji.opt.po.strategy.IdeaPO;
import net.wanji.opt.po.strategy.ScenePO;
import net.wanji.opt.po.strategy.SceneStrategyIdeaPO;
import net.wanji.opt.po.strategy.SceneStrategyPO;
import net.wanji.opt.po.strategy.StrategyPO;
import net.wanji.opt.service.strategy.SceneService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
/**
* @author Kent HAN
* @date 2023/2/27 11:42
*/
@Service
public class SceneServiceImpl implements SceneService {
private final SceneMapper sceneMapper;
private final SceneStrategyMapper sceneStrategyMapper;
private final SceneStrategyIdeaMapper sceneStrategyIdeaMapper;
private final StrategyMapper strategyMapper;
private final IdeaMapper ideaMapper;
public SceneServiceImpl(SceneMapper sceneMapper, SceneStrategyMapper sceneStrategyMapper,
SceneStrategyIdeaMapper sceneStrategyIdeaMapper, StrategyMapper strategyMapper, IdeaMapper ideaMapper) {
this.sceneMapper = sceneMapper;
this.sceneStrategyMapper = sceneStrategyMapper;
this.sceneStrategyIdeaMapper = sceneStrategyIdeaMapper;
this.strategyMapper = strategyMapper;
this.ideaMapper = ideaMapper;
}
@Override
@Transactional
public void addOrUpdateScene(AddOrUpdateSceneDTO addOrUpdateSceneDTO) {
Integer id = addOrUpdateSceneDTO.getId();
if (id == 0 || ObjectUtil.isEmpty(id)) {
// 不传ID为新增
// 插入场景表获取场景ID
ScenePO scenePO = new ScenePO();
fillData(addOrUpdateSceneDTO, scenePO);
sceneMapper.insertOne(scenePO);
// 插入关系表
Integer sceneId = scenePO.getId();
updateRelationship(addOrUpdateSceneDTO, sceneId);
} else {
// 传ID为修改
// 修改场景表
ScenePO scenePO = new ScenePO();
scenePO.setId(id);
fillData(addOrUpdateSceneDTO, scenePO);
sceneMapper.updateOne(scenePO);
// 删除关系表并重新插入
List<Integer> sceneIdList = new ArrayList<>();
sceneIdList.add(id);
sceneStrategyMapper.deleteBySceneIds(sceneIdList);
sceneStrategyIdeaMapper.deleteBySceneIds(sceneIdList);
updateRelationship(addOrUpdateSceneDTO, id);
}
}
private void updateRelationship(AddOrUpdateSceneDTO addOrUpdateSceneDTO, Integer id) {
List<AddOrUpdateSceneDTO.StrategyListElement> strategyList = addOrUpdateSceneDTO.getStrategyList();
for (AddOrUpdateSceneDTO.StrategyListElement strategy : strategyList) {
SceneStrategyPO sceneStrategyPO = new SceneStrategyPO();
sceneStrategyPO.setSceneId(id);
Integer strategyId = strategy.getStrategyId();
sceneStrategyPO.setStrategyId(strategyId);
Integer priority = strategy.getPriority();
sceneStrategyPO.setSceneStrategyPriority(priority);
sceneStrategyMapper.insertOne(sceneStrategyPO);
// 插入场景-策略-方法关系表
List<AddOrUpdateSceneDTO.IdeaListElement> ideaList = strategy.getIdeaList();
for (AddOrUpdateSceneDTO.IdeaListElement idea : ideaList) {
SceneStrategyIdeaPO sceneStrategyIdeaPO = new SceneStrategyIdeaPO();
sceneStrategyIdeaPO.setSceneId(id);
sceneStrategyIdeaPO.setStrategyId(strategyId);
Integer ideaId = idea.getIdeaId();
sceneStrategyIdeaPO.setIdeaId(ideaId);
sceneStrategyIdeaMapper.insertOne(sceneStrategyIdeaPO);
}
}
}
private static void fillData(AddOrUpdateSceneDTO addOrUpdateSceneDTO, ScenePO scenePO) {
String sceneCode = addOrUpdateSceneDTO.getSceneCode();
scenePO.setSceneCode(sceneCode);
String sceneName = addOrUpdateSceneDTO.getSceneName();
scenePO.setSceneName(sceneName);
Integer secneTarget = addOrUpdateSceneDTO.getSecneTarget();
scenePO.setSceneTarget(secneTarget);
}
@Override
@Transactional
public void deleteScene(IntegerIdsDTO integerIdsDTO) {
List<Integer> ids = integerIdsDTO.getIds();
sceneMapper.deleteByIds(ids);
sceneStrategyMapper.deleteBySceneIds(ids);
sceneStrategyIdeaMapper.deleteBySceneIds(ids);
}
@Override
public List<AddOrUpdateSceneDTO> queryScene(QuerySceneDTO querySceneDTO) {
List<AddOrUpdateSceneDTO> res = new ArrayList<>();
String sceneName = querySceneDTO.getSceneName();
Integer sceneTarget = querySceneDTO.getSceneTarget();
List<ScenePO> scenePOList = sceneMapper.selectByNameAndTarget(sceneName, sceneTarget);
for (ScenePO scenePO : scenePOList) {
AddOrUpdateSceneDTO addOrUpdateSceneDTO = new AddOrUpdateSceneDTO();
Integer id = scenePO.getId();
addOrUpdateSceneDTO.setId(id);
String sceneCode = scenePO.getSceneCode();
addOrUpdateSceneDTO.setSceneCode(sceneCode);
String sceneNameFromDb = scenePO.getSceneName();
addOrUpdateSceneDTO.setSceneName(sceneNameFromDb);
Integer sceneTargetFromDb = scenePO.getSceneTarget();
addOrUpdateSceneDTO.setSecneTarget(sceneTargetFromDb);
// 构造策略列表
List<AddOrUpdateSceneDTO.StrategyListElement> strategyList = buildStrategyList(id);
addOrUpdateSceneDTO.setStrategyList(strategyList);
res.add(addOrUpdateSceneDTO);
}
return res;
}
private List<AddOrUpdateSceneDTO.StrategyListElement> buildStrategyList(Integer sceneId) {
List<AddOrUpdateSceneDTO.StrategyListElement> strategyList = new ArrayList<>();
List<SceneStrategyPO> sceneStrategyPOList = sceneStrategyMapper.selectBySceneId(sceneId);
for (SceneStrategyPO sceneStrategyPO : sceneStrategyPOList) {
AddOrUpdateSceneDTO.StrategyListElement strategyListElement = new AddOrUpdateSceneDTO.StrategyListElement();
Integer strategyId = sceneStrategyPO.getStrategyId();
strategyListElement.setStrategyId(strategyId);
StrategyPO strategyPO = strategyMapper.selectById(strategyId);
strategyListElement.setStrategyName(strategyPO.getStrategyName());
strategyListElement.setPriority(sceneStrategyPO.getSceneStrategyPriority());
// 构造方法列表
List<AddOrUpdateSceneDTO.IdeaListElement> ideaList = buildIdeaList(sceneId, strategyId);
strategyListElement.setIdeaList(ideaList);
strategyList.add(strategyListElement);
}
return strategyList;
}
private List<AddOrUpdateSceneDTO.IdeaListElement> buildIdeaList(Integer sceneId, Integer strategyId) {
List<AddOrUpdateSceneDTO.IdeaListElement> ideaList = new ArrayList<>();
List<SceneStrategyIdeaPO> sceneStrategyIdeaPOList = sceneStrategyIdeaMapper
.selectBySceneIdAndStrategyId(sceneId, strategyId);
for (SceneStrategyIdeaPO sceneStrategyIdeaPO : sceneStrategyIdeaPOList) {
AddOrUpdateSceneDTO.IdeaListElement ideaListElement = new AddOrUpdateSceneDTO.IdeaListElement();
Integer ideaId = sceneStrategyIdeaPO.getIdeaId();
IdeaPO ideaPO = ideaMapper.selectById(ideaId);
ideaListElement.setIdeaId(ideaId);
ideaListElement.setIdeaName(ideaPO.getIdeaName());
ideaList.add(ideaListElement);
}
return ideaList;
}
}
package net.wanji.opt.service.strategy.impl; package net.wanji.opt.service.strategy.impl;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import net.wanji.opt.dao.mapper.strategy.SceneStrategyIdeaMapper;
import net.wanji.opt.dao.mapper.strategy.SceneStrategyMapper;
import net.wanji.opt.dao.mapper.strategy.StrategyMapper; import net.wanji.opt.dao.mapper.strategy.StrategyMapper;
import net.wanji.opt.dto.IntegerIdsDTO; import net.wanji.opt.dto.IntegerIdsDTO;
import net.wanji.opt.dto.strategy.AddOrUpdateStrategyDTO; import net.wanji.opt.dto.strategy.AddOrUpdateStrategyDTO;
...@@ -19,9 +21,13 @@ import java.util.List; ...@@ -19,9 +21,13 @@ import java.util.List;
@Service @Service
public class StrategyServiceImpl implements StrategyService { public class StrategyServiceImpl implements StrategyService {
private final StrategyMapper strategyMapper; private final StrategyMapper strategyMapper;
private final SceneStrategyMapper sceneStrategyMapper;
private final SceneStrategyIdeaMapper sceneStrategyIdeaMapper;
public StrategyServiceImpl(StrategyMapper strategyMapper) { public StrategyServiceImpl(StrategyMapper strategyMapper, SceneStrategyMapper sceneStrategyMapper, SceneStrategyIdeaMapper sceneStrategyIdeaMapper) {
this.strategyMapper = strategyMapper; this.strategyMapper = strategyMapper;
this.sceneStrategyMapper = sceneStrategyMapper;
this.sceneStrategyIdeaMapper = sceneStrategyIdeaMapper;
} }
@Override @Override
...@@ -52,13 +58,14 @@ public class StrategyServiceImpl implements StrategyService { ...@@ -52,13 +58,14 @@ public class StrategyServiceImpl implements StrategyService {
public void deleteStrategy(IntegerIdsDTO integerIdsDTO) { public void deleteStrategy(IntegerIdsDTO integerIdsDTO) {
List<Integer> ids = integerIdsDTO.getIds(); List<Integer> ids = integerIdsDTO.getIds();
strategyMapper.deleteByIds(ids); strategyMapper.deleteByIds(ids);
// todo 删除关系表数据 // 删除关系表数据
sceneStrategyMapper.deleteByStrategyIds(ids);
sceneStrategyIdeaMapper.deleteByStrategyIds(ids);
} }
@Override @Override
public List<StrategyPO> queryStrategy(QueryStrategyDTO queryStrategyDTO) { public List<StrategyPO> queryStrategy(QueryStrategyDTO queryStrategyDTO) {
String strategyName = queryStrategyDTO.getStrategyName(); List<StrategyPO> strategyPOList = strategyMapper.selectByStrategyNameAndTarget(queryStrategyDTO);
List<StrategyPO> strategyPOList = strategyMapper.selectByStrategyName(strategyName);
return strategyPOList; return strategyPOList;
} }
} }
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
</foreach> </foreach>
</delete> </delete>
<select id="selectByIdeaName" resultType="net.wanji.opt.po.strategy.IdeaPO"> <select id="selectByIdeaNameAndIdeaTarget" resultType="net.wanji.opt.po.strategy.IdeaPO">
select select
id,idea_code,idea_name,idea_target,idea_detail,gmt_create,gmt_modified id,idea_code,idea_name,idea_target,idea_detail,gmt_create,gmt_modified
from t_strategy_idea from t_strategy_idea
...@@ -46,7 +46,17 @@ ...@@ -46,7 +46,17 @@
<if test="ideaName != null and ideaName != ''"> <if test="ideaName != null and ideaName != ''">
AND idea_name LIKE CONCAT('%',#{ideaName},'%') AND idea_name LIKE CONCAT('%',#{ideaName},'%')
</if> </if>
<if test="ideaTarget != null">
AND idea_target = #{ideaTarget}
</if>
</where> </where>
</select> </select>
<select id="selectById" resultType="net.wanji.opt.po.strategy.IdeaPO">
select
id,idea_code,idea_name,idea_target,idea_detail,gmt_create,gmt_modified
from t_strategy_idea
where id = #{ideaId}
</select>
</mapper> </mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="net.wanji.opt.dao.mapper.strategy.SceneMapper">
<insert id="insertOne" keyProperty="id" useGeneratedKeys="true">
insert into t_strategy_scene(scene_code,scene_name,scene_target)
values (#{sceneCode},#{sceneName},#{sceneTarget})
</insert>
<update id="updateOne">
update t_strategy_scene
<set>
<if test="sceneCode != null and sceneCode != ''">
scene_code = #{sceneCode},
</if>
<if test="sceneName != null and sceneName != ''">
scene_name = #{sceneName},
</if>
<if test="sceneTarget != null and sceneTarget != ''">
scene_target = #{sceneTarget},
</if>
</set>
where id = #{id}
</update>
<delete id="deleteByIds">
DELETE FROM t_strategy_scene
WHERE id in
<foreach collection="ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</delete>
<select id="selectByNameAndTarget" resultType="net.wanji.opt.po.strategy.ScenePO">
select
id,scene_code,scene_name,scene_target,gmt_create,gmt_modified
from t_strategy_scene
<where>
<if test="sceneName != null and sceneName != ''">
AND scene_name LIKE CONCAT('%',#{sceneName},'%')
</if>
<if test="sceneTarget != null">
AND scene_target = #{sceneTarget}
</if>
</where>
</select>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="net.wanji.opt.dao.mapper.strategy.SceneStrategyIdeaMapper">
<insert id="insertOne" keyProperty="id" useGeneratedKeys="true">
insert into t_strategy_scene_strategy_idea(scene_id,strategy_id,idea_id)
values (#{sceneId},#{strategyId},#{ideaId})
</insert>
<delete id="deleteBySceneIds">
DELETE FROM t_strategy_scene_strategy_idea
where scene_id in
<foreach collection="ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</delete>
<delete id="deleteByIdeaIds">
DELETE FROM t_strategy_scene_strategy_idea
where idea_id in
<foreach collection="ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</delete>
<delete id="deleteByStrategyIds">
DELETE FROM t_strategy_scene_strategy_idea
where strategy_id in
<foreach collection="ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</delete>
<select id="selectBySceneIdAndStrategyId" resultType="net.wanji.opt.po.strategy.SceneStrategyIdeaPO">
select
id,scene_id,strategy_id,idea_id,gmt_create,gmt_modified
from t_strategy_scene_strategy_idea
where scene_id = #{sceneId} and strategy_id = #{strategyId}
</select>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="net.wanji.opt.dao.mapper.strategy.SceneStrategyMapper">
<insert id="insertOne" keyProperty="id" useGeneratedKeys="true">
insert into t_strategy_scene_strategy(scene_id,strategy_id,scene_strategy_priority)
values (#{sceneId},#{strategyId},#{sceneStrategyPriority})
</insert>
<delete id="deleteBySceneIds">
DELETE FROM t_strategy_scene_strategy
where scene_id in
<foreach collection="ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</delete>
<delete id="deleteByStrategyIds">
DELETE FROM t_strategy_scene_strategy
where strategy_id in
<foreach collection="ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</delete>
<select id="selectBySceneId" resultType="net.wanji.opt.po.strategy.SceneStrategyPO">
select
id,scene_id,strategy_id,scene_strategy_priority,gmt_create,gmt_modified
from t_strategy_scene_strategy
where scene_id = #{sceneId}
</select>
</mapper>
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
</foreach> </foreach>
</delete> </delete>
<select id="selectByStrategyName" resultType="net.wanji.opt.po.strategy.StrategyPO"> <select id="selectByStrategyNameAndTarget" resultType="net.wanji.opt.po.strategy.StrategyPO">
select select
id,strategy_code,strategy_name,strategy_target,strategy_detail,gmt_create,gmt_modified id,strategy_code,strategy_name,strategy_target,strategy_detail,gmt_create,gmt_modified
from t_strategy_strategy from t_strategy_strategy
...@@ -47,6 +47,18 @@ ...@@ -47,6 +47,18 @@
AND strategy_name LIKE CONCAT('%',#{strategyName},'%') AND strategy_name LIKE CONCAT('%',#{strategyName},'%')
</if> </if>
</where> </where>
<where>
<if test="strategyTarget != null">
AND strategyTarget = #{strategyTarget}
</if>
</where>
</select>
<select id="selectById" resultType="net.wanji.opt.po.strategy.StrategyPO">
select
id,strategy_code,strategy_name,strategy_target,strategy_detail,gmt_create,gmt_modified
from t_strategy_strategy
where id = #{strategyId}
</select> </select>
</mapper> </mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment