喻忠伟 4 months ago
parent 8fd3ae7e52
commit 4d5aea7bce
  1. 90
      jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/expert/controller/ExpertController.java
  2. 6
      jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/expert/service/IExpertService.java
  3. 62
      jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/expert/service/impl/ExpertServiceImpl.java

@ -242,13 +242,33 @@ public class ExpertController extends JeecgController<Expert, IExpertService> {
CompExp compExp = new CompExp();
QueryWrapper<CompExp> queryWrapper1 = QueryGenerator.initQueryWrapper(compExp, req.getParameterMap());
queryWrapper1.eq("expid",model.getId());
List<CompExp> list1 = compExpService.list(queryWrapper1);
if(list1.size()>0) {
CompExp compExpModel=list1.get(0);
model.setCompid(compExpModel.getCompid());
model.setStat(compExpModel.getStat());
model.setCompName(compExpModel.getCompName());
String Compid = "";
String CompName = "";
String Stat = "";
// 使用 StringBuilder 来构建字符串,比直接使用字符串连接更高效
StringBuilder sbCompid = new StringBuilder();
StringBuilder sbCompName = new StringBuilder();
StringBuilder sbStat = new StringBuilder();
for(CompExp item: list1) {
if (sbCompid.length() > 0) {
sbCompid.append(","); // 只在不是第一个元素时添加逗号
sbCompName.append(",");
sbStat.append(",");
}
sbCompid.append(item.getCompid());
sbCompName.append(item.getCompName());
sbStat.append(item.getStat());
}
// 将 StringBuilder 转换为 String
Compid = sbCompid.toString();
CompName = sbCompName.toString();
Stat = sbStat.toString();
// 现在 Compid, CompName 和 Stat 包含了逗号分隔的值
model.setCompName(CompName);
model.setCompid(Compid);
model.setStat(Stat);
return Result.OK(model);
}
@ -413,65 +433,13 @@ public class ExpertController extends JeecgController<Expert, IExpertService> {
public Result<SysUser> editcompExp(@RequestBody JSONObject jsonObject,HttpServletRequest req) {
Result<SysUser> result = new Result<SysUser>();
try {
SysUser sysUser = sysUserService.getById(jsonObject.getString("id"));
baseCommonService.addLog("编辑用户,username: " +sysUser.getUsername() ,CommonConstant.LOG_TYPE_2, 2);
String user_id=jsonObject.getString("id");
SysUser sysUser = sysUserService.getById(user_id);
baseCommonService.addLog("编辑专家比赛,username: " +sysUser.getUsername() ,CommonConstant.LOG_TYPE_2, 2);
if(sysUser==null) {
result.error500("未找到对应实体");
}else {
SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class);
user.setUpdateTime(new Date());
//String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), sysUser.getSalt());
user.setPassword(sysUser.getPassword());
String roles = "1731948288626339841";
String departs = jsonObject.getString("selecteddeparts");
String expSc = jsonObject.getString("expSc");
String expResume = jsonObject.getString("expResume");
String expTitle = jsonObject.getString("expTitle");
String compid = jsonObject.getString("compid");
String compName = jsonObject.getString("compName");
String stat = jsonObject.getString("stat");
String expXw = jsonObject.getString("expXw");//学位
String expZc = jsonObject.getString("expZc");//职称
String expYjfx = jsonObject.getString("expYjfx");//研究方向
String expCsgz = jsonObject.getString("expCsgz");//从事工作
if(oConvertUtils.isEmpty(departs)){
//vue3.0前端只传递了departIds
departs=user.getDepartIds();
}
//用户表字段org_code不能在这里设置他的值
user.setOrgCode(null);
// 修改用户走一个service 保证事务
//获取租户ids
String relTenantIds = jsonObject.getString("relTenantIds");
sysUserService.editUser(user, roles, departs, relTenantIds);
Expert expert = new Expert();
QueryWrapper<Expert> queryWrapper = QueryGenerator.initQueryWrapper(expert, req.getParameterMap());
queryWrapper.eq("user_id",user.getId());
List<Expert> listex = expertService.list(queryWrapper);
expert = listex.get(0);
expert.setUserId(user.getId());
expert.setExpImg(user.getAvatar());
expert.setExpSc(expSc);
expert.setExpResume(expResume);
expert.setExpTitle(expTitle);
expert.setName(user.getRealname());
expert.setExpXw(expXw);//学位
expert.setExpZc(expZc);//职称
expert.setExpYjfx(expYjfx);//研究方向
expert.setExpCsgz(expCsgz);//从事工作
expertService.updateById(expert);
CompExp compExp = new CompExp();
QueryWrapper<CompExp> queryWrapper1 = QueryGenerator.initQueryWrapper(compExp, req.getParameterMap());
queryWrapper1.eq("expid",expert.getId());
List<CompExp> listce = compExpService.list(queryWrapper1);
compExp = listce.get(0);
compExp.setCompid(compid);
compExp.setCompName(compName);
compExp.setExpid(expert.getId());
compExp.setStat(stat);
compExpService.updateById(compExp);
expertService.updateCompExpert(jsonObject);
result.success("修改成功!");
}
} catch (Exception e) {

@ -1,5 +1,6 @@
package org.jeecg.modules.demo.expert.service;
import com.alibaba.fastjson.JSONObject;
import org.jeecg.modules.demo.expert.entity.Expert;
import com.baomidou.mybatisplus.extension.service.IService;
@ -11,4 +12,9 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/
public interface IExpertService extends IService<Expert> {
/**
* 修改专家项目之间的关系
* @param jsonObject
*/
void updateCompExpert(JSONObject jsonObject);
}

@ -1,12 +1,24 @@
package org.jeecg.modules.demo.expert.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.demo.compexp.entity.CompExp;
import org.jeecg.modules.demo.compexp.mapper.CompExpMapper;
import org.jeecg.modules.demo.expert.entity.Expert;
import org.jeecg.modules.demo.expert.mapper.ExpertMapper;
import org.jeecg.modules.demo.expert.service.IExpertService;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.entity.SysUserDepart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
/**
* @Description: 专家表
* @Author: jeecg-boot
@ -16,4 +28,54 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@Service
public class ExpertServiceImpl extends ServiceImpl<ExpertMapper, Expert> implements IExpertService {
//专家比赛
@Autowired
private CompExpMapper compExpMapper;
/**
* 修改专家项目之间的关系
* @param jsonObject
*/
@Override
public void updateCompExpert(JSONObject jsonObject) {
String user_id = jsonObject.getString("id");
String compid = jsonObject.getString("compid");
String compName = jsonObject.getString("compName");
String stat = jsonObject.getString("stat");
String[] compNames = {};
String[] compids = {};
if(oConvertUtils.isNotEmpty(compid)&&oConvertUtils.isNotEmpty(compName)){
compNames = compName.split(",");
compids = compid.split(",");
}
//根据user id查询专家
LambdaQueryWrapper<Expert> query = new LambdaQueryWrapper<Expert>()
.like(Expert::getUserId, user_id);
List<Expert> list = this.baseMapper.selectList(query);
if(list.size()>0)
{
Expert exp=list.get(0);
//先删后加
compExpMapper.delete(new QueryWrapper<CompExp>().lambda().eq(CompExp::getExpid, exp.getId()));
if(oConvertUtils.isNotEmpty(compid)) {
if (compNames.length == compids.length) {
for (int i = 0; i < compNames.length; i++) {
CompExp compExp = new CompExp();
compExp.setCompid(compids[i]);
compExp.setCompName(compNames[i]);
compExp.setExpid(exp.getId());
compExp.setStat(stat);
compExpMapper.insert(compExp);
}
} else {
throw new JeecgBootException("比赛项目数据错误!");
}
}
}else
{
throw new JeecgBootException("该专家不存在!");
}
}
}

Loading…
Cancel
Save