yuj 7 лет назад
Родитель
Сommit
77abf2680f

+ 2 - 8
src/main/java/com/uas/platform/b2c/fa/settlement/controller/BillController.java

@@ -1,6 +1,7 @@
 package com.uas.platform.b2c.fa.settlement.controller;
 package com.uas.platform.b2c.fa.settlement.controller;
 
 
 
 
+import com.uas.platform.b2c.common.account.model.User;
 import com.uas.platform.b2c.common.base.model.FileUpload;
 import com.uas.platform.b2c.common.base.model.FileUpload;
 import com.uas.platform.b2c.core.config.SysConf;
 import com.uas.platform.b2c.core.config.SysConf;
 import com.uas.platform.b2c.fa.settlement.model.Bill;
 import com.uas.platform.b2c.fa.settlement.model.Bill;
@@ -72,14 +73,7 @@ public class BillController {
 	@ApiOperation(value = "保存开票资料", httpMethod = "POST")
 	@ApiOperation(value = "保存开票资料", httpMethod = "POST")
 	public Bill saveBill(@ApiParam(required = true, value = "发票信息json") String bill, @ApiParam(required = true, value = "上传的附件") FileUpload uploadItem) {
 	public Bill saveBill(@ApiParam(required = true, value = "发票信息json") String bill, @ApiParam(required = true, value = "上传的附件") FileUpload uploadItem) {
 		Bill b = FastjsonUtils.fromJson(bill, Bill.class);
 		Bill b = FastjsonUtils.fromJson(bill, Bill.class);
-		Long useruu = SystemSession.getUser().getUserUU();
-		Long enuu = SystemSession.getUser().getEnterprise() != null ? SystemSession.getUser().getEnterprise().getUu() : null;
-        if (enuu == null) {
-            b.setDissociative(Type.PERSONAL.value());
-        } else {
-            b.setDissociative(Type.ENTERPRISING.value());
-        }
-		Bill bi = billService.save(b, uploadItem, useruu, enuu);
+		Bill bi = billService.save(b, uploadItem, null, null);
 		logger.log("发票管理", "保存发票资料","保存发票的资料信息,发票的id" + bi.getId() + ",发票开头:" + bi.getHead()+ "发票类型:" + bi.getKind()+ ",操作人:" + SystemSession.getUser().getUserUU());
 		logger.log("发票管理", "保存发票资料","保存发票的资料信息,发票的id" + bi.getId() + ",发票开头:" + bi.getHead()+ "发票类型:" + bi.getKind()+ ",操作人:" + SystemSession.getUser().getUserUU());
 		return bi;
 		return bi;
 	}
 	}

+ 3 - 23
src/main/java/com/uas/platform/b2c/fa/settlement/dao/BillDao.java

@@ -18,23 +18,13 @@ import java.util.List;
 @Repository
 @Repository
 public interface BillDao extends JpaSpecificationExecutor<Bill>, JpaRepository<Bill, Long>{
 public interface BillDao extends JpaSpecificationExecutor<Bill>, JpaRepository<Bill, Long>{
 
 
-    /**
-     * 根据用户UU号和企业UU号获取发票列表
-     *
-     * @param useruu the useruu 个人uu
-     * @param enuu   the enuu 企业enuu
-     * @return the bill by useruu and enuu
-     */
-    public List<Bill> getBillByUseruuAndEnuu(Long useruu, Long enuu);
-
-
 	/**
 	/**
 	 * 根据用户UU号和企业UU号获取发票列表
 	 * 根据用户UU号和企业UU号获取发票列表
 	 *
 	 *
 	 * @param enuu   the enuu 企业enuu
 	 * @param enuu   the enuu 企业enuu
 	 * @return the bill by useruu and enuu
 	 * @return the bill by useruu and enuu
 	 */
 	 */
-	List<Bill> getBillByEnuu(Long enuu);
+	List<Bill> getBillByEnuuAndDissociative(Long enuu, Integer dissociative);
 
 
     /**
     /**
      * 根据个人UU号和是否个人用户获取发票列表
      * 根据个人UU号和是否个人用户获取发票列表
@@ -54,16 +44,6 @@ public interface BillDao extends JpaSpecificationExecutor<Bill>, JpaRepository<B
 	 */
 	 */
 	public List<Bill> getBillByUseruuAndDissociativeAndKind(Long useruu, Integer dissociative, Integer kind);
 	public List<Bill> getBillByUseruuAndDissociativeAndKind(Long useruu, Integer dissociative, Integer kind);
 
 
-    /**
-     * 根据个人UU号和企业UU号和发票类型(增值税专用 和 增值税普通)获取发票列表
-     *
-     * @param useruu the useruu 个人uu
-     * @param enuu   the enuu 企业enuu
-     * @param kind   the kind 发票类型
-     * @return the bill by useruu and enuu and kind
-     */
-    public List<Bill> getBillByUseruuAndEnuuAndKind(Long useruu, Long enuu, Integer kind);
-
 	/**
 	/**
 	 * 根据企业UU号和发票类型(增值税专用 和 增值税普通)获取发票列表
 	 * 根据企业UU号和发票类型(增值税专用 和 增值税普通)获取发票列表
 	 *
 	 *
@@ -71,7 +51,7 @@ public interface BillDao extends JpaSpecificationExecutor<Bill>, JpaRepository<B
 	 * @param kind   the kind 发票类型
 	 * @param kind   the kind 发票类型
 	 * @return the bill by useruu and enuu and kind
 	 * @return the bill by useruu and enuu and kind
 	 */
 	 */
-	List<Bill> getBillByEnuuAndKind(Long enuu, Integer kind);
+	List<Bill> getBillByEnuuAndKindAndDissociative(Long enuu, Integer kind, Integer dissociative);
 
 
     /**
     /**
      * 根据个人UU号和企业UU号和发票类型(增值税专用 和 增值税普通) 和是否个人用户获取发票列表
      * 根据个人UU号和企业UU号和发票类型(增值税专用 和 增值税普通) 和是否个人用户获取发票列表
@@ -82,5 +62,5 @@ public interface BillDao extends JpaSpecificationExecutor<Bill>, JpaRepository<B
      * @return the bill by useruu and enuu and kind and dissociative
      * @return the bill by useruu and enuu and kind and dissociative
      */
      */
     @Query("select b from Bill b where b.useruu=:useruu and b.dissociative=:dissociative and b.kind=:kind")
     @Query("select b from Bill b where b.useruu=:useruu and b.dissociative=:dissociative and b.kind=:kind")
-	public List<Bill> getBillByUseruuAndEnuuAndKindAndDissociative(@Param("useruu") Long useruu, @Param("dissociative") Integer dissociative, @Param("kind") Integer kind);
+	public List<Bill> getBillByUseruuAndKindAndDissociative(@Param("useruu") Long useruu, @Param("dissociative") Integer dissociative, @Param("kind") Integer kind);
 }
 }

+ 33 - 21
src/main/java/com/uas/platform/b2c/fa/settlement/service/impl/BillServiceImpl.java

@@ -1,5 +1,6 @@
 package com.uas.platform.b2c.fa.settlement.service.impl;
 package com.uas.platform.b2c.fa.settlement.service.impl;
 
 
+import com.uas.platform.b2c.common.account.model.User;
 import com.uas.platform.b2c.common.base.model.FileUpload;
 import com.uas.platform.b2c.common.base.model.FileUpload;
 import com.uas.platform.b2c.common.base.service.FileService;
 import com.uas.platform.b2c.common.base.service.FileService;
 import com.uas.platform.b2c.core.config.SysConf;
 import com.uas.platform.b2c.core.config.SysConf;
@@ -45,8 +46,6 @@ public class BillServiceImpl implements BillService {
 
 
 	@Override
 	@Override
 	public Page<Bill> findBills(final PageInfo info, String keyword) {
 	public Page<Bill> findBills(final PageInfo info, String keyword) {
-		// Long enuu = SystemSession.getUser().getEnterprise().getUu();
-		// info.filter("enuu", enuu);
 		if (StringUtils.hasText(keyword)) {
 		if (StringUtils.hasText(keyword)) {
 			info.filter("orderid", keyword);
 			info.filter("orderid", keyword);
 		}
 		}
@@ -62,17 +61,27 @@ public class BillServiceImpl implements BillService {
 	public Bill save(Bill bill, FileUpload fileItem, Long useruu, Long enuu) {
 	public Bill save(Bill bill, FileUpload fileItem, Long useruu, Long enuu) {
 		if (bill.getId() == null) {
 		if (bill.getId() == null) {
 			List<Bill> billList = new ArrayList<Bill>();
 			List<Bill> billList = new ArrayList<Bill>();
-			if (Type.ENTERPRISING.value() == bill.getDissociative())
-				billList = billDao.getBillByEnuuAndKind(enuu, bill.getKind());
-			if (Type.PERSONAL.value() == bill.getDissociative())
-				billList = billDao.getBillByUseruuAndEnuuAndKindAndDissociative(useruu, Type.PERSONAL.value(),bill.getKind());
+			User user = SystemSession.getUser();
+			Long userUu = useruu, enUU = enuu;
+			if ((enUU == null) && (user.getEnterprise() != null)) {
+				userUu = user.getEnterprise().getUu();
+			}
+			if (enUU == null && userUu == null) {
+				userUu = user.getUserUU();
+			}
+			bill.setCreateTime(new Date());
+			if (enUU == null) {
+				bill.setDissociative(Type.PERSONAL.value());
+				bill.setUseruu(userUu);
+				billList = billDao.getBillByUseruuAndKindAndDissociative(user.getUserUU(), Type.PERSONAL.value(),bill.getKind());
+			} else {
+				bill.setDissociative(Type.ENTERPRISING.value());
+				bill.setEnuu(enUU);
+				billList = billDao.getBillByEnuuAndKindAndDissociative(user.getEnterprise().getUu(), bill.getKind(), Type.ENTERPRISING.value());
+			}
 			if (billList.size() > 0) {
 			if (billList.size() > 0) {
 				throw new IllegalOperatorException("相同类型的发票信息不能同时存在两条!");
 				throw new IllegalOperatorException("相同类型的发票信息不能同时存在两条!");
 			}
 			}
-			bill.setCreateTime(new Date());
-			if (Type.ENTERPRISING.value() == bill.getDissociative())
-				bill.setEnuu(enuu);
-			bill.setUseruu(useruu);
 		}
 		}
 		if ((fileItem != null) && (fileItem.getFile() != null)) {
 		if ((fileItem != null) && (fileItem.getFile() != null)) {
 			String attachUrl = fileService.save(fileItem);
 			String attachUrl = fileService.save(fileItem);
@@ -83,9 +92,10 @@ public class BillServiceImpl implements BillService {
 
 
 	@Override
 	@Override
 	public List<Bill> getBills() {
 	public List<Bill> getBills() {
-		Long useruu = SystemSession.getUser().getUserUU();
-		if (SystemSession.getUser().getEnterprise() != null) {
-			return billDao.getBillByEnuu(SystemSession.getUser().getEnterprise().getUu());
+		User user = SystemSession.getUser();
+		Long useruu = user.getUserUU();
+		if (user.getEnterprise() != null) {
+			return billDao.getBillByEnuuAndDissociative(user.getEnterprise().getUu(), Type.ENTERPRISING.value());
 		} else {
 		} else {
 			return billDao.getBillByUseruuAndDissociative(useruu, Type.PERSONAL.value());
 			return billDao.getBillByUseruuAndDissociative(useruu, Type.PERSONAL.value());
 		}
 		}
@@ -108,21 +118,23 @@ public class BillServiceImpl implements BillService {
 
 
 	@Override
 	@Override
 	public List<Bill> getAdminBills() {
 	public List<Bill> getAdminBills() {
-		Long useruu = sysConf.getAdminUU();
-		Long enuu = sysConf.getEnUU();
-		List<Bill> billList = billDao.getBillByUseruuAndEnuu(useruu, enuu);
+		List<Bill> billList = billDao.getBillByEnuuAndDissociative(sysConf.getEnUU(), Type.ENTERPRISING.value());
 		return billList;
 		return billList;
 	}
 	}
 
 
 	@Override
 	@Override
 	public Bill getPersonalSpecial() {
 	public Bill getPersonalSpecial() {
-		Long userUU = SystemSession.getUser().getUserUU();
-		Long uu = SystemSession.getUser().getEnterprise().getUu();
-		List<Bill> billByUseruuAndEnuuAndKind = billDao.getBillByUseruuAndEnuuAndKind(userUU, uu, Type.Bill_Deduct.value());
-		if(CollectionUtils.isEmpty(billByUseruuAndEnuuAndKind)) {
+		User user = SystemSession.getUser();
+		List<Bill> bills = null;
+		if (user.getEnterprise() == null) {
+			bills = billDao.getBillByUseruuAndDissociativeAndKind(user.getUserUU(), Type.PERSONAL.value(), Type.Bill_Deduct.value());
+		} else {
+			bills = billDao.getBillByEnuuAndKindAndDissociative(user.getEnterprise().getUu(), Type.Bill_Deduct.value(), Type.ENTERPRISING.value());
+		}
+		if(CollectionUtils.isEmpty(bills)) {
 			return null;
 			return null;
 		}else {
 		}else {
-			return billByUseruuAndEnuuAndKind.get(0);
+			return bills.get(0);
 		}
 		}
 	}
 	}
 }
 }