评测新增、修改时关联评测员工表,删除添加限制条件

main 003
hshansha 6 months ago
parent 32187e08f1
commit e6d4d10e8e

@ -1,9 +1,14 @@
package com.ruoyi.kaohe.controller; package com.ruoyi.kaohe.controller;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.ruoyi.kaohe.domain.*;
import com.ruoyi.kaohe.service.IKhPcEmpService;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.PutMapping;
@ -16,7 +21,6 @@ import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.kaohe.domain.KhPingce;
import com.ruoyi.kaohe.service.IKhPingceService; import com.ruoyi.kaohe.service.IKhPingceService;
import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.core.page.TableDataInfo;
@ -33,6 +37,8 @@ public class KhPingceController extends BaseController
{ {
@Autowired @Autowired
private IKhPingceService khPingceService; private IKhPingceService khPingceService;
@Autowired
private IKhPcEmpService pcEmpService;
/** /**
* *
@ -74,10 +80,25 @@ public class KhPingceController extends BaseController
*/ */
@PreAuthorize("@ss.hasPermi('kaohe:pingce:add')") @PreAuthorize("@ss.hasPermi('kaohe:pingce:add')")
@Log(title = "考核评测", businessType = BusinessType.INSERT) @Log(title = "考核评测", businessType = BusinessType.INSERT)
@Transactional
@PostMapping @PostMapping
public AjaxResult add(@RequestBody KhPingce khPingce) public AjaxResult add(@RequestBody KhPingce khPingce)
{ {
return toAjax(khPingceService.insertKhPingce(khPingce)); khPingceService.insertKhPingce(khPingce);
//增加关联表
List<KhEmployee> pcEmps = khPingce.getPcEmps();
if(pcEmps !=null&& pcEmps.size()>0){
for(KhEmployee item:pcEmps){
KhPcEmp pcEmp = new KhPcEmp();
pcEmp.setPcId(khPingce.getId());
pcEmp.setEmpId(item.getId());
pcEmp.setEmpName(item.getEmpName());
pcEmp.setDeptId(item.getDeptId());
pcEmp.setDeptName(item.getDeptName());
pcEmpService.insertKhPcEmp(pcEmp);
}
}
return AjaxResult.success();
} }
/** /**
@ -86,9 +107,30 @@ public class KhPingceController extends BaseController
@PreAuthorize("@ss.hasPermi('kaohe:pingce:edit')") @PreAuthorize("@ss.hasPermi('kaohe:pingce:edit')")
@Log(title = "考核评测", businessType = BusinessType.UPDATE) @Log(title = "考核评测", businessType = BusinessType.UPDATE)
@PutMapping @PutMapping
@Transactional
public AjaxResult edit(@RequestBody KhPingce khPingce) public AjaxResult edit(@RequestBody KhPingce khPingce)
{ {
return toAjax(khPingceService.updateKhPingce(khPingce)); khPingceService.updateKhPingce(khPingce);
List<KhEmployee> pcEmps = khPingce.getPcEmps();
if(pcEmps !=null&& pcEmps.size()>0){
//删除原来关联
KhPcEmp query = new KhPcEmp();
query.setPcId(khPingce.getId());
List<KhPcEmp> temItems = pcEmpService.selectKhPcEmpList(query);
List<Long> ids = temItems.stream().map(KhPcEmp::getId).collect(Collectors.toList());
pcEmpService.deleteKhPcEmpByIds(ids.toArray(new Long[ids.size()]));
//增加新的关联
for(KhEmployee item:pcEmps){
KhPcEmp pcEmp = new KhPcEmp();
pcEmp.setEmpId(item.getId());
pcEmp.setEmpName(item.getEmpName());
pcEmp.setDeptId(item.getDeptId());
pcEmp.setDeptName(item.getDeptName());
pcEmpService.insertKhPcEmp(pcEmp);
}
}
return AjaxResult.success();
} }
/** /**
@ -99,6 +141,12 @@ public class KhPingceController extends BaseController
@DeleteMapping("/{ids}") @DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) public AjaxResult remove(@PathVariable Long[] ids)
{ {
for(Long id:ids){
KhPingce khPingce = khPingceService.selectKhPingceById(id);
if(!khPingce.getState().equals("0")){
return AjaxResult.error("评测:"+khPingce.getPcTitle()+" 不是未开始状态,不允许删除");
}
}
return toAjax(khPingceService.deleteKhPingceByIds(ids)); return toAjax(khPingceService.deleteKhPingceByIds(ids));
} }
} }

@ -87,6 +87,7 @@ public class KhTemplateController extends BaseController
public AjaxResult add(@RequestBody KhTemplate khTemplate) public AjaxResult add(@RequestBody KhTemplate khTemplate)
{ {
khTemplateService.insertKhTemplate(khTemplate); khTemplateService.insertKhTemplate(khTemplate);
//增加关联表
List<KhItems> items = khTemplate.getItems(); List<KhItems> items = khTemplate.getItems();
if(items !=null&& items.size()>0){ if(items !=null&& items.size()>0){
for(KhItems item:items){ for(KhItems item:items){
@ -119,6 +120,7 @@ public class KhTemplateController extends BaseController
List<KhTemItem> temItems = temItemService.selectKhTemItemList(query); List<KhTemItem> temItems = temItemService.selectKhTemItemList(query);
List<Long> ids = temItems.stream().map(KhTemItem::getId).collect(Collectors.toList()); List<Long> ids = temItems.stream().map(KhTemItem::getId).collect(Collectors.toList());
temItemService.deleteKhTemItemByIds(ids.toArray(new Long[ids.size()])); temItemService.deleteKhTemItemByIds(ids.toArray(new Long[ids.size()]));
//增加新的关联
for(KhItems item:items){ for(KhItems item:items){
KhTemItem temItem = new KhTemItem(); KhTemItem temItem = new KhTemItem();
temItem.setTemName(khTemplate.getTemName()); temItem.setTemName(khTemplate.getTemName());

@ -5,6 +5,8 @@ import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity; import com.ruoyi.common.core.domain.BaseEntity;
import java.util.List;
/** /**
* kh_pingce * kh_pingce
* *
@ -42,6 +44,16 @@ public class KhPingce extends BaseEntity
@Excel(name = "评测状态(0 开始 1 进行中 2 完成)") @Excel(name = "评测状态(0 开始 1 进行中 2 完成)")
private String state; private String state;
private List<KhEmployee> pcEmps;
public List<KhEmployee> getPcEmps() {
return pcEmps;
}
public void setPcEmps(List<KhEmployee> pcEmps) {
this.pcEmps = pcEmps;
}
public void setId(Long id) public void setId(Long id)
{ {
this.id = id; this.id = id;

@ -17,6 +17,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="updateBy" column="update_by" /> <result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" /> <result property="updateTime" column="update_time" />
<result property="remark" column="remark" /> <result property="remark" column="remark" />
<collection property="pcEmps" ofType="KhEmployee">
<result property="id" column="emp_id" />
<result property="empName" column="emp_name" />
<result property="deptId" column="dept_id" />
<result property="deptName" column="dept_name" />
</collection >
</resultMap> </resultMap>
<sql id="selectKhPingceVo"> <sql id="selectKhPingceVo">
@ -24,7 +30,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</sql> </sql>
<select id="selectKhPingceList" parameterType="KhPingce" resultMap="KhPingceResult"> <select id="selectKhPingceList" parameterType="KhPingce" resultMap="KhPingceResult">
<include refid="selectKhPingceVo"/> select p.*, emp_id,emp_name,dept_id,dept_name from kh_pingce p left join kh_pc_emp pe on p.id=pe.pc_id
<where> <where>
<if test="pcTitle != null and pcTitle != ''"> and pc_title = #{pcTitle}</if> <if test="pcTitle != null and pcTitle != ''"> and pc_title = #{pcTitle}</if>
<if test="pcDescription != null and pcDescription != ''"> and pc_description = #{pcDescription}</if> <if test="pcDescription != null and pcDescription != ''"> and pc_description = #{pcDescription}</if>
@ -36,8 +42,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<select id="selectKhPingceById" parameterType="Long" resultMap="KhPingceResult"> <select id="selectKhPingceById" parameterType="Long" resultMap="KhPingceResult">
<include refid="selectKhPingceVo"/> select p.*, emp_id,emp_name,dept_id,dept_name from kh_pingce p left join kh_pc_emp pe on p.id=pe.pc_id
where id = #{id} where p.id = #{id}
</select> </select>
<insert id="insertKhPingce" parameterType="KhPingce" useGeneratedKeys="true" keyProperty="id"> <insert id="insertKhPingce" parameterType="KhPingce" useGeneratedKeys="true" keyProperty="id">

Loading…
Cancel
Save