| | |
| | | import java.net.URLEncoder; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | |
| | | } |
| | | Page<TErpGoods> tErpGoodsPage = new Page<>(query.getPageNum(), query.getPageSize()); |
| | | |
| | | Page<TErpGoods> page = erpGoodsService.page(tErpGoodsPage, new LambdaQueryWrapper<TErpGoods>().eq(TErpGoods::getGoodsSource, 1).eq(BaseModel::getDisabled, 0).isNotNull(TErpGoods::getPlatformCommissionPrice).last(" NOT FIND_IN_SET(" + clinicSupplierId + ",clinic_ids)")); |
| | | Page<TErpGoods> page = erpGoodsService.page(tErpGoodsPage, new LambdaQueryWrapper<TErpGoods>().eq(TErpGoods::getGoodsSource, 1).eq(BaseModel::getDisabled, 0).isNotNull(TErpGoods::getPlatformCommissionPrice).last("and (NOT FIND_IN_SET(" + clinicSupplierId + ",clinic_ids) or clinic_ids is null)")); |
| | | for (TErpGoods record : page.getRecords()) { |
| | | TCrmSupplier byId = crmSupplierService.getById(record.getSupplierClinicId()); |
| | | record.setSupplierName(byId.getSupplierName()); |
| | |
| | | @PostMapping(value = "/add") |
| | | public R<Boolean> add(@Validated @RequestBody TErpGoodsAddDto dto) { |
| | | SysUser user = tokenService.getLoginUser().getUser(); |
| | | if (erpGoodsService.isExit(dto.getGoodsIdCode(), dto.getQuasiNumber())) { |
| | | if (erpGoodsService.isExit(dto.getGoodsIdCode(), dto.getQuasiNumber(),null)) { |
| | | return R.fail("erp商品已存在"); |
| | | } |
| | | Integer roleType = user.getRoleType(); |
| | |
| | | @PostMapping(value = "/clinicAdd") |
| | | public R<Boolean> clinicAdd(@Validated @RequestBody TErpClinicGoodsAddDto dto) { |
| | | SysUser user = tokenService.getLoginUser().getUser(); |
| | | if (erpGoodsService.isExit(dto.getGoodsIdCode(), dto.getQuasiNumber())) { |
| | | if (erpGoodsService.isExit(dto.getGoodsIdCode(), dto.getQuasiNumber(),null)) { |
| | | return R.fail("erp商品已存在"); |
| | | } |
| | | Integer roleType = user.getRoleType(); |
| | |
| | | return R.ok(erpGoodsService.save(goods)); |
| | | } |
| | | |
| | | @ApiOperation(value = "供应商删除商品") |
| | | @ApiOperation(value = "诊所编辑商品") |
| | | @PostMapping(value = "/clinicUpdate") |
| | | public R<Boolean> clinicUpdate(@Validated @RequestBody TErpClinicGoodsUpdateDto dto) { |
| | | SysUser user = tokenService.getLoginUser().getUser(); |
| | | if (erpGoodsService.isExit(dto.getGoodsIdCode(), dto.getQuasiNumber(),dto.getId())) { |
| | | return R.fail("erp商品已存在"); |
| | | } |
| | | Integer roleType = user.getRoleType(); |
| | | TErpGoods goods = new TErpGoods(); |
| | | BeanUtils.copyProperties(dto,goods); |
| | | if(roleType == 5){ |
| | | // 诊所 |
| | | TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class) |
| | | .eq(TCrmClinic::getUserId, user.getUserId()) |
| | | .last("LIMIT 1")); |
| | | goods.setSupplierClinicId(crmClinic.getId()); |
| | | goods.setGoodsSource(2); |
| | | } |
| | | goods.setCreateId(user.getUserId().toString()); |
| | | goods.setGoodsIdCode(dto.getGoodsIdCode()); |
| | | goods.setId(dto.getId()); |
| | | return R.ok(erpGoodsService.updateById(goods)); |
| | | } |
| | | |
| | | @ApiOperation(value = "供应商/诊所 删除商品") |
| | | @DeleteMapping(value = "/delete/{id}") |
| | | public R<Boolean> delete(@PathVariable String id) { |
| | | return R.ok(erpGoodsService.removeById(id)); |
| | | TErpGoods goods = erpGoodsService.getById(id); |
| | | SysUser user = tokenService.getLoginUser().getUser(); |
| | | String cid = null; |
| | | |
| | | if(user.getRoleType() == 5){ |
| | | // 诊所 |
| | | TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class) |
| | | .eq(TCrmClinic::getUserId, user.getUserId()) |
| | | .last("LIMIT 1")); |
| | | cid = crmClinic.getId(); |
| | | if(goods.getGoodsSource()==1){ |
| | | String clinicIds = goods.getClinicIds(); |
| | | String[] split = clinicIds.split(","); |
| | | // clinicIds 移除cid |
| | | ArrayList<String> strings = new ArrayList<>(); |
| | | for (String s : split) { |
| | | if(!s.equals(cid)){ |
| | | strings.add(s); |
| | | } |
| | | } |
| | | goods.setClinicIds(String.join(",",strings)); |
| | | erpGoodsService.updateById(goods); |
| | | }else { |
| | | erpGoodsService.removeById(id); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | erpGoodsService.removeById(id); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @ApiOperation(value = "诊所 一键添加商品") |
| | | @PostMapping(value = "/addSupplierGoods") |
| | | public R<Boolean> addSupplierGoods(String goodsIds) { |
| | | List<String> split = Arrays.asList(goodsIds.split(",")); |
| | | List<TErpGoods> list = erpGoodsService.list(new LambdaQueryWrapper<TErpGoods>().in(TErpGoods::getId, split)); |
| | | SysUser user = tokenService.getLoginUser().getUser(); |
| | | String cid = null; |
| | | |
| | | if(user.getRoleType() == 5){ |
| | | TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class) |
| | | .eq(TCrmClinic::getUserId, user.getUserId()) |
| | | .last("LIMIT 1")); |
| | | cid = crmClinic.getId(); |
| | | for (TErpGoods goods : list) { |
| | | String clinicIds = goods.getClinicIds(); |
| | | List<String> split1 = Arrays.asList(clinicIds.split(",")); |
| | | if(!split1.contains(cid)){ |
| | | split1.add(cid); |
| | | goods.setClinicIds(String.join(",",split1)); |
| | | } |
| | | } |
| | | erpGoodsService.updateBatchById(list); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | |
| | | List<TErpGoodsExcel> carAnnuallyImportExcels = ExcelImportUtil.importExcel(inputStream, TErpGoodsExcel.class, params); |
| | | Set<String> collect = carAnnuallyImportExcels.stream().map(TErpGoodsExcel::getGoodsIdCode).collect(Collectors.toSet()); |
| | | if (collect.size() != carAnnuallyImportExcels.size()) { |
| | | return AjaxResult.error("导入数据中商品标识码重复"); |
| | | return AjaxResult.error("导入数据中商品条码重复"); |
| | | } |
| | | Integer roleType = user.getRoleType(); |
| | | for (TErpGoodsExcel erpGoodsExcel : carAnnuallyImportExcels) { |
| | |
| | | } |
| | | goods.setGoodsName(erpGoodsExcel.getGoodsName()); |
| | | // 判断数据是否正确 |
| | | // 判断标识码是否重复 |
| | | // 判断条码是否重复 |
| | | long count = erpGoodsService.count(new QueryWrapper<TErpGoods>().eq("goods_id_code", erpGoodsExcel.getGoodsIdCode())); |
| | | if(count>0){ |
| | | names.add(erpGoodsExcel.getGoodsName() + " :标识码重复"); |
| | | names.add(erpGoodsExcel.getGoodsName() + " :条码重复"); |
| | | continue; |
| | | } |
| | | goods.setGoodsIdCode(erpGoodsExcel.getGoodsIdCode()); |