Forráskód Böngészése

后勤人员就餐明细详情

yanliming 4 éve
szülő
commit
6062e4ab2e

+ 36 - 34
common/src/main/resources/mapper/base/CanteenDiningRecord.xml

@@ -163,6 +163,9 @@
 			<if test="searchParams.personId != null">
 				and a.person_id = #{searchParams.personId}
 			</if>
+			<if test="searchParams.category != null">
+				and a.category_ = #{searchParams.category}
+			</if>
 			<if test="searchParams.isOutsourcer != null">
 				and a.is_outsourcer = #{searchParams.isOutsourcer}
 			</if>
@@ -436,13 +439,9 @@
         </foreach>
     </select>
 
-
-
-
 	<select id="canteenHqPersonList" parameterType="hashmap" resultType="hashmap">
-
-		SELECT count(a.person_id) as personNum,b.name_ as personName,b.job_number as jobNumber,c.name_ as companyName,a.person_id,
-		(SELECT count(z.person_id) from base_canteen_dining_record z WHERE z.person_id = a.person_id and  z.category_='2' and z.del_flag=FALSE
+		SELECT a.person_id as personId,b.job_number as jobNumber,b.name_ as personName,IFNULL(c.full_name, c.name_) as companyName,
+		(SELECT count(id_) FROM base_canteen_dining_record z WHERE z.person_id=a.person_id and z.del_flag=FALSE and z.category_='2'
 		<if test="searchParams.beginTime != null">
 			<![CDATA[
                   and z.record_time >= #{searchParams.beginTime}
@@ -454,7 +453,7 @@
 				]]>
 		</if>
 		) as 'lunch',
-		(SELECT count(z.person_id) from base_canteen_dining_record z WHERE z.person_id = a.person_id and  z.category_='3' and z.del_flag=FALSE
+		(SELECT count(id_) FROM base_canteen_dining_record z WHERE z.person_id=a.person_id and z.del_flag=FALSE and z.category_='3'
 		<if test="searchParams.beginTime != null">
 			<![CDATA[
                   and z.record_time >= #{searchParams.beginTime}
@@ -466,7 +465,31 @@
 				]]>
 		</if>
 		) as 'supper',
-		(SELECT count(z.person_id) from base_canteen_dining_record z WHERE z.person_id = a.person_id and  z.category_='4' and z.del_flag=FALSE
+		(SELECT count(id_) FROM base_canteen_dining_record z WHERE z.person_id=a.person_id and z.del_flag=FALSE and z.category_='4'
+		<if test="searchParams.beginTime != null">
+			<![CDATA[
+                  and z.record_time >= #{searchParams.beginTime}
+             ]]>
+		</if>
+		<if test="searchParams.endTime != null">
+			<![CDATA[
+				and z.record_time <= #{searchParams.endTime}
+			]]>
+		</if>
+		) as 'nightSnack',
+		(SELECT count(id_) FROM base_canteen_dining_record z WHERE z.person_id=a.person_id and z.del_flag=FALSE
+		<if test="searchParams.beginTime != null">
+			<![CDATA[
+                  and z.record_time >= #{searchParams.beginTime}
+             ]]>
+		</if>
+		<if test="searchParams.endTime != null">
+			<![CDATA[
+				and z.record_time <= #{searchParams.endTime}
+			]]>
+		</if>
+		) as 'personNum',
+		(SELECT IFNULL(sum(z.category_amount), 0.0) FROM base_canteen_dining_record z WHERE z.person_id=a.person_id and z.del_flag=FALSE
 		<if test="searchParams.beginTime != null">
 			<![CDATA[
                   and z.record_time >= #{searchParams.beginTime}
@@ -477,39 +500,18 @@
 				and z.record_time <= #{searchParams.endTime}
 			]]>
 		</if>
-		) as 'nightSnack'
-		FROM base_canteen_dining_record a
-		inner join base_person_info b on a.person_id=b.id_
-		inner join base_company_info c on b.company_id = c.id_
+		) as 'totalFee'
+		FROM base_hq_person a
+		left join base_person_info b on a.person_id=b.id_
+		left join base_company_info c on b.company_id=c.id_
 		<where>
 			a.del_flag = FALSE and b.del_flag = FALSE and c.del_flag = FALSE
 			<if test='searchParams.companyCode!=null'>
 				and c.code_ like #{searchParams.companyCode}
 			</if>
 			<if test="searchParams.hqStatus != null">
-				and a.person_id in(
-				select person_id from base_hq_person
-				where hq_status=#{searchParams.hqStatus}
-				and del_flag=0
-				)
-			</if>
-			<if test="searchParams.querHq != null">
-				and a.person_id in(
-				select person_id from base_hq_person
-				where del_flag=0
-				)
-			</if>
-			<if test="searchParams.beginTime != null">
-				<![CDATA[
-                  and a.record_time >= #{searchParams.beginTime}
-                ]]>
-			</if>
-			<if test="searchParams.endTime != null">
-				<![CDATA[
-                  and a.record_time <= #{searchParams.endTime}
-                ]]>
+				and a.hq_status = #{searchParams.hqStatus}
 			</if>
-			GROUP BY a.person_id
 		</where>
 		<foreach item="sort" collection="sortList"  open="order by" separator=",">
 			${sort.name} ${sort.order}

+ 173 - 81
web/src/main/java/com/jpsoft/shinestar/modules/base/controller/CanteenRearServiceController.java

@@ -4,14 +4,8 @@ package com.jpsoft.shinestar.modules.base.controller;
 import com.github.pagehelper.Page;
 import com.github.pagehelper.util.StringUtil;
 import com.jpsoft.shinestar.config.OSSConfig;
-import com.jpsoft.shinestar.modules.base.entity.CanteenDining;
-import com.jpsoft.shinestar.modules.base.entity.CanteenDiningRecord;
-import com.jpsoft.shinestar.modules.base.entity.CanteenInfo;
-import com.jpsoft.shinestar.modules.base.entity.CompanyInfo;
-import com.jpsoft.shinestar.modules.base.service.CanteenDiningRecordService;
-import com.jpsoft.shinestar.modules.base.service.CanteenDiningService;
-import com.jpsoft.shinestar.modules.base.service.CanteenInfoService;
-import com.jpsoft.shinestar.modules.base.service.CompanyInfoService;
+import com.jpsoft.shinestar.modules.base.entity.*;
+import com.jpsoft.shinestar.modules.base.service.*;
 import com.jpsoft.shinestar.modules.common.dto.MessageResult;
 import com.jpsoft.shinestar.modules.common.dto.Sort;
 import com.jpsoft.shinestar.modules.common.utils.OSSUtil;
@@ -33,6 +27,7 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -54,7 +49,7 @@ public class CanteenRearServiceController {
     private CompanyInfoService companyInfoService;
 
     @Autowired
-    private CanteenDiningService canteenDiningService;
+    private PersonInfoService personInfoService;
 
     @ApiOperation(value="食堂后勤人员就餐明细表")
     @RequestMapping(value = "canteenRearServiceList",method = RequestMethod.POST)
@@ -74,12 +69,9 @@ public class CanteenRearServiceController {
         try {
 
             Map<String, Object> searchParams = new HashMap<>();
-            Map<String, Object> searchParams1 = new HashMap<>();
-            Map<String, Object> searchParams2 = new HashMap<>();
-            Map<String, Object> searchParams3 = new HashMap<>();
 
             List<Sort> sortList = new ArrayList<>();
-            sortList.add(new Sort("a.create_time", "desc"));
+            sortList.add(new Sort("b.hq_sort_no", "asc"));
 
             if (StringUtils.isNotEmpty(recordTimeRange)) {
                 String[] timeRangeArray = recordTimeRange.split(",");
@@ -97,15 +89,6 @@ public class CanteenRearServiceController {
 
                 searchParams.put("beginTime", beginTime);
                 searchParams.put("endTime", endTime);
-
-                searchParams1.put("beginTime", beginTime);
-                searchParams1.put("endTime", endTime);
-
-                searchParams2.put("beginTime", beginTime);
-                searchParams2.put("endTime", endTime);
-
-                searchParams3.put("beginTime", beginTime);
-                searchParams3.put("endTime", endTime);
             }
 
 
@@ -125,86 +108,195 @@ public class CanteenRearServiceController {
                     searchParams.put("hqStatus", parentCompanyInfo.getClassify());
                 }
             }
-            else{
-                searchParams.put("querHq", "yes");
-            }
 
             Page<Map> page = canteenDiningRecordService.canteenHqPersonList(searchParams, pageIndex, pageSize, true, sortList);
 
             List<Map> mapList = new ArrayList<>();
 
-            //行政食堂
-            List<CanteenDining> canteenDiningList = canteenDiningService.findByCanteenId("2");
-
-            BigDecimal lunFee = BigDecimal.ZERO;
-            BigDecimal supFee = BigDecimal.ZERO;
+            for (Map map : page) {
+                mapList.add(map);
+            }
 
-            for (CanteenDining canteenDining:canteenDiningList) {
-                if(canteenDining.getDiningType().equals("2")){
-                    lunFee = canteenDining.getOutsourcerDiningFee();
-                }
-                else if(canteenDining.getDiningType().equals("3")){
-                    supFee = canteenDining.getOutsourcerDiningFee();
-                }
+            if(exportFlag) {
+                String filePath = canteenExportXls(mapList);
+                msgResult.setData(filePath);
+            }
+            else{
+                Map<String, Object> dataMap = PojoUtils.pageWrapper(page);
+                dataMap.put("data", mapList);
+                msgResult.setData(dataMap);
             }
 
+            msgResult.setResult(true);
+        }
+        catch (Exception ex) {
+            logger.error(ex.getMessage(), ex);
+            msgResult.setResult(false);
+        }
+
+        return msgResult;
 
-            for (Map map : page) {
-                if(map.get("person_id")!=null){
-                    Long personId = Long.parseLong(map.get("person_id").toString());
+    }
+
+
+    private String canteenExportXls(List<Map> mapList) throws IOException {
+        String downloadUrl = "";
+
+        Workbook workbook = new HSSFWorkbook();
+        Sheet sheet = workbook.createSheet();
+
+        //表头
+        Row rowTitle = sheet.createRow(0);
+
+        String[] titles = new String[]{"序号","部门","工号","姓名","中餐就餐总数","晚餐就餐总数", "宵夜就餐总数","总计总数","就餐金额(元)",};
+
+        for (int i=0;i<titles.length;i++) {
+            Cell cell = rowTitle.createCell(i);
+            cell.setCellValue(titles[i]);
+        }
+
+        for (int i=0;i<mapList.size();i++){
+            Map<String,Object> map = mapList.get(i);
+
+            Row row = sheet.createRow(i+1);
+
+            int colIndex = 0;
+            row.createCell(colIndex++).setCellValue(i+1);
+            row.createCell(colIndex++).setCellValue(com.jpsoft.shinestar.modules.common.utils.StringUtils.strValue(map.get("companyName"),""));
+            row.createCell(colIndex++).setCellValue(com.jpsoft.shinestar.modules.common.utils.StringUtils.strValue(map.get("jobNumber"),""));
+            row.createCell(colIndex++).setCellValue(com.jpsoft.shinestar.modules.common.utils.StringUtils.strValue(map.get("personName"),""));
+            row.createCell(colIndex++).setCellValue(com.jpsoft.shinestar.modules.common.utils.StringUtils.strValue(map.get("lunch"),""));
+            row.createCell(colIndex++).setCellValue(com.jpsoft.shinestar.modules.common.utils.StringUtils.strValue(map.get("supper"),""));
+            row.createCell(colIndex++).setCellValue(com.jpsoft.shinestar.modules.common.utils.StringUtils.strValue(map.get("nightSnack"),""));
+            row.createCell(colIndex++).setCellValue(com.jpsoft.shinestar.modules.common.utils.StringUtils.strValue(map.get("personNum"),""));
+            row.createCell(colIndex++).setCellValue(com.jpsoft.shinestar.modules.common.utils.StringUtils.strValue(map.get("totalFee"),""));
+        }
 
-                    searchParams1.put("personId", personId);
-                    searchParams2.put("personId", personId);
-                    searchParams3.put("personId", personId);
+        ByteArrayOutputStream output = new ByteArrayOutputStream();
+
+        try {
+            workbook.write(output);
 
-                    //总数
-                    int countTotal = canteenDiningRecordService.findCountByPersonIdAndAddress(searchParams1);
+            byte[] buffer = output.toByteArray();
+            ByteArrayInputStream input = new ByteArrayInputStream(buffer);
+
+            downloadUrl = OSSUtil.upload(ossConfig,"canteenRearService","后勤人员就餐统计表.xls",input);
+        }
+        catch (Exception ex){
+            logger.error(ex.getMessage(),ex);
+        }
 
-                    searchParams2.put("category", "2");
-                    searchParams2.put("address", "行政食堂%");
+        return downloadUrl;
+    }
 
-                    //中餐
-                    int countLun = canteenDiningRecordService.findCountByPersonIdAndAddress(searchParams2);
 
-                    searchParams3.put("category", "3");
-                    searchParams3.put("address", "行政食堂%");
 
-                    //晚餐
-                    int countSup = canteenDiningRecordService.findCountByPersonIdAndAddress(searchParams3);
 
+    @ApiOperation(value="食堂后勤人员就餐详情")
+    @RequestMapping(value = "canteenRearServiceDetail",method = RequestMethod.POST)
+    public MessageResult<Object> canteenRearServiceDetail(
+            String recordTimeRange,String personId,String categoryStr,
+            @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
+            @RequestParam(value="pageSize",defaultValue="20") int pageSize,
+            @RequestParam(value = "exportFlag", defaultValue = "false") Boolean exportFlag,
+            @RequestAttribute String subject) {
 
-                    BigDecimal decLun = BigDecimal.valueOf(countLun);
-                    BigDecimal decSup = BigDecimal.valueOf(countSup);
+        //当前用户ID
+        System.out.println(subject);
 
-                    int countOther = countTotal - countLun - countSup;
+        MessageResult<Object> msgResult = new MessageResult<>();
 
-                    BigDecimal decOther = BigDecimal.valueOf(countOther);
 
-                    BigDecimal totalFee = BigDecimal.ZERO;
+        try {
 
-                    totalFee = totalFee.add(lunFee.multiply(decLun));
-                    totalFee = totalFee.add(supFee.multiply(decSup));
-                    totalFee = totalFee.add(decOther);
+            Map<String, Object> searchParams = new HashMap<>();
 
-                    map.put("totalFee",totalFee);
+            List<Sort> sortList = new ArrayList<>();
+            sortList.add(new Sort("record_time", "desc"));
 
-//                    List<CanteenDiningRecord> list = canteenDiningRecordService.findByPersonId(personId);
-//                    for (CanteenDiningRecord canteenDiningRecord:list) {
-//                        if (canteenDiningRecord.getCategory().equals("2") && canteenDiningRecord.getAddress().contains("行政食堂")) {
-//                            totalFee = totalFee.add(lunFee);
-//                        } else if (canteenDiningRecord.getCategory().equals("3") && canteenDiningRecord.getAddress().contains("行政食堂")) {
-//                            totalFee = totalFee.add(supFee);
-//                        } else {
-//                            totalFee = totalFee.add(BigDecimal.ONE);
-//                        }
-//                    }
+            if (StringUtils.isNotEmpty(recordTimeRange)) {
+                String[] timeRangeArray = recordTimeRange.split(",");
+                String beginTime = "";
+                String endTime = "";
+                beginTime+=" 00:00:00";
+                if (timeRangeArray.length == 1) {
+                    beginTime = timeRangeArray[0];
+                } else if (timeRangeArray.length == 2) {
+                    beginTime = timeRangeArray[0];
+                    endTime = timeRangeArray[1];
+                    beginTime+=" 00:00:00";
+                    endTime+=" 23:59:59";
                 }
 
+                searchParams.put("beginTime", beginTime);
+                searchParams.put("endTime", endTime);
+            }
+
+
+            searchParams.put("personId", personId);
+
+            if(StringUtils.isNotEmpty(categoryStr)){
+                searchParams.put("category", categoryStr);
+            }
+
+
+            Page<CanteenDiningRecord> page = canteenDiningRecordService.pageSearch(searchParams, pageIndex, pageSize, true, sortList);
+
+            List<Map> mapList = new ArrayList<>();
+
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+
+            for (CanteenDiningRecord canteenDiningRecord : page) {
+                Map map = new HashMap();
+                String personName="";
+                String jobNumber="";
+                String companyName="";
+                String recordTime="";
+                String categoryN="";
+
+                PersonInfo personInfo = personInfoService.get(canteenDiningRecord.getPersonId());
+                if(personInfo!=null){
+                    personName = personInfo.getName();
+                    jobNumber = personInfo.getJobNumber();
+
+                    CompanyInfo companyInfo = companyInfoService.get(personInfo.getCompanyId());
+                    if(companyInfo!=null){
+                        if(StringUtils.isNotEmpty(companyInfo.getFullName())){
+                            companyName = companyInfo.getFullName();
+                        }
+                        else{
+                            companyName = companyInfo.getName();
+                        }
+                    }
+                }
+
+                map.put("companyName",companyName);
+                map.put("personName",personName);
+                map.put("jobNumber",jobNumber);
+                if(StringUtils.isNotEmpty(canteenDiningRecord.getCategory())){
+                    if(canteenDiningRecord.getCategory().equals("2")){
+                        categoryN="中餐";
+                    }
+                    else if(canteenDiningRecord.getCategory().equals("3")){
+                        categoryN="晚餐";
+                    }
+                    else if(canteenDiningRecord.getCategory().equals("4")){
+                        categoryN="宵夜";
+                    }
+                }
+                map.put("category",categoryN);
+                map.put("categoryAmount",canteenDiningRecord.getCategoryAmount());
+                if(canteenDiningRecord.getRecordTime()!=null){
+                    recordTime = sdf.format(canteenDiningRecord.getRecordTime());
+                }
+                map.put("recordTime",recordTime);
+                map.put("address",canteenDiningRecord.getAddress());
+
                 mapList.add(map);
             }
 
             if(exportFlag) {
-                String filePath = canteenExportXls(mapList);
+                String filePath = canteenDetailExportXls(mapList);
                 msgResult.setData(filePath);
             }
             else{
@@ -225,7 +317,8 @@ public class CanteenRearServiceController {
     }
 
 
-    private String canteenExportXls(List<Map> mapList) throws IOException {
+
+    private String canteenDetailExportXls(List<Map> mapList) throws IOException {
         String downloadUrl = "";
 
         Workbook workbook = new HSSFWorkbook();
@@ -234,7 +327,7 @@ public class CanteenRearServiceController {
         //表头
         Row rowTitle = sheet.createRow(0);
 
-        String[] titles = new String[]{"序号","部门","工号","姓名","中餐就餐总数","晚餐就餐总数", "宵夜就餐总数","总计总数","就餐金额(元)",};
+        String[] titles = new String[]{"序号","部门","工号","姓名","就餐时间","就餐地点", "餐别","就餐金额(元)",};
 
         for (int i=0;i<titles.length;i++) {
             Cell cell = rowTitle.createCell(i);
@@ -251,11 +344,10 @@ public class CanteenRearServiceController {
             row.createCell(colIndex++).setCellValue(com.jpsoft.shinestar.modules.common.utils.StringUtils.strValue(map.get("companyName"),""));
             row.createCell(colIndex++).setCellValue(com.jpsoft.shinestar.modules.common.utils.StringUtils.strValue(map.get("jobNumber"),""));
             row.createCell(colIndex++).setCellValue(com.jpsoft.shinestar.modules.common.utils.StringUtils.strValue(map.get("personName"),""));
-            row.createCell(colIndex++).setCellValue(com.jpsoft.shinestar.modules.common.utils.StringUtils.strValue(map.get("lunch"),""));
-            row.createCell(colIndex++).setCellValue(com.jpsoft.shinestar.modules.common.utils.StringUtils.strValue(map.get("supper"),""));
-            row.createCell(colIndex++).setCellValue(com.jpsoft.shinestar.modules.common.utils.StringUtils.strValue(map.get("nightSnack"),""));
-            row.createCell(colIndex++).setCellValue(com.jpsoft.shinestar.modules.common.utils.StringUtils.strValue(map.get("personNum"),""));
-            row.createCell(colIndex++).setCellValue(com.jpsoft.shinestar.modules.common.utils.StringUtils.strValue(map.get("totalFee"),""));
+            row.createCell(colIndex++).setCellValue(com.jpsoft.shinestar.modules.common.utils.StringUtils.strValue(map.get("recordTime"),""));
+            row.createCell(colIndex++).setCellValue(com.jpsoft.shinestar.modules.common.utils.StringUtils.strValue(map.get("address"),""));
+            row.createCell(colIndex++).setCellValue(com.jpsoft.shinestar.modules.common.utils.StringUtils.strValue(map.get("category"),""));
+            row.createCell(colIndex++).setCellValue(com.jpsoft.shinestar.modules.common.utils.StringUtils.strValue(map.get("categoryAmount"),""));
         }
 
         ByteArrayOutputStream output = new ByteArrayOutputStream();
@@ -266,7 +358,7 @@ public class CanteenRearServiceController {
             byte[] buffer = output.toByteArray();
             ByteArrayInputStream input = new ByteArrayInputStream(buffer);
 
-            downloadUrl = OSSUtil.upload(ossConfig,"canteenRearService","后勤人员就餐统计表.xls",input);
+            downloadUrl = OSSUtil.upload(ossConfig,"canteenRearServiceDetail","后勤人员就餐详情表.xls",input);
         }
         catch (Exception ex){
             logger.error(ex.getMessage(),ex);