Browse Source

任务工时开发

anderx 7 years ago
parent
commit
62f906ff93

+ 7 - 0
src/main/java/com/goafanti/common/dao/TTaskHoursMapper.java

@@ -2,6 +2,9 @@ package com.goafanti.common.dao;
 
 import com.goafanti.common.model.TTaskHours;
 import com.goafanti.common.model.TTaskHoursExample;
+import com.goafanti.order.bo.TOrderNewBo;
+import com.goafanti.order.bo.TOrderTaskListBo;
+
 import java.util.List;
 import org.apache.ibatis.annotations.Param;
 
@@ -74,4 +77,8 @@ public interface TTaskHoursMapper {
 	int updateByPrimaryKey(TTaskHours record);
 
 	String getTaskSuperHours(String id);
+
+	List<TOrderTaskListBo> getOrderDunData(String name, String taskId, String starTime, String endTime);
+
+	List<TOrderTaskListBo> getTaskHoursData( @Param("name")String name,  @Param("taskId")String taskId,  @Param("starTime")String starTime,  @Param("endTime")String endTime);
 }

+ 3 - 3
src/main/java/com/goafanti/common/mapper/TOrderNewMapper.xml

@@ -1134,7 +1134,7 @@
     date_format(a.start_time, '%Y-%m-%d') as startDate
     from t_order_dun a left join t_order_new b on a.order_no=b.order_no
     left join `user` c on b.buyer_id=c.id 
-    left join admin d on b.salesman_id=c.id
+    left join admin d on b.salesman_id=d.id
     where a.start_time is not null and b.delete_sign = 0
     <if test="name != null">
   	and c.nickname like CONCAT('%',#{name,jdbcType=VARCHAR},'%')
@@ -1156,7 +1156,7 @@
 		count(*)
     from t_order_dun a left join t_order_new b on a.order_no=b.order_no
     left join `user` c on b.buyer_id=c.id 
-    where b.delete_sign = 0
+    where a.start_time is not null and b.delete_sign = 0
     <if test="name != null">
   	and c.nickname like CONCAT('%',#{name,jdbcType=VARCHAR},'%')
   	</if>
@@ -1164,7 +1164,7 @@
   	and a.order_no = #{orderNo,jdbcType=VARCHAR}
   	</if>
   	<if test="starTime !=null and endTime !=null">
-	and b.sign_time between #{starTime,jdbcType=VARCHAR} and #{endTime,jdbcType=VARCHAR}
+  	and b.sign_time between #{starTime,jdbcType=VARCHAR} and #{endTime,jdbcType=VARCHAR}
   	</if>
   </select>
   

+ 21 - 0
src/main/java/com/goafanti/common/mapper/TTaskHoursMapper.xml

@@ -320,4 +320,25 @@
     left join t_order_task b on a.task_id=b.id
     where b.super_id=#{id,jdbcType=VARCHAR}
   </select>
+  <select id="getTaskHoursData" resultType="com.goafanti.order.bo.TOrderTaskListBo">
+  select  a.id,a.commodity_name as taskName,a.order_no as orderNo,c.cname,d.name as receiverName,
+    a.task_status as taskStatus,f.nickname as userName,ifnull(g.hours,0) as hours,a.commodity_quantity as commodityQuantity
+  	from t_order_task a left join business_project b on a.commodity_id=b.id
+  	left join business_category c on b.cid=c.id
+    left join admin d on a.task_receiver=d.id
+    left join t_order_new e on a.order_no=e.order_no
+    left join user f on e.buyer_id=f.id
+    left join (select task_id,sum(hours) as hours from t_task_hours group by task_id) g on a.id=g.task_id
+    where e.delete_sign=0 and a.super_id is null
+    <if test="name != null">
+  	and f.nickname like CONCAT('%',#{name,jdbcType=VARCHAR},'%')
+  	</if>
+  	<if test="taskId != null">
+  	and a.id= #{taskId,jdbcType=VARCHAR}
+  	</if>
+  	<if test="starTime !=null and endTime !=null">
+  	and a.task_start_time between #{starTime,jdbcType=VARCHAR} and #{endTime,jdbcType=VARCHAR}
+  	</if>
+  	order by  a.task_start_time desc
+  </select>
 </mapper>

+ 17 - 0
src/main/java/com/goafanti/common/task/OrderTaskDun.java

@@ -0,0 +1,17 @@
+package com.goafanti.common.task;
+
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+@Component
+//@Controller
+public class OrderTaskDun {
+
+	
+	
+	
+	@Scheduled(cron = "0 0 2  * * ?") 
+	public void updatrTaskDun(){
+		
+	}
+}

+ 43 - 0
src/main/java/com/goafanti/common/utils/ExportExcelUtil.java

@@ -23,9 +23,11 @@ import org.apache.poi.ss.util.CellRangeAddress;
 
 import com.goafanti.common.model.TOrderBillNew;
 import com.goafanti.order.bo.TOrderNewBo;
+import com.goafanti.order.bo.TOrderTaskListBo;
 import com.goafanti.order.enums.LiquidationNewState;
 import com.goafanti.order.enums.OrderNewState;
 import com.goafanti.order.enums.ProjectNewStage;
+import com.goafanti.techproject.enums.TaskState;
 
 public class ExportExcelUtil {
 	
@@ -268,6 +270,47 @@ public class ExportExcelUtil {
 		if ("29".equals(dunSubject)) return "项目拨款";
 		return "";
 	}
+
+	public static HSSFWorkbook exportTaskHoursListData(List<TOrderTaskListBo> list, String[] comment, String filePath) {
+
+		//map 数据 comment表头 (列名称)
+ 		//1,创建一个workbook,对应的是一个excel文件
+		HSSFWorkbook wb = new HSSFWorkbook();
+		//2.创建一个sheet
+			HSSFSheet sheet = wb.createSheet();
+			//创建表头
+			HSSFCellStyle style1 = setCellStyle1(wb);
+			HSSFRow row = sheet.createRow(0);
+			for(int i = 0; i < comment.length; i++){
+				sheet.setColumnWidth(i, 3000);//设置列宽
+				HSSFCell c = row.createCell(i);
+				c.setCellValue(comment[i]);
+				c.setCellStyle(style1);
+			}
+			for (TOrderTaskListBo ob : list) {
+				//新增一行
+				HSSFRow r = sheet.createRow(sheet.getLastRowNum()+1);
+				for (int i = 0; i < comment.length; i++) {
+					//当前列的只
+					String o ;
+					switch (comment[i]) {
+					//"任务编号","任务名称","订单编号","业务别类","客户名称","任务负责人","任务状态","工时"
+					case "任务编号": o = ob.getId(); break;
+					case "任务名称": o = ob.getTaskName(); break;
+					case "订单编号": o = ob.getOrderNo(); break;
+					case "业务别类": o = ob.getCname();break;
+					case "客户名称": o = ob.getUserName(); break;
+					case "任务负责人": o = ob.getReceiverName(); break;
+					case "任务状态": o = TaskState.getValueByCode(ob.getTaskStatus()); break;
+					case "工时": o = ob.getHours(); break;
+					default: o = ""; break;
+					}
+					HSSFCell c = r.createCell(i);
+					c.setCellValue(o);
+				}
+			}
+		return wb;
+	}
 	
 	
 }

+ 1 - 1
src/main/java/com/goafanti/order/controller/AdminNewOrderApiController.java

@@ -28,7 +28,7 @@ import com.goafanti.order.enums.OrderNewState;
 import com.goafanti.order.service.OrderNewService;
 
 @RestController
-@RequestMapping(value = "/open/api/admin/newOrder")
+@RequestMapping(value = "/api/admin/newOrder")
 public class AdminNewOrderApiController extends CertifyApiController {
 	
 	@Autowired

+ 33 - 0
src/main/java/com/goafanti/order/controller/OrderProjectApiController.java

@@ -1,11 +1,16 @@
 package com.goafanti.order.controller;
 
 
+import java.io.IOException;
+import java.io.OutputStream;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.Date;
 
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
@@ -115,4 +120,32 @@ public class OrderProjectApiController extends CertifyApiController {
 		res.setData(handleFile(res, "/order_task_file/", false, req, sign));
 		return res;
 	}
+	/**
+	 * 任务工时表
+	 * @throws IOException 
+	 */
+	@RequestMapping(value = "/exportTaskHoursListData", method = RequestMethod.POST)
+	public Result exportTaskHoursListData(String name, String taskId ,String starTime,String endTime ,HttpServletResponse response) throws IOException{
+		 Result res = new Result();
+		 HSSFWorkbook wb = orderProjectService.exportTaskHoursListData( name, taskId, starTime, endTime);
+		 if(null == wb){
+			 res.getError().add(buildError("", "没有找到数据"));
+			 return res;
+		 }
+		 String fileName = "任务工时表  " + new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + ".xls";
+		 OutputStream out = response.getOutputStream();
+		 response.addHeader("Content-Disposition", "attachment;filename="  + new String(fileName.getBytes(),"iso-8859-1"));  
+         response.setContentType("application/octet-stream;charset=utf-8");  
+		try {
+			// 返回数据流
+			wb.write(out);
+			out.flush();
+			out.close();
+		} finally {
+			out.flush();
+			out.close();
+		}
+		
+		return res;
+	}
 }

+ 4 - 1
src/main/java/com/goafanti/order/service/OrderProjectService.java

@@ -1,8 +1,9 @@
 package com.goafanti.order.service;
 
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+
 import com.goafanti.common.model.TTaskHours;
 import com.goafanti.core.mybatis.page.Pagination;
-import com.goafanti.order.bo.TOrderTaskBo;
 import com.goafanti.order.bo.TOrderTaskDetailBo;
 import com.goafanti.order.bo.TOrderTaskListBo;
 
@@ -21,5 +22,7 @@ public interface OrderProjectService {
 	
 	Pagination<TOrderTaskListBo> taskHoursList(String name, String taskId,String starTime,String endTime ,
 			Integer pageNo, Integer pageSize);
+
+	HSSFWorkbook exportTaskHoursListData(String name, String taskId, String starTime, String endTime);
 	
 }

+ 2 - 1
src/main/java/com/goafanti/order/service/impl/OrderNewServiceImpl.java

@@ -472,7 +472,7 @@ public class OrderNewServiceImpl extends BaseMybatisDao<TOrderNewMapper> impleme
 	@Override
 	public HSSFWorkbook exportOrderDunData(String name, String orderNo, String starTime, String endTime) {
 		if(endTime!=null) endTime=endTime+" 23:59:59";
-		List<TOrderNewBo> list=tOrderDunMapper.getOrderDunData( name,  orderNo,  starTime,  endTime);
+		List<TOrderNewBo> list=tOrderDunMapper.getOrderDunData(name,orderNo,starTime,endTime);
 		if (list==null && list.size()==0) {
 			return null;
 		}
@@ -484,4 +484,5 @@ public class OrderNewServiceImpl extends BaseMybatisDao<TOrderNewMapper> impleme
 	
 	
 	
+	
 }

+ 20 - 2
src/main/java/com/goafanti/order/service/impl/OrderProjectServiceImpl.java

@@ -13,7 +13,9 @@ import org.apache.commons.beanutils.BeanUtils;
 import org.apache.commons.beanutils.ConvertUtils;
 import org.apache.commons.beanutils.converters.DateConverter;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -23,16 +25,15 @@ import com.goafanti.common.dao.TTaskHoursMapper;
 import com.goafanti.common.model.TOrderNew;
 import com.goafanti.common.model.TOrderTask;
 import com.goafanti.common.model.TTaskHours;
+import com.goafanti.common.utils.ExportExcelUtil;
 import com.goafanti.core.mybatis.BaseMybatisDao;
 import com.goafanti.core.mybatis.page.Pagination;
 import com.goafanti.core.shiro.token.TokenManager;
 import com.goafanti.order.bo.TOrderNewBo;
-import com.goafanti.order.bo.TOrderRefundBo;
 import com.goafanti.order.bo.TOrderTaskBo;
 import com.goafanti.order.bo.TOrderTaskDetailBo;
 import com.goafanti.order.bo.TOrderTaskListBo;
 import com.goafanti.order.enums.ProcessStatus;
-import com.goafanti.order.enums.ProjectNewStage;
 import com.goafanti.order.service.OrderProjectService;
 import com.goafanti.techproject.enums.TaskState;
 @Service
@@ -43,6 +44,9 @@ public class OrderProjectServiceImpl extends BaseMybatisDao<TOrderTaskMapper> im
 	private TOrderNewMapper	tOrderNewMapper;
 	@Autowired
 	private TTaskHoursMapper	tTaskHoursMapper;
+	@Value(value = "${upload.path}")
+	private String 					uploadPath 			= null;
+	
 	
 	@Override
 	public int updateProjectDistribution(Integer taskId, String taskReceiverId,Integer specially) {
@@ -183,6 +187,20 @@ public class OrderProjectServiceImpl extends BaseMybatisDao<TOrderTaskMapper> im
 		}
 		return p;
 	}
+
+	@SuppressWarnings("null")
+	@Override
+	public HSSFWorkbook exportTaskHoursListData(String name, String taskId, String starTime, String endTime) {
+		if(endTime!=null) endTime=endTime+" 23:59:59";
+		List<TOrderTaskListBo> list=tTaskHoursMapper.getTaskHoursData(name,taskId,starTime,endTime);
+		if (list==null && list.size()==0) {
+			return null;
+		}
+		String[] comment = {"任务编号","任务名称","订单编号","业务别类","客户名称","任务负责人","任务状态","工时"};
+		String filePath = uploadPath + "/TaskHours";
+		HSSFWorkbook wb = ExportExcelUtil.exportTaskHoursListData(list, comment, filePath);
+		return wb;
+	}
 	
 	
 }

+ 10 - 0
src/main/java/com/goafanti/techproject/enums/TaskState.java

@@ -3,6 +3,8 @@ package com.goafanti.techproject.enums;
 import java.util.HashMap;
 import java.util.Map;
 
+import com.goafanti.order.enums.LiquidationNewState;
+
 public enum TaskState {
 	/** 未分配 **/
 	UN_DISTRIBUTION(0,"未分配"),
@@ -32,6 +34,14 @@ public enum TaskState {
 		}
 		return INVALID;
 	}
+	public static String getValueByCode(Integer code){
+        for(TaskState taskState:TaskState.values()){
+            if(code.equals(taskState.getCode())){
+                return taskState.getDesc();
+            }
+        }
+        return  null;
+    }
 	public static boolean containsType(Integer code) {
 		return status.containsKey(code);
 	}