| | |
| | | package com.vincent.rsf.server.manager.controller; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.vincent.rsf.framework.common.Cools; |
| | | import com.vincent.rsf.framework.common.R; |
| | | import com.vincent.rsf.framework.exception.CoolException; |
| | | import com.vincent.rsf.server.common.domain.PageResult; |
| | | import com.vincent.rsf.server.common.utils.CommonUtil; |
| | | import com.vincent.rsf.server.common.utils.ExcelUtil; |
| | | import com.vincent.rsf.server.common.annotation.OperationLog; |
| | | import com.vincent.rsf.server.common.domain.BaseParam; |
| | | import com.vincent.rsf.server.common.domain.KeyValVo; |
| | | import com.vincent.rsf.server.common.domain.PageParam; |
| | | import com.vincent.rsf.server.common.utils.FieldsUtils; |
| | | import com.vincent.rsf.server.manager.controller.params.MatnrToGroupParams; |
| | | import com.vincent.rsf.server.manager.entity.Matnr; |
| | | import com.vincent.rsf.server.manager.entity.excel.MatnrsTemplate; |
| | | import com.vincent.rsf.server.manager.service.MatnrService; |
| | | import com.vincent.rsf.server.system.controller.BaseController; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.v3.oas.annotations.security.SecurityRequirement; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.*; |
| | | |
| | |
| | | @PreAuthorize("hasAuthority('manager:matnr:list')") |
| | | @PostMapping("/matnr/page") |
| | | public R page(@RequestBody Map<String, Object> map) { |
| | | // if (!Objects.isNull(map.get("groupId"))) { |
| | | // return R.ok(matnrService.getPages(map)); |
| | | // } else { |
| | | // BaseParam baseParam = buildParam(map, BaseParam.class); |
| | | // PageParam<Matnr, BaseParam> pageParam = new PageParam<>(baseParam, Matnr.class); |
| | | // return R.ok().add(matnrService.getMatnrPage(pageParam, map)); |
| | | // } |
| | | BaseParam baseParam = buildParam(map, BaseParam.class); |
| | | PageParam<Matnr, BaseParam> pageParam = new PageParam<>(baseParam, Matnr.class); |
| | | return R.ok().add(matnrService.page(pageParam, pageParam.buildWrapper(true))); |
| | | return R.ok().add(matnrService.getMatnrPage(pageParam, map)); |
| | | |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:matnr:list')") |
| | |
| | | @PreAuthorize("hasAuthority('manager:matnr:list')") |
| | | @GetMapping("/matnr/{id}") |
| | | public R get(@PathVariable("id") Long id) { |
| | | return R.ok().add(matnrService.getById(id)); |
| | | return R.ok(matnrService.selectMatnrById(id)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:matnr:save')") |
| | | @OperationLog("Create 物料信息表") |
| | | @PostMapping("/matnr/save") |
| | | public R save(@RequestBody Matnr matnr) { |
| | | matnr.setCreateBy(getLoginUserId()); |
| | | matnr.setCreateTime(new Date()); |
| | | matnr.setUpdateBy(getLoginUserId()); |
| | | matnr.setUpdateTime(new Date()); |
| | | if (!matnrService.save(matnr)) { |
| | | return R.error("Save Fail"); |
| | | public R save(@RequestBody Map<String, Object> matnr) { |
| | | if (Objects.isNull(matnr)) { |
| | | throw new CoolException("参数不能为空!!"); |
| | | } |
| | | return R.ok("Save Success").add(matnr); |
| | | if (Objects.isNull(matnr.get("name"))) { |
| | | throw new CoolException("名称不能为空!!"); |
| | | } |
| | | if (Objects.isNull(matnr.get("groupId"))) { |
| | | throw new CoolException("物料分组不能为空!!"); |
| | | } |
| | | matnr.put("createBy", getLoginUserId()); |
| | | matnr.put("updateBy", getLoginUserId()); |
| | | return matnrService.saveMatnrs(matnr); |
| | | |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:matnr:update')") |
| | | @OperationLog("Update 物料信息表") |
| | | @PostMapping("/matnr/update") |
| | | public R update(@RequestBody Matnr matnr) { |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R update(@RequestBody Map<String, Object> params) throws Exception { |
| | | Matnr matnr = JSONObject.parseObject(JSONObject.toJSONString(params), Matnr.class); |
| | | if (Objects.isNull(matnr.getCode())) { |
| | | throw new CoolException("编码不能为空!!"); |
| | | } |
| | | if (Objects.isNull(matnr.getName())) { |
| | | throw new CoolException("名称不能为空!!"); |
| | | } |
| | | matnr.setUpdateBy(getLoginUserId()); |
| | | matnr.setUpdateTime(new Date()); |
| | | |
| | | if (!FieldsUtils.getFieldsSta().isEmpty()) { |
| | | Matnr matnr1 = matnrService.getById(matnr.getId()); |
| | | if (!Objects.isNull(matnr1.getFieldsIndex())) { |
| | | params.put("fieldsIndex", matnr1.getFieldsIndex()); |
| | | } else { |
| | | String uuid16 = CommonUtil.randomUUID16(); |
| | | params.put("index", uuid16); |
| | | matnr.setFieldsIndex(uuid16); |
| | | } |
| | | FieldsUtils.updateFieldsValue(params); |
| | | } |
| | | |
| | | if (!matnrService.updateById(matnr)) { |
| | | return R.error("Update Fail"); |
| | | } |
| | |
| | | return R.ok().add(vos); |
| | | } |
| | | |
| | | @SecurityRequirement(name = HttpHeaders.AUTHORIZATION) |
| | | @PreAuthorize("hasAuthority('manager:matnr:list')") |
| | | @ApiOperation(value = "获取分类物料明细列表") |
| | | @PostMapping("/matnr/group") |
| | |
| | | } |
| | | |
| | | |
| | | @PreAuthorize("hasAuthority('manager:matnr:list')") |
| | | @ApiOperation("绑定物料分组") |
| | | @PostMapping("/matnr/group/bind") |
| | | public R bindMatnrToGroup(@RequestBody MatnrToGroupParams params) { |
| | | if (Objects.isNull(params)) { |
| | | return R.error("参数不能为空!!"); |
| | | } |
| | | if (matnrService.bindMatnrs(params)) { |
| | | return R.ok(); |
| | | } else { |
| | | return R.error("操作失败!!"); |
| | | } |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:matnr:update')") |
| | | @ApiOperation("批量修改") |
| | | @PostMapping("/matnr/batch/update") |
| | | public R batchUpdate(@RequestBody MatnrToGroupParams params) { |
| | | if (Objects.isNull(params)) { |
| | | return R.error("参数不能为空!!"); |
| | | } |
| | | if (Objects.isNull(params.getMatnr())) { |
| | | return R.error("物料属性不能为空!!"); |
| | | } |
| | | if (matnrService.batchUpdate(params)) { |
| | | return R.ok(); |
| | | }else { |
| | | return R.error("操作失败!!"); |
| | | } |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:matnr:list')") |
| | | @ApiOperation("导出物料信息") |
| | | @PostMapping("/matnr/export") |
| | | public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { |
| | | ExcelUtil.build(ExcelUtil.create(matnrService.list(), Matnr.class), response); |
| | | List<Matnr> matnrs = new ArrayList<>(); |
| | | if (!Objects.isNull(map.get("ids"))) { |
| | | matnrs = matnrService.list(new LambdaQueryWrapper<Matnr>().in(Matnr::getId, map.get("ids")).eq(Matnr::getStatus, 1)); |
| | | } else { |
| | | matnrs = matnrService.list(); |
| | | } |
| | | ExcelUtil.build(ExcelUtil.create(matnrs, Matnr.class, false), response); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:matnr:list')") |
| | | @ApiOperation("下载物料模板") |
| | | @PostMapping("/matnr/template/download") |
| | | public void download(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { |
| | | ExcelUtil.build(ExcelUtil.create(null, MatnrsTemplate.class), response); |
| | | } |
| | | |
| | | |
| | | @PreAuthorize("hasAuthority('manager:matnr:update')") |
| | | @ApiOperation(value = "excel表格导入物料信息") |
| | | @PostMapping("/matnr/import") |
| | | public R listImport(MultipartFile file) throws Exception { |
| | | if (Objects.isNull(file)) { |
| | | throw new CoolException("文件不能为空!!"); |
| | | } |
| | | return matnrService.importExcels(file); |
| | | } |
| | | |
| | | } |