|
@@ -4,15 +4,22 @@ import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
+import com.imed.costaccount.common.exception.CostException;
|
|
import com.imed.costaccount.common.util.PageUtils;
|
|
import com.imed.costaccount.common.util.PageUtils;
|
|
import com.imed.costaccount.model.ProductDTO;
|
|
import com.imed.costaccount.model.ProductDTO;
|
|
import com.imed.costaccount.model.User;
|
|
import com.imed.costaccount.model.User;
|
|
|
|
+import com.imed.costaccount.model.dto.ProductEditDTO;
|
|
|
|
+import com.imed.costaccount.model.vo.CommonVO;
|
|
import com.imed.costaccount.model.vo.ProductVO;
|
|
import com.imed.costaccount.model.vo.ProductVO;
|
|
import com.imed.costaccount.utils.BeanUtil;
|
|
import com.imed.costaccount.utils.BeanUtil;
|
|
import io.swagger.models.auth.In;
|
|
import io.swagger.models.auth.In;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.util.Collection;
|
|
|
|
+import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Objects;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
|
@@ -58,20 +65,70 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
* @param user
|
|
* @param user
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
|
|
|
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
public void saveProduct(ProductDTO productDTO, User user) {
|
|
public void saveProduct(ProductDTO productDTO, User user) {
|
|
// 校验code
|
|
// 校验code
|
|
-
|
|
|
|
|
|
+ this.checkProductCode(productDTO.getProductCode(), user.getHospId());
|
|
|
|
+ Product product = BeanUtil.convertObj(productDTO, Product.class);
|
|
|
|
+ product.setCreateTime(System.currentTimeMillis());
|
|
|
|
+ product.setHospId(user.getHospId());
|
|
|
|
+ this.save(product);
|
|
}
|
|
}
|
|
|
|
|
|
- private void checkProductCode(Integer code, Integer hospId) {
|
|
|
|
|
|
+ private void checkProductCode(String code, Integer hospId) {
|
|
List<Product> list = this.list(
|
|
List<Product> list = this.list(
|
|
new LambdaQueryWrapper<Product>()
|
|
new LambdaQueryWrapper<Product>()
|
|
.eq(Product::getProductCode, code)
|
|
.eq(Product::getProductCode, code)
|
|
.eq(Product::getHospId, hospId)
|
|
.eq(Product::getHospId, hospId)
|
|
);
|
|
);
|
|
if (CollUtil.isNotEmpty(list)) {
|
|
if (CollUtil.isNotEmpty(list)) {
|
|
-
|
|
|
|
|
|
+ throw new CostException(500, "成本代码已存在");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 编辑某个成本项目
|
|
|
|
+ *
|
|
|
|
+ * @param productEditDTO
|
|
|
|
+ * @param user
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
|
|
+ public void editProduct(ProductEditDTO productEditDTO, User user) {
|
|
|
|
+ Product byId = this.getById(productEditDTO.getId());
|
|
|
|
+ if (Objects.isNull(byId)) {
|
|
|
|
+ throw new CostException(500, "选中的会计科目不存在");
|
|
|
|
+ }
|
|
|
|
+ this.removeById(productEditDTO.getId());
|
|
|
|
+ this.checkProductCode(productEditDTO.getProductCode(), user.getHospId());
|
|
|
|
+ Product product = byId.setId(null).setHospId(user.getHospId())
|
|
|
|
+ .setProductCode(productEditDTO.getProductCode())
|
|
|
|
+ .setProductName(productEditDTO.getProductName())
|
|
|
|
+ .setCreateTime(System.currentTimeMillis());
|
|
|
|
+ this.save(product);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 修改或新增会计科目对照列表
|
|
|
|
+ *
|
|
|
|
+ * @param user
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public List<CommonVO> getProducts(User user) {
|
|
|
|
+ List<Product> list = this.list(
|
|
|
|
+ new LambdaQueryWrapper<Product>().select(Product::getId, Product::getProductCode, Product::getProductName)
|
|
|
|
+ .eq(Product::getHospId, user.getHospId())
|
|
|
|
+ );
|
|
|
|
+ if (list.isEmpty()) {
|
|
|
|
+ return Collections.emptyList();
|
|
}
|
|
}
|
|
|
|
+ return list.stream().map(i -> {
|
|
|
|
+ CommonVO commonVO = new CommonVO();
|
|
|
|
+ commonVO.setId(i.getId());
|
|
|
|
+ commonVO.setName(i.getProductName() + "[" + i.getProductCode() + "]");
|
|
|
|
+ return commonVO;
|
|
|
|
+ }).collect(Collectors.toList());
|
|
}
|
|
}
|
|
}
|
|
}
|