新增组织机台授权相关接口

This commit is contained in:
yangsb
2024-04-15 11:52:14 +08:00
parent 350614454e
commit 63f8c800d6
17 changed files with 503 additions and 41 deletions
@@ -2,10 +2,10 @@ package com.cf.imes.module.system.controller.admin.machine;
import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.common.util.object.BeanUtils;
import com.cf.imes.module.system.controller.admin.machine.vo.*;
import com.cf.imes.module.system.dal.dataobject.machine.MachineDO;
import com.cf.imes.module.system.dal.dataobject.machinetemplate.MachineTemplateDO;
import com.cf.imes.module.system.service.machine.MachineTemplateService;
import com.cf.imes.module.system.service.machine.MachineService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -22,48 +22,48 @@ import static com.cf.imes.framework.common.pojo.CommonResult.success;
* @author Beal
*/
@RestController
@Tag(name = "机台模板授权")
@RequestMapping("/system/machine-template-auth")
@Tag(name = "机台授权")
@RequestMapping("/system/machine-auth")
public class MachineAuthController {
@Resource
private MachineTemplateService machineTemplateService;
private MachineService machineService;
@PostMapping("organ-auth-template")
@Operation(summary = "组织模板授权")
@PostMapping("organ-auth")
@Operation(summary = "组织机台授权")
@PreAuthorize("@ss.hasPermission('machine-template::query')")
public CommonResult<Boolean> auth(@RequestBody MachineOrgAuthReq vo) {
return success(machineTemplateService.auth(vo));
return success(machineService.auth(vo));
}
@GetMapping("organ-template-page")
@Operation(summary = "组织模板授权分页列表")
@GetMapping("organ-page")
@Operation(summary = "组织机台授权分页列表")
@PreAuthorize("@ss.hasPermission('machine-template::query')")
public CommonResult<PageResult<OrganTemplateResp>> organTemplatePage(OrganTemplatePage page) {
return success(machineTemplateService.organTemplatePage(page));
public CommonResult<PageResult<OrganMachineResp>> organTemplatePage(OrganMachinePage page) {
return success(machineService.organMachinePage(page));
}
@GetMapping("organ-template-by-organId")
@Operation(summary = "根据组织id查询组织模板授权")
@GetMapping("organ-by-organId")
@Operation(summary = "根据组织id查询组织机台授权")
@PreAuthorize("@ss.hasPermission('machine-template::query')")
@Parameter(name = "organId", description = "组织id", required = true, example = "1")
public CommonResult<OrganTemplateResp> organTemplateByOrganId(@RequestParam Long organId ) {
return success(machineTemplateService.organTemplateByOrganId(organId));
public CommonResult<OrganMachineResp> organTemplateByOrganId(@RequestParam Long organId ) {
return success(machineService.organMachineByOrganId(organId));
}
@GetMapping("page-template-machine-auth")
@Operation(summary = "授权机台模板分页")
@GetMapping("page-machine-auth")
@Operation(summary = "授权机台分页")
@PreAuthorize("@ss.hasPermission('machine-template::query')")
public CommonResult<PageResult<TemplateAutoResp>> pageTemplateAuth(MachinePageReqVO pageParam) {
PageResult<MachineTemplateDO> page = machineTemplateService.page(pageParam);
List<TemplateAutoResp> list = page.getList().stream().map(e->TemplateAutoResp.builder()
public CommonResult<PageResult<MachineAuthResp>> pageTemplateAuth(MachinePageReqVO pageParam) {
PageResult<MachineDO> page = machineService.page(pageParam);
List<MachineAuthResp> list = page.getList().stream().map(e->MachineAuthResp.builder()
.id(e.getId())
.machineType(e.getMachineType())
.templateName(e.getName())
.isDefault(e.getIsDefault())
.machineName(e.getName())
.build()
).collect(Collectors.toList());
return success(new PageResult<TemplateAutoResp>(list, page.getTotal()));
return success(new PageResult<MachineAuthResp>(list, page.getTotal()));
}
}
@@ -0,0 +1,68 @@
package com.cf.imes.module.system.controller.admin.machine;
import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.module.system.controller.admin.machine.vo.*;
import com.cf.imes.module.system.dal.dataobject.machinetemplate.MachineTemplateDO;
import com.cf.imes.module.system.service.machine.MachineTemplateService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
import static com.cf.imes.framework.common.pojo.CommonResult.success;
/**
* @author Beal
*/
@RestController
@Tag(name = "机台模板授权")
@RequestMapping("/system/machine-template-auth")
public class MachineTemplateAuthController {
@Resource
private MachineTemplateService machineTemplateService;
@PostMapping("organ-auth-template")
@Operation(summary = "组织模板授权")
@PreAuthorize("@ss.hasPermission('machine-template::query')")
public CommonResult<Boolean> auth(@RequestBody MachineOrgAuthReq vo) {
return success(machineTemplateService.auth(vo));
}
@GetMapping("organ-template-page")
@Operation(summary = "组织模板授权分页列表")
@PreAuthorize("@ss.hasPermission('machine-template::query')")
public CommonResult<PageResult<OrganTemplateResp>> organTemplatePage(OrganTemplatePage page) {
return success(machineTemplateService.organTemplatePage(page));
}
@GetMapping("organ-template-by-organId")
@Operation(summary = "根据组织id查询组织模板授权")
@PreAuthorize("@ss.hasPermission('machine-template::query')")
@Parameter(name = "organId", description = "组织id", required = true, example = "1")
public CommonResult<OrganTemplateResp> organTemplateByOrganId(@RequestParam Long organId ) {
return success(machineTemplateService.organTemplateByOrganId(organId));
}
@GetMapping("page-template-machine-auth")
@Operation(summary = "授权机台模板分页")
@PreAuthorize("@ss.hasPermission('machine-template::query')")
public CommonResult<PageResult<TemplateAutoResp>> pageTemplateAuth(MachinePageReqVO pageParam) {
PageResult<MachineTemplateDO> page = machineTemplateService.page(pageParam);
List<TemplateAutoResp> list = page.getList().stream().map(e->TemplateAutoResp.builder()
.id(e.getId())
.machineType(e.getMachineType())
.templateName(e.getName())
.isDefault(e.getIsDefault())
.build()
).collect(Collectors.toList());
return success(new PageResult<TemplateAutoResp>(list, page.getTotal()));
}
}
@@ -0,0 +1,29 @@
package com.cf.imes.module.system.controller.admin.machine.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author Beal
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class MachineAuthResp {
@Schema(description = "机台id")
private Long id;
@Schema(description = "机台名称")
private String machineName;
@Schema(description = "机台类别")
private Integer machineType;
@Schema(description ="加工模式 开料机加工模式 默认true,显示开料机工作模式(是否排钻/造型,sc)配置")
private Boolean showPriorFacing = false;
@Schema(description = "双工位")
private Boolean showDualWorkstation = false;
@Schema(description = "自动贴标")
private Boolean showAutoNotePrinter = false;
}
@@ -0,0 +1,16 @@
package com.cf.imes.module.system.controller.admin.machine.vo;
import com.cf.imes.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
* @author Beal
*/
@Data
public class OrganMachinePage extends PageParam {
@Schema(description = "组织id")
private Long organId;
@Schema(description = "机台名称")
private String machineName;
}
@@ -0,0 +1,33 @@
package com.cf.imes.module.system.controller.admin.machine.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
import java.util.List;
import static com.cf.imes.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
import static com.cf.imes.framework.common.util.date.DateUtils.TIME_ZONE_DEFAULT;
/**
* @author Beal
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class OrganMachineResp {
@Schema(description = "组织id")
private Long organId;
@Schema(description = "组织名称")
private String organName;
@Schema(description = "更新时间")
@JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT)
private Date updateTime;
@Schema(description = "机台模板列表")
private List<OrganMachineVO> authMachineList;
}
@@ -0,0 +1,27 @@
package com.cf.imes.module.system.controller.admin.machine.vo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
* @author Beal
*/
@Data
public class OrganMachineVO {
@Schema(description = "机台id")
private Long machineId;
@Schema(description = "机台名称")
private String machineName;
@Schema(description = "机台类型")
private Integer machineType;
@Schema(description ="加工模式 开料机加工模式 默认true,显示开料机工作模式(是否排钻/造型,sc)配置")
private Boolean showPriorFacing;
@Schema(description = "双工位")
private Boolean showDualWorkstation;
@Schema(description = "自动贴标")
private Boolean showAutoNotePrinter;
@JsonIgnore
private Long organId;
}
@@ -12,7 +12,7 @@ import javax.validation.constraints.Size;
public class NoticeSaveReqVO {
@Schema(description = "岗位公告编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@NotNull(message = "岗位公告编号不能为空")
//@NotNull(message = "岗位公告编号不能为空")
private Long id;
@Schema(description = "公告标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "小博主")
@@ -1,12 +1,16 @@
package com.cf.imes.module.system.dal.mysql.machine;
import java.util.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX;
import com.cf.imes.module.system.controller.admin.machine.vo.MachinePageReqVO;
import com.cf.imes.module.system.controller.admin.machine.vo.*;
import com.cf.imes.module.system.dal.dataobject.machine.MachineDO;
import com.cf.imes.module.system.dal.dataobject.machinetemplate.MachineTemplateDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* 机台 Mapper
@@ -24,4 +28,17 @@ public interface MachineMapper extends BaseMapperX<MachineDO> {
.orderByDesc(MachineDO::getCreateTime));
}
Page<OrganMachineResp> selectOrganMachinePage(@Param("page") Page<OrganMachineResp> respPage, @Param("vo") OrganMachinePage page);
List<OrganMachineVO> selectOrganMachineList(Map<String, Object> map);
OrganMachineResp selectOrganMachine(Long organId);
default PageResult<MachineDO> selectPage(MachinePageReqVO pageParam, Collection<Long> ids) {
return selectPage(pageParam, new LambdaQueryWrapperX<MachineDO>()
.eqIfPresent(MachineDO::getMachineType, pageParam.getMachineType())
.likeIfPresent(MachineDO::getName, pageParam.getName())
.betweenIfPresent(MachineDO::getCreateTime, pageParam.getCreateTime())
.orderByDesc(MachineDO::getCreateTime));
};
}
@@ -72,4 +72,12 @@ public interface MachineService {
List<MachineDO> list(Collection<Long> ids);
Map<Integer, List<MachineVO>> getMachineTree(Long organId);
Boolean auth(MachineOrgAuthReq vo);
PageResult<OrganMachineResp> organMachinePage(OrganMachinePage page);
OrganMachineResp organMachineByOrganId(Long organId);
PageResult<MachineDO> page(MachinePageReqVO pageParam);
}
@@ -10,6 +10,7 @@ import co.elastic.clients.elasticsearch.core.DeleteByQueryRequest;
import co.elastic.clients.elasticsearch.core.SearchRequest;
import co.elastic.clients.elasticsearch.core.SearchResponse;
import co.elastic.clients.elasticsearch.core.search.Hit;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cf.imes.framework.es.core.dal.ESDocument;
import com.cf.imes.framework.es.core.service.ESDocumentService;
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
@@ -25,13 +26,13 @@ import com.cf.imes.module.system.dal.dataobject.machinetemplate.MachineTemplateL
import com.cf.imes.module.system.dal.mysql.machine.MachineMapper;
import com.cf.imes.module.system.dal.mysql.machine.MachineLimitMapper;
import com.cf.imes.module.system.dal.mysql.machinetemplate.MachineTemplateLimitMapper;
import com.cf.imes.module.system.dal.mysql.machinetemplate.MachineTemplateMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
@@ -251,6 +252,51 @@ public class MachineServiceImpl implements MachineService {
return map;
}
@Override
public Boolean auth(MachineOrgAuthReq vo) {
machineLimitMapper.delete(new LambdaQueryWrapperX<MachineLimitDO>().eq(MachineLimitDO::getOrganId, vo.getOrganId()));
List<MachineAuth> machineAuthList = vo.getMachineAuthList();
if(CollectionUtil.isNotEmpty(machineAuthList)) {
List<MachineLimitDO> organMachineDOS = new ArrayList<>();
LocalDateTime now = LocalDateTime.now();
for (MachineAuth machineAuth : machineAuthList) {
organMachineDOS.add(
MachineLimitDO.builder()
.createTime(now)
.organId(vo.getOrganId())
.machineId(machineAuth.getMachineId())
.showDualWorkstation(machineAuth.getShowDualWorkstation())
.showAutoNotePrinter(machineAuth.getShowAutoNotePrinter())
.showPriorFacing(machineAuth.getShowPriorFacing())
.build()
);
}
machineLimitMapper.insertBatch(organMachineDOS);
}
return Boolean.TRUE;
}
@Override
public PageResult<OrganMachineResp> organMachinePage(OrganMachinePage page) {
Page<OrganMachineResp> respPage = new Page<>(page.getPageNo(), page.getPageSize());
Page<OrganMachineResp> pageRes = machineMapper.selectOrganMachinePage(respPage, page);
return new PageResult<>(pageRes.getRecords(), pageRes.getTotal());
}
@Override
public OrganMachineResp organMachineByOrganId(Long organId) {
return machineMapper.selectOrganMachine(organId);
}
@Override
public PageResult<MachineDO> page(MachinePageReqVO pageParam) {
return machineMapper.selectPage(pageParam, new ArrayList<>());
}
private void validateExists(Long id) {
if (machineMapper.selectById(id) == null) {
throw exception(MACHINE_NOT_EXISTS);
@@ -65,7 +65,7 @@ public class MachineTemplateServiceImpl implements MachineTemplateService {
private MachineTemplateMapper machineTemplateMapper;
@Resource
private MachineTemplateLimitMapper organMachineMapper;
private MachineTemplateLimitMapper machineTemplateLimitMapper;
@Override
@Transactional(rollbackFor = Exception.class)
@@ -323,7 +323,7 @@ public class MachineTemplateServiceImpl implements MachineTemplateService {
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean auth(MachineOrgAuthReq vo) {
organMachineMapper.delete(new LambdaQueryWrapperX<MachineTemplateLimitDO>().eq(MachineTemplateLimitDO::getOrganId, vo.getOrganId()));
machineTemplateLimitMapper.delete(new LambdaQueryWrapperX<MachineTemplateLimitDO>().eq(MachineTemplateLimitDO::getOrganId, vo.getOrganId()));
List<MachineAuth> machineAuthList = vo.getMachineAuthList();
@@ -343,7 +343,7 @@ public class MachineTemplateServiceImpl implements MachineTemplateService {
);
}
organMachineMapper.insertBatch(organMachineDOS);
machineTemplateLimitMapper.insertBatch(organMachineDOS);
}
return Boolean.TRUE;
@@ -0,0 +1,77 @@
<?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="com.cf.imes.module.system.dal.mysql.machine.MachineMapper">
<resultMap id="xxMap" type="com.cf.imes.module.system.controller.admin.machine.vo.OrganMachineResp">
<result property="organId" column="organId"/>
<result property="organName" column="organName"/>
<result property="updateTime" column="updateTime"/>
<collection property="authMachineList" javaType="java.util.List" ofType="com.cf.imes.module.system.controller.admin.machine.vo.OrganTemplateVO"
select="selectOrganMachineList" column="{organId=organId, machineName = machineName}" notNullColumn="machineName" >
</collection>
</resultMap>
<resultMap id="orgMap" type="com.cf.imes.module.system.controller.admin.machine.vo.OrganMachineResp">
<result property="organId" column="organId"/>
<result property="organName" column="organName"/>
<result property="updateTime" column="updateTime"/>
<collection property="authMachineList" javaType="java.util.List" ofType="com.cf.imes.module.system.controller.admin.machine.vo.OrganMachineVO"
select="selectOrganMachineList" column="{organId=organId}" >
</collection>
</resultMap>
<select id="selectOrganMachinePage" resultMap="xxMap">
select * from (
select a.id as organId, a.name as organName, max(b.create_time) as updateTime,
case when ('${vo.machineName}' != '') then '${vo.machineName}' else '' end as machineName
from system_organization a, system_machine_limit b
<where>
a.id = b.organ_id
<if test="vo.organId !=null">
and a.id = #{vo.organId}
</if>
</where>
GROUP BY organId
) t1
LEFT JOIN (
select b.organ_id t2_organId
from system_machine_limit b inner join system_machine c on b.machine_id = c.id and c.deleted = 0
<where>
<if test="vo.machineName !=null and vo.machineName !='' " >
c.name like concat('%',#{vo.machineName},'%')
</if>
</where>
) t2 on t1.organId = t2.t2_organId
where t2.t2_organId is not null
GROUP BY organId
order by updateTime desc
</select>
<select id="selectOrganMachineList"
resultType="com.cf.imes.module.system.controller.admin.machine.vo.OrganMachineVO">
select b.organ_id organId, b.show_prior_facing, b.show_dual_workstation, b.show_auto_note_printer,
c.name AS machineName, c.id AS machineId, c.machine_type
from system_machine_limit b
inner join system_machine c on b.machine_id = c.id and c.deleted = 0
<where>
b.organ_id = #{organId}
<if test="machineName != null and machineName != ''">
and c.name like concat('%',#{machineName},'%')
</if>
</where>
</select>
<select id="selectOrganMachine" resultMap="orgMap">
select a.id as organId, a.name as organName, max(b.create_time) as updateTime
from system_organization a, system_machine_limit b
<where>
a.id = b.organ_id
and a.id = #{vo.organId}
</where>
GROUP BY organId
</select>
</mapper>