package org.jeecg.modules.base.controller;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import lombok.extern.slf4j.Slf4j;
|
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.constant.CommonConstant;
|
import org.jeecg.common.util.oConvertUtils;
|
import org.jeecg.modules.base.entity.EncodeRule;
|
import org.jeecg.modules.base.entity.EncodeRuleDetail;
|
import org.jeecg.modules.base.entity.EncodeRuleTableFieldRelate;
|
import org.jeecg.modules.base.service.IEncodeRuleDetailService;
|
import org.jeecg.modules.base.service.IEncodeRuleService;
|
import org.jeecg.modules.base.service.IEncodeRuleTableFieldRelateService;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.annotation.Resource;
|
import java.util.List;
|
|
/**
|
* @Title: Controller
|
* @Description: 编码规则表 前端控制器
|
* @Author: cuijian
|
* @Date: 2022-11-03
|
* @Version: V1.0
|
*/
|
@RestController
|
@RequestMapping("/base/codeRule")
|
@Slf4j
|
public class EncodeRuleController {
|
|
@Resource
|
private IEncodeRuleService encodeRuleService;
|
@Resource
|
private IEncodeRuleDetailService encodeRuleDetailService;
|
@Resource
|
private IEncodeRuleTableFieldRelateService encodeRuleTableFieldRelateService;
|
/**
|
* 查询数据 根据菜单id查询编码规则信息
|
* @author cj
|
* @param permissionId
|
* @return
|
*/
|
@GetMapping(value = "/getCodeRuleByPermissionId")
|
public Result<List<EncodeRule>> getCodeRuleByPermissionId(@RequestParam String permissionId, String enterpriseId){
|
Result<List<EncodeRule>> result = new Result<>();
|
LambdaQueryWrapper<EncodeRule> queryWrapper = new LambdaQueryWrapper<>();
|
queryWrapper.eq(EncodeRule::getPermissionId,permissionId);
|
queryWrapper.eq(EncodeRule::getEnterpriseId,enterpriseId);
|
List<EncodeRule> list = encodeRuleService.list(queryWrapper);
|
result.setResult(list);
|
return result;
|
}
|
/**
|
* 增加数据 添加和修改编码规则信息
|
* @author cj
|
* @param encodeRule
|
* @return
|
*/
|
@PostMapping(value = "/addEncodeRule")
|
public Result<EncodeRule> addEncodeRule(@RequestBody EncodeRule encodeRule){
|
Result<EncodeRule> result = new Result<>();
|
try{
|
encodeRuleService.saveOrUpdate(encodeRule);
|
EncodeRuleTableFieldRelate encodeRuleTableFieldRelate = new EncodeRuleTableFieldRelate();
|
encodeRuleTableFieldRelate.setEncodeRuleId(encodeRule.getId());
|
encodeRuleTableFieldRelate.setFieldName(encodeRule.getFieldName());
|
encodeRuleTableFieldRelate.setTableName(encodeRule.getTableName());
|
encodeRuleTableFieldRelateService.save(encodeRuleTableFieldRelate);
|
result.success("操作成功");
|
}catch (Exception e){
|
result.error500("操作失败");
|
}
|
return result;
|
}
|
|
/**
|
* 启用停用编码规则信息
|
* @author cj
|
* @param json
|
* @return
|
*/
|
@PostMapping(value = "/changeStatus")
|
public Result<EncodeRule> changeStatus(@RequestBody JSONObject json){
|
Result<EncodeRule> result = new Result<>();
|
String ids = json.getString("ids");
|
String flag = json.getString("flag");
|
if(oConvertUtils.isEmpty(ids)) {
|
result.error500("未选中编码规则!");
|
}else {
|
String[] ls = ids.split(",");
|
for (String id : ls) {
|
EncodeRule encodeRule = encodeRuleService.lambdaQuery().eq(EncodeRule::getId,id).eq(EncodeRule::getDelFlag, CommonConstant.STATUS_0).one();
|
encodeRule.setStatus(flag);
|
encodeRuleService.updateById(encodeRule);
|
}
|
result.success("变更成功!");
|
}
|
return result;
|
}
|
/**
|
* 删除数据 删除选中的编码规则信息
|
* @author cj
|
* @param ids
|
* @return
|
*/
|
@DeleteMapping(value = "/deleteEncodeRule")
|
public Result<EncodeRule> deleteEncodeRule(@RequestParam String ids){
|
Result<EncodeRule> result = new Result<>();
|
if(oConvertUtils.isEmpty(ids)) {
|
result.error500("未选中编码规则!");
|
}else {
|
String[] ls = ids.split(",");
|
for (String id : ls) {
|
//删除规则详情信息
|
LambdaQueryWrapper<EncodeRuleDetail> queryWrapper = new LambdaQueryWrapper<>();
|
queryWrapper.eq(EncodeRuleDetail::getCodeRuleId ,id);
|
List<EncodeRuleDetail> list = encodeRuleDetailService.list(queryWrapper);
|
for(EncodeRuleDetail l : list){
|
encodeRuleDetailService.removeById(l.getId());
|
}
|
if(encodeRuleService.removeById(id)){
|
result.success("删除成功!");
|
}else {
|
result.success("删除失败!");
|
}
|
|
}
|
}
|
return result;
|
}
|
|
}
|