Commit 3cca5819 authored by luzhuang's avatar luzhuang

发布积分页接口完毕

parent 6abc7642
...@@ -34,7 +34,7 @@ import java.util.List; ...@@ -34,7 +34,7 @@ import java.util.List;
/** /**
* Created by on 2019-11-13 13:28:39. * Created by on 2019-11-13 13:28:39.
*/ */
@Api(tags = "发布积分") @Api(tags = "15 发布积分")
@RestController @RestController
@RequestMapping("breleasevalue") @RequestMapping("breleasevalue")
@Slf4j @Slf4j
...@@ -43,7 +43,7 @@ public class BReleaseValueController extends PaginationController<BReleaseValue> ...@@ -43,7 +43,7 @@ public class BReleaseValueController extends PaginationController<BReleaseValue>
@Autowired @Autowired
private BReleaseValueService bReleaseValueServiceImpl; private BReleaseValueService bReleaseValueServiceImpl;
@ApiOperation(value = "分页查询", notes = "根据条件分页查询", response = BBanner.class) @ApiOperation(value = "1501 分页查询", notes = "根据条件分页查询", response = BBanner.class)
@GetMapping(value = "/queryByPagination") @GetMapping(value = "/queryByPagination")
public Result queryByPagination(CurUser curUser) { public Result queryByPagination(CurUser curUser) {
bReleaseValueServiceImpl.queryByPagination(getPaginationUtility(), curUser.getCorpId()); bReleaseValueServiceImpl.queryByPagination(getPaginationUtility(), curUser.getCorpId());
...@@ -54,9 +54,9 @@ public class BReleaseValueController extends PaginationController<BReleaseValue> ...@@ -54,9 +54,9 @@ public class BReleaseValueController extends PaginationController<BReleaseValue>
gridModel); gridModel);
} }
@ApiOperation(value="添加", notes="添加") @ApiOperation(value="1502 添加、编辑", notes="添加编辑接口(businessId为空是添加)")
@PostMapping(value = "/add") @PostMapping(value = "/add")
public Result add(CurUser user, @Valid BReleaseValueDto bReleaseValueDto, BindingResult bindingResult) { public Result add(CurUser curUser, @Valid BReleaseValueDto bReleaseValueDto, BindingResult bindingResult) {
PersistModel data = bReleaseValueServiceImpl.save(bReleaseValueDto); PersistModel data = bReleaseValueServiceImpl.save(bReleaseValueDto);
return Result.builder(data, return Result.builder(data,
MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_SUCCESS,
...@@ -64,7 +64,7 @@ public class BReleaseValueController extends PaginationController<BReleaseValue> ...@@ -64,7 +64,7 @@ public class BReleaseValueController extends PaginationController<BReleaseValue>
bReleaseValueDto); bReleaseValueDto);
} }
@ApiOperation(value="删除", notes="删除") @ApiOperation(value="1503 删除", notes="删除")
@ApiImplicitParam(name = "businessId", value = "主键id", required = true, dataType = "varchar") @ApiImplicitParam(name = "businessId", value = "主键id", required = true, dataType = "varchar")
@PostMapping(value = "/delete") @PostMapping(value = "/delete")
public Result delete(CurUser curUser, String businessId ) { public Result delete(CurUser curUser, String businessId ) {
......
...@@ -34,8 +34,10 @@ public interface BReleaseValueRepository extends BaseMapper<BReleaseValue> { ...@@ -34,8 +34,10 @@ public interface BReleaseValueRepository extends BaseMapper<BReleaseValue> {
@Update("update b_release_value set del_flag= 1 where business_id = #{releaseId} and corp_id = #{corpId}") @Update("update b_release_value set del_flag= 1 where business_id = #{releaseId} and corp_id = #{corpId}")
int remove(@Param("releaseId") String releaseId,@Param("corpId") String corpId); int remove(@Param("releaseId") String releaseId,@Param("corpId") String corpId);
@Delete("delete from b_release_value_son where user_id = #{userId}") @Delete("<script><foreach collection=\"userId\" item=\"item\" separator=\";\">" +
int deleteSonForUserId(@Param("userId") String userId); " delete from b_release_value_son where user_id = #{item}" +
"</foreach></script>")
int deleteSonForUserId(@Param("userId") String[] userId);
@Delete("delete from b_release_value_son where release_id = #{releaseId}") @Delete("delete from b_release_value_son where release_id = #{releaseId}")
int deleteSonForReleaseId(@Param("releaseId") String releaseId); int deleteSonForReleaseId(@Param("releaseId") String releaseId);
......
...@@ -34,37 +34,26 @@ public class BReleaseValueServiceImpl implements BReleaseValueService { ...@@ -34,37 +34,26 @@ public class BReleaseValueServiceImpl implements BReleaseValueService {
@Autowired @Autowired
private BReleaseValueRepository bReleaseValueRepository; private BReleaseValueRepository bReleaseValueRepository;
@Override @Override
public PersistModel save(BReleaseValueDto bReleaseValueDto) { public PersistModel save(BReleaseValueDto bReleaseValueDto) {
if(bReleaseValueDto.getBusinessId() != null){ if(bReleaseValueDto.getBusinessId() != null){
// 编辑 // 编辑
BReleaseValue bReleaseValue = new BReleaseValue(); BReleaseValue bReleaseValue = new BReleaseValue();
BeanUtils.copyProperties(bReleaseValueDto, bReleaseValue); BeanUtils.copyProperties(bReleaseValueDto, bReleaseValue);
UserUtil.setCurrentMergeOperation(bReleaseValue); UserUtil.setCurrentMergeOperation(bReleaseValue);
int line = bReleaseValueRepository.updateByPrimaryKeySelective(bReleaseValue);
// 删除子表中的相关记录
bReleaseValueRepository.deleteSonForReleaseId(bReleaseValueDto.getBusinessId());
this.splitUser(bReleaseValueDto.getUserIds(),bReleaseValueDto.getBusinessId());
return new PersistModel(line);
} }
//新增 //新增
BReleaseValue bReleaseValue = new BReleaseValue(); BReleaseValue bReleaseValue = new BReleaseValue();
BeanUtils.copyProperties(bReleaseValueDto, bReleaseValue); BeanUtils.copyProperties(bReleaseValueDto, bReleaseValue);
UserUtil.setCurrentPersistOperation(bReleaseValue); UserUtil.setCurrentPersistOperation(bReleaseValue);
String [] ids = bReleaseValueDto.getUserIds().split(","); this.splitUser(bReleaseValueDto.getUserIds(),bReleaseValue.getBusinessId());
List<BReleaseValueSon> list = new ArrayList<>();
if(ids.length > 0){
for (String id : ids){
BReleaseValueSon bReleaseValueSon = new BReleaseValueSon();
bReleaseValueSon.setBusinessId(IdGen.uuid());
bReleaseValueSon.setReleaseId(bReleaseValue.getBusinessId());
bReleaseValueSon.setUserId(id);
list.add(bReleaseValueSon);
}
bReleaseValueRepository.insertIntoSon(list);
}
int line = bReleaseValueRepository.insert(bReleaseValue); int line = bReleaseValueRepository.insert(bReleaseValue);
return new PersistModel(line); return new PersistModel(line);
} }
...@@ -83,4 +72,28 @@ public class BReleaseValueServiceImpl implements BReleaseValueService { ...@@ -83,4 +72,28 @@ public class BReleaseValueServiceImpl implements BReleaseValueService {
bReleaseValueRepository.deleteSonForReleaseId(businessId); bReleaseValueRepository.deleteSonForReleaseId(businessId);
return new PersistModel(line); return new PersistModel(line);
} }
/**
* 去掉子表中已有用户信息,插入新的数据
* @param userIds
* @param businessId
*/
public void splitUser(String userIds , String businessId){
String [] ids = userIds.split(",");
// 删除子表中与当前选中用户相关的信息
bReleaseValueRepository.deleteSonForUserId(ids);
//将关联信息插入子表
List<BReleaseValueSon> list = new ArrayList<>();
if(ids.length > 0){
for (String id : ids){
BReleaseValueSon bReleaseValueSon = new BReleaseValueSon();
bReleaseValueSon.setBusinessId(IdGen.uuid());
bReleaseValueSon.setReleaseId(businessId);
bReleaseValueSon.setUserId(id);
list.add(bReleaseValueSon);
}
bReleaseValueRepository.insertIntoSon(list);
}
}
} }
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