diff --git a/youchain-generator/src/main/java/com/youchain/rest/ExcelConfigController.java b/youchain-generator/src/main/java/com/youchain/rest/ExcelConfigController.java index 289ba74..52cbbe5 100644 --- a/youchain-generator/src/main/java/com/youchain/rest/ExcelConfigController.java +++ b/youchain-generator/src/main/java/com/youchain/rest/ExcelConfigController.java @@ -43,7 +43,9 @@ import io.swagger.annotations.*; import org.springframework.web.multipart.MultipartFile; import java.io.File; +import java.text.SimpleDateFormat; import java.util.Arrays; +import java.util.Date; import java.util.List; import java.util.Map; import javax.persistence.*; @@ -102,10 +104,11 @@ public class ExcelConfigController { return new ResponseEntity<>(HttpStatus.OK); } @PostMapping(value = "/import") - @ApiOperation("导入点位") @AnonymousAccess @Transactional public ResponseEntity importPoint(@RequestParam("file") MultipartFile multipartFile,@RequestParam("tableName") String tableNames) { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String startData=dateFormat.format(new Date()); /*通过权限匹配对应的数据库表*/ String tableName = getTableName(tableNames); FileUtil.checkSize(properties.getMaxSize(), multipartFile.getSize()); @@ -133,73 +136,78 @@ public class ExcelConfigController { Map readMap=readAll.get(i); for (int j = 0; j < excelConfigList.size(); j++) { ExcelConfig EI=excelConfigList.get(j); - /* 唯一判定*/ - if (EI.getOnlyFlag()==true){ - if (readMap.get(EI.getExcelColumnName())==null){ - throw new BadRequestException(EI.getExcelColumnName()+"本字段不能为空"); - }else { - Object value=readMap.get(EI.getExcelColumnName()); - - String hql ="select * from "+tableName+" where "+EI.getTableColumnName()+"="+ EI.getFormat(value,EI.getTableColumnType()); -// System.out.println(hql); - Query query = entityManager.createNativeQuery(hql); - List qL= query.getResultList(); - if (qL.size()<1){ - //新增 + try { + /* 唯一判定*/ + if (EI.getOnlyFlag()==true){ + if (readMap.get(EI.getExcelColumnName())==null){ + throw new BadRequestException(EI.getExcelColumnName()+"本字段不能为空"); }else { - //修改 - editEI=EI; - } - } - } + Object value=readMap.get(EI.getExcelColumnName()); - if (readMap.get(EI.getExcelColumnName())!=null||(EI.getDefaultValue()!=null&&EI.getDefaultValue().length()>0)){ - /* 获取导入值*/ - Object value; - if (readMap.get(EI.getExcelColumnName())!=null){ - value = readMap.get(EI.getExcelColumnName()); - }else { - value=EI.getDefaultValue(); - } - /*添加到sql字段集*/ - if (EI.getGlbType()==1){ - /* 外键关联*/ - ExcelConfigKey excelConfigKey=EI.getEcKey(); - if (excelConfigKey!=null){ - /*获取外键id*/ - String hql ="select "+excelConfigKey.getKeyName()+" from "+excelConfigKey.getTableName()+" where "+excelConfigKey.getTableColumnName()+"="+ EI.getFormat(value,excelConfigKey.getTableColumnType()); -// System.out.println(hql); + String hql ="select * from "+tableName+" where "+EI.getTableColumnName()+"="+ EI.getFormat(value,EI.getTableColumnType()); +// System.out.println(hql); Query query = entityManager.createNativeQuery(hql); List qL= query.getResultList(); - if (qL.size()>0){ - value=qL.get(0); + if (qL.size()<1){ + //新增 }else { - value=null; + //修改 + editEI=EI; } } - }else - if (EI.getGlbType()==2){ - /*关联字典*/ - String hql =" select dd.`value` from sys_dict_detail dd " - +" left join sys_dict d on dd.dict_id=d.dict_id " - +" where d.`name`='"+EI.getDictName()+"' and dd.label='"+value+"' "; - Query query = entityManager.createNativeQuery(hql); - List qL= query.getResultList(); - if (qL.size()<1){ - throw new BadRequestException("未找到字典:"+EI.getExcelColumnName()+","+value); + } + + if (readMap.get(EI.getExcelColumnName())!=null||(EI.getDefaultValue()!=null&&EI.getDefaultValue().length()>0)){ + /* 获取导入值*/ + Object value; + /*写入 默认值*/ + if (readMap.get(EI.getExcelColumnName())!=null){ + value = readMap.get(EI.getExcelColumnName()); + }else { + value=EI.getDefaultValue(); + } + /*添加到sql字段集*/ + if (EI.getGlbType()==1){ + /* 外键关联*/ + ExcelConfigKey excelConfigKey=EI.getEcKey(); + if (excelConfigKey!=null){ + /*获取外键id*/ + String hql ="select "+excelConfigKey.getKeyName()+" from "+excelConfigKey.getTableName()+" where "+excelConfigKey.getTableColumnName()+"="+ EI.getFormat(value,excelConfigKey.getTableColumnType()); +// System.out.println(hql); + Query query = entityManager.createNativeQuery(hql); + List qL= query.getResultList(); + if (qL.size()>0){ + value=qL.get(0); + }else { + value=null; + } + } + }else + if (EI.getGlbType()==2){ + /*关联字典*/ + String hql =" select dd.`value` from sys_dict_detail dd " + +" left join sys_dict d on dd.dict_id=d.dict_id " + +" where d.`name`='"+EI.getDictName()+"' and dd.label='"+value+"' "; + Query query = entityManager.createNativeQuery(hql); + List qL= query.getResultList(); + if (qL.size()<1){ + throw new BadRequestException("未找到字典:"+EI.getExcelColumnName()+","+value); + } + value=qL.get(0); + } + if (columns.toString().length() < 1) { + columns.append(EI.getTableColumnName()); + } else { + columns.append("," + EI.getTableColumnName()); + } + if (values.toString().length() < 1) { + values.append(EI.getFormat(value,EI.getTableColumnType())); + } else { + values.append("," + EI.getFormat(value,EI.getTableColumnType())); } - value=qL.get(0); - } - if (columns.toString().length() < 1) { - columns.append(EI.getTableColumnName()); - } else { - columns.append("," + EI.getTableColumnName()); - } - if (values.toString().length() < 1) { - values.append(EI.getFormat(value,EI.getTableColumnType())); - } else { - values.append("," + EI.getFormat(value,EI.getTableColumnType())); } + }catch (Exception e){ + throw new BadRequestException("第"+i+"行,"+EI.getExcelColumnName()+"列"+","+e.getMessage()); } } String sql; @@ -222,6 +230,11 @@ public class ExcelConfigController { entityManager.createNativeQuery(sql) .executeUpdate(); } + String endDate=dateFormat.format(new Date()); + + System.out.println("导入,开始时间:"+ dateFormat.format(new Date())+"结束时间:"+ dateFormat.format(new Date())); + /*entityManager.createNativeQuery(sqlBf.toString()) + .executeUpdate();*/ /*System.out.println(sqlBf); *//* 执行sql语句*//* entityManager.createNativeQuery(sqlBf.toString()) diff --git a/youchain-system/src/main/java/com/youchain/basicdata/domain/WorkPoint.java b/youchain-system/src/main/java/com/youchain/basicdata/domain/WorkPoint.java new file mode 100644 index 0000000..b3ae543 --- /dev/null +++ b/youchain-system/src/main/java/com/youchain/basicdata/domain/WorkPoint.java @@ -0,0 +1,126 @@ +/* +* Copyright 2019-2020 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package com.youchain.basicdata.domain; + +import com.youchain.base.BaseEntity; +import lombok.Data; +import cn.hutool.core.bean.BeanUtil; +import io.swagger.annotations.ApiModelProperty; +import cn.hutool.core.bean.copier.CopyOptions; +import javax.persistence.*; +import javax.validation.constraints.*; +import java.sql.Timestamp; +import java.io.Serializable; + +/** +* @website https://eladmin.vip +* @description / +* @author houjianlan +* @date 2024-09-26 +**/ +@Entity +@Data +@Table(name="base_work_point") +public class WorkPoint extends BaseEntity implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "`id`") + @ApiModelProperty(value = "主键") + private Long id; + + @Column(name = "`code`",unique = true,nullable = false) + @NotBlank + @ApiModelProperty(value = "编码") + private String code; + + @Column(name = "`name`") + @ApiModelProperty(value = "名称") + private String name; + + @OneToOne + @JoinColumn(name = "area_id") + @ApiModelProperty(value = "库区ID") + private Area area; + + @Column(name = "`up_number`",nullable = false) + @NotNull + @ApiModelProperty(value = "上料接驳口数") + private Integer upNumber; + + @OneToOne + @JoinColumn(name = "up_point_id",nullable = false) + @ApiModelProperty(value = "上料料接驳口") + @NotNull + private Point upPoint; + + @Column(name = "`down_number`") + @ApiModelProperty(value = "下料接驳口数") + private Integer downNumber; + @OneToOne + @JoinColumn(name = "down_point_id",nullable = false) + @ApiModelProperty(value = "下料接驳口") + @NotNull + private Point downPoint; + + @Column(name = "`agv_number`") + @ApiModelProperty(value = "接驳口车辆数") + private Integer agvNumber; + + @Column(name = "`max_number`") + @ApiModelProperty(value = "输送线最大容量") + private Integer maxNumber; + + @Column(name = "`back_number`") + @ApiModelProperty(value = "输送线返库料箱数") + private Integer backNumber; + + @Column(name = "`max_stock_number`") + @ApiModelProperty(value = "最大料箱任务数") + private Integer maxStockNumber; + + @Column(name = "`dept_id`") + @ApiModelProperty(value = "仓库ID") + private Long deptId; + + @Column(name = "`description`") + @ApiModelProperty(value = "描述") + private String description; + + @Column(name = "`enabled`") + @ApiModelProperty(value = "是否启用") + private Boolean enabled; + + @Column(name = "`create_by`") + @ApiModelProperty(value = "创建人") + private String createBy; + + @Column(name = "`update_by`") + @ApiModelProperty(value = "修改人") + private String updateBy; + + @Column(name = "`create_time`") + @ApiModelProperty(value = "创建时间") + private Timestamp createTime; + + @Column(name = "`update_time`") + @ApiModelProperty(value = "修改时间") + private Timestamp updateTime; + + public void copy(WorkPoint source){ + BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); + } +} diff --git a/youchain-system/src/main/java/com/youchain/basicdata/repository/WorkPointRepository.java b/youchain-system/src/main/java/com/youchain/basicdata/repository/WorkPointRepository.java new file mode 100644 index 0000000..beb76c2 --- /dev/null +++ b/youchain-system/src/main/java/com/youchain/basicdata/repository/WorkPointRepository.java @@ -0,0 +1,34 @@ +/* +* Copyright 2019-2020 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package com.youchain.basicdata.repository; + +import com.youchain.basicdata.domain.WorkPoint; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; + +/** +* @website https://eladmin.vip +* @author houjianlan +* @date 2024-09-26 +**/ +public interface WorkPointRepository extends JpaRepository, JpaSpecificationExecutor { + /** + * 根据 Code 查询 + * @param code / + * @return / + */ + WorkPoint findByCode(String code); +} \ No newline at end of file diff --git a/youchain-system/src/main/java/com/youchain/basicdata/rest/WorkPointController.java b/youchain-system/src/main/java/com/youchain/basicdata/rest/WorkPointController.java new file mode 100644 index 0000000..3b398a1 --- /dev/null +++ b/youchain-system/src/main/java/com/youchain/basicdata/rest/WorkPointController.java @@ -0,0 +1,87 @@ +/* +* Copyright 2019-2020 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package com.youchain.basicdata.rest; + +import com.youchain.annotation.Log; +import com.youchain.basicdata.domain.WorkPoint; +import com.youchain.basicdata.service.WorkPointService; +import com.youchain.basicdata.service.dto.WorkPointQueryCriteria; +import org.springframework.data.domain.Pageable; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import io.swagger.annotations.*; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; + +/** +* @website https://eladmin.vip +* @author houjianlan +* @date 2024-09-26 +**/ +@RestController +@RequiredArgsConstructor +@Api(tags = "workPoint管理") +@RequestMapping("/api/workPoint") +public class WorkPointController { + + private final WorkPointService workPointService; + + @Log("导出数据") + @ApiOperation("导出数据") + @GetMapping(value = "/download") + @PreAuthorize("@el.check('workPoint:list')") + public void exportWorkPoint(HttpServletResponse response, WorkPointQueryCriteria criteria) throws Exception { + workPointService.download(workPointService.queryAll(criteria), response); + } + + @GetMapping + @Log("查询workPoint") + @ApiOperation("查询workPoint") + @PreAuthorize("@el.check('workPoint:list')") + public ResponseEntity queryWorkPoint(WorkPointQueryCriteria criteria, Pageable pageable){ + return new ResponseEntity<>(workPointService.queryAll(criteria,pageable),HttpStatus.OK); + } + + @PostMapping + @Log("新增workPoint") + @ApiOperation("新增workPoint") + @PreAuthorize("@el.check('workPoint:add')") + public ResponseEntity createWorkPoint(@Validated @RequestBody WorkPoint resources){ + return new ResponseEntity<>(workPointService.create(resources),HttpStatus.CREATED); + } + + @PutMapping + @Log("修改workPoint") + @ApiOperation("修改workPoint") + @PreAuthorize("@el.check('workPoint:edit')") + public ResponseEntity updateWorkPoint(@Validated @RequestBody WorkPoint resources){ + workPointService.update(resources); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @DeleteMapping + @Log("删除workPoint") + @ApiOperation("删除workPoint") + @PreAuthorize("@el.check('workPoint:del')") + public ResponseEntity deleteWorkPoint(@RequestBody Long[] ids) { + workPointService.deleteAll(ids); + return new ResponseEntity<>(HttpStatus.OK); + } +} \ No newline at end of file diff --git a/youchain-system/src/main/java/com/youchain/basicdata/service/WorkPointService.java b/youchain-system/src/main/java/com/youchain/basicdata/service/WorkPointService.java new file mode 100644 index 0000000..b568ffb --- /dev/null +++ b/youchain-system/src/main/java/com/youchain/basicdata/service/WorkPointService.java @@ -0,0 +1,83 @@ +/* +* Copyright 2019-2020 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package com.youchain.basicdata.service; + +import com.youchain.basicdata.domain.WorkPoint; +import com.youchain.basicdata.service.dto.WorkPointDto; +import com.youchain.basicdata.service.dto.WorkPointQueryCriteria; +import org.springframework.data.domain.Pageable; +import java.util.Map; +import java.util.List; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; + +/** +* @website https://eladmin.vip +* @description 服务接口 +* @author houjianlan +* @date 2024-09-26 +**/ +public interface WorkPointService { + + /** + * 查询数据分页 + * @param criteria 条件 + * @param pageable 分页参数 + * @return Map + */ + Map queryAll(WorkPointQueryCriteria criteria, Pageable pageable); + + /** + * 查询所有数据不分页 + * @param criteria 条件参数 + * @return List + */ + List queryAll(WorkPointQueryCriteria criteria); + + /** + * 根据ID查询 + * @param id ID + * @return WorkPointDto + */ + WorkPointDto findById(Long id); + + /** + * 创建 + * @param resources / + * @return WorkPointDto + */ + WorkPointDto create(WorkPoint resources); + + /** + * 编辑 + * @param resources / + */ + void update(WorkPoint resources); + + /** + * 多选删除 + * @param ids / + */ + void deleteAll(Long[] ids); + + /** + * 导出数据 + * @param all 待导出的数据 + * @param response / + * @throws Exception / + */ + void download(List all, HttpServletResponse response) throws Exception; +} \ No newline at end of file diff --git a/youchain-system/src/main/java/com/youchain/basicdata/service/dto/WorkPointDto.java b/youchain-system/src/main/java/com/youchain/basicdata/service/dto/WorkPointDto.java new file mode 100644 index 0000000..cda78ae --- /dev/null +++ b/youchain-system/src/main/java/com/youchain/basicdata/service/dto/WorkPointDto.java @@ -0,0 +1,90 @@ +/* +* Copyright 2019-2020 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package com.youchain.basicdata.service.dto; + +import com.youchain.basicdata.domain.Area; +import com.youchain.basicdata.domain.Point; +import com.youchain.modules.system.domain.Dept; +import lombok.Data; +import java.sql.Timestamp; +import java.io.Serializable; + +/** +* @website https://eladmin.vip +* @description / +* @author houjianlan +* @date 2024-09-26 +**/ +@Data +public class WorkPointDto implements Serializable { + + /** 主键 */ + private Long id; + + /** 编码 */ + private String code; + + /** 名称 */ + private String name; + + /** 所属库区 */ + private Area area; + + /** 上料接驳口数 */ + private Integer upNumber; + + /** 上料接驳口 */ + private Point upPoint; + + /** 下料接驳口数 */ + private Integer downNumber; + + /** 下料接驳口 */ + private Point downPoint; + + /** 接驳口车辆数 */ + private Integer agvNumber; + + /** 输送线最大容量 */ + private Integer maxNumber; + + /** 输送线返库料箱数 */ + private Integer backNumber; + + /** 最大料箱任务数 */ + private Integer maxStockNumber; + + /** 仓库ID */ + private Dept dept; + + /** 描述 */ + private String description; + + /** 是否启用 */ + private Boolean enabled; + + /** 创建人 */ + private String createBy; + + /** 修改人 */ + private String updateBy; + + /** 创建时间 */ + private Timestamp createTime; + + /** 修改时间 */ + private Timestamp updateTime; +} \ No newline at end of file diff --git a/youchain-system/src/main/java/com/youchain/basicdata/service/dto/WorkPointQueryCriteria.java b/youchain-system/src/main/java/com/youchain/basicdata/service/dto/WorkPointQueryCriteria.java new file mode 100644 index 0000000..30c16dd --- /dev/null +++ b/youchain-system/src/main/java/com/youchain/basicdata/service/dto/WorkPointQueryCriteria.java @@ -0,0 +1,37 @@ +/* +* Copyright 2019-2020 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package com.youchain.basicdata.service.dto; + +import lombok.Data; +import java.util.List; +import com.youchain.annotation.Query; + +/** +* @website https://eladmin.vip +* @author houjianlan +* @date 2024-09-26 +**/ +@Data +public class WorkPointQueryCriteria{ + + /** 模糊 */ + @Query(type = Query.Type.INNER_LIKE) + private String code; + + /** 精确 */ + @Query + private Long areaId; +} \ No newline at end of file diff --git a/youchain-system/src/main/java/com/youchain/basicdata/service/impl/WorkPointServiceImpl.java b/youchain-system/src/main/java/com/youchain/basicdata/service/impl/WorkPointServiceImpl.java new file mode 100644 index 0000000..3a9a32c --- /dev/null +++ b/youchain-system/src/main/java/com/youchain/basicdata/service/impl/WorkPointServiceImpl.java @@ -0,0 +1,105 @@ +/* +* Copyright 2019-2020 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package com.youchain.basicdata.service.impl; + +import com.youchain.basicdata.domain.WorkPoint; +import com.youchain.exception.EntityExistException; +import com.youchain.utils.*; +import lombok.RequiredArgsConstructor; +import com.youchain.basicdata.repository.WorkPointRepository; +import com.youchain.basicdata.service.WorkPointService; +import com.youchain.basicdata.service.dto.WorkPointDto; +import com.youchain.basicdata.service.dto.WorkPointQueryCriteria; +import com.youchain.basicdata.service.mapstruct.WorkPointMapper; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import java.util.List; +import java.util.Map; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.LinkedHashMap; + +/** +* @website https://eladmin.vip +* @description 服务实现 +* @author houjianlan +* @date 2024-09-26 +**/ +@Service +@RequiredArgsConstructor +public class WorkPointServiceImpl implements WorkPointService { + + private final WorkPointRepository workPointRepository; + private final WorkPointMapper workPointMapper; + + @Override + public Map queryAll(WorkPointQueryCriteria criteria, Pageable pageable){ + Page page = workPointRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); + return PageUtil.toPage(page.map(workPointMapper::toDto)); + } + + @Override + public List queryAll(WorkPointQueryCriteria criteria){ + return workPointMapper.toDto(workPointRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); + } + + @Override + @Transactional + public WorkPointDto findById(Long id) { + WorkPoint workPoint = workPointRepository.findById(id).orElseGet(WorkPoint::new); + ValidationUtil.isNull(workPoint.getId(),"WorkPoint","id",id); + return workPointMapper.toDto(workPoint); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public WorkPointDto create(WorkPoint resources) { + if(workPointRepository.findByCode(resources.getCode()) != null){ + throw new EntityExistException(WorkPoint.class,"code",resources.getCode()); + } + return workPointMapper.toDto(workPointRepository.save(resources)); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(WorkPoint resources) { + WorkPoint workPoint = workPointRepository.findById(resources.getId()).orElseGet(WorkPoint::new); + ValidationUtil.isNull( workPoint.getId(),"WorkPoint","id",resources.getId()); + WorkPoint workPoint1 = null; + workPoint1 = workPointRepository.findByCode(resources.getCode()); + if(workPoint1 != null && !workPoint1.getId().equals(workPoint.getId())){ + throw new EntityExistException(WorkPoint.class,"code",resources.getCode()); + } + workPoint.copy(resources); + workPointRepository.save(workPoint); + } + + @Override + public void deleteAll(Long[] ids) { + for (Long id : ids) { + workPointRepository.deleteById(id); + } + } + + @Override + public void download(List all, HttpServletResponse response) throws Exception { + List> list= ExcelDownUtils.CreateMap(all,"WorkPoint"); + FileUtil.downloadExcel(list, response); + } +} \ No newline at end of file diff --git a/youchain-system/src/main/java/com/youchain/basicdata/service/mapstruct/WorkPointMapper.java b/youchain-system/src/main/java/com/youchain/basicdata/service/mapstruct/WorkPointMapper.java new file mode 100644 index 0000000..a7cbccd --- /dev/null +++ b/youchain-system/src/main/java/com/youchain/basicdata/service/mapstruct/WorkPointMapper.java @@ -0,0 +1,32 @@ +/* +* Copyright 2019-2020 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package com.youchain.basicdata.service.mapstruct; + +import com.youchain.base.BaseMapper; +import com.youchain.basicdata.domain.WorkPoint; +import com.youchain.basicdata.service.dto.WorkPointDto; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +/** +* @website https://eladmin.vip +* @author houjianlan +* @date 2024-09-26 +**/ +@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface WorkPointMapper extends BaseMapper { + +} \ No newline at end of file