|
@@ -0,0 +1,182 @@
|
|
|
+package thyyxxk.webserver.service.reports;
|
|
|
+
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import thyyxxk.webserver.config.exception.ExceptionEnum;
|
|
|
+import thyyxxk.webserver.dao.his.reports.IllegalChargesAnalysisDao;
|
|
|
+import thyyxxk.webserver.entity.ResultVo;
|
|
|
+import thyyxxk.webserver.entity.dictionary.PureCodeName;
|
|
|
+import thyyxxk.webserver.entity.reports.illegalChargesAnalysis.IllegalChargeData;
|
|
|
+import thyyxxk.webserver.entity.reports.illegalChargesAnalysis.IllegalChargeTemplate;
|
|
|
+import thyyxxk.webserver.entity.reports.illegalChargesAnalysis.SearchChargeItem;
|
|
|
+import thyyxxk.webserver.utils.ResultVoUtil;
|
|
|
+import thyyxxk.webserver.utils.StringUtil;
|
|
|
+import thyyxxk.webserver.utils.TokenUtil;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description: 违规收费项目分析实现类
|
|
|
+ * @author: DingJie
|
|
|
+ * @create: 2021-04-15 16:47:34
|
|
|
+ **/
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class IllegalChargesAnalysisService {
|
|
|
+ private final IllegalChargesAnalysisDao dao;
|
|
|
+ private static final String DASH = "_";
|
|
|
+ private static final String ADMIN = "admin";
|
|
|
+ private static final String ADMIN_2 = "admin_2";
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public IllegalChargesAnalysisService(IllegalChargesAnalysisDao dao) {
|
|
|
+ this.dao = dao;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultVo<List<IllegalChargeTemplate>> fetchMyTemplates() {
|
|
|
+ String code = TokenUtil.getTokenUserId() + "%";
|
|
|
+ List<IllegalChargeTemplate> tempList = dao.selectMyTemplates(code);
|
|
|
+ List<IllegalChargeTemplate> resultList = new ArrayList<>();
|
|
|
+ Map<String ,IllegalChargeTemplate> treeMap = new HashMap<>(tempList.size());
|
|
|
+ for (IllegalChargeTemplate item : tempList) {
|
|
|
+ item.analyzeValue();
|
|
|
+ treeMap.put(item.getId(), item);
|
|
|
+ if (null == item.getParent()) {
|
|
|
+ resultList.add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (IllegalChargeTemplate item : tempList) {
|
|
|
+ IllegalChargeTemplate template = treeMap.get(item.getParent());
|
|
|
+ if (null != template) {
|
|
|
+ if (null == template.getChildren()) {
|
|
|
+ template.setChildren(new ArrayList<>());
|
|
|
+ }
|
|
|
+ template.getChildren().add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResultVoUtil.success(resultList);
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultVo<String> insertNewTemplate(IllegalChargeTemplate template) {
|
|
|
+ if (StringUtil.isBlank(template.getLabel())) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "模板名称不能为空!");
|
|
|
+ }
|
|
|
+ if (template.getPersonal() == 0) {
|
|
|
+ dao.insertNewTemplate(template);
|
|
|
+ return ResultVoUtil.success("创建成功。");
|
|
|
+ }
|
|
|
+ StringBuilder id = new StringBuilder(template.getId());
|
|
|
+ if (!id.toString().contains(DASH)) {
|
|
|
+ template.setId(TokenUtil.getTokenUserId() + DASH + id);
|
|
|
+ } else {
|
|
|
+ if (id.toString().startsWith(ADMIN)) {
|
|
|
+ id = new StringBuilder(id.toString().replace(ADMIN, TokenUtil.getTokenUserId()));
|
|
|
+ template.setId(id.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (template.getParent().startsWith(ADMIN) && !template.getParent().equals(ADMIN_2)) {
|
|
|
+ template.setParent(template.getParent().replace("admin", TokenUtil.getTokenUserId()));
|
|
|
+ }
|
|
|
+ id = new StringBuilder(template.getId());
|
|
|
+ String[] idArr = id.toString().split("-");
|
|
|
+ String lastBit = idArr[idArr.length - 1];
|
|
|
+ int position = Integer.parseInt(lastBit);
|
|
|
+ Integer exist = dao.selectCurrentId(id.toString());
|
|
|
+ while (exist != null) {
|
|
|
+ position++;
|
|
|
+ idArr[idArr.length - 1] = String.valueOf(position);
|
|
|
+ id = new StringBuilder();
|
|
|
+ for (int i = 0; i < idArr.length - 1; i++) {
|
|
|
+ id.append(idArr[i]).append("-");
|
|
|
+ }
|
|
|
+ id.append(position);
|
|
|
+ exist = dao.selectCurrentId(id.toString());
|
|
|
+ }
|
|
|
+ template.setId(id.toString());
|
|
|
+ dao.insertNewTemplate(template);
|
|
|
+ return ResultVoUtil.success("创建成功。");
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultVo<String> deleteTemplate(IllegalChargeTemplate template) {
|
|
|
+ String id = template.getId() + "%";
|
|
|
+ dao.deleteTemplate(id);
|
|
|
+ return ResultVoUtil.success("删除成功。");
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultVo<List<PureCodeName>> searchChargeItem(SearchChargeItem param) {
|
|
|
+ String pyCode = "%" + param.getContent().toUpperCase() + "%";
|
|
|
+ switch (param.getMethod()) {
|
|
|
+ case "alpha":
|
|
|
+ return ResultVoUtil.success(dao.selectChargeItemByPyCode(pyCode));
|
|
|
+ case "code":
|
|
|
+ return ResultVoUtil.success(dao.selectChargeItemByCode(pyCode));
|
|
|
+ case "name":
|
|
|
+ return ResultVoUtil.success(dao.selectChargeItemByName(pyCode));
|
|
|
+ default:
|
|
|
+ return ResultVoUtil.success(new ArrayList<>());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultVo<String> saveTemplateChanges(IllegalChargeTemplate template) {
|
|
|
+ if (null == template.getMainCharges() || template.getMainCharges().isEmpty()) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "收费主体不能为空!");
|
|
|
+ }
|
|
|
+ if (null == template.getConflictCharges() || template.getConflictCharges().isEmpty()) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "冲突收费不能为空!");
|
|
|
+ }
|
|
|
+ String value = genTemplateValue(template.getMainCharges()).append("$")
|
|
|
+ .append(genTemplateValue(template.getConflictCharges())).toString();
|
|
|
+ template.setValue(value);
|
|
|
+ dao.updateTemplate(template);
|
|
|
+ return ResultVoUtil.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ private StringBuilder genTemplateValue(List<PureCodeName> charges) {
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
+ for (int i = 0; i < charges.size(); i ++) {
|
|
|
+ PureCodeName charge = charges.get(i);
|
|
|
+ builder.append(charge.getCode()).append("|").append(charge.getName());
|
|
|
+ if (i < charges.size() - 1) {
|
|
|
+ builder.append("#");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return builder;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultVo<List<IllegalChargeData>> analyzeTargetData(IllegalChargeTemplate template) {
|
|
|
+ String start = template.getStart() + " 00:00:00";
|
|
|
+ String end = template.getEnd() + " 23:59:59";
|
|
|
+ List<IllegalChargeData> mainList = new ArrayList<>();
|
|
|
+ for (PureCodeName mainCharge : template.getMainCharges()) {
|
|
|
+ mainList.addAll(dao.selectChargeData(start, end, mainCharge.getCode()));
|
|
|
+ }
|
|
|
+ List<IllegalChargeData> conflictList = new ArrayList<>();
|
|
|
+ for (PureCodeName conflictCharge : template.getConflictCharges()) {
|
|
|
+ conflictList.addAll(dao.selectChargeData(start, end, conflictCharge.getCode()));
|
|
|
+ }
|
|
|
+ Map<String, IllegalChargeData> map = new HashMap<>(mainList.size());
|
|
|
+ for (IllegalChargeData item : mainList) {
|
|
|
+ String key = item.getInpatientNo() + "_" + item.getChargeDay();
|
|
|
+ map.put(key, item);
|
|
|
+ }
|
|
|
+ List<IllegalChargeData> resultList = new ArrayList<>();
|
|
|
+ for (IllegalChargeData item : conflictList) {
|
|
|
+ String key = item.getInpatientNo() + "_" + item.getChargeDay();
|
|
|
+ if (map.containsKey(key)) {
|
|
|
+ IllegalChargeData data = map.get(key);
|
|
|
+ data.setConflictChargeCode(item.getChargeCode());
|
|
|
+ data.setConflictChargeAmount(item.getChargeAmount());
|
|
|
+ data.setConflictChargeDate(item.getChargeDate());
|
|
|
+ data.setConflictChargeFee(item.getChargeFee());
|
|
|
+ data.setConflictChargeName(item.getChargeName());
|
|
|
+ data.setConflictDetailSn(item.getDetailSn());
|
|
|
+ resultList.add(data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResultVoUtil.success(resultList);
|
|
|
+ }
|
|
|
+}
|